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]