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

Hook fail_fast stops pre-commit if any prior hook fails #3167

Closed
tp832944 opened this issue Mar 22, 2024 · 0 comments · Fixed by #3168
Closed

Hook fail_fast stops pre-commit if any prior hook fails #3167

tp832944 opened this issue Mar 22, 2024 · 0 comments · Fixed by #3168

Comments

@tp832944
Copy link

tp832944 commented Mar 22, 2024

search you tried in the issue tracker

fail fast hook

describe your issue

Description

Hook fail_fast says in the documentation that pre-commit will stop if this hook fails, which suggests it is referring only to the present hook. The actual behaviour appears to be that pre-commit will stop if this or any previous hook fails.

Example

Add a Python file containing including a blank line at the end:

def my_function(b=):
    a = "a"

Use the config below and call pre-commit run -a.

Expected behaviour

All three hooks run. The first and third fail.

Observed behaviour

The first two hooks run. The first hook fails and the second hook passes.

Note

I had previously submitted this as a documentation issue (pre-commit/pre-commit.com#945), because I find the actual behaviour quite useful, as it means we can avoid running a slow hook (e.g. pytest) if any other hook has failed. However, @asottile said this is not the intended behaviour, so resubmitting here as a bug.

pre-commit --version

pre-commit 3.6.2

.pre-commit-config.yaml

repos:
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v4.5.0
    hooks:
      - id: check-ast
      - id: end-of-file-fixer
        fail_fast: true
      - id: double-quote-string-fixer

~/.cache/pre-commit/pre-commit.log (if present)

Log from terminal, not file.

> pre-commit run -a
check python ast.........................................................Failed
- hook id: check-ast
- exit code: 1

file1.py: failed parsing with CPython 3.11.7:

    Traceback (most recent call last):
      File "<path_redacted>\check_ast.py", line 21, in main
        ast.parse(f.read(), filename=filename)
      File "C:\Program Files\Python311\Lib\ast.py", line 50, in parse
        return compile(source, filename, mode, flags,
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "file1.py", line 1
        def my_function(b=):
                         ^
    SyntaxError: expected default value expression

fix end of files.........................................................Passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant