Short-circuit hooks · hack3ric/pre-commit@5d692d7 · GitHub
Skip to content

Commit 5d692d7

Browse files
mxrasottile
authored andcommitted
Short-circuit hooks
1 parent 0845e4e commit 5d692d7

4 files changed

Lines changed: 42 additions & 40 deletions

File tree

pre_commit/commands/run.py

Lines changed: 25 additions & 25 deletions

pre_commit/meta_hooks/check_hooks_apply.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def check_all_hooks_match_files(config_file: str) -> int:
2121
for hook in all_hooks(config, Store()):
2222
if hook.always_run or hook.language == 'fail':
2323
continue
24-
elif not classifier.filenames_for_hook(hook):
24+
elif not any(classifier.filenames_for_hook(hook)):
2525
print(f'{hook.id} does not apply to this repository')
2626
retv = 1
2727

pre_commit/meta_hooks/check_useless_excludes.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import argparse
44
import re
5+
from typing import Iterable
56
from typing import Sequence
67

78
from cfgv import apply_defaults
@@ -14,7 +15,7 @@
1415

1516

1617
def exclude_matches_any(
17-
filenames: Sequence[str],
18+
filenames: Iterable[str],
1819
include: str,
1920
exclude: str,
2021
) -> bool:
@@ -50,11 +51,12 @@ def check_useless_excludes(config_file: str) -> int:
5051
# Not actually a manifest dict, but this more accurately reflects
5152
# the defaults applied during runtime
5253
hook = apply_defaults(hook, MANIFEST_HOOK_DICT)
53-
names = classifier.filenames
54-
types = hook['types']
55-
types_or = hook['types_or']
56-
exclude_types = hook['exclude_types']
57-
names = classifier.by_types(names, types, types_or, exclude_types)
54+
names = classifier.by_types(
55+
classifier.filenames,
56+
hook['types'],
57+
hook['types_or'],
58+
hook['exclude_types'],
59+
)
5860
include, exclude = hook['files'], hook['exclude']
5961
if not exclude_matches_any(names, include, exclude):
6062
print(

tests/commands/run_test.py

Lines changed: 8 additions & 8 deletions

0 commit comments

Comments
 (0)