[clang-tools-extra] [clang-tidy] filter check options by enabled checks in '--dump-config' (PR #147142)
Victor Chernyakin via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 7 09:20:00 PDT 2025
================
@@ -503,6 +503,21 @@ getCheckNames(const ClangTidyOptions &Options,
return Factory.getCheckNames();
}
+void filterCheckOptions(ClangTidyOptions &Options,
+ const std::vector<std::string> &EnabledChecks) {
+ StringSet<> EnabledChecksSet(llvm::from_range, EnabledChecks);
+ ClangTidyOptions::OptionMap FilteredOptions;
+ for (const auto &[OptionName, Value] : Options.CheckOptions) {
+ const size_t CheckNameEndPos = OptionName.find('.');
+ if (CheckNameEndPos == StringRef::npos)
+ continue;
+ const StringRef CheckName = OptionName.substr(0, CheckNameEndPos);
+ if (EnabledChecksSet.contains(CheckName))
+ FilteredOptions[OptionName] = Value;
+ }
+ Options.CheckOptions = std::move(FilteredOptions);
+}
----------------
localspook wrote:
`StringMap::erase` returns `void`, which I *think* means it doesn't invalidate iterators, but I agree, involving iterators at all makes it less readable. If `StringMap` was compatible with `llvm::erase_if`, we could get the best of both worlds, but it doesn't seem to be right now...
https://github.com/llvm/llvm-project/pull/147142
More information about the cfe-commits
mailing list