22
33[ Clang-Tidy] ( https://clang.llvm.org/extra/clang-tidy/ ) is a powerful C++ linter.
44
5+ ## Prerequisites
6+
7+ Install ` fd-find ` to make it easier to feed file lists to ` run-clang-tidy ` .
8+ More info can be found in the [ fd documentation] ( https://github.com/sharkdp/fd?tab=readme-ov-file#on-ubuntu ) .
9+
10+ ``` bash
11+ sudo apt-get install fd-find
12+ ```
13+
14+ Install ` clang-tidy ` and ` clang-apply-replacements ` .
15+
16+ ``` bash
17+ sudo apt-get install clang-tidy clang-tools
18+ ```
19+
20+ If you encounter ` clang-diagnostic-error ` , try installing ` libomp-dev ` .
21+ Related: < https://github.com/autowarefoundation/autoware-github-actions/pull/172 >
22+
23+ ``` bash
24+ sudo apt-get install libomp-dev
25+ ```
26+
527## Preparation
628
729You need to generate ` build/compile_commands.json ` before using Clang-Tidy.
@@ -12,17 +34,29 @@ colcon build --cmake-args -DCMAKE_EXPORT_COMPILE_COMMANDS=1
1234
1335## Usage
1436
37+ If you are on Ubuntu 22.04, run the following command ** only once** to help ` run-clang-tidy ` find the correct include paths.
38+ ** Reference:** [ autoware/pull/5543] ( https://github.com/autowarefoundation/autoware/pull/5543#issuecomment-2533325979 ) .
39+
40+ ``` bash
41+ sed -i ' /- -Wno-c11-extensions/a\ - -I/usr/include/c++/11\n - -I/usr/include/x86_64-linux-gnu/c++/11' .clang-tidy-ci
42+ ```
43+
44+ To run Clang-Tidy with all files in a package and export fixes to a YAML file, run the following command from the workspace root.
45+ Here we use ` autoware_utils ` as an example package name.
46+
1547``` bash
16- clang-tidy -p build/ path/to/file1 path/to/file2 ...
48+ cd autoware/
49+ run-clang-tidy -p build/ -config=" $( cat .clang-tidy-ci) " -export-fixes clang-tidy-fixes.yaml -j $( nproc) $( fdfind -e cpp -e hpp --full-path " /autoware_utils/" ) > clang-tidy-report.log
1750```
1851
19- If you want to apply Clang-Tidy to all files in a package, using the [ fd] ( https://github.com/sharkdp/fd ) command is useful.
20- To install ` fd ` , see the [ installation manual] ( https://github.com/sharkdp/fd#on-ubuntu ) .
52+ To apply fixes directly, run the following command.
2153
2254``` bash
23- clang-tidy -p build/ $( fd -e cpp -e hpp --full-path " /autoware_utils/" )
55+ run- clang-tidy -p build/ -config= " $( cat .clang-tidy-ci ) " -j $( nproc ) -fix $( fdfind -e cpp -e hpp --full-path " /autoware_utils/" )
2456```
2557
58+ ` clang-apply-replacements ` command can also be used to apply fixes from a YAML file.
59+
2660## IDE integration
2761
2862### CLion
@@ -35,9 +69,3 @@ Use either one of the following extensions:
3569
3670- [ C/C++] ( https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools )
3771- [ clangd] ( https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.vscode-clangd )
38-
39- ## Troubleshooting
40-
41- If you encounter ` clang-diagnostic-error ` , try installing ` libomp-dev ` .
42-
43- Related: < https://github.com/autowarefoundation/autoware-github-actions/pull/172 >
0 commit comments