File tree Expand file tree Collapse file tree 5 files changed +38
-3
lines changed Expand file tree Collapse file tree 5 files changed +38
-3
lines changed Original file line number Diff line number Diff line change @@ -505,6 +505,20 @@ getCheckNames(const ClangTidyOptions &Options,
505
505
return Factory.getCheckNames ();
506
506
}
507
507
508
+ void filterCheckOptions (ClangTidyOptions &Options,
509
+ const std::vector<std::string> &EnabledChecks) {
510
+ ClangTidyOptions::OptionMap FilteredOptions;
511
+ for (const auto &[OptionName, Value] : Options.CheckOptions ) {
512
+ const size_t CheckNameEndPos = OptionName.find (' .' );
513
+ if (CheckNameEndPos == StringRef::npos)
514
+ continue ;
515
+ const StringRef CheckName = OptionName.substr (0 , CheckNameEndPos);
516
+ if (llvm::binary_search (EnabledChecks, CheckName))
517
+ FilteredOptions[OptionName] = Value;
518
+ }
519
+ Options.CheckOptions = std::move (FilteredOptions);
520
+ }
521
+
508
522
ClangTidyOptions::OptionMap
509
523
getCheckOptions (const ClangTidyOptions &Options,
510
524
bool AllowEnablingAnalyzerAlphaCheckers) {
Original file line number Diff line number Diff line change @@ -76,6 +76,11 @@ ClangTidyOptions::OptionMap
76
76
getCheckOptions (const ClangTidyOptions &Options,
77
77
bool AllowEnablingAnalyzerAlphaCheckers);
78
78
79
+ // / Filters CheckOptions in \p Options to only include options specified in
80
+ // / the \p EnabledChecks which is a sorted vector.
81
+ void filterCheckOptions (ClangTidyOptions &Options,
82
+ const std::vector<std::string> &EnabledChecks);
83
+
79
84
// / Run a set of clang-tidy checks on a set of files.
80
85
// /
81
86
// / \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) {
659
659
if (DumpConfig) {
660
660
EffectiveOptions.CheckOptions =
661
661
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 " ;
665
666
return 0 ;
666
667
}
667
668
Original file line number Diff line number Diff line change @@ -108,6 +108,9 @@ Improvements to clang-tidy
108
108
- Improved :program: `clang-tidy-diff.py ` script. Add the `-warnings-as-errors `
109
109
argument to treat warnings as errors.
110
110
111
+ - Improved :program: `clang-tidy ` to show `CheckOptions ` only for checks enabled
112
+ in `Checks ` when running ``--dump-config ``.
113
+
111
114
- Fixed bug in :program: `clang-tidy ` by which `HeaderFilterRegex ` did not take
112
115
effect when passed via the `.clang-tidy ` file.
113
116
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