Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ IndentCaseLabels: false
IndentPPDirectives: None
IndentWrappedFunctionNames: false
IndentGotoLabels: true
NamespaceIndentation: None
NamespaceIndentation: All
AccessModifierOffset: -4

AlignAfterOpenBracket: true
Expand Down
20 changes: 15 additions & 5 deletions cmake/CheckCoverageThreshold.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,25 @@ file(READ "${COVERAGE_FILE}" COVERAGE_CONTENT)

# Extract line coverage percentage
# lcov format: LH:<lines hit> LF:<lines found>
string(REGEX MATCH "LF:([0-9]+)" LF_MATCH "${COVERAGE_CONTENT}")
string(REGEX MATCH "LH:([0-9]+)" LH_MATCH "${COVERAGE_CONTENT}")
string(REGEX MATCHALL "LF:([0-9]+)" LF_ALL "${COVERAGE_CONTENT}")
string(REGEX MATCHALL "LH:([0-9]+)" LH_ALL "${COVERAGE_CONTENT}")

if(NOT LF_MATCH OR NOT LH_MATCH)
if(NOT LF_ALL OR NOT LH_ALL)
message(FATAL_ERROR "Could not parse coverage data from ${COVERAGE_FILE}")
endif()

string(REGEX REPLACE "LF:([0-9]+)" "\\1" LINES_FOUND "${LF_MATCH}")
string(REGEX REPLACE "LH:([0-9]+)" "\\1" LINES_HIT "${LH_MATCH}")
set(LINES_FOUND 0)
set(LINES_HIT 0)

foreach(LF_ENTRY IN LISTS LF_ALL)
string(REGEX REPLACE "LF:([0-9]+)" "\\1" VALUE "${LF_ENTRY}")
math(EXPR LINES_FOUND "${LINES_FOUND} + ${VALUE}")
endforeach()

foreach(LH_ENTRY IN LISTS LH_ALL)
string(REGEX REPLACE "LH:([0-9]+)" "\\1" VALUE "${LH_ENTRY}")
math(EXPR LINES_HIT "${LINES_HIT} + ${VALUE}")
endforeach()

if(LINES_FOUND EQUAL 0)
message(FATAL_ERROR "No lines found in coverage data")
Expand Down
7 changes: 4 additions & 3 deletions cmake/CodeCoverage.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,19 @@ if(ENABLE_COVERAGE)
${LCOV_EXECUTABLE} --capture --directory src --directory tests --output-file ${COVERAGE_DIR}/coverage.info
--base-directory ${CMAKE_SOURCE_DIR}
--gcov-tool ${GCOV_EXECUTABLE}
--ignore-errors mismatch,format,unsupported,version,empty
--ignore-errors mismatch,format,unsupported,version,empty,inconsistent
COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_BINARY_DIR}
${LCOV_EXECUTABLE} --remove ${COVERAGE_DIR}/coverage.info
'/usr/*' '*/tests/*' '*/build/*' '*/external/*'
'/usr/*' '*/tests/*' '*/build/*' '*/external/*' '*/gtest/*' '*/gmock/*'
--output-file ${COVERAGE_DIR}/coverage_filtered.info
--gcov-tool ${GCOV_EXECUTABLE}
--ignore-errors unused,format,unsupported,version,empty
--ignore-errors unused,format,unsupported,version,empty,inconsistent
COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_BINARY_DIR}
${GENHTML_EXECUTABLE} ${COVERAGE_DIR}/coverage_filtered.info
--output-directory ${COVERAGE_DIR}/html
--title "${PROJECT_NAME} Code Coverage"
--legend --show-details
--rc genhtml_med_limit=60 --rc genhtml_hi_limit=80
--ignore-errors empty
COMMAND ${CMAKE_COMMAND} -E echo "Coverage report generated at: ${COVERAGE_DIR}/html/index.html"
COMMAND ${CMAKE_COMMAND}
Expand Down
13 changes: 13 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
coverage:
range: 60..80
round: down
precision: 2
status:
project:
default:
target: 80%
threshold: 0%
patch:
default:
target: 80%
Comment thread
Copilot marked this conversation as resolved.
threshold: 0%
76 changes: 50 additions & 26 deletions docs/LINTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,20 @@ All three are integrated into CMake as custom targets and can be run manually or

### Checking Formatting

Checks if files comply with `.clang-format` without modifying them:
Checks if files comply with `.clang-format` without modifying them.

