Task #3837
openInvestigate clang-tidy usage to enforce coding standards
Description
We shall investigate using clang-tidy to enforce coding style guide that cannot be done with clang-format. It can also be used to enforce some "best practices".
Limitation of clang-format is that it only reformats code. clang-tidy can be used to e.g. enforce "always use brace for if()".
Updated by Roland Fischer over 4 years ago
What's the difference between scan-build and clang-tidy?¶
scan-build does static analysis of code and as such does flow-control and path analysis. Use it to help finding bugs.
clang-tidy provides linter-based checks only that is mostly used to enforce coding standards. It's only based on the AST afaik. It's fully configurable on what to check for.
clang-tidy can also be used to "fix the code for some checks", i.e. it's convenient to use clang-tidy to upgrade" a code base to certain standards, such as the "shall always use braces" in this example.FYI, scan-build is used as static analysis tool in private QA builds.
Updated by Roland Fischer over 4 years ago
Also check out CodeChecker that could combine static analysis and clang-tidy: https://clang-analyzer.llvm.org/command-line.html
Integration with github probably would be an issue
Updated by Roland Fischer over 4 years ago
Documentation can be found at: https://clang.llvm.org/extra/clang-tidy/index.html
Version-specific doc, e.g. for clang 9: https://releases.llvm.org/9.0.0/tools/clang/tools/extra/docs/clang-tidy/index.html
List of available clang-tidy checks including whether a 'fix" is available (for latest clang): https://clang.llvm.org/extra/clang-tidy/checks/list.html
E.g. enforcing braces for if statements and loops: https://clang.llvm.org/extra/clang-tidy/checks/readability-braces-around-statements.html
Updated by Philippe Antoine 6 months ago
- Assignee set to Community Ticket
- Target version set to TBD