diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..39f8f126 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,24 @@ +# Runs the same Ruff checks as CI on the development code. Install with +# uvx pre-commit install +# Keep the Ruff revision equal to the version in uv.lock. +repos: + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.17.3 + hooks: + - id: ruff-check + files: ^(scripts|src|tests)/ + - id: ruff-format + files: ^(scripts|src|tests)/ + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v6.0.0 + hooks: + - id: check-yaml + exclude: ^tasks/ + - id: check-toml + exclude: ^tasks/ + - id: check-json + files: ^src/websitebench/.*\.json$ + - id: end-of-file-fixer + exclude: ^(tasks/|assets/) + - id: trailing-whitespace + exclude: ^(tasks/|assets/) diff --git a/docs/development.md b/docs/development.md index 898bc24e..3550326e 100644 --- a/docs/development.md +++ b/docs/development.md @@ -41,6 +41,12 @@ Format edited development code with: uv run ruff format scripts src tests ``` +To run Ruff and basic YAML, TOML and whitespace checks on every commit, install the [pre-commit](https://pre-commit.com/) hooks: + +```sh +uvx pre-commit install +``` + ## CI [CI](../.github/workflows/ci.yml) runs on Python 3.12 and 3.13. It installs locked dependencies, checks source task definitions, runs the unit tests and Ruff checks, and verifies the official Harbor command's help output.