[PATCH] D34415: Allow passing a regex for headers to exclude from clang-tidy
toddlipcon added a comment. Anyone able to review this? Repository: rL LLVM https://reviews.llvm.org/D34415 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D34654: Allow passing a regex for headers to exclude from clang-tidy
toddlipcon created this revision. toddlipcon added a project: clang-tools-extra. Herald added a subscriber: JDevlieghere. This patch adds the ability to specify a regex of headers to exclude from clang-tidy diagnostics. This is the inverse of the existing header regex. In our project we want to do something like include src/.*.h but exclude src/some-thirdparty/.*.h. Given only a positive regex configuration, we would have had to list all directories aside from 'some-thirdparty' such as src/(foo|bar|baz|...)/, which isn't practical or maintainable. A while back there was a thread http://lists.llvm.org/pipermail/cfe-dev/2015-November/046203.html which suggested using extended regexes which offer negative lookahead assertions to achieve this, but it was rejected due to poor stdlib support. I think an "exclude" regex is also more familiar to users since it shows up commonly in tools like rsync/tar/etc. (note: I previously posted this as https://reviews.llvm.org/D34415 but was asked to re-post it with cfe-commits as a subscriber. Sorry for the double-post) Repository: rL LLVM https://reviews.llvm.org/D34654 Files: clang-tidy/ClangTidyDiagnosticConsumer.cpp clang-tidy/ClangTidyDiagnosticConsumer.h clang-tidy/ClangTidyOptions.cpp clang-tidy/ClangTidyOptions.h clang-tidy/tool/ClangTidyMain.cpp docs/clang-tidy/index.rst test/clang-tidy/file-filter.cpp Index: test/clang-tidy/file-filter.cpp === --- test/clang-tidy/file-filter.cpp +++ test/clang-tidy/file-filter.cpp @@ -9,6 +9,7 @@ // file-filter\header*.h due to code order between '/' and '\\'. // RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='.*' -system-headers %s -- -I %S/Inputs/file-filter/system/.. -isystem %S/Inputs/file-filter/system 2>&1 | FileCheck --check-prefix=CHECK4 %s // RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='.*' -system-headers -quiet %s -- -I %S/Inputs/file-filter/system/.. -isystem %S/Inputs/file-filter/system 2>&1 | FileCheck --check-prefix=CHECK4-QUIET %s +// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='.*' -exclude-header-filter='header1\.h' %s -- -I %S/Inputs/file-filter -isystem %S/Inputs/file-filter/system 2>&1 | FileCheck --check-prefix=CHECK5 %s #include "header1.h" // CHECK-NOT: warning: @@ -19,6 +20,7 @@ // CHECK3-QUIET-NOT: warning: // CHECK4: header1.h:1:12: warning: single-argument constructors // CHECK4-QUIET: header1.h:1:12: warning: single-argument constructors +// CHECK5-NOT: warning: #include "header2.h" // CHECK-NOT: warning: @@ -29,6 +31,7 @@ // CHECK3-QUIET: header2.h:1:12: warning: single-argument constructors // CHECK4: header2.h:1:12: warning: single-argument constructors // CHECK4-QUIET: header2.h:1:12: warning: single-argument constructors +// CHECK5: header2.h:1:12: warning: single-argument constructors #include // CHECK-NOT: warning: @@ -39,6 +42,7 @@ // CHECK3-QUIET-NOT: warning: // CHECK4: system-header.h:1:12: warning: single-argument constructors // CHECK4-QUIET: system-header.h:1:12: warning: single-argument constructors +// CHECK5-NOT: warning: class A { A(int); }; // CHECK: :[[@LINE-1]]:11: warning: single-argument constructors @@ -49,6 +53,7 @@ // CHECK3-QUIET: :[[@LINE-6]]:11: warning: single-argument constructors // CHECK4: :[[@LINE-7]]:11: warning: single-argument constructors // CHECK4-QUIET: :[[@LINE-8]]:11: warning: single-argument constructors +// CHECK5: :[[@LINE-9]]:11: warning: single-argument constructors // CHECK-NOT: warning: // CHECK-QUIET-NOT: warning: @@ -58,9 +63,10 @@ // CHECK3-QUIET-NOT: warning: // CHECK4-NOT: warning: // CHECK4-QUIET-NOT: warning: +// CHECK5-NOT: warning: // CHECK: Suppressed 3 warnings (3 in non-user code) -// CHECK: Use -header-filter=.* to display errors from all non-system headers. +// CHECK: Use -header-filter=.* -exclude-header-filter='' to display errors from all non-system headers. // CHECK-QUIET-NOT: Suppressed // CHECK2: Suppressed 1 warnings (1 in non-user code) // CHECK2: Use -header-filter=.* {{.*}} @@ -71,3 +77,5 @@ // CHECK4-NOT: Suppressed {{.*}} warnings // CHECK4-NOT: Use -header-filter=.* {{.*}} // CHECK4-QUIET-NOT: Suppressed +// CHECK5: Suppressed 2 warnings (2 in non-user code) +// CHECK5: Use -header-filter=.* {{.*}} Index: docs/clang-tidy/index.rst === --- docs/clang-tidy/index.rst +++ docs/clang-tidy/index.rst @@ -238,6 +238,7 @@ Checks: '-*,some-check' WarningsAsErrors: '' HeaderFilterRegex: '' + ExcludeHeaderFilterRegex: '' AnalyzeTemporaryDtors: false FormatStyle: none User:user Index: clang-tidy/tool/ClangTidyMain.cpp === --- clang-tidy/tool/ClangTidyMain.cpp +++ clang-tidy/tool/ClangTidyMain.cpp @@ -40,6 +40,7 @@
[PATCH] D34415: Allow passing a regex for headers to exclude from clang-tidy
toddlipcon abandoned this revision. toddlipcon added a comment. Re-posted as https://reviews.llvm.org/D34654 Repository: rL LLVM https://reviews.llvm.org/D34415 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D34654: Allow passing a regex for headers to exclude from clang-tidy
toddlipcon updated this revision to Diff 107148. toddlipcon added a comment. Regenerated patch with full context Repository: rL LLVM https://reviews.llvm.org/D34654 Files: clang-tidy/ClangTidyDiagnosticConsumer.cpp clang-tidy/ClangTidyDiagnosticConsumer.h clang-tidy/ClangTidyOptions.cpp clang-tidy/ClangTidyOptions.h clang-tidy/tool/ClangTidyMain.cpp docs/clang-tidy/index.rst test/clang-tidy/file-filter.cpp Index: test/clang-tidy/file-filter.cpp === --- test/clang-tidy/file-filter.cpp +++ test/clang-tidy/file-filter.cpp @@ -9,6 +9,7 @@ // file-filter\header*.h due to code order between '/' and '\\'. // RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='.*' -system-headers %s -- -I %S/Inputs/file-filter/system/.. -isystem %S/Inputs/file-filter/system 2>&1 | FileCheck --check-prefix=CHECK4 %s // RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='.*' -system-headers -quiet %s -- -I %S/Inputs/file-filter/system/.. -isystem %S/Inputs/file-filter/system 2>&1 | FileCheck --check-prefix=CHECK4-QUIET %s +// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='.*' -exclude-header-filter='header1\.h' %s -- -I %S/Inputs/file-filter -isystem %S/Inputs/file-filter/system 2>&1 | FileCheck --check-prefix=CHECK5 %s #include "header1.h" // CHECK-NOT: warning: @@ -19,6 +20,7 @@ // CHECK3-QUIET-NOT: warning: // CHECK4: header1.h:1:12: warning: single-argument constructors // CHECK4-QUIET: header1.h:1:12: warning: single-argument constructors +// CHECK5-NOT: warning: #include "header2.h" // CHECK-NOT: warning: @@ -29,6 +31,7 @@ // CHECK3-QUIET: header2.h:1:12: warning: single-argument constructors // CHECK4: header2.h:1:12: warning: single-argument constructors // CHECK4-QUIET: header2.h:1:12: warning: single-argument constructors +// CHECK5: header2.h:1:12: warning: single-argument constructors #include // CHECK-NOT: warning: @@ -39,6 +42,7 @@ // CHECK3-QUIET-NOT: warning: // CHECK4: system-header.h:1:12: warning: single-argument constructors // CHECK4-QUIET: system-header.h:1:12: warning: single-argument constructors +// CHECK5-NOT: warning: class A { A(int); }; // CHECK: :[[@LINE-1]]:11: warning: single-argument constructors @@ -49,6 +53,7 @@ // CHECK3-QUIET: :[[@LINE-6]]:11: warning: single-argument constructors // CHECK4: :[[@LINE-7]]:11: warning: single-argument constructors // CHECK4-QUIET: :[[@LINE-8]]:11: warning: single-argument constructors +// CHECK5: :[[@LINE-9]]:11: warning: single-argument constructors // CHECK-NOT: warning: // CHECK-QUIET-NOT: warning: @@ -58,9 +63,10 @@ // CHECK3-QUIET-NOT: warning: // CHECK4-NOT: warning: // CHECK4-QUIET-NOT: warning: +// CHECK5-NOT: warning: // CHECK: Suppressed 3 warnings (3 in non-user code) -// CHECK: Use -header-filter=.* to display errors from all non-system headers. +// CHECK: Use -header-filter=.* -exclude-header-filter='' to display errors from all non-system headers. // CHECK-QUIET-NOT: Suppressed // CHECK2: Suppressed 1 warnings (1 in non-user code) // CHECK2: Use -header-filter=.* {{.*}} @@ -71,3 +77,5 @@ // CHECK4-NOT: Suppressed {{.*}} warnings // CHECK4-NOT: Use -header-filter=.* {{.*}} // CHECK4-QUIET-NOT: Suppressed +// CHECK5: Suppressed 2 warnings (2 in non-user code) +// CHECK5: Use -header-filter=.* {{.*}} Index: docs/clang-tidy/index.rst === --- docs/clang-tidy/index.rst +++ docs/clang-tidy/index.rst @@ -240,6 +240,7 @@ Checks: '-*,some-check' WarningsAsErrors: '' HeaderFilterRegex: '' + ExcludeHeaderFilterRegex: '' AnalyzeTemporaryDtors: false FormatStyle: none User:user Index: clang-tidy/tool/ClangTidyMain.cpp === --- clang-tidy/tool/ClangTidyMain.cpp +++ clang-tidy/tool/ClangTidyMain.cpp @@ -40,6 +40,7 @@ Checks: '-*,some-check' WarningsAsErrors: '' HeaderFilterRegex: '' +ExcludeHeaderFilterRegex: '' AnalyzeTemporaryDtors: false FormatStyle: none User:user @@ -89,6 +90,19 @@ cl::init(""), cl::cat(ClangTidyCategory)); +static cl::opt +ExcludeHeaderFilter("exclude-header-filter", cl::desc(R"( +Regular expression matching the names of the +headers to exclude when outputting diagnostics. +Diagnostics from the main file of each translation +unit are always displayed. +Can be used together with -line-filter. +This option overrides the 'ExcludeHeaderFilter' option +in .clang-tidy file, if any. +)"), + cl::init(""), + cl::cat(ClangTidyCategory)); + static cl::opt SystemHeaders("system-headers", cl::desc("Display th