Skip to content

Commit 12f62d2

Browse files
authored
Merge pull request #2026 from pre-commit/incorrect-regular-expressions
make `repo: meta` only apply to top level configuration
2 parents 40e21bb + f963bf6 commit 12f62d2

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

pre_commit/clientlib.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,14 +216,14 @@ def warn_unknown_keys_repo(
216216
(
217217
'check-hooks-apply', (
218218
('name', 'Check hooks apply to the repository'),
219-
('files', C.CONFIG_FILE),
219+
('files', f'^{re.escape(C.CONFIG_FILE)}$'),
220220
('entry', _entry('check_hooks_apply')),
221221
),
222222
),
223223
(
224224
'check-useless-excludes', (
225225
('name', 'Check for useless excludes'),
226-
('files', C.CONFIG_FILE),
226+
('files', f'^{re.escape(C.CONFIG_FILE)}$'),
227227
('entry', _entry('check_useless_excludes')),
228228
),
229229
),

tests/clientlib_test.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import re
23

34
import cfgv
45
import pytest
@@ -10,6 +11,7 @@
1011
from pre_commit.clientlib import CONFIG_SCHEMA
1112
from pre_commit.clientlib import DEFAULT_LANGUAGE_VERSION
1213
from pre_commit.clientlib import MANIFEST_SCHEMA
14+
from pre_commit.clientlib import META_HOOK_DICT
1315
from pre_commit.clientlib import MigrateShaToRev
1416
from pre_commit.clientlib import validate_config_main
1517
from pre_commit.clientlib import validate_manifest_main
@@ -392,6 +394,15 @@ def test_meta_hook_invalid(config_repo):
392394
cfgv.validate(config_repo, CONFIG_REPO_DICT)
393395

394396

397+
def test_meta_check_hooks_apply_only_at_top_level():
398+
cfg = {'id': 'check-hooks-apply'}
399+
cfg = cfgv.apply_defaults(cfg, META_HOOK_DICT)
400+
401+
files_re = re.compile(cfg['files'])
402+
assert files_re.search('.pre-commit-config.yaml')
403+
assert not files_re.search('foo/.pre-commit-config.yaml')
404+
405+
395406
@pytest.mark.parametrize(
396407
'mapping',
397408
(

0 commit comments

Comments
 (0)