Skip to content

Commit bfaa3fd

Browse files
authored
fix: PC191 raising TypeError when no ruff config present (#746)
* Add failing unit test * Switch to parametrized test * Fix PC191 raising TypeError when no ruff config present
1 parent 24700e7 commit bfaa3fd

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

src/sp_repo_review/checks/precommit.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,11 @@ class PC191(PreCommit):
149149
repos = {"https://github.com/astral-sh/ruff-pre-commit"}
150150

151151
@classmethod
152-
def check(cls, precommit: dict[str, Any], ruff: dict[str, Any]) -> bool | None: # type: ignore[override]
152+
def check( # type: ignore[override]
153+
cls,
154+
precommit: dict[str, Any],
155+
ruff: dict[str, Any] | None,
156+
) -> bool | None:
153157
"""
154158
If `--fix` is present, `--show-fixes` must be too.
155159
"""
@@ -161,7 +165,9 @@ def check(cls, precommit: dict[str, Any], ruff: dict[str, Any]) -> bool | None:
161165
and "args" in hook
162166
and "--fix" in hook["args"]
163167
):
164-
return "--show-fixes" in hook["args"] or "show-fixes" in ruff
168+
return "--show-fixes" in hook["args"] or (
169+
ruff is not None and "show-fixes" in ruff
170+
)
165171
return None
166172
return False
167173

tests/test_precommit.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,15 +200,16 @@ def test_pc191_ruffconfig(ruff_check: str):
200200
assert compute_check("PC191", precommit=precommit, ruff={"show-fixes": True}).result
201201

202202

203-
def test_pc191_no_show_fixes(ruff_check: str):
203+
@pytest.mark.parametrize("ruffconfig", [{}, None])
204+
def test_pc191_no_show_fixes(ruff_check: str, ruffconfig):
204205
precommit = yaml.safe_load(f"""
205206
repos:
206207
- repo: https://github.com/astral-sh/ruff-pre-commit
207208
hooks:
208209
- id: {ruff_check}
209210
args: ["--fix"]
210211
""")
211-
res = compute_check("PC191", precommit=precommit, ruff={})
212+
res = compute_check("PC191", precommit=precommit, ruff=ruffconfig)
212213
assert not res.result
213214
assert "--show-fixes" in res.err_msg
214215

0 commit comments

Comments
 (0)