Skip to content

Commit

Permalink
feat(pre-commit): suggest pre-commit install
Browse files Browse the repository at this point in the history
  • Loading branch information
andreoliwa committed Mar 2, 2019
1 parent 062b13e commit 76b980f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions flake8_nitpick/__init__.py
Expand Up @@ -274,6 +274,7 @@ class BaseChecker(NitpickMixin):

file_name: str
error_base_number = 300
missing_file_extra_message: Optional[str] = None

def __init__(self, config: NitpickConfig) -> None:
"""Init instance."""
Expand All @@ -294,10 +295,12 @@ def check_exists(self) -> YieldFlake8Error:

if should_exist and not file_exists:
suggestion = self.suggest_initial_file()
message = "Missing file"
phrases = ["Missing file"]
if self.missing_file_extra_message:
phrases.append(self.missing_file_extra_message)
if suggestion:
message = f"{message}. Suggested initial content:\n{suggestion}"
yield self.flake8_error(1, message)
phrases.append(f"Suggested initial content:\n{suggestion}")
yield self.flake8_error(1, ". ".join(phrases))
elif not should_exist and file_exists:
yield self.flake8_error(2, "File should be deleted")
elif file_exists:
Expand Down Expand Up @@ -424,6 +427,7 @@ class PreCommitChecker(BaseChecker):

file_name = ".pre-commit-config.yaml"
error_base_number = 330
missing_file_extra_message = "Run 'pre-commit install' to install the hooks"

KEY_REPOS = "repos"
KEY_HOOKS = "hooks"
Expand Down
4 changes: 2 additions & 2 deletions tests/test_pre_commit.py
Expand Up @@ -23,7 +23,7 @@ def test_missing_pre_commit_config_yaml(request):
)
project.assert_errors_contain(
"""
NIP331 File: .pre-commit-config.yaml: Missing file. Suggested initial content:
NIP331 File: .pre-commit-config.yaml: Missing file. Run 'pre-commit install' to install the hooks. Suggested initial content:
repos:
- hooks:
- any: valid
Expand Down Expand Up @@ -51,7 +51,7 @@ def test_root_values_on_missing_file(request):
)
project.assert_errors_contain(
"""
NIP331 File: .pre-commit-config.yaml: Missing file. Suggested initial content:
NIP331 File: .pre-commit-config.yaml: Missing file. Run 'pre-commit install' to install the hooks. Suggested initial content:
fail_fast: true
whatever: '1'
"""
Expand Down

0 comments on commit 76b980f

Please sign in to comment.