From a21b51d624ed3d5c9060d60f7c45e1db8cb3edd1 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Tue, 19 Nov 2024 20:24:55 +0100 Subject: [PATCH 01/12] first clang-tidy checks for modern cpp --- .clang-tidy | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 .clang-tidy diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 00000000..a46dbf43 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,64 @@ +--- +Checks: > + # Modernize checks + modernize-* + # Avoid raw pointers + modernize-use-auto, + modernize-use-nullptr, + modernize-avoid-c-arrays, + modernize-make-unique, + modernize-make-shared, + modernize-smart-ptr, + modernize-use-override, + modernize-use-equals-default, + modernize-use-equals-delete, + modernize-use-bool-literals, + modernize-loop-convert, + modernize-use-emplace, + modernize-use-using, + modernize-deprecated-headers, + modernize-pass-by-value, + modernize-concat-nested-namespaces, + + # Core guidelines + cppcoreguidelines-*, + cppcoreguidelines-owning-memory, + cppcoreguidelines-pro-bounds-array-to-pointer-decay, + cppcoreguidelines-pro-bounds-constant-array-index, + cppcoreguidelines-pro-type-cstyle-cast, + cppcoreguidelines-pro-type-member-init, + cppcoreguidelines-no-malloc, + + # Performance and safety + performance-*, + readability-*, + hicpp-*, + bugprone-*, + misc-*, + + # Remove unnecessary code + readability-redundant-* + + # Optional - highly aggressive rules (uncomment if needed) + # clang-analyzer-*, + +WarningsAsErrors: '*' +HeaderFilterRegex: '.*' +AnalyzeTemporaryDtors: true +FormatStyle: file +CheckOptions: + - key: modernize-use-auto.MinTypeNameLength + value: '4' # Avoid auto for short types like int, bool + - key: cppcoreguidelines-pro-bounds-pointer-arithmetic.Strict + value: 'true' + - key: modernize-loop-convert.IgnoreUserDefined + value: 'false' + - key: readability-function-cognitive-complexity.Threshold + value: '25' + - key: modernize-use-emplace.Hint + value: 'false' + - key: cppcoreguidelines-init-variables.Suppress + value: 'false' + - key: modernize-avoid-c-arrays.StrictMode + value: 'true' + From d2ddf3ee396f0d487c02a74ffe63a02bd5643ca3 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Tue, 19 Nov 2024 20:28:16 +0100 Subject: [PATCH 02/12] uncomment clang-analyzer --- .clang-tidy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.clang-tidy b/.clang-tidy index a46dbf43..e5003554 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -40,7 +40,7 @@ Checks: > readability-redundant-* # Optional - highly aggressive rules (uncomment if needed) - # clang-analyzer-*, + clang-analyzer-*, WarningsAsErrors: '*' HeaderFilterRegex: '.*' From c174473f337e3bd14ad2f5a6fa6d1b3651838d5a Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Tue, 19 Nov 2024 20:39:00 +0100 Subject: [PATCH 03/12] add basic clang-tidy workflow --- .github/workflows/linter.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 .github/workflows/linter.yml diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml new file mode 100644 index 00000000..e69de29b From 4f02369aaa2faa02782ed08e38372b8de3060f42 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Tue, 19 Nov 2024 20:40:43 +0100 Subject: [PATCH 04/12] add basic clang-tidy workflow --- .github/workflows/linter.yml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index e69de29b..7be6216c 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -0,0 +1,29 @@ +name: Run Clang-tidy Check + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + clang-tidy-check: + runs-on: ubuntu-latest + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Install Clang-Tidy + run: | + sudo apt-get update + sudo apt-get install -y clang-tidy + + - name: Configure with CMake + run: | + cmake -S . -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=Debug + + - name: Run Clang-Tidy + run: | + clang-tidy --version # Verify installed version + clang-tidy -p build $(find . -name '*.cpp' '*.c' '*.hpp' '*.h') + \ No newline at end of file From 32bb672a1b74d3efd65293d13cad1103fcab7fb0 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Tue, 19 Nov 2024 20:42:53 +0100 Subject: [PATCH 05/12] fix find command --- .github/workflows/linter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 7be6216c..23511a43 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -25,5 +25,5 @@ jobs: - name: Run Clang-Tidy run: | clang-tidy --version # Verify installed version - clang-tidy -p build $(find . -name '*.cpp' '*.c' '*.hpp' '*.h') + clang-tidy -p build $(find . -name '*.cpp' -o -name '*.c' -o -name '*.hpp' -o -name '*.h') \ No newline at end of file From 01f62f8e9d674078346dafa96afecf3362ceaeeb Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Wed, 20 Nov 2024 19:31:59 +0100 Subject: [PATCH 06/12] add max warnings and fix clang-tidy version --- .github/workflows/linter.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 23511a43..8d8acc91 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -16,7 +16,8 @@ jobs: - name: Install Clang-Tidy run: | sudo apt-get update - sudo apt-get install -y clang-tidy + sudo apt-get install -y clang-tidy-14 + ln -s /usr/bin/clang-tidy-14 /usr/bin/clang-tidy - name: Configure with CMake run: | @@ -25,5 +26,6 @@ jobs: - name: Run Clang-Tidy run: | clang-tidy --version # Verify installed version - clang-tidy -p build $(find . -name '*.cpp' -o -name '*.c' -o -name '*.hpp' -o -name '*.h') + clang-tidy -p build -max-warnings=10 $(find . -name '*.cpp' -o -name '*.c' -o -name '*.hpp' -o -name '*.h') + \ No newline at end of file From ea709c9d530d06e136e7ff68d376d7d33520c061 Mon Sep 17 00:00:00 2001 From: TimSiebert1 <128799979+TimSiebert1@users.noreply.github.com> Date: Wed, 20 Nov 2024 19:33:18 +0100 Subject: [PATCH 07/12] rm symbolic linking --- .github/workflows/linter.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 8d8acc91..b9ea7cd7 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -17,7 +17,6 @@ jobs: run: | sudo apt-get update sudo apt-get install -y clang-tidy-14 - ln -s /usr/bin/clang-tidy-14 /usr/bin/clang-tidy - name: Configure with CMake run: | @@ -28,4 +27,4 @@ jobs: clang-tidy --version # Verify installed version clang-tidy -p build -max-warnings=10 $(find . -name '*.cpp' -o -name '*.c' -o -name '*.hpp' -o -name '*.h') - \ No newline at end of file + From a3730702a0910c7162427e3640c65d6e72bf22f0 Mon Sep 17 00:00:00 2001 From: TimSiebert1 <128799979+TimSiebert1@users.noreply.github.com> Date: Wed, 20 Nov 2024 19:36:15 +0100 Subject: [PATCH 08/12] replace with right option --- .github/workflows/linter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index b9ea7cd7..577ea7dc 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -25,6 +25,6 @@ jobs: - name: Run Clang-Tidy run: | clang-tidy --version # Verify installed version - clang-tidy -p build -max-warnings=10 $(find . -name '*.cpp' -o -name '*.c' -o -name '*.hpp' -o -name '*.h') + clang-tidy -p build -warnings-as-errors $(find . -name '*.cpp' -o -name '*.c' -o -name '*.hpp' -o -name '*.h') From db0de9e663e649f986349ad990a3dd602db169f2 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Wed, 20 Nov 2024 19:38:32 +0100 Subject: [PATCH 09/12] uncomment clang-analyzer for the beginning --- .clang-tidy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.clang-tidy b/.clang-tidy index e5003554..df9a14e0 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -40,7 +40,7 @@ Checks: > readability-redundant-* # Optional - highly aggressive rules (uncomment if needed) - clang-analyzer-*, + #clang-analyzer-*, WarningsAsErrors: '*' HeaderFilterRegex: '.*' From f17b48617f07b9e75ddba5980d2056b606874e58 Mon Sep 17 00:00:00 2001 From: Tim Siebert Date: Wed, 20 Nov 2024 19:39:21 +0100 Subject: [PATCH 10/12] warning as error is specified in .clang-tidy --- .github/workflows/linter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 577ea7dc..6b562049 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -25,6 +25,6 @@ jobs: - name: Run Clang-Tidy run: | clang-tidy --version # Verify installed version - clang-tidy -p build -warnings-as-errors $(find . -name '*.cpp' -o -name '*.c' -o -name '*.hpp' -o -name '*.h') + clang-tidy -p build $(find . -name '*.cpp' -o -name '*.c' -o -name '*.hpp' -o -name '*.h') From 15ea9d17f6ac06566f048c2a6e934d52714b04bd Mon Sep 17 00:00:00 2001 From: TimSiebert1 <128799979+TimSiebert1@users.noreply.github.com> Date: Wed, 20 Nov 2024 19:50:14 +0100 Subject: [PATCH 11/12] be a bit more precise which files to check --- .github/workflows/linter.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 6b562049..ca208dd7 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -25,6 +25,8 @@ jobs: - name: Run Clang-Tidy run: | clang-tidy --version # Verify installed version - clang-tidy -p build $(find . -name '*.cpp' -o -name '*.c' -o -name '*.hpp' -o -name '*.h') + clang-tidy -p build $(find ADOL-C/ADOL-C/src/ -name '*.cpp' -o -name '*.c' -o -name '*.hpp' -o -name '*.h') + clang-tidy -p build $(find ADOL-C/ADOL-C/include/ -name '*.cpp' -o -name '*.c' -o -name '*.hpp' -o -name '*.h') + clang-tidy -p build $(find ADOL-C/ADOL-C/c_interface -name '*.cpp' -o -name '*.c' -o -name '*.hpp' -o -name '*.h') From f974b97ae9ca6bc8e3247f6fbcdfcfeaaa9646bb Mon Sep 17 00:00:00 2001 From: TimSiebert1 <128799979+TimSiebert1@users.noreply.github.com> Date: Wed, 20 Nov 2024 19:51:33 +0100 Subject: [PATCH 12/12] correct path --- .github/workflows/linter.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index ca208dd7..8dbd0608 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -25,8 +25,8 @@ jobs: - name: Run Clang-Tidy run: | clang-tidy --version # Verify installed version - clang-tidy -p build $(find ADOL-C/ADOL-C/src/ -name '*.cpp' -o -name '*.c' -o -name '*.hpp' -o -name '*.h') - clang-tidy -p build $(find ADOL-C/ADOL-C/include/ -name '*.cpp' -o -name '*.c' -o -name '*.hpp' -o -name '*.h') - clang-tidy -p build $(find ADOL-C/ADOL-C/c_interface -name '*.cpp' -o -name '*.c' -o -name '*.hpp' -o -name '*.h') + clang-tidy -p build $(find ADOL-C/src/ -name '*.cpp' -o -name '*.c' -o -name '*.hpp' -o -name '*.h') + clang-tidy -p build $(find ADOL-C/include/ -name '*.cpp' -o -name '*.c' -o -name '*.hpp' -o -name '*.h') + clang-tidy -p build $(find ADOL-C/c_interface -name '*.cpp' -o -name '*.c' -o -name '*.hpp' -o -name '*.h')