From edab682601cbe1aa73d35a7b849dab554c42948a Mon Sep 17 00:00:00 2001 From: Berscheid <1885260+pantor@users.noreply.github.com> Date: Sat, 18 Oct 2025 06:33:11 -0700 Subject: [PATCH] Enable clang tidy in CI (#314) * add clang tidy check * test * check * check * test * check * test * header filter * fix header filter * check * check * check * recheck * re-check * undo removing ci --- .clang-tidy | 30 +++++++++++++++--------------- .github/workflows/ci.yml | 7 ++++++- CMakeLists.txt | 20 +++++++++++++------- scripts/clang_tidy.sh | 1 - 4 files changed, 34 insertions(+), 24 deletions(-) delete mode 100644 scripts/clang_tidy.sh diff --git a/.clang-tidy b/.clang-tidy index 211bb9b..317748b 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,19 +1,19 @@ Checks: > - -*, - bugprone-*, - google-*, - misc-*, - modernize-*, - performance-*, - portability-*, - readability-*, - -google-readability-namespace-comments, - -google-runtime-int, - -google-runtime-references, + *, + -abseil-*, + -altera-*, + -cppcoreguidelines-avoid-goto, + -cppcoreguidelines-non-private-member-variables-in-classes, + -fuchsia-*, + -hicpp-*, + -llvm-*, + -llvmlibc-*, -misc-non-private-member-variables-in-classes, - -readability-named-parameter, - -readability-braces-around-statements, - -readability-magic-numbers + -modernize-*, + -readability-function-cognitive-complexity, + -readability-identifier-length # Turn all the warnings from the checks above into errors. -WarningsAsErrors: "" +HeaderFilterRegex: '.*/include/inja/.*\.hpp$' +UseColor: true +WarningsAsErrors: '' diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 03a0a11..8a8494b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,6 +19,11 @@ jobs: os: ubuntu-22.04 compiler: clang + - name: ubuntu-22.04-clang-tidy + os: ubuntu-22.04 + compiler: clang + cmake_vars: "-DINJA_ENABLE_CLANG_TIDY=ON" + - name: ubuntu-22.04-clang-15-no-exceptions os: ubuntu-22.04 compiler: clang-15 @@ -56,7 +61,7 @@ jobs: - uses: actions/checkout@v4 - name: Setup Cpp - uses: aminya/setup-cpp@v0.44.0 + uses: aminya/setup-cpp@v0.46.1 with: compiler: ${{ matrix.compiler }} diff --git a/CMakeLists.txt b/CMakeLists.txt index 45c17d6..4bdfe3f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,13 +8,14 @@ cmake_policy(SET CMP0077 NEW) project(inja LANGUAGES CXX VERSION 3.4.0) -option(INJA_USE_EMBEDDED_JSON "Use the shipped json header if not available on the system" ON) +option(BUILD_TESTING "Build unit tests" ON) +option(COVERALLS "Generate coveralls data" OFF) +option(INJA_BUILD_TESTS "Build unit tests when BUILD_TESTING is enabled." ON) +option(INJA_ENABLE_CLANG_TIDY "Enable clang-tidy" OFF) +option(INJA_EXPORT "Export the current build tree to the package registry" ON) option(INJA_INSTALL "Generate install targets for inja" ON) option(INJA_INSTALL_SINGLE_HEADER "Install the single header instead" OFF) -option(INJA_EXPORT "Export the current build tree to the package registry" ON) -option(BUILD_TESTING "Build unit tests" ON) -option(INJA_BUILD_TESTS "Build unit tests when BUILD_TESTING is enabled." ON) -option(COVERALLS "Generate coveralls data" OFF) +option(INJA_USE_EMBEDDED_JSON "Use the shipped json header if not available on the system" ON) set(INJA_INSTALL_INCLUDE_DIR "include") @@ -94,6 +95,12 @@ if(BUILD_TESTING AND INJA_BUILD_TESTS) target_compile_options(inja_test PRIVATE -Wall -Wextra -Werror) endif() + if(INJA_ENABLE_CLANG_TIDY) + find_program(CLANG_TIDY_EXE NAMES "clang-tidy" REQUIRED) + set(CLANG_TIDY_COMMAND "${CLANG_TIDY_EXE}" "-config-file=${CMAKE_CURRENT_SOURCE_DIR}/.clang-tidy") + set_target_properties(inja_test PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}") + endif() + add_library(single_inja INTERFACE) target_compile_features(single_inja INTERFACE cxx_std_17) @@ -106,8 +113,7 @@ if(BUILD_TESTING AND INJA_BUILD_TESTS) add_test(single_inja_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/single_inja_test) - add_executable(inja_benchmark test/benchmark.cpp - test/test-common.hpp) + add_executable(inja_benchmark test/benchmark.cpp test/test-common.hpp) target_link_libraries(inja_benchmark PRIVATE inja) target_include_directories(inja_benchmark PRIVATE third_party/include) endif() diff --git a/scripts/clang_tidy.sh b/scripts/clang_tidy.sh deleted file mode 100644 index 95e549f..0000000 --- a/scripts/clang_tidy.sh +++ /dev/null @@ -1 +0,0 @@ -clang-tidy test/test.cpp -- -Iinclude -Ithird_party/include