mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-14 21:10:27 -06:00
Implement exclude_types
This commit is contained in:
@@ -49,7 +49,13 @@ MANIFEST_HOOK_DICT = schema.Map(
|
||||
'files', schema.check_and(schema.check_string, schema.check_regex),
|
||||
'',
|
||||
),
|
||||
schema.Optional(
|
||||
'exclude',
|
||||
schema.check_and(schema.check_string, schema.check_regex),
|
||||
'^$',
|
||||
),
|
||||
schema.Optional('types', schema.check_array(check_type_tag), ['file']),
|
||||
schema.Optional('exclude_types', schema.check_array(check_type_tag), []),
|
||||
|
||||
schema.Optional(
|
||||
'additional_dependencies', schema.check_array(schema.check_string), [],
|
||||
@@ -58,11 +64,6 @@ MANIFEST_HOOK_DICT = schema.Map(
|
||||
schema.Optional('always_run', schema.check_bool, False),
|
||||
schema.Optional('pass_filenames', schema.check_bool, True),
|
||||
schema.Optional('description', schema.check_string, ''),
|
||||
schema.Optional(
|
||||
'exclude',
|
||||
schema.check_and(schema.check_string, schema.check_regex),
|
||||
'^$',
|
||||
),
|
||||
schema.Optional('language_version', schema.check_string, 'default'),
|
||||
schema.Optional('log_file', schema.check_string, ''),
|
||||
schema.Optional('minimum_pre_commit_version', schema.check_string, '0'),
|
||||
|
||||
@@ -43,12 +43,14 @@ def get_changed_files(new, old):
|
||||
)[1].splitlines()
|
||||
|
||||
|
||||
def filter_filenames_by_types(filenames, types):
|
||||
types = frozenset(types)
|
||||
return tuple(
|
||||
filename for filename in filenames
|
||||
if tags_from_path(filename) >= types
|
||||
)
|
||||
def filter_filenames_by_types(filenames, types, exclude_types):
|
||||
types, exclude_types = frozenset(types), frozenset(exclude_types)
|
||||
ret = []
|
||||
for filename in filenames:
|
||||
tags = tags_from_path(filename)
|
||||
if tags >= types and not tags & exclude_types:
|
||||
ret.append(filename)
|
||||
return tuple(ret)
|
||||
|
||||
|
||||
def get_filenames(args, include_expr, exclude_expr):
|
||||
@@ -73,7 +75,9 @@ NO_FILES = '(no files to check)'
|
||||
|
||||
def _run_single_hook(hook, repo, args, skips, cols):
|
||||
filenames = get_filenames(args, hook['files'], hook['exclude'])
|
||||
filenames = filter_filenames_by_types(filenames, hook['types'])
|
||||
filenames = filter_filenames_by_types(
|
||||
filenames, hook['types'], hook['exclude_types'],
|
||||
)
|
||||
if hook['id'] in skips:
|
||||
output.write(get_hook_message(
|
||||
_hook_msg_start(hook, args.verbose),
|
||||
|
||||
Reference in New Issue
Block a user