File tree Expand file tree Collapse file tree 8 files changed +73
-23
lines changed
Expand file tree Collapse file tree 8 files changed +73
-23
lines changed Original file line number Diff line number Diff line change 2626 uses : actions/checkout@v4
2727
2828 - name : Install clang-format
29- run : sudo apt update && sudo apt install -y clang-format
29+ run : sudo apt update && sudo apt install -y clang-format cmake ninja-build g++ gcc
3030
31- - name : Run clang-format check
32- run : |
33- FILES=$(find . \( -name '*.cpp' -o -name '*.hpp' \) -not -path "./build/*")
34- clang-format --dry-run --Werror $FILES
31+ - name : Configure project
32+ run : cmake --preset gcc-RelWithDebInfo
33+
34+ - name : Run clang-format
35+ run : cmake --build build/gcc-RelWithDebInfo/ --target clang-format
Original file line number Diff line number Diff line change 3636 run : cmake --preset gcc-RelWithDebInfo
3737
3838 - name : Run clang-tidy
39- run : |
40- find src include tests -name '*.cpp' | xargs clang-tidy -p build/gcc-RelWithDebInfo
39+ run : cmake --build build/gcc-RelWithDebInfo/ --target clang-tidy
Original file line number Diff line number Diff line change @@ -53,3 +53,9 @@ include(tools/Doxygen)
5353
5454# === Installation ===
5555include (install /InstallConfig)
56+
57+ # === Formatting ===
58+ include (tools/ClangFormat)
59+
60+ # === Linting ===
61+ include (tools/ClangTidy)
Original file line number Diff line number Diff line change 1+ find_program (CLANG_FORMAT_EXE NAMES clang-format)
2+
3+ if (CLANG_FORMAT_EXE)
4+
5+ # Collect all relevant source/header files recursively
6+ file (GLOB_RECURSE ALL_SOURCE_FILES
7+ "${CMAKE_SOURCE_DIR} /src/*.cpp"
8+ "${CMAKE_SOURCE_DIR} /src/**/*.cpp"
9+ "${CMAKE_SOURCE_DIR} /include/*.hpp"
10+ "${CMAKE_SOURCE_DIR} /include/**/*.hpp"
11+ "${CMAKE_SOURCE_DIR} /tests/*.cpp"
12+ "${CMAKE_SOURCE_DIR} /tests/**/*.cpp"
13+ "${CMAKE_SOURCE_DIR} /tests/*.hpp"
14+ "${CMAKE_SOURCE_DIR} /tests/**/*.hpp"
15+ )
16+
17+ add_custom_target (clang-format
18+ COMMAND ${CLANG_FORMAT_EXE} --dry-run --Werror ${ALL_SOURCE_FILES}
19+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
20+ COMMENT "🔍 Checking format (clang-format --dry-run --Werror)"
21+ VERBATIM
22+ )
23+ else ()
24+ message (STATUS "⚠️\t clang-format not found — 'clang-format' target will not be available." )
25+ endif ()
Original file line number Diff line number Diff line change 1+ find_program (CLANG_TIDY_EXE NAMES clang-tidy)
2+
3+ if (CLANG_TIDY_EXE)
4+ file (GLOB_RECURSE TIDY_SOURCE_FILES
5+ "${CMAKE_SOURCE_DIR} /src/*.cpp"
6+ "${CMAKE_SOURCE_DIR} /src/**/*.cpp"
7+ "${CMAKE_SOURCE_DIR} /tests/*.cpp"
8+ "${CMAKE_SOURCE_DIR} /tests/**/*.cpp"
9+ )
10+
11+ add_custom_target (clang-tidy
12+ COMMAND ${CLANG_TIDY_EXE} ${TIDY_SOURCE_FILES} --quiet -p ${CMAKE_BINARY_DIR}
13+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
14+ COMMENT "🔍 Running clang-tidy analysis"
15+ VERBATIM
16+ )
17+ else ()
18+ message (STATUS "⚠️ clang-tidy not found — 'clang-tidy' target will not be available." )
19+ endif ()
Original file line number Diff line number Diff line change @@ -12,20 +12,20 @@ namespace math
1212/* *
1313 * @brief Adds two integers.
1414 *
15- * @param a First integer.
16- * @param b Second integer.
17- * @return Sum of a and b .
15+ * @param left First integer.
16+ * @param right Second integer.
17+ * @return Sum of left and right .
1818 */
19- int add (int a , int b );
19+ int add (int left , int right );
2020
2121/* *
2222 * @brief Subtracts two integers.
2323 *
24- * @param a First integer.
25- * @param b Second integer.
26- * @return Difference of a and b .
24+ * @param left First integer.
25+ * @param right Second integer.
26+ * @return Difference of left and right .
2727 */
28- int subtract (int a , int b );
28+ int subtract (int left , int right );
2929
3030} // namespace math
3131
Original file line number Diff line number Diff line change 33namespace math
44{
55
6- int add (int a , int b )
6+ int add (int left , int right )
77{
8- return a + b ;
8+ return left + right ;
99}
1010
11- int subtract (int a , int b )
11+ int subtract (int left , int right )
1212{
13- return a - b ;
13+ return left - right ;
1414}
1515
1616} // namespace math
Original file line number Diff line number Diff line change 44
55int main ()
66{
7- const int a = 10 ;
8- const int b = 4 ;
7+ const int left = 10 ;
8+ const int right = 4 ;
99
10- std::cout << " Add: " << math::add (a, b ) << ' \n ' ;
11- std::cout << " Subtract: " << math::subtract (a, b ) << ' \n ' ;
10+ std::cout << " Add: " << math::add (left, right ) << ' \n ' ;
11+ std::cout << " Subtract: " << math::subtract (left, right ) << ' \n ' ;
1212
1313 return 0 ;
1414}
You can’t perform that action at this time.
0 commit comments