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

ENH: update Prettier pre-commit URL to ComPWA #386

Merged
merged 3 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ repos:
language: python
files: ^\.pre\-commit\-(config|hooks)\.yaml$

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v4.0.0-alpha.8
- repo: https://github.com/ComPWA/prettier-pre-commit
rev: v3.3.3
hooks:
- id: prettier

Expand Down
2 changes: 0 additions & 2 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,3 @@ dependencies:
- pip
- pip:
- -e .[dev]
variables:
PRETTIER_LEGACY_CLI: 1
7 changes: 1 addition & 6 deletions src/compwa_policy/.template/.cspell.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
{
"version": "0.2",
"enableFiletypes": [
"git-commit",
"github-actions-workflow",
"julia",
"jupyter"
],
"enableFiletypes": ["git-commit", "github-actions-workflow", "julia", "jupyter"],
"flagWords": [
"analyse",
"colour",
Expand Down
2 changes: 1 addition & 1 deletion src/compwa_policy/check_dev_files/precommit.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def _update_conda_environment(precommit: Precommit) -> None:


def __has_prettier_v4alpha(config: PrecommitConfig) -> bool:
repo = find_repo(config, search_pattern=r"^.*/mirrors-prettier$")
repo = find_repo(config, search_pattern=r"^.*/(mirrors-)?prettier(-pre-commit)?$")
if repo is None:
return False
rev = repo.get("rev", "")
Expand Down
17 changes: 14 additions & 3 deletions src/compwa_policy/check_dev_files/prettier.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from compwa_policy.utilities.readme import add_badge, remove_badge

if TYPE_CHECKING:
from compwa_policy.utilities.precommit import Precommit
from compwa_policy.utilities.precommit import ModifiablePrecommit

# cspell:ignore esbenp rettier
__VSCODE_EXTENSION_NAME = "esbenp.prettier-vscode"
Expand All @@ -25,14 +25,15 @@
__EXPECTED_CONFIG = __STREAM.read()


def main(precommit: Precommit, no_prettierrc: bool) -> None:
if precommit.find_repo(r".*/mirrors-prettier") is None:
def main(precommit: ModifiablePrecommit, no_prettierrc: bool) -> None:
if precommit.find_repo(r".*/(mirrors-)?prettier(-pre-commit)?$") is None:
_remove_configuration()
else:
with Executor() as do:
do(_fix_config_content, no_prettierrc)
do(add_badge, __BADGE)
do(vscode.add_extension_recommendation, __VSCODE_EXTENSION_NAME)
do(_update_prettier_hook, precommit)
do(_update_prettier_ignore)


Expand Down Expand Up @@ -84,6 +85,16 @@ def __remove_prettierrc() -> None:
raise PrecommitError(msg)


def _update_prettier_hook(precommit: ModifiablePrecommit) -> None:
repo = precommit.find_repo(r".*/mirrors-prettier$")
if repo is None:
repo = precommit.find_repo(r".*/prettier$")
redeboer marked this conversation as resolved.
Show resolved Hide resolved
if repo is None:
return
repo["repo"] = "https://github.com/ComPWA/prettier-pre-commit"
precommit.changelog.append("Updated URL for Prettier pre-commit hook")


def _update_prettier_ignore() -> None:
__remove_forbidden_paths()
__insert_expected_paths()
Expand Down
Loading