Skip to content

Commit 7ca5bb4

Browse files
committed
Tools: Update documentation of Clang-Tidy and Cppcheck
1 parent 7c5ba97 commit 7ca5bb4

2 files changed

Lines changed: 38 additions & 7 deletions

File tree

docs/gettingstarted/contributingtocode.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,9 @@ The CI checks evaluate:
9292

9393
- Code formatting
9494
- Code quality
95-
- [MegaLinter](https://megalinter.io/)
95+
- [MegaLinter](https://megalinter.io/) (e.g. [cpplint](https://github.com/cpplint/cpplint), [Cppcheck](../tools/README.md#cppcheck))
9696
- [O2 linter](../tools/o2linter.md)
97+
- [Clang-Tidy](../tools/README.md#clang-tidy)
9798
- Compilation: Verifies that the code compiles without problems on all supported platforms.
9899
- PR properties
99100
- Labeler: Assigns [labels](https://github.com/AliceO2Group/O2Physics/labels) to the PR based on which parts of the code base were modified.

docs/tools/README.md

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,41 @@ Next time you execute `git commit`, the hooks will run automatically.
5151
## [Clang-Tidy](https://clang.llvm.org/extra/clang-tidy/)
5252

5353
Clang-Tidy is a clang-based C++ linter tool for diagnosing and fixing typical programming errors, like style violations or bugs.
54-
(See the [list of checks](https://clang.llvm.org/extra/clang-tidy/checks/list.html).)
54+
(See the [list of checks](https://releases.llvm.org/20.1.0/tools/clang/tools/extra/docs/clang-tidy/checks/list.html).)
5555

56-
To use Clang-Tidy, you need to have O2Physics compiled and a valid symbolic link `compile_commands.json` in the O2Physics directory pointing to the `alice/sw/BUILD/.../O2Physics` directory.
56+
By default, Clang-Tidy uses the configuration in [`.clang-tidy`](https://github.com/AliceO2Group/O2Physics/blob/master/.clang-tidy).
57+
58+
False positives can be suppressed per line with `// NOLINT(check-name,...)`. (See the [documentation](https://releases.llvm.org/20.1.0/tools/clang/tools/extra/docs/clang-tidy/index.html#suppressing-undesired-diagnostics) for details.)
59+
60+
### Running directly
61+
62+
To run Clang-Tidy directly locally, you need to have O2Physics compiled and a valid symbolic link `compile_commands.json` in the O2Physics directory pointing to the `alice/sw/BUILD/.../O2Physics` directory.
63+
64+
Without further options, you can run Clang-Tidy with
65+
66+
```bash
67+
clang-tidy file1 file2 ...
68+
```
69+
70+
### Running with O2Physics-code-check
71+
72+
Clang-Tidy runs on O2Physics PRs as the O2Physics-code-check tool under the `build/O2Physics/code-check` CI check, using the repository configuration.
73+
You can run the check locally to test C++ files modified since `<base-commit>` until `<head-commit>` with
74+
75+
```bash
76+
aliBuild build O2Physics-code-check -e ALIBUILD_BASE_HASH=<base-commit> -e ALIBUILD_HEAD_HASH=<head-commit>
77+
```
78+
79+
where `<base-commit>` is typically `upstream/master` and `<head-commit>` is `HEAD` by default if `ALIBUILD_HEAD_HASH` is omitted.
80+
If `ALIBUILD_BASE_HASH` is omitted, all tracked C++ files are analysed.
81+
82+
Enabled checks can be modified with the `O2PHYSICS_CHECKER_CHECKS=...` option.
83+
84+
Fixes can be enabled with the `O2PHYSICS_CHECKER_FIX=1` option.
5785

5886
### Checking naming conventions
5987

60-
The [`readability-identifier-naming`](https://clang.llvm.org/extra/clang-tidy/checks/readability/identifier-naming.html) check can fix deviations from the [naming conventions](https://rawgit.com/AliceO2Group/CodingGuidelines/master/naming_formatting.html) using the configuration in [`.clang-tidy`](https://github.com/AliceO2Group/O2Physics/blob/master/.clang-tidy).
88+
The [`readability-identifier-naming`](https://clang.llvm.org/extra/clang-tidy/checks/readability/identifier-naming.html) check can fix deviations from the [naming conventions](https://rawgit.com/AliceO2Group/CodingGuidelines/master/naming_formatting.html).
6189

6290
```tip
6391
Learn how to form a [correct camelCase name](https://google.github.io/styleguide/javaguide.html#s5.3-camel-case).
@@ -113,6 +141,8 @@ The include format is corrected automatically in O2Physics PRs as part of the au
113141

114142
Cppcheck is a static analysis tool for C/C++ code that detects bugs, undefined behaviour, and dangerous coding constructs that compilers typically miss.
115143

144+
False positives can be suppressed per line with `// cppcheck-suppress check-name`. (See the [documentation](https://github.com/cppcheck-opensource/cppcheck/blob/main/man/manual.md#inline-suppressions) for details.)
145+
116146
Cppcheck can analyse individual files (file mode) or entire projects (project mode).
117147
The two modes give slightly different results so one can consider using both for maximum coverage.
118148

@@ -123,15 +153,15 @@ The file mode is used in the MegaLinter check on GitHub.
123153
To use this mode, provide paths of files you want to analyse in the following way:
124154

125155
```bash
126-
cppcheck --language=c++ --std=c++20 --enable=style --check-level=exhaustive --suppressions-list=cppcheck_config file1 file2 ... 2> "err.log"
156+
cppcheck --language=c++ --std=c++20 --enable=style --check-level=exhaustive --suppressions-list=cppcheck_suppressions --inline-suppr --force file1 file2 ... 2> "err.log"
127157
```
128158

129159
The report will be stored in the `err.log` file.
130160

131161
To run a parallelised analysis of all `.h`, `.cxx`, `.C` files in the current directory (`.`), execute:
132162

133163
```bash
134-
find . -name "*.h" -o -name "*.cxx" -o -name "*.C" | parallel "cppcheck --language=c++ --std=c++20 --enable=style --check-level=exhaustive --suppressions-list=cppcheck_config {}" 2> "err.log"
164+
find . -name "*.h" -o -name "*.cxx" -o -name "*.C" | parallel "cppcheck --language=c++ --std=c++20 --enable=style --check-level=exhaustive --suppressions-list=cppcheck_suppressions --inline-suppr --force {}" 2> "err.log"
135165
```
136166

137167
Note: It is possible to parallelise the execution with the `-j` option instead but it usually produces less results than analysing files independently.
@@ -143,7 +173,7 @@ To use this mode, you need to have O2Physics compiled and a valid symbolic link
143173
Instead of providing file paths, provide the path to the project compilation database and use the `-j` option for parallelisation:
144174

145175
```bash
146-
cppcheck --language=c++ --std=c++20 --enable=style --check-level=exhaustive --suppressions-list=cppcheck_config --project=compile_commands.json -j $(nproc) 2> "err.log"
176+
cppcheck --language=c++ --std=c++20 --enable=style --check-level=exhaustive --suppressions-list=cppcheck_suppressions --inline-suppr --force --project=compile_commands.json -j $(nproc) 2> "err.log"
147177
```
148178

149179
### Generating browsable HTML output

0 commit comments

Comments
 (0)