Skip to content

Commit 8b6a945

Browse files
committed
fix: allow flake8 as a linter too
Signed-off-by: Henry Schreiner <henryfs@princeton.edu>
1 parent e05c33a commit 8b6a945

2 files changed

Lines changed: 45 additions & 8 deletions

File tree

src/sp_repo_review/checks/precommit.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class PreCommit:
2828
url = mk_url("style")
2929
renamed: ClassVar[dict[str, str]] = {}
3030
repos: ClassVar[set[str]] = set()
31-
ids: ClassVar[dict[str, str]] = {}
31+
ids: ClassVar[dict[str, set[str]]] = {}
3232

3333
@property
3434
def describe(self) -> str:
@@ -53,7 +53,7 @@ def check(cls, precommit: dict[str, Any]) -> bool | None | str:
5353
if repo in cls.repos:
5454
if cls.ids and repo in cls.ids:
5555
if any(
56-
hook.get("id", "") == cls.ids[repo]
56+
hook.get("id", "") in cls.ids[repo]
5757
for hook in repo_item.get("hooks", {})
5858
):
5959
return True
@@ -83,7 +83,7 @@ class PC110(PreCommit):
8383
renamed = {
8484
"https://github.com/psf/black": "https://github.com/psf/black-pre-commit-mirror"
8585
}
86-
ids = {"https://github.com/astral-sh/ruff-pre-commit": "ruff-format"}
86+
ids = {"https://github.com/astral-sh/ruff-pre-commit": {"ruff-format"}}
8787

8888

8989
class PC111(PreCommit):
@@ -97,12 +97,17 @@ class PC111(PreCommit):
9797

9898

9999
class PC190(PreCommit):
100-
"Uses Ruff"
100+
"Uses a linter (Ruff/Flake8)"
101101

102-
repos = {"https://github.com/astral-sh/ruff-pre-commit"}
102+
repos = {
103+
"https://github.com/astral-sh/ruff-pre-commit",
104+
"https://github.com/pycqa/flake8",
105+
}
103106
renamed = {
104-
"https://github.com/charliermarsh/ruff-pre-commit": "https://github.com/astral-sh/ruff-pre-commit"
107+
"https://github.com/charliermarsh/ruff-pre-commit": "https://github.com/astral-sh/ruff-pre-commit",
108+
"https://gitlab.com/pycqa/flake8 ": "https://github.com/pycqa/flake8",
105109
}
110+
ids = {"https://github.com/astral-sh/ruff-pre-commit": {"ruff-check", "ruff"}}
106111

107112

108113
class PC140(PreCommit):

tests/test_precommit.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,24 +76,56 @@ def test_pc111_rename():
7676
assert "adamchainz" in res.err_msg
7777

7878

79-
def test_pc190():
79+
def test_pc190_ruff_check():
8080
precommit = yaml.safe_load("""
8181
repos:
8282
- repo: https://github.com/astral-sh/ruff-pre-commit
83+
hooks:
84+
- id: ruff-check
85+
""")
86+
assert compute_check("PC190", precommit=precommit).result
87+
88+
89+
def test_pc190_ruff():
90+
precommit = yaml.safe_load("""
91+
repos:
92+
- repo: https://github.com/astral-sh/ruff-pre-commit
93+
hooks:
94+
- id: ruff
95+
""")
96+
assert compute_check("PC190", precommit=precommit).result
97+
98+
99+
def test_pc190_flake8():
100+
precommit = yaml.safe_load("""
101+
repos:
102+
- repo: https://github.com/pycqa/flake8
83103
""")
84104
assert compute_check("PC190", precommit=precommit).result
85105

86106

87-
def test_pc190_rename():
107+
def test_pc190_rename_ruff():
88108
precommit = yaml.safe_load("""
89109
repos:
90110
- repo: https://github.com/charliermarsh/ruff-pre-commit
111+
hooks:
112+
- id: ruff-check
91113
""")
92114
res = compute_check("PC190", precommit=precommit)
93115
assert not res.result
94116
assert "astral-sh" in res.err_msg
95117

96118

119+
def test_pc190_rename_flake8():
120+
precommit = yaml.safe_load("""
121+
repos:
122+
- repo: https://gitlab.com/pycqa/flake8
123+
""")
124+
res = compute_check("PC190", precommit=precommit)
125+
assert not res.result
126+
assert "github" in res.err_msg
127+
128+
97129
def test_pc140():
98130
precommit = yaml.safe_load("""
99131
repos:

0 commit comments

Comments
 (0)