Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: intelligently exclude Python files from editorconfig #365

Merged
merged 1 commit into from
Aug 7, 2024
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
2 changes: 1 addition & 1 deletion src/compwa_policy/check_dev_files/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def main(argv: Sequence[str] | None = None) -> int:
do(cspell.main, precommit_config, args.no_cspell_update)
do(dependabot.main, args.dependabot)
do(direnv.main)
do(editorconfig.main, precommit_config, args.no_python)
do(editorconfig.main, precommit_config)
if not args.allow_labels:
do(github_labels.main)
if not args.no_github_actions:
Expand Down
9 changes: 5 additions & 4 deletions src/compwa_policy/check_dev_files/editorconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,25 @@
from ruamel.yaml.scalarstring import FoldedScalarString

from compwa_policy.utilities import CONFIG_PATH
from compwa_policy.utilities.match import filter_files
from compwa_policy.utilities.precommit.struct import Hook, Repo

if TYPE_CHECKING:
from compwa_policy.utilities.precommit import ModifiablePrecommit


def main(precommit: ModifiablePrecommit, no_python: bool) -> None:
def main(precommit: ModifiablePrecommit) -> None:
if CONFIG_PATH.editorconfig.exists():
_update_precommit_config(precommit, no_python)
_update_precommit_config(precommit)


def _update_precommit_config(precommit: ModifiablePrecommit, no_python: bool) -> None:
def _update_precommit_config(precommit: ModifiablePrecommit) -> None:
hook = Hook(
id="editorconfig-checker",
name="editorconfig",
alias="ec",
)
if not no_python:
if filter_files(["**/*.py"]):
msg = R"""
(?x)^(
.*\.py
Expand Down

This file was deleted.

11 changes: 3 additions & 8 deletions tests/check_dev_files/editorconfig/test_editorconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
from compwa_policy.utilities.precommit import ModifiablePrecommit


@pytest.mark.parametrize("no_python", [True, False])
def test_update_precommit_config(no_python: bool):
def test_update_precommit_config():
this_dir = Path(__file__).parent
with open(this_dir / ".pre-commit-config-bad.yaml") as file:
src = file.read()
Expand All @@ -18,13 +17,9 @@ def test_update_precommit_config(no_python: bool):
with pytest.raises(
PrecommitError, match=r"Updated editorconfig-checker hook"
), ModifiablePrecommit.load(stream) as precommit:
_update_precommit_config(precommit, no_python)
_update_precommit_config(precommit)

result = precommit.dumps()
if no_python:
expected_file = this_dir / ".pre-commit-config-good-no-python.yaml"
else:
expected_file = this_dir / ".pre-commit-config-good.yaml"
with open(expected_file) as file:
with open(this_dir / ".pre-commit-config-good.yaml") as file:
expected = file.read()
assert result == expected
Loading