Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ messages_control.disable = [
]


[tool.ruff]
show-fixes = true
extend-exclude = ["\\{\\{cookiecutter.project_name\\}\\}"]

[tool.ruff.lint]
extend-select = [
"ARG", # flake8-unused-arguments
Expand Down
11 changes: 10 additions & 1 deletion src/sp_repo_review/checks/precommit.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,5 +245,14 @@ def check(precommit: dict[str, Any]) -> bool:
return "autoupdate_schedule" in precommit.get("ci", {})


def repo_review_checks() -> dict[str, PreCommit]:
def repo_review_checks(
list_all: bool = True,
root: Traversable | None = None,
) -> dict[str, PreCommit]:
if root and not list_all:
precommit_path = root.joinpath(".pre-commit-config.yaml")
lefthook_path = root.joinpath("lefthook.yml")
if not precommit_path.is_file() and lefthook_path.is_file():
return {}

return {p.__name__: p() for p in PreCommit.__subclasses__()}
18 changes: 18 additions & 0 deletions tests/test_precommit.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from pathlib import Path

import pytest
import yaml
from repo_review.testing import compute_check

from sp_repo_review.checks.precommit import repo_review_checks


@pytest.fixture(params=["ruff", "ruff-check"])
def ruff_check(request: pytest.FixtureRequest) -> str:
Expand Down Expand Up @@ -283,3 +287,17 @@ def test_pc903_no_msg():
res = compute_check("PC903", precommit=precommit)
assert not res.result
assert "autoupdate_schedule" in res.err_msg


def test_repo_review_checks_skips_with_lefthook_only(tmp_path: Path) -> None:
"""PreCommit checks should be omitted if only lefthook.yml is present.

When a repository uses `lefthook.yml` and does not have a
`.pre-commit-config.yaml`, `repo_review_checks` should return an empty
mapping when `list_all=False` indicating the pre-commit family is skipped.
"""
# Create only a lefthook configuration
(tmp_path / "lefthook.yml").write_text("hooks:\n", encoding="utf-8")

checks = repo_review_checks(list_all=False, root=tmp_path)
assert checks == {}