Skip to content

Commit 5bb2c6c

Browse files
committed
doc
1 parent 0df6f7e commit 5bb2c6c

File tree

11 files changed

+72
-7
lines changed

11 files changed

+72
-7
lines changed

clang-tools-extra/clang-tidy/ClangTidyOptions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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

clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff 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'.

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff 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

100103
New checks
101104
^^^^^^^^^^
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
}

clang-tools-extra/docs/clang-tidy/index.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff 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'.

clang-tools-extra/test/clang-tidy/checkers/custom/Inputs/clang-tidy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CustomeChecks:
1+
CustomChecks:
22
- Name: test-diag-level
33
Query: |
44
match varDecl(

clang-tools-extra/test/clang-tidy/checkers/custom/Inputs/incorrect-clang-tidy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CustomeChecks:
1+
CustomChecks:
22
- Name: test-let-bind
33
Query: |
44
let expr varDecl(isStaticStorageClass()).bind("vd")

clang-tools-extra/test/clang-tidy/infrastructure/Inputs/custom-query-check/append-clang-tidy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
InheritParentConfig: true
2-
CustomeChecks:
2+
CustomChecks:
33
- Name: function-decl
44
Query: match functionDecl().bind("func")
55
Diagnostic:

clang-tools-extra/test/clang-tidy/infrastructure/Inputs/custom-query-check/override-clang-tidy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CustomeChecks:
1+
CustomChecks:
22
- Name: avoid-long-type
33
Query: |
44
match varDecl(

clang-tools-extra/test/clang-tidy/infrastructure/Inputs/custom-query-check/root-clang-tidy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CustomeChecks:
1+
CustomChecks:
22
- Name: avoid-long-type
33
Query: |
44
match varDecl(

clang-tools-extra/test/clang-tidy/infrastructure/custom-query-check.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ void f();
2323
// LIST-CHECK: custom-avoid-long-type
2424
// LIST-CHECK: custom-function-decl
2525

26-
// DUMP-CONFIG: CustomeChecks:
26+
// DUMP-CONFIG: CustomChecks:
2727
// DUMP-CONFIG: - Name: avoid-long-type
2828
// DUMP-CONFIG: Query: |
2929
// DUMP-CONFIG: match varDecl(

0 commit comments

Comments
 (0)