Linux command
clang-tidy 命令
文件
复制后可按需替换文件名、目录或参数。
常用示例
Run checks on file
clang-tidy [file.cpp] -- -I[include/path]
List enabled checks
clang-tidy --list-checks
List all available checks
clang-tidy --list-checks -checks='*'
Run specific checks
clang-tidy -checks='-*,modernize-*' [file.cpp]
Apply automatic fixes
clang-tidy --fix [file.cpp]
Export fixes to file
clang-tidy --export-fixes=[fixes.yaml] [file.cpp]
Dump configuration
clang-tidy --dump-config
说明
clang-tidy is a clang-based C++ linter tool for diagnosing and fixing typical programming errors including style violations, interface misuse, and bugs detectable via static analysis. It is part of the LLVM/Clang extra tools. The tool provides hundreds of checks organized into categories such as bugprone, modernize, performance, readability, and cppcoreguidelines. Many checks can automatically apply fixes to source code, making it useful for large-scale code modernization (e.g., migrating to modern C++ idioms). clang-tidy uses a .clang-tidy configuration file for project-level settings and supports inline suppression with NOLINT comments. For large projects, run-clang-tidy.py provides parallel execution across multiple files.
参数
- -checks=_list_
- Comma-separated list of checks (+/- prefixed globs)
- --list-checks
- List enabled checks
- --fix
- Apply suggested fixes
- --fix-errors
- Apply fixes even if errors occur
- --export-fixes=_file_
- Write fixes to YAML file
- --dump-config
- Dump configuration to stdout
- --warnings-as-errors=_list_
- Treat specified warnings as errors
- -p _path_
- Path to compilation database
- --config-file=_file_
- Path to .clang-tidy config
- --format-style=_style_
- Format style for applied fixes (none, file, llvm, google, webkit, mozilla)
- --extra-arg=_arg_
- Additional argument to append to the compiler command line
- --fix-notes
- Apply fixes from diagnostic notes (implies --fix)
- --allow-no-checks
- Allow empty enabled checks without error
FAQ
What is the clang-tidy command used for?
clang-tidy is a clang-based C++ linter tool for diagnosing and fixing typical programming errors including style violations, interface misuse, and bugs detectable via static analysis. It is part of the LLVM/Clang extra tools. The tool provides hundreds of checks organized into categories such as bugprone, modernize, performance, readability, and cppcoreguidelines. Many checks can automatically apply fixes to source code, making it useful for large-scale code modernization (e.g., migrating to modern C++ idioms). clang-tidy uses a .clang-tidy configuration file for project-level settings and supports inline suppression with NOLINT comments. For large projects, run-clang-tidy.py provides parallel execution across multiple files.
How do I run a basic clang-tidy example?
Run `clang-tidy [file.cpp] -- -I[include/path]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -checks=_list_ do in clang-tidy?
Comma-separated list of checks (+/- prefixed globs)