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> {
228
228
IO.mapOptional (" InheritParentConfig" , Options.InheritParentConfig );
229
229
IO.mapOptional (" UseColor" , Options.UseColor );
230
230
IO.mapOptional (" SystemHeaders" , Options.SystemHeaders );
231
- IO.mapOptional (" CustomeChecks " , Options.CustomChecks );
231
+ IO.mapOptional (" CustomChecks " , Options.CustomChecks );
232
232
}
233
233
};
234
234
Original file line number Diff line number Diff line change @@ -60,6 +60,8 @@ Configuration files:
60
60
Checks - Same as '--checks'. Additionally, the list of
61
61
globs can be specified as a list instead of a
62
62
string.
63
+ CustomChecks - Array of user defined checks based on
64
+ clang-query syntax.
63
65
ExcludeHeaderFilterRegex - Same as '--exclude-header-filter'.
64
66
ExtraArgs - Same as '--extra-arg'.
65
67
ExtraArgsBefore - Same as '--extra-arg-before'.
Original file line number Diff line number Diff line change @@ -96,6 +96,9 @@ Improvements to clang-tidy
96
96
`SystemHeaders ` option is enabled.
97
97
Note: this may lead to false negatives; downstream users may need to adjust
98
98
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 >`
99
102
100
103
New checks
101
104
^^^^^^^^^^
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:
10
10
:maxdepth: 1
11
11
12
12
List of Clang-Tidy Checks <checks/list >
13
+ Query Based Custom Clang-Tidy Checks <QueryBasedCustomChecks >
13
14
Clang-tidy IDE/Editor Integrations <Integrations >
14
15
Getting Involved <Contributing >
15
16
External Clang-Tidy Examples <ExternalClang-TidyExamples >
@@ -292,6 +293,8 @@ An overview of all the command-line options:
292
293
Checks - Same as '--checks'. Additionally, the list of
293
294
globs can be specified as a list instead of a
294
295
string.
296
+ CustomChecks - Array of user defined checks based on
297
+ clang-query syntax.
295
298
ExcludeHeaderFilterRegex - Same as '--exclude-header-filter'.
296
299
ExtraArgs - Same as '--extra-arg'.
297
300
ExtraArgsBefore - Same as '--extra-arg-before'.
Original file line number Diff line number Diff line change 1
- CustomeChecks :
1
+ CustomChecks :
2
2
- Name : test-diag-level
3
3
Query : |
4
4
match varDecl(
Original file line number Diff line number Diff line change 1
- CustomeChecks :
1
+ CustomChecks :
2
2
- Name : test-let-bind
3
3
Query : |
4
4
let expr varDecl(isStaticStorageClass()).bind("vd")
Original file line number Diff line number Diff line change 1
1
InheritParentConfig : true
2
- CustomeChecks :
2
+ CustomChecks :
3
3
- Name : function-decl
4
4
Query : match functionDecl().bind("func")
5
5
Diagnostic :
Original file line number Diff line number Diff line change 1
- CustomeChecks :
1
+ CustomChecks :
2
2
- Name : avoid-long-type
3
3
Query : |
4
4
match varDecl(
Original file line number Diff line number Diff line change 1
- CustomeChecks :
1
+ CustomChecks :
2
2
- Name : avoid-long-type
3
3
Query : |
4
4
match varDecl(
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ void f();
23
23
// LIST-CHECK: custom-avoid-long-type
24
24
// LIST-CHECK: custom-function-decl
25
25
26
- // DUMP-CONFIG: CustomeChecks :
26
+ // DUMP-CONFIG: CustomChecks :
27
27
// DUMP-CONFIG: - Name: avoid-long-type
28
28
// DUMP-CONFIG: Query: |
29
29
// DUMP-CONFIG: match varDecl(
You can’t perform that action at this time.
0 commit comments