File tree Expand file tree Collapse file tree 3 files changed +32
-1
lines changed
src/sp_repo_review/checks Expand file tree Collapse file tree 3 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -159,6 +159,10 @@ messages_control.disable = [
159159]
160160
161161
162+ [tool .ruff ]
163+ show-fixes = true
164+ extend-exclude = [" \\ {\\ {cookiecutter.project_name\\ }\\ }" ]
165+
162166[tool .ruff .lint ]
163167extend-select = [
164168 " ARG" , # flake8-unused-arguments
Original file line number Diff line number Diff line change @@ -245,5 +245,14 @@ def check(precommit: dict[str, Any]) -> bool:
245245 return "autoupdate_schedule" in precommit .get ("ci" , {})
246246
247247
248- def repo_review_checks () -> dict [str , PreCommit ]:
248+ def repo_review_checks (
249+ list_all : bool = True ,
250+ root : Traversable | None = None ,
251+ ) -> dict [str , PreCommit ]:
252+ if root and not list_all :
253+ precommit_path = root .joinpath (".pre-commit-config.yaml" )
254+ lefthook_path = root .joinpath ("lefthook.yml" )
255+ if not precommit_path .is_file () and lefthook_path .is_file ():
256+ return {}
257+
249258 return {p .__name__ : p () for p in PreCommit .__subclasses__ ()}
Original file line number Diff line number Diff line change 1+ from pathlib import Path
2+
13import pytest
24import yaml
35from repo_review .testing import compute_check
46
7+ from sp_repo_review .checks .precommit import repo_review_checks
8+
59
610@pytest .fixture (params = ["ruff" , "ruff-check" ])
711def ruff_check (request : pytest .FixtureRequest ) -> str :
@@ -283,3 +287,17 @@ def test_pc903_no_msg():
283287 res = compute_check ("PC903" , precommit = precommit )
284288 assert not res .result
285289 assert "autoupdate_schedule" in res .err_msg
290+
291+
292+ def test_repo_review_checks_skips_with_lefthook_only (tmp_path : Path ) -> None :
293+ """PreCommit checks should be omitted if only lefthook.yml is present.
294+
295+ When a repository uses `lefthook.yml` and does not have a
296+ `.pre-commit-config.yaml`, `repo_review_checks` should return an empty
297+ mapping when `list_all=False` indicating the pre-commit family is skipped.
298+ """
299+ # Create only a lefthook configuration
300+ (tmp_path / "lefthook.yml" ).write_text ("hooks:\n " , encoding = "utf-8" )
301+
302+ checks = repo_review_checks (list_all = False , root = tmp_path )
303+ assert checks == {}
You can’t perform that action at this time.
0 commit comments