Skip to content

Commit 0c9eda1

Browse files
authored
fix: if show-fixes is set in config, count that (#686)
Signed-off-by: Henry Schreiner <[email protected]>
1 parent 853b0f6 commit 0c9eda1

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ messages_control.disable = [
155155
"invalid-name",
156156
"redefined-outer-name",
157157
"no-member", # better handled by mypy, etc.
158+
"arguments-differ", # better handled by mypy, etc.
158159
]
159160

160161

src/sp_repo_review/checks/precommit.py

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

151151
@classmethod
152-
def check(cls, precommit: dict[str, Any]) -> bool | None:
152+
def check(cls, precommit: dict[str, Any], ruff: dict[str, Any]) -> bool | None: # type: ignore[override]
153153
"""
154154
If `--fix` is present, `--show-fixes` must be too.
155155
"""
@@ -161,7 +161,7 @@ def check(cls, precommit: dict[str, Any]) -> bool | None:
161161
and "args" in hook
162162
and "--fix" in hook["args"]
163163
):
164-
return "--show-fixes" in hook["args"]
164+
return "--show-fixes" in hook["args"] or "show-fixes" in ruff
165165
return None
166166
return False
167167

tests/test_precommit.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,18 @@ def test_pc191(ruff_check: str):
182182
- id: {ruff_check}
183183
args: ["--fix", "--show-fixes"]
184184
""")
185-
assert compute_check("PC191", precommit=precommit).result
185+
assert compute_check("PC191", precommit=precommit, ruff={}).result
186+
187+
188+
def test_pc191_ruffconfig(ruff_check: str):
189+
precommit = yaml.safe_load(f"""
190+
repos:
191+
- repo: https://github.com/astral-sh/ruff-pre-commit
192+
hooks:
193+
- id: {ruff_check}
194+
args: ["--fix"]
195+
""")
196+
assert compute_check("PC191", precommit=precommit, ruff={"show-fixes": True}).result
186197

187198

188199
def test_pc191_no_show_fixes(ruff_check: str):
@@ -193,7 +204,7 @@ def test_pc191_no_show_fixes(ruff_check: str):
193204
- id: {ruff_check}
194205
args: ["--fix"]
195206
""")
196-
res = compute_check("PC191", precommit=precommit)
207+
res = compute_check("PC191", precommit=precommit, ruff={})
197208
assert not res.result
198209
assert "--show-fixes" in res.err_msg
199210

0 commit comments

Comments
 (0)