Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[clang-tidy] readability-identifier-naming checks configs for include…
…d files When checking for the style of a decl that isn't in the main file, the check will now search for the configuration that the included files uses to gather the style for its decls. This can be useful to silence warnings in header files that follow a different naming convention without using header-filter to silence all warnings(even from other checks) in the header file. Reviewed By: aaron.ballman, gribozavr2 Differential Revision: https://reviews.llvm.org/D84814
- Loading branch information
Showing
11 changed files
with
201 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
...lang-tidy/checkers/Inputs/readability-identifier-naming/global-style-disabled/.clang-tidy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Checks: -readability-identifier-naming | ||
CheckOptions: | ||
- key: readability-identifier-naming.GlobalFunctionCase | ||
value: lower_case | ||
|
3 changes: 3 additions & 0 deletions
3
...t/clang-tidy/checkers/Inputs/readability-identifier-naming/global-style-disabled/header.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
void disabled_style_1(); | ||
void disabledStyle2(); | ||
void DISABLED_STYLE_3(); |
5 changes: 5 additions & 0 deletions
5
...a/test/clang-tidy/checkers/Inputs/readability-identifier-naming/global-style1/.clang-tidy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Checks: readability-identifier-naming | ||
CheckOptions: | ||
- key: readability-identifier-naming.GlobalFunctionCase | ||
value: lower_case | ||
|
5 changes: 5 additions & 0 deletions
5
...xtra/test/clang-tidy/checkers/Inputs/readability-identifier-naming/global-style1/header.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
|
||
void style_first_good(); | ||
|
||
void styleFirstBad(); |
5 changes: 5 additions & 0 deletions
5
...a/test/clang-tidy/checkers/Inputs/readability-identifier-naming/global-style2/.clang-tidy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Checks: readability-identifier-naming | ||
CheckOptions: | ||
- key: readability-identifier-naming.GlobalFunctionCase | ||
value: UPPER_CASE | ||
|
5 changes: 5 additions & 0 deletions
5
...xtra/test/clang-tidy/checkers/Inputs/readability-identifier-naming/global-style2/header.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
|
||
void STYLE_SECOND_GOOD(); | ||
|
||
void styleSecondBad(); |
64 changes: 64 additions & 0 deletions
64
clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming-multiple-styles.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Setup header directory | ||
|
||
// RUN: rm -rf %theaders | ||
// RUN: mkdir %theaders | ||
// RUN: cp -R %S/Inputs/readability-identifier-naming/. %theaders | ||
|
||
// C++11 isn't explicitly required, but failing to specify a standard means the | ||
// check will run multiple times for different standards. This will cause the | ||
// second test to fail as the header file will be changed during the first run. | ||
// InheritParentConfig is needed to look for the clang-tidy configuration files. | ||
|
||
// RUN: %check_clang_tidy -check-suffixes=ENABLED,SHARED -std=c++11 %s \ | ||
// RUN: readability-identifier-naming %t -- \ | ||
// RUN: -config='{ InheritParentConfig: true, CheckOptions: [ \ | ||
// RUN: {key: readability-identifier-naming.FunctionCase, value: camelBack}, \ | ||
// RUN: {key: readability-identifier-naming.GetConfigPerFile, value: true} \ | ||
// RUN: ]}' -header-filter='.*' -- -I%theaders | ||
|
||
// On DISABLED run, everything should be made 'camelBack'. | ||
|
||
// RUN: cp -R %S/Inputs/readability-identifier-naming/. %theaders | ||
// RUN: %check_clang_tidy -check-suffixes=DISABLED,SHARED -std=c++11 %s \ | ||
// RUN: readability-identifier-naming %t -- \ | ||
// RUN: -config='{ InheritParentConfig: true, CheckOptions: [ \ | ||
// RUN: {key: readability-identifier-naming.FunctionCase, value: camelBack}, \ | ||
// RUN: {key: readability-identifier-naming.GetConfigPerFile, value: false} \ | ||
// RUN: ]}' -header-filter='.*' -- -I%theaders | ||
|
||
#include "global-style-disabled/header.h" | ||
#include "global-style1/header.h" | ||
#include "global-style2/header.h" | ||
// CHECK-MESSAGES-ENABLED-DAG: global-style1/header.h:5:6: warning: invalid case style for global function 'styleFirstBad' | ||
// CHECK-MESSAGES-ENABLED-DAG: global-style2/header.h:5:6: warning: invalid case style for global function 'styleSecondBad' | ||
// CHECK-MESSAGES-DISABLED-DAG: global-style1/header.h:3:6: warning: invalid case style for function 'style_first_good' | ||
// CHECK-MESSAGES-DISABLED-DAG: global-style2/header.h:3:6: warning: invalid case style for function 'STYLE_SECOND_GOOD' | ||
// CHECK-MESSAGES-DISABLED-DAG: global-style-disabled/header.h:1:6: warning: invalid case style for function 'disabled_style_1' | ||
// CHECK-MESSAGES-DISABLED-DAG: global-style-disabled/header.h:3:6: warning: invalid case style for function 'DISABLED_STYLE_3' | ||
|
||
void goodStyle() { | ||
style_first_good(); | ||
STYLE_SECOND_GOOD(); | ||
// CHECK-FIXES-DISABLED: styleFirstGood(); | ||
// CHECK-FIXES-DISABLED-NEXT: styleSecondGood(); | ||
} | ||
// CHECK-MESSAGES-SHARED-DAG: :[[@LINE+1]]:6: warning: invalid case style for function 'bad_style' | ||
void bad_style() { | ||
styleFirstBad(); | ||
styleSecondBad(); | ||
} | ||
// CHECK-FIXES-SHARED: void badStyle() { | ||
// CHECK-FIXES-DISABLED-NEXT: styleFirstBad(); | ||
// CHECK-FIXES-ENABLED-NEXT: style_first_bad(); | ||
// CHECK-FIXES-DISABLED-NEXT: styleSecondBad(); | ||
// CHECK-FIXES-ENABLED-NEXT: STYLE_SECOND_BAD(); | ||
// CHECK-FIXES-SHARED-NEXT: } | ||
|
||
void expectNoStyle() { | ||
disabled_style_1(); | ||
disabledStyle2(); | ||
DISABLED_STYLE_3(); | ||
// CHECK-FIXES-DISABLED: disabledStyle1(); | ||
// CHECK-FIXES-DISABLED-NEXT: disabledStyle2(); | ||
// CHECK-FIXES-DISABLED-NEXT: disabledStyle3(); | ||
} |