mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-20 09:34:42 +04:00
Merge pull request #2026 from pre-commit/incorrect-regular-expressions
make `repo: meta` only apply to top level configuration
This commit is contained in:
commit
12f62d2191
2 changed files with 13 additions and 2 deletions
|
|
@ -216,14 +216,14 @@ _meta = (
|
||||||
(
|
(
|
||||||
'check-hooks-apply', (
|
'check-hooks-apply', (
|
||||||
('name', 'Check hooks apply to the repository'),
|
('name', 'Check hooks apply to the repository'),
|
||||||
('files', C.CONFIG_FILE),
|
('files', f'^{re.escape(C.CONFIG_FILE)}$'),
|
||||||
('entry', _entry('check_hooks_apply')),
|
('entry', _entry('check_hooks_apply')),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
'check-useless-excludes', (
|
'check-useless-excludes', (
|
||||||
('name', 'Check for useless excludes'),
|
('name', 'Check for useless excludes'),
|
||||||
('files', C.CONFIG_FILE),
|
('files', f'^{re.escape(C.CONFIG_FILE)}$'),
|
||||||
('entry', _entry('check_useless_excludes')),
|
('entry', _entry('check_useless_excludes')),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import logging
|
import logging
|
||||||
|
import re
|
||||||
|
|
||||||
import cfgv
|
import cfgv
|
||||||
import pytest
|
import pytest
|
||||||
|
|
@ -10,6 +11,7 @@ from pre_commit.clientlib import CONFIG_REPO_DICT
|
||||||
from pre_commit.clientlib import CONFIG_SCHEMA
|
from pre_commit.clientlib import CONFIG_SCHEMA
|
||||||
from pre_commit.clientlib import DEFAULT_LANGUAGE_VERSION
|
from pre_commit.clientlib import DEFAULT_LANGUAGE_VERSION
|
||||||
from pre_commit.clientlib import MANIFEST_SCHEMA
|
from pre_commit.clientlib import MANIFEST_SCHEMA
|
||||||
|
from pre_commit.clientlib import META_HOOK_DICT
|
||||||
from pre_commit.clientlib import MigrateShaToRev
|
from pre_commit.clientlib import MigrateShaToRev
|
||||||
from pre_commit.clientlib import validate_config_main
|
from pre_commit.clientlib import validate_config_main
|
||||||
from pre_commit.clientlib import validate_manifest_main
|
from pre_commit.clientlib import validate_manifest_main
|
||||||
|
|
@ -392,6 +394,15 @@ def test_meta_hook_invalid(config_repo):
|
||||||
cfgv.validate(config_repo, CONFIG_REPO_DICT)
|
cfgv.validate(config_repo, CONFIG_REPO_DICT)
|
||||||
|
|
||||||
|
|
||||||
|
def test_meta_check_hooks_apply_only_at_top_level():
|
||||||
|
cfg = {'id': 'check-hooks-apply'}
|
||||||
|
cfg = cfgv.apply_defaults(cfg, META_HOOK_DICT)
|
||||||
|
|
||||||
|
files_re = re.compile(cfg['files'])
|
||||||
|
assert files_re.search('.pre-commit-config.yaml')
|
||||||
|
assert not files_re.search('foo/.pre-commit-config.yaml')
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
'mapping',
|
'mapping',
|
||||||
(
|
(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue