CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
84 lines
2.8 KiB
ReStructuredText
84 lines
2.8 KiB
ReStructuredText
====================================
|
|
Query Based Custom Clang-Tidy Checks
|
|
====================================
|
|
|
|
Introduction
|
|
============
|
|
|
|
This page provides examples of how to add query based custom checks for
|
|
:program:`clang-tidy`.
|
|
|
|
Custom checks are based on :program:`clang-query` syntax. Every custom checks
|
|
will be registered in `custom` module to avoid name conflict. They can be
|
|
enabled or disabled by the checks option like the built-in checks.
|
|
|
|
Custom checks support inheritance from parent configurations like other
|
|
configuration items.
|
|
|
|
Goals: easy to write, cross platform, multiple versions supported toolkit for
|
|
custom clang-tidy rules.
|
|
Non-Goals: complex checks, performance, fix-its, etc.
|
|
|
|
Configuration
|
|
=============
|
|
|
|
`CustomChecks` is a list of custom checks. Each check must contain
|
|
- Name: check name can be used in `-checks` option.
|
|
- Query: `clang-query` string
|
|
- Diagnostic: list of diagnostics to be reported.
|
|
- BindName: name of the node to be bound in `Query`.
|
|
- Message: message to be reported.
|
|
- Level: severity of the diagnostic, the possible values are
|
|
`Note`, `Warning`.
|
|
|
|
`CustomChecks` can be configured by `Checks` option in the configuration file.
|
|
|
|
Example
|
|
=======
|
|
|
|
.. code-block:: yaml
|
|
|
|
Checks: -*,custom-call-main-function
|
|
CustomChecks:
|
|
- Name: call-main-function
|
|
Query: |
|
|
match callExpr(
|
|
callee(
|
|
functionDecl(isMain()).bind("fn")
|
|
)
|
|
).bind("callee")
|
|
Diagnostic:
|
|
- BindName: fn
|
|
Message: main function.
|
|
Level: Note
|
|
- BindName: callee
|
|
Message: call to main function.
|
|
Level: Warning
|
|
|
|
.. code-block:: c++
|
|
|
|
int main(); // note: main function.
|
|
|
|
void bar() {
|
|
main(); // warning: call to main function. [custom-call-main-function]
|
|
}
|
|
|
|
Matters Need Attention
|
|
======================
|
|
|
|
This feature needs to be explicitly enabled by `--experimental-custom-checks`
|
|
because it is currently in the experimental stage. Welcome to submit any
|
|
suggestions in the `link <https://discourse.llvm.org/t/support-query-based-clang-tidy-external-check/85331>`_.
|
|
|
|
During the experimental stage, the required configuration structure of this
|
|
feature may be changed in the future. Future changes will be as
|
|
forward-compatible as possible, but this is not a guarantee.
|
|
|
|
In subsequent versions, including non-experimental stage, the query statements
|
|
will change at any time. The essence of :program:`clang-query` is to parse the
|
|
query string and dynamically generate the corresponding AST matcher.
|
|
Therefore, its functionality is entirely dependent on the functions provided by
|
|
the AST matcher library.
|
|
The ast matcher will change along with the changes in the clang AST.
|
|
Please refer to `ast matcher reference <https://clang.llvm.org/docs/LibASTMatchersReference.html>`_.
|