Skip to content

Commit a68c1ab

Browse files
committed
Add 'types' to the schema
1 parent 70bd821 commit a68c1ab

File tree

5 files changed

+23
-3
lines changed

5 files changed

+23
-3
lines changed

pre_commit/clientlib.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import functools
66

77
from aspy.yaml import ordered_load
8+
from identify.identify import ALL_TAGS
89

910
import pre_commit.constants as C
1011
from pre_commit import schema
@@ -19,6 +20,14 @@ def check_language(v):
1920
)
2021

2122

23+
def check_type_tag(tag):
24+
if tag not in ALL_TAGS:
25+
raise schema.ValidationError(
26+
'Type tag {!r} is not recognized. '
27+
'Try upgrading identify and pre-commit?'.format(tag),
28+
)
29+
30+
2231
def _make_argparser(filenames_help):
2332
parser = argparse.ArgumentParser()
2433
parser.add_argument('filenames', nargs='*', help=filenames_help)
@@ -36,10 +45,11 @@ def _make_argparser(filenames_help):
3645
'language', schema.check_and(schema.check_string, check_language),
3746
),
3847

39-
schema.Conditional(
48+
schema.Optional(
4049
'files', schema.check_and(schema.check_string, schema.check_regex),
41-
condition_key='always_run', condition_value=False,
50+
'',
4251
),
52+
schema.Optional('types', schema.check_array(check_type_tag), ['file']),
4353

4454
schema.Optional(
4555
'additional_dependencies', schema.check_array(schema.check_string), [],

pre_commit/commands/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def get_filenames(args, include_expr, exclude_expr):
5858

5959

6060
def _run_single_hook(hook, repo, args, skips, cols):
61-
filenames = get_filenames(args, hook.get('files', '^$'), hook['exclude'])
61+
filenames = get_filenames(args, hook['files'], hook['exclude'])
6262
if hook['id'] in skips:
6363
output.write(get_hook_message(
6464
_hook_msg_start(hook, args.verbose),

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
install_requires=[
4242
'aspy.yaml',
4343
'cached-property',
44+
'identify>=1.0.0',
4445
'nodeenv>=0.11.1',
4546
'pyyaml',
4647
'six',

tests/clientlib_test.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from pre_commit import schema
66
from pre_commit.clientlib import check_language
7+
from pre_commit.clientlib import check_type_tag
78
from pre_commit.clientlib import CONFIG_HOOK_DICT
89
from pre_commit.clientlib import CONFIG_SCHEMA
910
from pre_commit.clientlib import is_local_repo
@@ -27,6 +28,12 @@ def test_check_language_failures(value):
2728
check_language(value)
2829

2930

31+
@pytest.mark.parametrize('value', ('definitely-not-a-tag', 'fiel'))
32+
def test_check_type_tag_failures(value):
33+
with pytest.raises(schema.ValidationError):
34+
check_type_tag(value)
35+
36+
3037
@pytest.mark.parametrize('value', ('python', 'node', 'pcre'))
3138
def test_check_language_ok(value):
3239
check_language(value)

tests/manifest_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def test_manifest_contents(manifest):
3434
'name': 'Bash hook',
3535
'pass_filenames': True,
3636
'stages': [],
37+
'types': ['file'],
3738
}]
3839

3940

@@ -54,6 +55,7 @@ def test_hooks(manifest):
5455
'name': 'Bash hook',
5556
'pass_filenames': True,
5657
'stages': [],
58+
'types': ['file'],
5759
}
5860

5961

0 commit comments

Comments
 (0)