From e64a2c226e9886cc4985b1e0b3b43b104b562d02 Mon Sep 17 00:00:00 2001 From: Iiro Rahkonen Date: Sat, 21 Feb 2026 19:05:10 +0200 Subject: [PATCH] feat: Add pre-commit hooks for ruff, mypy, and pytest Adds .pre-commit-config.yaml with local hooks that run ruff check, mypy type checking, and pytest before each commit. Also fixes a ruff SIM114 lint violation in protect_directories.py. Co-Authored-By: Claude Opus 4.6 --- .pre-commit-config.yaml | 21 +++++++++++++++++++++ hooks/protect_directories.py | 6 +++--- pyproject.toml | 1 + 3 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..0919707 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,21 @@ +repos: + - repo: local + hooks: + - id: ruff + name: ruff + entry: python -m ruff check --fix + language: system + types: [python] + + - id: mypy + name: mypy + entry: python -m mypy --ignore-missing-imports + language: system + files: ^hooks/protect_directories\.py$ + + - id: pytest + name: pytest + entry: python -m pytest tests/ -x -q + language: system + pass_filenames: false + always_run: true diff --git a/hooks/protect_directories.py b/hooks/protect_directories.py index 266216d..d104d5d 100755 --- a/hooks/protect_directories.py +++ b/hooks/protect_directories.py @@ -751,9 +751,9 @@ def get_bash_target_paths(command: str) -> list: scan = i + 1 while scan < len(tokens) and tokens[scan] not in ("|", ";", "&", "&&", "||"): arg = tokens[scan] - if arg.startswith("--in-place"): - has_inplace = True - elif arg.startswith("-") and not arg.startswith("--") and "i" in arg[1:]: + if arg.startswith("--in-place") or ( + arg.startswith("-") and not arg.startswith("--") and "i" in arg[1:] + ): has_inplace = True if arg in ("-e", "-f"): has_explicit_script = True diff --git a/pyproject.toml b/pyproject.toml index 8e1d429..b507d27 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,6 +31,7 @@ packages = [] dev = [ "pytest>=7.0", "pytest-cov>=4.0", + "pre-commit>=3.0", ] [tool.pytest.ini_options]