**Prerequisites:** Install `clang-format` first (see [Common Issues](#clang-format-not-found)).

```bash
cmake --build build --target format-check
cmake --preset debug-full
cmake --build --preset debug-full --target format-check
```

**Real example:**

```bash
cmake --build build/release --target format-check
cmake --preset debug-full
cmake --build --preset debug-full --target format-check
```

**Expected output (clean):**
Expand All @@ -65,16 +69,20 @@ The command exits with a non-zero status if any file is unformatted, making it s

### Auto-Fixing Formatting

Applies formatting rules to all source and header files:
Applies formatting rules to all source and header files.

**Prerequisites:** Install `clang-format` first (see [Common Issues](#clang-format-not-found)).

```bash
cmake --build build --target format-fix
cmake --preset debug-full
cmake --build --preset debug-full --target format-fix
```

**Real example:**

```bash
cmake --build build/release --target format-fix
cmake --preset debug-full
cmake --build --preset debug-full --target format-fix
```

**Expected output:**
Expand Down Expand Up @@ -117,14 +125,18 @@ clang-format -i src/*.cpp include/**/*.hpp tests/*.cpp

### Running the Linter

**Prerequisites:** Install `clang-tidy` first (see [Common Issues](#clang-tidy-not-found)).

```bash
cmake --build build --target lint
cmake --preset debug-full
cmake --build --preset debug-full --target lint
```

**Real example:**

```bash
cmake --build build/release --target lint
cmake --preset debug-full
cmake --build --preset debug-full --target lint
```

**Expected output (clean):**
Expand Down Expand Up @@ -192,14 +204,18 @@ Verifies that every header file in `include/` contains `#pragma once` at the top

### Running the Check

**Prerequisites:** Configure the project first with `cmake --preset debug-full` (or any preset).

```bash
cmake --build build --target check-headers
cmake --preset debug-full
cmake --build --preset debug-full --target check-headers
```

**Real example:**

```bash
cmake --build build/release --target check-headers
cmake --preset debug-full
cmake --build --preset debug-full --target check-headers
```

**Expected output (clean):**
Expand Down Expand Up @@ -405,16 +421,20 @@ Enforced by `.clang-tidy` via `readability-identifier-naming`:

1. **Write code** in your editor/IDE
2. **Save files** — your editor may auto-format on save if configured
3. **Run format-fix** to ensure consistent formatting:
3. **Configure once** (generates build files and finds clang-format/clang-tidy):
```bash
cmake --build build/release --target format-fix
cmake --preset debug-full
```
4. **Run lint** to catch issues early:
4. **Run format-fix** to ensure consistent formatting:
```bash
cmake --build build/release --target lint
cmake --build --preset debug-full --target format-fix
```
5. **Fix any warnings** reported by lint
6. **Commit** — pre-commit hooks run clang-format as a safety net:
5. **Run lint** to catch issues early:
```bash
cmake --build --preset debug-full --target lint
```
6. **Fix any warnings** reported by lint
7. **Commit** — pre-commit hooks run clang-format as a safety net:
```bash
git add .
git commit -m "Add feature"
Expand All @@ -425,20 +445,23 @@ Enforced by `.clang-tidy` via `readability-identifier-naming`:
Run all checks to ensure CI will pass:

```bash
# Configure first (required for all lint targets)
cmake --preset debug-full

# Format check
cmake --build build/release --target format-check
cmake --build --preset debug-full --target format-check

# Lint
cmake --build build/release --target lint
cmake --build --preset debug-full --target lint

# Header check
cmake --build build/release --target check-headers
cmake --build --preset debug-full --target check-headers

# Build
cmake --build --preset release
cmake --build --preset debug-full

# Test
ctest --preset release
ctest --preset debug-full --output-on-failure

# Pre-commit on all files
pre-commit run --all-files
Expand Down Expand Up @@ -519,11 +542,12 @@ pre-commit install

| Task | Command |
|---|---|
| Check formatting | `cmake --build build/release --target format-check` |
| Auto-fix formatting | `cmake --build build/release --target format-fix` |
| Run linter | `cmake --build build/release --target lint` |
| Check headers | `cmake --build build/release --target check-headers` |
| Enforce during build | `cmake --preset release -DENABLE_LINTING=ON` |
| Configure (required first) | `cmake --preset debug-full` |
| Check formatting | `cmake --build --preset debug-full --target format-check` |
| Auto-fix formatting | `cmake --build --preset debug-full --target format-fix` |
| Run linter | `cmake --build --preset debug-full --target lint` |
| Check headers | `cmake --build --preset debug-full --target check-headers` |
| Enforce during build | `cmake --preset debug-full` (linting enabled by default) |
| Install pre-commit | `pip install pre-commit && pre-commit install` |
| Run all hooks | `pre-commit run --all-files` |

Expand Down
Loading
Loading