Skip to content

Commit f931f3a

Browse files
committed
[Clang-Tidy] Add documentation for running Clang-Tidy on diffs
1 parent 184da5e commit f931f3a

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,46 @@ Example invocations:
372372
# Run with parallel execution (uses all CPU cores by default)
373373
$ run-clang-tidy.py -j 4
374374
375+
Running Clang-Tidy on Diff
376+
---------------------------
377+
378+
The :program:`clang-tidy-diff.py` script allows you to run :program:`clang-tidy`
379+
only on the lines that have been modified in your working directory or in a
380+
specific diff. This is particularly useful for code reviews and continuous
381+
integration, as it focuses analysis on the changed code rather than the entire
382+
codebase.
383+
384+
The script can work with various diff sources:
385+
386+
* Git working directory changes
387+
* Output from ``git diff``
388+
* Output from ``svn diff``
389+
* Patch files
390+
391+
Example invocations:
392+
393+
.. code-block:: console
394+
395+
# Run clang-tidy on all changes in the working directory
396+
$ git diff -U0 --no-color HEAD^ | clang-tidy-diff.py -p1
397+
398+
# Run with specific checks and apply fixes
399+
$ git diff -U0 --no-color HEAD^ | clang-tidy-diff.py -p1 -fix -checks=-*,readability-*
400+
401+
# Run on staged changes
402+
$ git diff -U0 --no-color --cached | clang-tidy-diff.py -p1
403+
404+
# Run on changes between two commits
405+
$ git diff -U0 --no-color HEAD~2 HEAD | clang-tidy-diff.py -p1
406+
407+
# Run on a patch file
408+
$ clang-tidy-diff.py -p1 < changes.patch
409+
410+
The ``-p1`` option tells the script to strip one level of path prefix from the
411+
diff, which is typically needed for Git diffs. The script supports most of the
412+
same options as :program:`clang-tidy` itself, including ``-checks=``, ``-fix``,
413+
``-header-filter=``, and configuration options.
414+
375415
.. _clang-tidy-nolint:
376416

377417
Suppressing Undesired Diagnostics

0 commit comments

Comments
 (0)