diff --git a/.clang-tidy b/.clang-tidy deleted file mode 100644 index 79c3326e3..000000000 --- a/.clang-tidy +++ /dev/null @@ -1,11 +0,0 @@ -Checks: > - -*, - cppcoreguidelines-pro-type-cstyle-cast, -WarningsAsErrors: '' -HeaderFilterRegex: '' -AnalyzeTemporaryDtors: false -FormatStyle: none -User: land -CheckOptions: -... - diff --git a/.clang-tidy b/.clang-tidy new file mode 120000 index 000000000..8bc57042a --- /dev/null +++ b/.clang-tidy @@ -0,0 +1 @@ +config/clang_tidy/default.yml \ No newline at end of file diff --git a/README.md b/README.md index f3c0890d3..15bb5e4ba 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/config/clang_tidy/README.md b/config/clang_tidy/README.md new file mode 100644 index 000000000..c1d636994 --- /dev/null +++ b/config/clang_tidy/README.md @@ -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 + + // 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) +``` diff --git a/config/clang_tidy/core.yml b/config/clang_tidy/core.yml new file mode 100644 index 000000000..3ae3d7076 --- /dev/null +++ b/config/clang_tidy/core.yml @@ -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' diff --git a/config/clang_tidy/neuland.yml b/config/clang_tidy/neuland.yml new file mode 100644 index 000000000..72febf9f1 --- /dev/null +++ b/config/clang_tidy/neuland.yml @@ -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' diff --git a/neuland/.clang-tidy b/neuland/.clang-tidy deleted file mode 100644 index 3ae3d7076..000000000 --- a/neuland/.clang-tidy +++ /dev/null @@ -1,50 +0,0 @@ -# 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' diff --git a/neuland/.clang-tidy b/neuland/.clang-tidy new file mode 120000 index 000000000..b28a1bedc --- /dev/null +++ b/neuland/.clang-tidy @@ -0,0 +1 @@ +../config/clang_tidy/neuland.yml \ No newline at end of file diff --git a/r3bbase/.clang-tidy b/r3bbase/.clang-tidy new file mode 120000 index 000000000..c229d10dd --- /dev/null +++ b/r3bbase/.clang-tidy @@ -0,0 +1 @@ +../config/clang_tidy/core.yml \ No newline at end of file diff --git a/r3bdata/neulandData/.clang-tidy b/r3bdata/neulandData/.clang-tidy new file mode 120000 index 000000000..d6bae9a4b --- /dev/null +++ b/r3bdata/neulandData/.clang-tidy @@ -0,0 +1 @@ +../../config/clang_tidy/neuland.yml \ No newline at end of file diff --git a/r3bsource/base/.clang-tidy b/r3bsource/base/.clang-tidy new file mode 120000 index 000000000..fb0f0fe64 --- /dev/null +++ b/r3bsource/base/.clang-tidy @@ -0,0 +1 @@ +../../config/clang_tidy/core.yml \ No newline at end of file diff --git a/r3bsource/neuland/.clang-tidy b/r3bsource/neuland/.clang-tidy new file mode 120000 index 000000000..d6bae9a4b --- /dev/null +++ b/r3bsource/neuland/.clang-tidy @@ -0,0 +1 @@ +../../config/clang_tidy/neuland.yml \ No newline at end of file