Skip to content

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

@tp832944

Description

@tp832944

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions