config: Allow rules to validate their configuration

packaging
Adrien Vergé 5 years ago
parent 483a8d89a5
commit 851d34b9fd

@ -177,6 +177,12 @@ def validate_rule_conf(rule, conf):
for optkey in options: for optkey in options:
if optkey not in conf: if optkey not in conf:
conf[optkey] = options_default[optkey] conf[optkey] = options_default[optkey]
if hasattr(rule, 'VALIDATE'):
res = rule.VALIDATE(conf)
if res:
raise YamlLintConfigError('invalid config: %s: %s' %
(rule.ID, res))
else: else:
raise YamlLintConfigError(('invalid config: rule "%s": should be ' raise YamlLintConfigError(('invalid config: rule "%s": should be '
'either "enable", "disable" or a dict') 'either "enable", "disable" or a dict')

Loading…
Cancel
Save