File tree Expand file tree Collapse file tree 11 files changed +72
-7
lines changed
Expand file tree Collapse file tree 11 files changed +72
-7
lines changed Original file line number Diff line number Diff line change @@ -228,7 +228,7 @@ template <> struct MappingTraits<ClangTidyOptions> {
228228 IO.mapOptional (" InheritParentConfig" , Options.InheritParentConfig );
229229 IO.mapOptional (" UseColor" , Options.UseColor );
230230 IO.mapOptional (" SystemHeaders" , Options.SystemHeaders );
231- IO.mapOptional (" CustomeChecks " , Options.CustomChecks );
231+ IO.mapOptional (" CustomChecks " , Options.CustomChecks );
232232 }
233233};
234234
Original file line number Diff line number Diff line change @@ -60,6 +60,8 @@ Configuration files:
6060 Checks - Same as '--checks'. Additionally, the list of
6161 globs can be specified as a list instead of a
6262 string.
63+ CustomChecks - Array of user defined checks based on
64+ clang-query syntax.
6365 ExcludeHeaderFilterRegex - Same as '--exclude-header-filter'.
6466 ExtraArgs - Same as '--extra-arg'.
6567 ExtraArgsBefore - Same as '--extra-arg-before'.
Original file line number Diff line number Diff line change @@ -96,6 +96,9 @@ Improvements to clang-tidy
9696 `SystemHeaders ` option is enabled.
9797 Note: this may lead to false negatives; downstream users may need to adjust
9898 their checks to preserve existing behavior.
99+ - :program: `clang-tidy ` now supports query based custom checks by `CustomChecks `
100+ configuration option.
101+ :doc: `Query Based Custom Check Document <clang-tidy/QueryBasedCustomChecks >`
99102
100103New checks
101104^^^^^^^^^^
Original file line number Diff line number Diff line change 1+ ====================================
2+ Query Based Custom Clang-Tidy Checks
3+ ====================================
4+
5+ Introduction
6+ ============
7+
8+ This page provides examples of how to add query based custom checks for
9+ :program: `clang-tidy `.
10+
11+ Custom checks are based on clang-query syntax. Every custom checks will be
12+ registered in `custom ` module to avoid name conflict. They can be enabled or
13+ disabled by the checks option like the builtin checks.
14+
15+ Custom checks support inheritance from parent configurations like other
16+ configuration items.
17+
18+ Configuration
19+ =============
20+
21+ `CustomChecks ` is a list of custom checks. Each check must contain
22+ - Name: check name can been used in `-checks ` option.
23+ - Query: query string
24+ - Diagnostic: list of diagnostics to be reported.
25+ - BindName: name of the node to be bound in `Query `.
26+ - Message: message to be reported.
27+ - Level: severity of the diagnostic, the possible values are `Note `, `Warning `, `Error `.
28+
29+ Example
30+ =======
31+
32+ .. code-block :: yaml
33+
34+ Checks : -*,custom-call-main-function
35+ CustomChecks :
36+ - Name : call-main-function
37+ Query : |
38+ match callExpr(
39+ callee(
40+ functionDecl(isMain()).bind("fn")
41+ )
42+ ).bind("callee")
43+ Diagnostic :
44+ - BindName : fn
45+ Message : main function.
46+ Level : Note
47+ - BindName : callee
48+ Message : call to main function.
49+ Level : Warning
50+
51+ .. code-block :: c++
52+
53+ int main(); // note: main function.
54+
55+ void bar() {
56+ main(); // warning: call to main function. [custom-call-main-function]
57+ }
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ See also:
1010 :maxdepth: 1
1111
1212 List of Clang-Tidy Checks <checks/list >
13+ Query Based Custom Clang-Tidy Checks <QueryBasedCustomChecks >
1314 Clang-tidy IDE/Editor Integrations <Integrations >
1415 Getting Involved <Contributing >
1516 External Clang-Tidy Examples <ExternalClang-TidyExamples >
@@ -292,6 +293,8 @@ An overview of all the command-line options:
292293 Checks - Same as '--checks'. Additionally, the list of
293294 globs can be specified as a list instead of a
294295 string.
296+ CustomChecks - Array of user defined checks based on
297+ clang-query syntax.
295298 ExcludeHeaderFilterRegex - Same as '--exclude-header-filter'.
296299 ExtraArgs - Same as '--extra-arg'.
297300 ExtraArgsBefore - Same as '--extra-arg-before'.
Original file line number Diff line number Diff line change 1- CustomeChecks :
1+ CustomChecks :
22 - Name : test-diag-level
33 Query : |
44 match varDecl(
Original file line number Diff line number Diff line change 1- CustomeChecks :
1+ CustomChecks :
22 - Name : test-let-bind
33 Query : |
44 let expr varDecl(isStaticStorageClass()).bind("vd")
Original file line number Diff line number Diff line change 11InheritParentConfig : true
2- CustomeChecks :
2+ CustomChecks :
33 - Name : function-decl
44 Query : match functionDecl().bind("func")
55 Diagnostic :
Original file line number Diff line number Diff line change 1- CustomeChecks :
1+ CustomChecks :
22 - Name : avoid-long-type
33 Query : |
44 match varDecl(
Original file line number Diff line number Diff line change 1- CustomeChecks :
1+ CustomChecks :
22 - Name : avoid-long-type
33 Query : |
44 match varDecl(
You can’t perform that action at this time.
0 commit comments