diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2022-01-21 19:59:08 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2022-01-21 19:59:08 +0000 |
commit | 20ff60e9f0e8528b00b03e036fa3d41743d53dfa (patch) | |
tree | 7baccf4096b08411ca191790015c7f6c835a85c7 /pre_commit/clientlib.py | |
parent | Adding upstream version 2.16.0. (diff) | |
download | pre-commit-20ff60e9f0e8528b00b03e036fa3d41743d53dfa.tar.xz pre-commit-20ff60e9f0e8528b00b03e036fa3d41743d53dfa.zip |
Adding upstream version 2.17.0.upstream/2.17.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'pre_commit/clientlib.py')
-rw-r--r-- | pre_commit/clientlib.py | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/pre_commit/clientlib.py b/pre_commit/clientlib.py index 6377a8b..47ebd54 100644 --- a/pre_commit/clientlib.py +++ b/pre_commit/clientlib.py @@ -144,18 +144,13 @@ class OptionalSensibleRegexAtHook(cfgv.OptionalNoDefault): f"regex, not a glob -- matching '/*' probably isn't what you " f'want here', ) - if r'[\/]' in dct.get(self.key, ''): - logger.warning( - fr'pre-commit normalizes slashes in the {self.key!r} field ' - fr'in hook {dct.get("id")!r} to forward slashes, so you ' - fr'can use / instead of [\/]', - ) - if r'[/\\]' in dct.get(self.key, ''): - logger.warning( - fr'pre-commit normalizes slashes in the {self.key!r} field ' - fr'in hook {dct.get("id")!r} to forward slashes, so you ' - fr'can use / instead of [/\\]', - ) + for fwd_slash_re in (r'[\\/]', r'[\/]', r'[/\\]'): + if fwd_slash_re in dct.get(self.key, ''): + logger.warning( + fr'pre-commit normalizes slashes in the {self.key!r} ' + fr'field in hook {dct.get("id")!r} to forward slashes, ' + fr'so you can use / instead of {fwd_slash_re}', + ) class OptionalSensibleRegexAtTop(cfgv.OptionalNoDefault): @@ -167,18 +162,13 @@ class OptionalSensibleRegexAtTop(cfgv.OptionalNoDefault): f'The top-level {self.key!r} field is a regex, not a glob -- ' f"matching '/*' probably isn't what you want here", ) - if r'[\/]' in dct.get(self.key, ''): - logger.warning( - fr'pre-commit normalizes the slashes in the top-level ' - fr'{self.key!r} field to forward slashes, so you can use / ' - fr'instead of [\/]', - ) - if r'[/\\]' in dct.get(self.key, ''): - logger.warning( - fr'pre-commit normalizes the slashes in the top-level ' - fr'{self.key!r} field to forward slashes, so you can use / ' - fr'instead of [/\\]', - ) + for fwd_slash_re in (r'[\\/]', r'[\/]', r'[/\\]'): + if fwd_slash_re in dct.get(self.key, ''): + logger.warning( + fr'pre-commit normalizes the slashes in the top-level ' + fr'{self.key!r} field to forward slashes, so you ' + fr'can use / instead of {fwd_slash_re}', + ) class MigrateShaToRev: @@ -261,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) |