mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-13 12:30:08 -06:00
Apply defaults to all of the configs. Much fewer .get()s
This commit is contained in:
@@ -4,6 +4,8 @@ import jsonschema.exceptions
|
||||
import os.path
|
||||
import yaml
|
||||
|
||||
from pre_commit.jsonschema_extensions import apply_defaults
|
||||
|
||||
|
||||
def get_validator(
|
||||
json_schema,
|
||||
@@ -39,6 +41,8 @@ def get_validator(
|
||||
'File {0} is not a valid file'.format(filename), e,
|
||||
)
|
||||
|
||||
obj = apply_defaults(obj, json_schema)
|
||||
|
||||
additional_validation_strategy(obj)
|
||||
|
||||
return obj
|
||||
|
||||
@@ -28,10 +28,10 @@ CONFIG_JSON_SCHEMA = {
|
||||
'properties': {
|
||||
'id': {'type': 'string'},
|
||||
'files': {'type': 'string'},
|
||||
'exclude': {'type': 'string'},
|
||||
'exclude': {'type': 'string', 'default': '^$'},
|
||||
'args': {
|
||||
'type': 'array',
|
||||
'minItems': 1,
|
||||
'default': [],
|
||||
'items': {'type': 'string'},
|
||||
},
|
||||
},
|
||||
@@ -59,7 +59,7 @@ def validate_config_extra(config):
|
||||
for repo in config:
|
||||
for hook in repo['hooks']:
|
||||
try_regex(repo, hook['id'], hook['files'], 'files')
|
||||
try_regex(repo, hook['id'], hook.get('exclude', ''), 'exclude')
|
||||
try_regex(repo, hook['id'], hook['exclude'], 'exclude')
|
||||
|
||||
|
||||
load_config = get_validator(
|
||||
|
||||
@@ -20,10 +20,10 @@ MANIFEST_JSON_SCHEMA = {
|
||||
'properties': {
|
||||
'id': {'type': 'string'},
|
||||
'name': {'type': 'string'},
|
||||
'description': {'type': 'string'},
|
||||
'description': {'type': 'string', 'default': ''},
|
||||
'entry': {'type': 'string'},
|
||||
'language': {'type': 'string'},
|
||||
'expected_return_value': {'type': 'number'},
|
||||
'expected_return_value': {'type': 'number', 'default': 0},
|
||||
},
|
||||
'required': ['id', 'name', 'entry', 'language'],
|
||||
},
|
||||
@@ -32,11 +32,9 @@ MANIFEST_JSON_SCHEMA = {
|
||||
|
||||
def additional_manifest_check(obj):
|
||||
for hook_config in obj:
|
||||
language = hook_config.get('language')
|
||||
language = hook_config['language']
|
||||
|
||||
if language is not None and not any(
|
||||
language.startswith(lang) for lang in all_languages
|
||||
):
|
||||
if not any(language.startswith(lang) for lang in all_languages):
|
||||
raise InvalidManifestError(
|
||||
'Expected language {0} for {1} to start with one of {2!r}'.format(
|
||||
hook_config['id'],
|
||||
|
||||
Reference in New Issue
Block a user