diff --git a/pipeline/.clang-format b/pipeline/.clang-format new file mode 100644 index 0000000..f608170 --- /dev/null +++ b/pipeline/.clang-format @@ -0,0 +1,10 @@ +--- +BasedOnStyle: Google +Standard: c++23 +ColumnLimit: 100 +IndentWidth: 2 +DerivePointerAlignment: false +PointerAlignment: Left +SortIncludes: true +IncludeBlocks: Preserve +... diff --git a/pipeline/.clang-tidy b/pipeline/.clang-tidy new file mode 100644 index 0000000..e4b27c2 --- /dev/null +++ b/pipeline/.clang-tidy @@ -0,0 +1,17 @@ +--- +Checks: > + -*, + bugprone-*, + clang-analyzer-*, + cppcoreguidelines-*, + google-*, + modernize-*, + performance-*, + readability-*, + -cppcoreguidelines-avoid-magic-numbers, + -cppcoreguidelines-owning-memory, + -readability-magic-numbers, + -google-readability-todo +HeaderFilterRegex: "^(src|includes)/.*" +FormatStyle: file +... diff --git a/pipeline/CMakeLists.txt b/pipeline/CMakeLists.txt index f9d27e1..a33b9b9 100644 --- a/pipeline/CMakeLists.txt +++ b/pipeline/CMakeLists.txt @@ -13,6 +13,20 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +option(ENABLE_CLANG_TIDY "Enable clang-tidy static analysis for project targets" ON) +option(ENABLE_CLANG_FORMAT_TARGETS "Enable clang-format helper targets" ON) + +if(ENABLE_CLANG_TIDY) + find_program(CLANG_TIDY_EXE NAMES clang-tidy) + if(CLANG_TIDY_EXE) + set(BIERGARTEN_CLANG_TIDY_COMMAND + "${CLANG_TIDY_EXE};--config-file=${CMAKE_CURRENT_SOURCE_DIR}/.clang-tidy") + message(STATUS "clang-tidy enabled: ${CLANG_TIDY_EXE}") + else() + message(STATUS "clang-tidy not found; static analysis is disabled") + endif() +endif() + # ----------------------------------------------------------------------------- # Compiler Options & Warnings (Interface Library) # ----------------------------------------------------------------------------- @@ -77,6 +91,12 @@ set(PIPELINE_SOURCES add_executable(biergarten-pipeline ${PIPELINE_SOURCES}) +if(BIERGARTEN_CLANG_TIDY_COMMAND) + set_target_properties(biergarten-pipeline PROPERTIES + CXX_CLANG_TIDY "${BIERGARTEN_CLANG_TIDY_COMMAND}" + ) +endif() + target_include_directories(biergarten-pipeline PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/includes @@ -94,6 +114,32 @@ target_link_libraries(biergarten-pipeline Boost::json ) +if(ENABLE_CLANG_FORMAT_TARGETS) + find_program(CLANG_FORMAT_EXE NAMES clang-format) + if(CLANG_FORMAT_EXE) + file(GLOB_RECURSE FORMAT_SOURCES CONFIGURE_DEPENDS + ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cc + ${CMAKE_CURRENT_SOURCE_DIR}/includes/*.h + ${CMAKE_CURRENT_SOURCE_DIR}/includes/*.hpp + ) + + add_custom_target(format + COMMAND ${CLANG_FORMAT_EXE} -style=file -i ${FORMAT_SOURCES} + COMMENT "Formatting source files with clang-format (Google style)" + VERBATIM + ) + + add_custom_target(format-check + COMMAND ${CLANG_FORMAT_EXE} -style=file --dry-run --Werror ${FORMAT_SOURCES} + COMMENT "Checking source formatting with clang-format (Google style)" + VERBATIM + ) + else() + message(STATUS "clang-format not found; format targets are disabled") + endif() +endif() + # ----------------------------------------------------------------------------- # Post-Build Steps & Utilities # ----------------------------------------------------------------------------- diff --git a/pipeline/README.md b/pipeline/README.md index 9488b53..3ef26d2 100644 --- a/pipeline/README.md +++ b/pipeline/README.md @@ -197,3 +197,28 @@ Run ./biergarten-pipeline Output: Logs to console; caches JSON in /tmp/countries+states+cities.json. + +Code Style and Static Analysis + +This project is configured to use: + +- clang-format with the Google C++ style guide (via .clang-format) +- clang-tidy checks focused on Google, modernize, performance, and bug-prone rules (via .clang-tidy) + +After configuring CMake, use: + +cmake --build . --target format + +to apply formatting, and: + +cmake --build . --target format-check + +to validate formatting without modifying files. + +clang-tidy runs automatically on the biergarten-pipeline target when available. You can disable it at configure time: + +cmake -DENABLE_CLANG_TIDY=OFF .. + +You can also disable format helper targets: + +cmake -DENABLE_CLANG_FORMAT_TARGETS=OFF ..