Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pre_commit/clientlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ def check(self, dct: dict[str, Any]) -> None:
item
for item in MANIFEST_HOOK_DICT.items
),
OptionalSensibleRegexAtHook('files', cfgv.check_string),
OptionalSensibleRegexAtHook('exclude', cfgv.check_string),
)
CONFIG_HOOK_DICT = cfgv.Map(
'Hook', 'id',
Expand Down
18 changes: 18 additions & 0 deletions tests/clientlib_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,24 @@ def test_validate_optional_sensible_regex_at_local_hook(caplog):
]


def test_validate_optional_sensible_regex_at_meta_hook(caplog):
config_obj = {
'repo': 'meta',
'hooks': [{'id': 'identity', 'files': 'dir/*.py'}],
}

cfgv.validate(config_obj, CONFIG_REPO_DICT)

assert caplog.record_tuples == [
(
'pre_commit',
logging.WARNING,
"The 'files' field in hook 'identity' is a regex, not a glob "
"-- matching '/*' probably isn't what you want here",
),
]


@pytest.mark.parametrize(
('regex', 'warning'),
(
Expand Down