mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-23 09:20:31 -06:00
forbid overriding entry for meta hooks
This commit is contained in:
@@ -251,12 +251,21 @@ _meta = (
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
class NotAllowed(cfgv.OptionalNoDefault):
|
||||
def check(self, dct: Dict[str, Any]) -> None:
|
||||
if self.key in dct:
|
||||
raise cfgv.ValidationError(f'{self.key!r} cannot be overridden')
|
||||
|
||||
|
||||
META_HOOK_DICT = cfgv.Map(
|
||||
'Hook', 'id',
|
||||
cfgv.Required('id', cfgv.check_string),
|
||||
cfgv.Required('id', cfgv.check_one_of(tuple(k for k, _ in _meta))),
|
||||
# language must be system
|
||||
cfgv.Optional('language', cfgv.check_one_of({'system'}), 'system'),
|
||||
# entry cannot be overridden
|
||||
NotAllowed('entry', cfgv.check_any),
|
||||
*(
|
||||
# default to the hook definition for the meta hooks
|
||||
cfgv.ConditionalOptional(key, cfgv.check_any, value, 'id', hook_id)
|
||||
|
||||
@@ -423,6 +423,13 @@ def test_migrate_to_sha_ok():
|
||||
{'repo': 'meta', 'hooks': [{'id': 'identity', 'language': 'python'}]},
|
||||
# name override must be string
|
||||
{'repo': 'meta', 'hooks': [{'id': 'identity', 'name': False}]},
|
||||
pytest.param(
|
||||
{
|
||||
'repo': 'meta',
|
||||
'hooks': [{'id': 'identity', 'entry': 'echo hi'}],
|
||||
},
|
||||
id='cannot override entry for meta hooks',
|
||||
),
|
||||
),
|
||||
)
|
||||
def test_meta_hook_invalid(config_repo):
|
||||
|
||||
Reference in New Issue
Block a user