diff --git a/src/sp_repo_review/checks/precommit.py b/src/sp_repo_review/checks/precommit.py index 67189b2c..d6c2ee5c 100644 --- a/src/sp_repo_review/checks/precommit.py +++ b/src/sp_repo_review/checks/precommit.py @@ -149,7 +149,11 @@ class PC191(PreCommit): repos = {"https://github.com/astral-sh/ruff-pre-commit"} @classmethod - def check(cls, precommit: dict[str, Any], ruff: dict[str, Any]) -> bool | None: # type: ignore[override] + def check( # type: ignore[override] + cls, + precommit: dict[str, Any], + ruff: dict[str, Any] | None, + ) -> bool | None: """ If `--fix` is present, `--show-fixes` must be too. """ @@ -161,7 +165,9 @@ def check(cls, precommit: dict[str, Any], ruff: dict[str, Any]) -> bool | None: and "args" in hook and "--fix" in hook["args"] ): - return "--show-fixes" in hook["args"] or "show-fixes" in ruff + return "--show-fixes" in hook["args"] or ( + ruff is not None and "show-fixes" in ruff + ) return None return False diff --git a/tests/test_precommit.py b/tests/test_precommit.py index 618a39c7..595c6bc3 100644 --- a/tests/test_precommit.py +++ b/tests/test_precommit.py @@ -200,7 +200,8 @@ def test_pc191_ruffconfig(ruff_check: str): assert compute_check("PC191", precommit=precommit, ruff={"show-fixes": True}).result -def test_pc191_no_show_fixes(ruff_check: str): +@pytest.mark.parametrize("ruffconfig", [{}, None]) +def test_pc191_no_show_fixes(ruff_check: str, ruffconfig): precommit = yaml.safe_load(f""" repos: - repo: https://github.com/astral-sh/ruff-pre-commit @@ -208,7 +209,7 @@ def test_pc191_no_show_fixes(ruff_check: str): - id: {ruff_check} args: ["--fix"] """) - res = compute_check("PC191", precommit=precommit, ruff={}) + res = compute_check("PC191", precommit=precommit, ruff=ruffconfig) assert not res.result assert "--show-fixes" in res.err_msg