diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..18319fda --- /dev/null +++ b/.clang-format @@ -0,0 +1,5 @@ +BasedOnStyle: Google +ColumnLimit: 120 +DerivePointerAlignment: false +PointerAlignment: Left +AllowShortFunctionsOnASingleLine: Inline diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..6f035b3f --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,14 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v5.0.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-added-large-files + + - repo: https://github.com/pre-commit/mirrors-clang-format + rev: v20.1.5 + hooks: + - id: clang-format + args: [-style=file] + files: '\.(cpp|hpp|c|h|cc|hh)$' diff --git a/docs/manual/PreCommitSetup.md b/docs/manual/PreCommitSetup.md new file mode 100644 index 00000000..297829d4 --- /dev/null +++ b/docs/manual/PreCommitSetup.md @@ -0,0 +1,45 @@ +### Code Formatting and Pre-commit Hooks + +This project uses [pre-commit](https://pre-commit.com) to ensure code quality and consistent formatting. + +To set it up: + +1. **Create a Virtual Environment**: + Create and activate a Python virtual environment: + ```bash + python3 -m venv venv + source venv/bin/activate + ``` + +2. **Install Development Dependencies**: + Install the required dependencies for building the project: + ```bash + pip install -r requirements.txt + ``` + +3. **Install the Git hooks**: + + ```bash + pre-commit install + ``` + +To update the hooks to their latest versions later: + +```bash +pre-commit autoupdate +``` + +**DO NOT** run. It is not recomended on legacy repositories: + + ```bash + pre-commit run --all-files + ``` + +The following hooks are used: + +* `clang-format` for C/C++ formatting +* `trailing-whitespace` to remove trailing spaces +* `end-of-file-fixer` to ensure files end with a single newline +* `check-added-large-files` to avoid accidentally committing large binaries + +All configuration is in `.pre-commit-config.yaml`. The hooks will run automatically every time you commit. diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..6031a1ef --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +pre-commit==4.2.0 +clang-format==20.1.5