mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-13 12:30:08 -06:00
fixes for cfgv>=2
This commit is contained in:
@@ -149,10 +149,16 @@ def _entry(modname):
|
||||
)
|
||||
|
||||
|
||||
def warn_unknown_keys(extra, orig_keys):
|
||||
def warn_unknown_keys_root(extra, orig_keys, dct):
|
||||
logger.warning(
|
||||
'Unexpected config key(s): {}'.format(
|
||||
', '.join(sorted(extra)),
|
||||
'Unexpected key(s) present at root: {}'.format(', '.join(extra)),
|
||||
)
|
||||
|
||||
|
||||
def warn_unknown_keys_repo(extra, orig_keys, dct):
|
||||
logger.warning(
|
||||
'Unexpected key(s) present on {}: {}'.format(
|
||||
dct['repo'], ', '.join(extra),
|
||||
),
|
||||
)
|
||||
|
||||
@@ -235,10 +241,7 @@ CONFIG_REPO_DICT = cfgv.Map(
|
||||
),
|
||||
|
||||
MigrateShaToRev(),
|
||||
cfgv.WarnAdditionalKeys(
|
||||
('repo', 'rev', 'hooks'),
|
||||
warn_unknown_keys,
|
||||
),
|
||||
cfgv.WarnAdditionalKeys(('repo', 'rev', 'hooks'), warn_unknown_keys_repo),
|
||||
)
|
||||
DEFAULT_LANGUAGE_VERSION = cfgv.Map(
|
||||
'DefaultLanguageVersion', None,
|
||||
@@ -273,7 +276,7 @@ CONFIG_SCHEMA = cfgv.Map(
|
||||
'fail_fast',
|
||||
'minimum_pre_commit_version',
|
||||
),
|
||||
warn_unknown_keys,
|
||||
warn_unknown_keys_root,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@@ -105,7 +105,7 @@ class Hook(collections.namedtuple('Hook', ('src', 'prefix') + _KEYS)):
|
||||
extra_keys = set(dct) - set(_KEYS)
|
||||
if extra_keys:
|
||||
logger.warning(
|
||||
'Unexpected keys present on {} => {}: '
|
||||
'Unexpected key(s) present on {} => {}: '
|
||||
'{}'.format(src, dct['id'], ', '.join(sorted(extra_keys))),
|
||||
)
|
||||
return cls(src=src, prefix=prefix, **{k: dct[k] for k in _KEYS})
|
||||
|
||||
@@ -25,7 +25,7 @@ classifiers =
|
||||
packages = find:
|
||||
install_requires =
|
||||
aspy.yaml
|
||||
cfgv>=1.4.0
|
||||
cfgv>=2.0.0
|
||||
identify>=1.0.0
|
||||
importlib-metadata
|
||||
nodeenv>=0.11.1
|
||||
|
||||
@@ -133,7 +133,8 @@ def test_validate_warn_on_unknown_keys_at_repo_level(tmpdir, caplog):
|
||||
(
|
||||
'pre_commit',
|
||||
logging.WARNING,
|
||||
'Unexpected config key(s): args',
|
||||
'Unexpected key(s) present on https://gitlab.com/pycqa/flake8: '
|
||||
'args',
|
||||
),
|
||||
]
|
||||
|
||||
@@ -155,7 +156,7 @@ def test_validate_warn_on_unknown_keys_at_top_level(tmpdir, caplog):
|
||||
(
|
||||
'pre_commit',
|
||||
logging.WARNING,
|
||||
'Unexpected config key(s): foo',
|
||||
'Unexpected key(s) present at root: foo',
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
@@ -588,7 +588,7 @@ def test_unknown_keys(store, fake_log_handler):
|
||||
}],
|
||||
}
|
||||
_get_hook(config, store, 'too-much')
|
||||
expected = 'Unexpected keys present on local => too-much: foo, hello'
|
||||
expected = 'Unexpected key(s) present on local => too-much: foo, hello'
|
||||
assert fake_log_handler.handle.call_args[0][0].msg == expected
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user