mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 16:24:40 +04:00
Make the config validator more strict for correct regexes
This commit is contained in:
parent
6b1097d3c9
commit
be8d1b811a
3 changed files with 37 additions and 5 deletions
|
|
@ -2,6 +2,7 @@
|
|||
from __future__ import print_function
|
||||
|
||||
import argparse
|
||||
import re
|
||||
|
||||
import pre_commit.constants as C
|
||||
from pre_commit.clientlib.validate_base import get_validator
|
||||
|
|
@ -41,10 +42,24 @@ CONFIG_JSON_SCHEMA = {
|
|||
}
|
||||
|
||||
|
||||
def validate_config_extra(config):
|
||||
for repo in config:
|
||||
for hook in repo['hooks']:
|
||||
try:
|
||||
re.compile(hook['files'])
|
||||
except re.error:
|
||||
raise InvalidConfigError(
|
||||
'Invalid file regex at {0}, {1}: {2}'.format(
|
||||
repo['repo'], hook['id'], hook['files'],
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
validate_config = get_validator(
|
||||
C.CONFIG_FILE,
|
||||
CONFIG_JSON_SCHEMA,
|
||||
InvalidConfigError,
|
||||
additional_validation_strategy=validate_config_extra,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -69,4 +84,4 @@ def run(argv):
|
|||
print(str(e.args[1]))
|
||||
return 1
|
||||
|
||||
return 0
|
||||
return 0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue