Skip to content

Commit eec11bd

Browse files
authored
Merge pull request #3311 from pre-commit/sensible-regex-for-meta
also apply sensible regex warning for `repo: meta`
2 parents 6c068a7 + fa08d1d commit eec11bd

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

pre_commit/clientlib.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ def check(self, dct: dict[str, Any]) -> None:
289289
item
290290
for item in MANIFEST_HOOK_DICT.items
291291
),
292+
OptionalSensibleRegexAtHook('files', cfgv.check_string),
293+
OptionalSensibleRegexAtHook('exclude', cfgv.check_string),
292294
)
293295
CONFIG_HOOK_DICT = cfgv.Map(
294296
'Hook', 'id',

tests/clientlib_test.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,24 @@ def test_validate_optional_sensible_regex_at_local_hook(caplog):
256256
]
257257

258258

259+
def test_validate_optional_sensible_regex_at_meta_hook(caplog):
260+
config_obj = {
261+
'repo': 'meta',
262+
'hooks': [{'id': 'identity', 'files': 'dir/*.py'}],
263+
}
264+
265+
cfgv.validate(config_obj, CONFIG_REPO_DICT)
266+
267+
assert caplog.record_tuples == [
268+
(
269+
'pre_commit',
270+
logging.WARNING,
271+
"The 'files' field in hook 'identity' is a regex, not a glob "
272+
"-- matching '/*' probably isn't what you want here",
273+
),
274+
]
275+
276+
259277
@pytest.mark.parametrize(
260278
('regex', 'warning'),
261279
(

0 commit comments

Comments
 (0)