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

Add specific prettier-commit config for prettier check, improve log message #2100

Merged
merged 6 commits into from
Dec 7, 2022
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 MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ graft nf_core/module-template
graft nf_core/pipeline-template
graft nf_core/subworkflow-template
include requirements.txt
include .pre-commit-config.yaml
include nf_core/.pre-commit-prettier-config.yaml
5 changes: 5 additions & 0 deletions nf_core/.pre-commit-prettier-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
repos:
- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v2.6.2"
hooks:
- id: prettier
8 changes: 6 additions & 2 deletions nf_core/lint_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def run_prettier_on_file(file):
If Prettier is not installed, a warning is logged.
"""

nf_core_pre_commit_config = Path(nf_core.__file__).parent.parent / ".pre-commit-config.yaml"
nf_core_pre_commit_config = Path(nf_core.__file__).parent / ".pre-commit-prettier-config.yaml"
try:
subprocess.run(
["pre-commit", "run", "--config", nf_core_pre_commit_config, "prettier", "--files", file],
Expand All @@ -73,7 +73,11 @@ def run_prettier_on_file(file):
except subprocess.CalledProcessError as e:
if ": SyntaxError: " in e.stdout.decode():
log.critical(f"Can't format {file} because it has a syntax error.\n{e.stdout.decode()}")
else:
elif "files were modified by this hook" in e.stdout.decode():
all_lines = [line for line in e.stdout.decode().split("\n")]
files = "\n".join(all_lines[3:])
log.debug(f"The following files were modified by prettier:\n {files}")
elif e.stderr.decode():
log.warning(
"There was an error running the prettier pre-commit hook.\n"
f"STDOUT: {e.stdout.decode()}\nSTDERR: {e.stderr.decode()}"
Expand Down