================
@@ -331,6 +331,106 @@ 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 or by using a compilation database. 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
+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
+
+  # Run with specific checks and apply fixes
+  $ run-clang-tidy.py -fix -checks=-*,readability-*
+
+  # Run on specific files/directories with header filtering
+  $ run-clang-tidy.py -header-filter=src/ src/
+
+  # Run with parallel execution (uses all CPU cores by default)
+  $ run-clang-tidy.py -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, clang-tidy-diff 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. The 
script
+is essentially a wrapper that parses diff output and passes it to
+:program:`clang-tidy` with the ``--line-filter`` option, which performs all the
+actual filtering. 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``), but the diagnostic will be reported at the
----------------
vbvictor wrote:

Write check name like this: \`bugprone-use-after-move 
<checks/bugprone/use-after-move.html>\`_

https://github.com/llvm/llvm-project/pull/153166
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to