From c10f5a48f2316b45ec5aa541ea3478e42c5ad43e Mon Sep 17 00:00:00 2001 From: Matt Fisher Date: Sat, 28 Feb 2026 14:26:08 -0700 Subject: [PATCH 1/3] Add failing unit test --- tests/test_precommit.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/test_precommit.py b/tests/test_precommit.py index 618a39c7..e41d3e47 100644 --- a/tests/test_precommit.py +++ b/tests/test_precommit.py @@ -213,6 +213,19 @@ def test_pc191_no_show_fixes(ruff_check: str): assert "--show-fixes" in res.err_msg +def test_pc191_no_show_fixes_no_ruffconfig(ruff_check: str): + precommit = yaml.safe_load(f""" + repos: + - repo: https://github.com/astral-sh/ruff-pre-commit + hooks: + - id: {ruff_check} + args: ["--fix"] + """) + res = compute_check("PC191", precommit=precommit, ruff=None) + assert not res.result + assert "--show-fixes" in res.err_msg + + def test_pc192(): precommit = yaml.safe_load(""" repos: From 94d73dd9b87f356832334c3106aa18d0aec0c673 Mon Sep 17 00:00:00 2001 From: Matt Fisher Date: Sat, 28 Feb 2026 14:30:56 -0700 Subject: [PATCH 2/3] Switch to parametrized test --- tests/test_precommit.py | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/tests/test_precommit.py b/tests/test_precommit.py index e41d3e47..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,20 +209,7 @@ def test_pc191_no_show_fixes(ruff_check: str): - id: {ruff_check} args: ["--fix"] """) - res = compute_check("PC191", precommit=precommit, ruff={}) - assert not res.result - assert "--show-fixes" in res.err_msg - - -def test_pc191_no_show_fixes_no_ruffconfig(ruff_check: str): - precommit = yaml.safe_load(f""" - repos: - - repo: https://github.com/astral-sh/ruff-pre-commit - hooks: - - id: {ruff_check} - args: ["--fix"] - """) - res = compute_check("PC191", precommit=precommit, ruff=None) + res = compute_check("PC191", precommit=precommit, ruff=ruffconfig) assert not res.result assert "--show-fixes" in res.err_msg From 0031a567826e730a44f65e05009ab61dcc509215 Mon Sep 17 00:00:00 2001 From: Matt Fisher Date: Sat, 28 Feb 2026 14:20:44 -0700 Subject: [PATCH 3/3] Fix PC191 raising TypeError when no ruff config present --- src/sp_repo_review/checks/precommit.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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