Skip to content

Commit

Permalink
Merge pull request #2026 from pre-commit/incorrect-regular-expressions
Browse files Browse the repository at this point in the history
make `repo: meta` only apply to top level configuration
  • Loading branch information
asottile committed Aug 28, 2021
2 parents 40e21bb + f963bf6 commit 12f62d2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pre_commit/clientlib.py
Expand Up @@ -216,14 +216,14 @@ def warn_unknown_keys_repo(
(
'check-hooks-apply', (
('name', 'Check hooks apply to the repository'),
('files', C.CONFIG_FILE),
('files', f'^{re.escape(C.CONFIG_FILE)}$'),
('entry', _entry('check_hooks_apply')),
),
),
(
'check-useless-excludes', (
('name', 'Check for useless excludes'),
('files', C.CONFIG_FILE),
('files', f'^{re.escape(C.CONFIG_FILE)}$'),
('entry', _entry('check_useless_excludes')),
),
),
Expand Down
11 changes: 11 additions & 0 deletions tests/clientlib_test.py
@@ -1,4 +1,5 @@
import logging
import re

import cfgv
import pytest
Expand All @@ -10,6 +11,7 @@
from pre_commit.clientlib import CONFIG_SCHEMA
from pre_commit.clientlib import DEFAULT_LANGUAGE_VERSION
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 validate_config_main
from pre_commit.clientlib import validate_manifest_main
Expand Down Expand Up @@ -392,6 +394,15 @@ def test_meta_hook_invalid(config_repo):
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(
'mapping',
(
Expand Down

0 comments on commit 12f62d2

Please sign in to comment.