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 .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
}
},

"postCreateCommand": "pre-commit install --hook-type pre-push",
"postStartCommand": "bash",

// Clean container name and setup
"runArgs": [
"--rm",
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Install deps
run: sudo apt-get update && sudo apt-get install -y cmake clang-format
run: sudo apt-get update && sudo apt-get install -y cmake clang-format clang-tidy
- name: Format check
run: ./scripts/format.sh --check
- name: Build
run: mkdir -p build && cd build && cmake .. && make
- name: Lint check
run: ./scripts/lint.sh
- name: Test
run: cd build && ctest --output-on-failure
18 changes: 11 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
repos:
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v14.0.0
- repo: local
hooks:
- id: clang-format
args: ["--style=file"]
name: clang-format
entry: ./scripts/format.sh --check
language: system
stages: [pre-push]
pass_filenames: false
types: [c, c++]

- repo: local
hooks:

- id: clang-tidy
name: clang-tidy
entry: ./scripts/lint_precommit.sh
description: "Requires build directory with compile_commands.json to exist. Please build the project before pushing."
entry: ./scripts/lint.sh
language: system
stages: [pre-push]
pass_filenames: false
types: [c, c++]
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ A modern, production-ready template for C++ development.

```bash
git clone <your-fork> my_project && cd my_project

# Install pre-commit hooks (for code quality checks on push)
pre-commit install --hook-type pre-push

./scripts/fetch_googletest.sh # optional, only if you need tests
cmake -S . -B build # -DENABLE_TESTS=OFF to skip tests
cmake --build build -j$(nproc)
Expand Down
22 changes: 18 additions & 4 deletions scripts/format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,24 @@

# --------------------------------------------------------------------
# Format all C++ source/header files in the project using clang-format
# Usage:
# ./format.sh - Format files in-place
# ./format.sh --check - Check formatting without modifying files
# --------------------------------------------------------------------

#!/usr/bin/env bash
set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"

echo "[INFO] Running clang-format on source files..."
# Check if --check flag is passed
CHECK_MODE=false
if [[ "$1" == "--check" ]]; then
CHECK_MODE=true
echo "[INFO] Running clang-format in check mode (no modifications)..."
else
echo "[INFO] Running clang-format on source files..."
fi

EXTENSIONS=("*.cpp" "*.hpp" "*.cc" "*.h" "*.cxx" "*.hxx")
FOUND=false
Expand All @@ -20,8 +29,13 @@ for ext in "${EXTENSIONS[@]}"; do

for f in $FILES; do
FOUND=true
echo "Formatting $f"
clang-format -i "$f"
if $CHECK_MODE; then
echo "Checking $f"
clang-format --dry-run --Werror "$f"
else
echo "Formatting $f"
clang-format -i "$f"
fi
done
done

Expand Down