File tree Expand file tree Collapse file tree 5 files changed +39
-3
lines changed Expand file tree Collapse file tree 5 files changed +39
-3
lines changed Original file line number Diff line number Diff line change @@ -503,6 +503,21 @@ getCheckNames(const ClangTidyOptions &Options,
503503 return Factory.getCheckNames ();
504504}
505505
506+ void filterCheckOptions (ClangTidyOptions &Options,
507+ const std::vector<std::string> &EnabledChecks) {
508+ StringSet<> EnabledChecksSet (llvm::from_range, EnabledChecks);
509+ ClangTidyOptions::OptionMap FilteredOptions;
510+ for (const auto &[OptionName, Value] : Options.CheckOptions ) {
511+ const size_t CheckNameEndPos = OptionName.find (' .' );
512+ if (CheckNameEndPos == StringRef::npos)
513+ continue ;
514+ const StringRef CheckName = OptionName.substr (0 , CheckNameEndPos);
515+ if (EnabledChecksSet.contains (CheckName))
516+ FilteredOptions[OptionName] = Value;
517+ }
518+ Options.CheckOptions = std::move (FilteredOptions);
519+ }
520+
506521ClangTidyOptions::OptionMap
507522getCheckOptions (const ClangTidyOptions &Options,
508523 bool AllowEnablingAnalyzerAlphaCheckers) {
Original file line number Diff line number Diff line change @@ -76,6 +76,11 @@ ClangTidyOptions::OptionMap
7676getCheckOptions (const ClangTidyOptions &Options,
7777 bool AllowEnablingAnalyzerAlphaCheckers);
7878
79+ // / Filters CheckOptions in \p Options to only include options specified in
80+ // / the \p EnabledChecks.
81+ void filterCheckOptions (ClangTidyOptions &Options,
82+ const std::vector<std::string> &EnabledChecks);
83+
7984// / Run a set of clang-tidy checks on a set of files.
8085// /
8186// / \param EnableCheckProfile If provided, it enables check profile collection
Original file line number Diff line number Diff line change @@ -659,9 +659,10 @@ int clangTidyMain(int argc, const char **argv) {
659659 if (DumpConfig) {
660660 EffectiveOptions.CheckOptions =
661661 getCheckOptions (EffectiveOptions, AllowEnablingAnalyzerAlphaCheckers);
662- llvm::outs () << configurationAsText (ClangTidyOptions::getDefaults ().merge (
663- EffectiveOptions, 0 ))
664- << " \n " ;
662+ ClangTidyOptions OptionsToDump =
663+ ClangTidyOptions::getDefaults ().merge (EffectiveOptions, 0 );
664+ filterCheckOptions (OptionsToDump, EnabledChecks);
665+ llvm::outs () << configurationAsText (OptionsToDump) << " \n " ;
665666 return 0 ;
666667 }
667668
Original file line number Diff line number Diff line change @@ -108,6 +108,9 @@ Improvements to clang-tidy
108108- Improved :program: `clang-tidy-diff.py ` script. Add the `-warnings-as-errors `
109109 argument to treat warnings as errors.
110110
111+ - Improved :program: `clang-tidy ` to show `CheckOptions ` only for checks enabled
112+ in `Checks ` when running ``--dump-config ``.
113+
111114- Fixed bug in :program: `clang-tidy ` by which `HeaderFilterRegex ` did not take
112115 effect when passed via the `.clang-tidy ` file.
113116
Original file line number Diff line number Diff line change 1+ // RUN: clang-tidy -checks='-*,misc-unused-parameters' -dump-config %s -- 2>/dev/null | FileCheck %s --check-prefix=CHECK
2+ // RUN: clang-tidy -checks='-*' -dump-config %s -- 2>/dev/null | FileCheck %s --check-prefix=CHECK-DISABLED
3+
4+ // CHECK: CheckOptions:
5+ // CHECK-NEXT: misc-unused-parameters.IgnoreVirtual: 'false'
6+ // CHECK-NEXT: misc-unused-parameters.StrictMode: 'false'
7+ // CHECK-NEXT: SystemHeaders: false
8+
9+ // CHECK-DISABLED: CheckOptions: {}
10+ // CHECK-DISABLED-NEXT: SystemHeaders: false
11+
12+ int main () { return 0 ; }
You can’t perform that action at this time.
0 commit comments