Skip to content

Commit 371c6f4

Browse files
authored
fix: correct logic for RF002 (#409)
Signed-off-by: Henry Schreiner <[email protected]>
1 parent 3b6de6c commit 371c6f4

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

src/sp_repo_review/checks/ruff.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,12 @@ def check(pyproject: dict[str, Any], ruff: dict[str, Any]) -> bool | str:
7373
"""
7474

7575
match pyproject:
76+
case {
77+
"project": {"requires-python": str()},
78+
"tool": {"ruff": {"target-version": object()}},
79+
}:
80+
return "You have both Ruff's `target-version` and `project.requires-python`. You only need the latter."
7681
case {"project": {"requires-python": str()}}:
77-
if "target-version" in ruff:
78-
return "You have both Ruff's `target-version` and `project.requires-python`. You only need the latter."
7982
return True
8083
case _:
8184
return "target-version" in ruff

tests/test_ruff.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from sp_repo_review._compat import tomllib
2+
from sp_repo_review.checks import ruff
3+
4+
5+
def test_rf003_with_rp():
6+
toml = tomllib.loads("""
7+
project.requires-python = ">=3.12"
8+
tool.ruff.anything = "1"
9+
""")
10+
assert ruff.RF002.check(toml, toml["tool"]["ruff"])
11+
12+
13+
def test_rf003_no_rp():
14+
toml = tomllib.loads("""
15+
project.name = "hi"
16+
tool.ruff.target-version = "3.12"
17+
""")
18+
assert ruff.RF002.check(toml, toml["tool"]["ruff"])
19+
20+
21+
def test_rf003_both():
22+
toml = tomllib.loads("""
23+
project.requires-python = ">=3.12"
24+
tool.ruff.target-version = "3.12"
25+
""")
26+
assert isinstance(ruff.RF002.check(toml, toml["tool"]["ruff"]), str)
27+
28+
29+
def test_rf003_split_ok():
30+
toml = tomllib.loads("""
31+
project.requires-python = ">=3.12"
32+
""")
33+
assert ruff.RF002.check(toml, {"target-version": "3.12"})

0 commit comments

Comments
 (0)