clang-tidy
Clang-based C++ linter and static analyzer
TLDR
Run checks on file
SYNOPSIS
clang-tidy [options] file [-- compileoptions_]
DESCRIPTION
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.
PARAMETERS
-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
CONFIGURATION
Create .clang-tidy in project root:
WarningsAsErrors: '*'
CHECK CATEGORIES
bugprone-*
Bug-prone patternsmodernize-*
C++ modernizationperformance-*
Performance issuesreadability-*
Code readabilitycppcoreguidelines-*
C++ Core Guidelines
SUPPRESSION
Use comments: NOLINT, NOLINTNEXTLINE, NOLINTBEGIN/NOLINTEND
CAVEATS
Requires compilation database for complex projects. Use run-clang-tidy.py for parallel execution.
SEE ALSO
clang(1), clang-format(1)
