Skip to content
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
6c7a972
[clang-tidy] Add documentation for running Clang-Tidy on multiple files
HARSHIL2836R Aug 12, 2025
2aea054
Merge branch 'main' of https://github.com/llvm/llvm-project
HARSHIL2836R Aug 12, 2025
ef4c290
Merge branch 'main' of https://github.com/llvm/llvm-project
HARSHIL2836R Aug 12, 2025
449afd4
Merge branch 'main' of https://github.com/llvm/llvm-project
HARSHIL2836R Aug 12, 2025
184da5e
[Clang-Tidy] Update documentation for running Clang-Tidy in parallel …
HARSHIL2836R Aug 12, 2025
f931f3a
[Clang-Tidy] Add documentation for running Clang-Tidy on diffs
HARSHIL2836R Aug 12, 2025
fedf016
Merge branch 'main' of https://github.com/llvm/llvm-project
HARSHIL2836R Aug 12, 2025
7aac780
[Clang-Tidy] Enhance documentation for clang-tidy-diff.py, clarifying…
HARSHIL2836R Aug 13, 2025
0d884d8
[Clang-Tidy] Clarify behavior of clang-tidy-diff.py regarding diagnos…
HARSHIL2836R Aug 13, 2025
42c3dfc
Merge branch 'main' into main
HARSHIL2836R Aug 13, 2025
66268ae
[Clang-Tidy][docs] clarify clang-tidy usage with compilation databases
HARSHIL2836R Aug 14, 2025
72e9ac6
[Clang-Tidy][docs] clarify clang-tidy usage with compilation database
HARSHIL2836R Aug 14, 2025
3ada15a
Merge branch 'main' of https://github.com/llvm/llvm-project
HARSHIL2836R Aug 14, 2025
b30f504
[Clang-Tidy][docs] Remove Technical Details not relevant to users
HARSHIL2836R Aug 14, 2025
2a7e33c
[clang-tidy][docs] Update run-clang-tidy.py usage examples to include…
HARSHIL2836R Aug 14, 2025
9db542f
Merge https://github.com/HARSHIL2836R/llvm-project
HARSHIL2836R Aug 14, 2025
15f16bc
Merge branch 'main' of https://github.com/llvm/llvm-project
HARSHIL2836R Aug 14, 2025
837bd50
[clang-tidy][docs] Fix formatting and improve clarity in Clang-Tidy d…
HARSHIL2836R Aug 14, 2025
4f3d3de
Update clang-tools-extra/docs/clang-tidy/index.rst
HARSHIL2836R Aug 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions clang-tools-extra/docs/clang-tidy/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,107 @@ An overview of all the command-line options:
some-check.SomeOption: 'some value'
...

Clang-Tidy Automation
=====================

:program:`clang-tidy` can analyze multiple source files by specifying them on
the command line. For larger projects, automation scripts provide additional
functionality like parallel execution and integration with version control
systems.

Running Clang-Tidy in Parallel
-------------------------------

:program:`clang-tidy` can process multiple files sequentially, but for projects
with many source files, the :program:`run-clang-tidy.py` script provides
parallel execution to significantly reduce analysis time. This script is
included with clang-tidy and runs :program:`clang-tidy` over all files in a
compilation database or a specified path concurrently.

The script requires a compilation database (``compile_commands.json``) which
can be generated by build systems like CMake (using
``-DCMAKE_EXPORT_COMPILE_COMMANDS=ON``) or by tools like `Bear`_.

The script supports most of the same options as :program:`clang-tidy` itself,
including ``-checks=``, ``-fix``, ``-header-filter=``, and configuration
options. Run ``run-clang-tidy.py --help`` for a complete list of available
options.

Example invocations:

.. code-block:: console

# Run clang-tidy on all files in the compilation database in parallel
$ run-clang-tidy.py -p=build/

# Run with specific checks and apply fixes
$ run-clang-tidy.py -p=build/ -fix -checks=-*,readability-*

# Run on specific files/directories with header filtering
$ run-clang-tidy.py -p=build/ -header-filter=src/ src/

# Run with parallel execution (uses all CPU cores by default)
$ run-clang-tidy.py -p=build/ -j 4

Running Clang-Tidy on Diff
---------------------------

The :program:`clang-tidy-diff.py` script allows you to run
:program:`clang-tidy` on the lines that have been modified in your working
directory or in a specific diff. Importantly, :program:`clang-tidy-diff.py` only reports
diagnostics for changed lines; :program:`clang-tidy` still analyzes the entire
file and filters out unchanged lines after analysis, so this does not improve
performance. This is particularly useful for code reviews and continuous
integration, as it focuses analysis on the changed code rather than the entire
codebase.

The script can work with various diff sources:

* Git working directory changes
* Output from ``git diff``
* Output from ``svn diff``
* Patch files

Example invocations:

.. code-block:: console

# Run clang-tidy on all changes in the working directory
$ git diff -U0 --no-color HEAD^ | clang-tidy-diff.py -p1

# Run with specific checks and apply fixes
$ git diff -U0 --no-color HEAD^ | clang-tidy-diff.py -p1 -fix \
-checks=-*,readability-*

# Run on staged changes
$ git diff -U0 --no-color --cached | clang-tidy-diff.py -p1

# Run on changes between two commits
$ git diff -U0 --no-color HEAD~2 HEAD | clang-tidy-diff.py -p1

# Run on a patch file
$ clang-tidy-diff.py -p1 < changes.patch

The ``-p1`` option tells the script to strip one level of path prefix from
the diff, which is typically needed for Git diffs. The script supports most of
the same options as :program:`clang-tidy` itself, including ``-checks=``,
``-fix``, ``-header-filter=``, and configuration options.

While :program:`clang-tidy-diff.py` is useful for focusing on recent changes,
relying solely on it may lead to incomplete analysis. Since the script only
reports warnings from the modified lines, it may miss issues that are caused
by the changes but manifest elsewhere in the code. For example, changes that
only add lines to a function may cause it to violate size limits (e.g.,
`readability-function-size <checks/readability/function-size.html>`_), but the
diagnostic will be reported at the function declaration, which may not be in
the diff and thus filtered out. Modifications to header files may also affect
many implementation files, but only warnings in the modified header lines will
be reported.

For comprehensive analysis, especially before merging significant changes,
consider running :program:`clang-tidy` on the entire affected files or the
whole project using :program:`run-clang-tidy.py`.

.. _clang-tidy-nolint:

Suppressing Undesired Diagnostics
Expand Down Expand Up @@ -458,5 +559,6 @@ example, ``NOLINTBEGIN(check-name)`` can be paired with
:program:`clang-tidy` will generate a ``clang-tidy-nolint`` error diagnostic if
any ``NOLINTBEGIN``/``NOLINTEND`` comment violates these requirements.

.. _Bear: https://github.com/rizsotto/Bear
.. _LibTooling: https://clang.llvm.org/docs/LibTooling.html
.. _How To Setup Tooling For LLVM: https://clang.llvm.org/docs/HowToSetupToolingForLLVM.html
Loading