CLANG-TIDY(1)
π NAME π
clang-tidy β the manual page for clang-tidy 11, bestie. She is your linter, your checker, your lil code-fixer, and honestly? she eats every time. π
β¨ DESCRIPTION β¨
π USAGE π
clang-tidy [options] <source0> [... <sourceN>]
π OPTIONS π
πΈ Generic Options πΈ
--helpβ shows you all the available options (and if you want the secret menu, there's--help-hiddenfor more π).--help-listβ prints a list of the available options (and yup,--help-list-hiddenexists for more).--versionβ tells you which version of this program you're running.
π¦ clang-tidy options π¦
--checks=<string>β a comma-separated list of globs, each one optionally prefixed with-. Globs get processed in the order they show up in the list. Globs with no-prefix add checks whose names match into the set, and globs with a-prefix remove matching checks from the set of enabled checks. Whatever you put here gets appended to the value of the'Checks'option in your.clang-tidyfile, if you have one.--config=<string>β lets you specify a configuration in YAML/JSON format:
-config="{Checks: '*',
CheckOptions: [{key: x,
value: y}]}"
When the value is empty, clang-tidy will go hunting for a file named .clang-tidy for each source file, looking through its parent directories. π
--dump-configβ dumps the configuration in YAML format to stdout. You can use this alongside a file name (plus--if the file lives outside a project with a configured compilation database). The configuration used for that file is what gets printed. Pair it with-checks=*to include the configuration of all the checks.--enable-check-profileβ turns on per-check timing profiles and prints a report to stderr. β±οΈ--explain-configβ for each enabled check, it explains where it got enabled β in the clang-tidy binary, on the command line, or in a specific configuration file. receipts, always.--export-fixes=<filename>β a YAML file to store suggested fixes in. Those stored fixes can then be applied to the input source code withclang-apply-replacements.--extra-arg=<string>β an extra argument to append to the compiler command line.--extra-arg-before=<string>β an extra argument to prepend to the compiler command line.--fixβ applies the suggested fixes. Heads up: without-fix-errors, clang-tidy will bail out if any compilation errors were found. π«£--fix-errorsβ applies suggested fixes even if compilation errors were found. And if the compiler errors have fix-its attached, clang-tidy applies those too.--format-style=<string>β the style used for formatting code around applied fixes:'none'(the default) turns off formatting'file'(literally the word'file', not a placeholder) uses the.clang-formatfile in the closest parent directory'{ <json> }'specifies options inline, e.g.-format-style='{BasedOnStyle: llvm, IndentWidth: 8}''llvm','google','webkit','mozilla'β go check the clang-format documentation for the up-to-date info about formatting styles and options. This option overrides the'FormatStyle`option in the.clang-tidyfile, if any.
--header-filter=<string>β a regular expression matching the names of the headers to output diagnostics from. Diagnostics from the main file of each translation unit are always displayed. Can be used together with-line-filter. This option overrides the'HeaderFilterRegex'option in the.clang-tidyfile, if any.--line-filter=<string>β a list of files with line ranges to filter the warnings. Can be used together with-header-filter. The format of the list is a JSON array of objects:
[ {"name":"file1.cpp","lines":[[1,3],[5,7]]}, {"name":"file2.h"}
]
--list-checksβ lists all enabled checks and exits. Use it with-checks=*to list every available check. π-p=<string>β build path.--quietβ runs clang-tidy in quiet mode. This suppresses printing statistics about ignored warnings and warnings treated as errors, if the respective options are specified. π€«--store-check-profile=<prefix>β by default, reports are printed in tabulated format to stderr. When you pass this option, those per-TU profiles get stored as JSON instead.--system-headersβ displays the errors from system headers.--use-colorβ uses colors in diagnostics. If it's not set, colors get used when the terminal connected to standard output supports colors. This option overrides the'UseColor'option in the.clang-tidyfile, if any. π--vfsoverlay=<filename>β overlays the virtual filesystem described by that file on top of the real file system.--warnings-as-errors=<string>β upgrades warnings to errors. Same format as'-checks'. This option's value is appended to the value of the'WarningsAsErrors'option in the.clang-tidyfile, if any.
-p <build-path> is used to read a compile command database. ποΈ
For example, it can be a CMake build directory that has a file named compile_commands.json in it (use the -DCMAKE_EXPORT_COMPILE_COMMANDS=ON CMake option to get that output). When no build path is specified, clang-tidy attempts a search for compile_commands.json through all the parent paths of the first input file. See: https://clang.llvm.org/docs/HowToSetupToolingForLLVM.html for an example of setting up Clang Tooling on a source tree.
<source0> ... specify the paths of source files. Those paths get looked up in the compile command database. If a file's path is absolute, it needs to point into CMake's source tree. If the path is relative, the current working directory needs to be in the CMake source tree and the file has to be in a subdirectory of the current working directory. "./" prefixes on relative files get automatically removed, but the rest of a relative path must be a suffix of a path in the compile command database. rules are rules bestie.
π Configuration files π
clang-tidy tries to read configuration for each source file from a .clang-tidy file located in the closest parent directory of the source file. If InheritParentConfig is true in a config file, the configuration file in the parent directory (if one exists) gets taken, and the current config file is applied on top of the parent one. If any configuration options have a corresponding command-line option, the command-line option takes precedence. You can inspect the effective configuration using -dump-config:
$ clang-tidy -dump-config
---
Checks: '-*,some-check'
WarningsAsErrors: ''
HeaderFilterRegex: ''
FormatStyle: none
InheritParentConfig: true
User: user
CheckOptions:
- key: some-check.SomeOption
value: 'some value'
...
okay that's the whole page, you made it, I'm so proud of you π«Ά
And that's a wrap! This was clang-tidy 11, dated January 2022, page CLANG-TIDY(1) β go forth and tidy, bestie, your code is gonna look immaculate. β¨ππ
π¦ where this page comes from
- ubuntu jammy: clang-tidy-11 1:11.1.0-6 Β· APACHE-2-LLVM-EXCEPTIONS
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms