Skip to content

Commit

Permalink
clang-tidy config for neuland and core
Browse files Browse the repository at this point in the history
  • Loading branch information
YanzhaoW committed Nov 16, 2023
1 parent 77deacb commit 4b76aa6
Show file tree
Hide file tree
Showing 11 changed files with 191 additions and 61 deletions.
11 changes: 0 additions & 11 deletions .clang-tidy

This file was deleted.

1 change: 1 addition & 0 deletions .clang-tidy
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,6 @@ The R3BRoot project uses clang-format-15 to ensure a common code formatting. The
~~~bash
source util/clang-format-all.sh
~~~

## Static analyzer using Clang-tidy
Please go to this [instruction](config/clang_tidy/README.md).
75 changes: 75 additions & 0 deletions config/clang_tidy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Configuration for clang-tidy

## Setup configuration file
Warnings given by clang-tidy or clangd are configured in `.clang-tidy` yaml file in the nearest folder. Detector specific folders can have different configurations defined in the [global.yml](./global.yml). The customary configuration files in folders for a detector should be symbolic links to a common file located at `config/clang_tidy/${detector_name}.yml`.

Currently there are 3 different folders for each detector:
* `R3BRoot/${detector_name}/`
* `R3BRoot/r3bsource/${detector_name}/`
* `R3BRoot/r3bdata/${detector_name}Data/`

Here is an example of how to create 3 symbolic links in the folders related to NeuLAND:
```shell
# in project root folder
ln -s ../config/clang_tidy/neuland.yml ./neuland/.clang-tidy
ln -s ../../config/clang_tidy/neuland.yml ./r3bsource/neuland/.clang-tidy
ln -s ../../config/clang_tidy/neuland.yml ./r3bdata/neulandData/.clang-tidy
```

## Suppressing undesired warnings

Ways to ignore certain warnings among the code can be found in [clang-tidy official website](https://clang.llvm.org/extra/clang-tidy/#suppressing-undesired-diagnostics).

Here is a summary with some examples (copied directly from the website):

1. `NOLINT`
```cpp
// Suppress all the diagnostics for the line
Foo(int param); // NOLINT

// Consider explaining the motivation to suppress the warning
Foo(char param); // NOLINT: Allow implicit conversion from `char`, because <some valid reason>

// Silence only the specified checks for the line
Foo(double param); // NOLINT(google-explicit-constructor, google-runtime-int)

// Silence all checks from the `google` module
Foo(bool param); // NOLINT(google*)

// Silence all checks ending with `-avoid-c-arrays`
int array[10]; // NOLINT(*-avoid-c-arrays
```
2. `NOLINTNEXTLINE`
```cpp
// Silence only the specified diagnostics for the next line
// NOLINTNEXTLINE(google-explicit-constructor, google-runtime-int)
Foo(bool param);
// Silence all checks from the `google` module for the next line
// NOLINTNEXTLINE(google*)
Foo(bool param);
// Silence all checks ending with `-avoid-c-arrays` for the next line
// NOLINTNEXTLINE(*-avoid-c-arrays)
int array[10];
```

3. `NOLINTBEGIN` and `NOLINTEND`
```cpp
// Silence only the specified checks for all lines between the BEGIN and END
// NOLINTBEGIN(google-explicit-constructor, google-runtime-int)
Foo(short param);
Foo(long param);
// NOLINTEND(google-explicit-constructor, google-runtime-int)

// Silence all checks from the `google` module for all lines between the BEGIN and END
// NOLINTBEGIN(google*)
Foo(bool param);
// NOLINTEND(google*)

// Silence all checks ending with `-avoid-c-arrays` for all lines between the BEGIN and END
// NOLINTBEGIN(*-avoid-c-arrays)
int array[10];
// NOLINTEND(*-avoid-c-arrays)
```
50 changes: 50 additions & 0 deletions config/clang_tidy/core.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# vi: ft=yaml
Checks: >
-*,
bugprone-*,
cert-dcl21-cpp,
cert-dcl50-cpp,
cert-env33-c,
cert-err34-c,
cert-err52-cpp,
cert-err60-cpp,
cert-flp30-c,
cert-msc50-cpp,
cert-msc51-cpp,
clang-analyzer-*,
cppcoreguidelines-*,
-cppcoreguidelines-pro-type-reinterpret-cast,
google-build-using-namespace,
google-explicit-constructor,
google-global-names-in-headers,
google-readability-casting,
google-runtime-int,
google-runtime-operator,
hicpp-*,
-hicpp-vararg,
misc-*,
modernize-*,
performance-*,
readability-*,
-hicpp-new-delete-operators,
-modernize-use-trailing-return-type
CheckOptions:
- key: bugprone-argument-comment.StrictMode
value: 1
- key: bugprone-easily-swappable-parameters.MinimumLength
value: 4
- key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
value: 1
- key: readability-identifier-length.IgnoredVariableNames
value: '^it$'
- key: readability-magic-numbers.IgnoreAllFloatingPointValues
value: 'true'
- key: cppcoreguidelines-avoid-magic-numbers.IgnoreAllFloatingPointValues
value: 'true'
- key: readability-function-cognitive-complexity.Threshold
value: 40
- key: readability-function-cognitive-complexity.IgnoreMacros
value: 'true'

FormatStyle: 'file'
11 changes: 11 additions & 0 deletions config/clang_tidy/default.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Checks: >
-*,
cppcoreguidelines-pro-type-cstyle-cast,
WarningsAsErrors: ''
HeaderFilterRegex: ''
AnalyzeTemporaryDtors: false
FormatStyle: none
User: land
CheckOptions:
...

46 changes: 46 additions & 0 deletions config/clang_tidy/neuland.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# vi: ft=yaml
Checks: >
-*,
bugprone-*,
cert-dcl21-cpp,
cert-dcl50-cpp,
cert-env33-c,
cert-err34-c,
cert-err52-cpp,
cert-err60-cpp,
cert-flp30-c,
cert-msc50-cpp,
cert-msc51-cpp,
clang-analyzer-*,
cppcoreguidelines-*,
-cppcoreguidelines-pro-type-reinterpret-cast,
google-build-using-namespace,
google-explicit-constructor,
google-global-names-in-headers,
google-readability-casting,
google-runtime-int,
google-runtime-operator,
hicpp-*,
-hicpp-vararg,
misc-*,
modernize-*,
performance-*,
readability-*
CheckOptions:
- key: bugprone-argument-comment.StrictMode
value: 1
- key: bugprone-easily-swappable-parameters.MinimumLength
value: 4
- key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
value: 1
- key: readability-identifier-length.IgnoredVariableNames
value: '^it$'
- key: readability-magic-numbers.IgnoredFloatingPointValues
value: '1.0;2.0;10.0;100.0;1000.0'
- key: readability-function-cognitive-complexity.Threshold
value: 40
- key: readability-function-cognitive-complexity.IgnoreMacros
value: 'true'

FormatStyle: 'file'
50 changes: 0 additions & 50 deletions neuland/.clang-tidy

This file was deleted.

1 change: 1 addition & 0 deletions neuland/.clang-tidy
1 change: 1 addition & 0 deletions r3bbase/.clang-tidy
1 change: 1 addition & 0 deletions r3bdata/neulandData/.clang-tidy
1 change: 1 addition & 0 deletions r3bsource/base/.clang-tidy
1 change: 1 addition & 0 deletions r3bsource/neuland/.clang-tidy

0 comments on commit 4b76aa6

Please sign in to comment.