config: Allow generic types inside lists

For example it's possible to define a conf like:

    rule:
      foo: [str],
      bar: [int, bool, 'magic'],
packaging
Adrien Vergé 5 years ago
parent 851d34b9fd
commit d68022b846

@ -157,11 +157,12 @@ def validate_rule_conf(rule, conf):
raise YamlLintConfigError( raise YamlLintConfigError(
'invalid config: option "%s" of "%s" should be in %s' 'invalid config: option "%s" of "%s" should be in %s'
% (optkey, rule.ID, options[optkey])) % (optkey, rule.ID, options[optkey]))
# Example: CONF = {option: ['flag1', 'flag2']} # Example: CONF = {option: ['flag1', 'flag2', int]}
# → {option: [flag1]} → {option: [flag1, flag2]} # → {option: [flag1]} → {option: [42, flag1, flag2]}
elif isinstance(options[optkey], list): elif isinstance(options[optkey], list):
if (type(conf[optkey]) is not list or if (type(conf[optkey]) is not list or
any(flag not in options[optkey] any(flag not in options[optkey] and
type(flag) not in options[optkey]
for flag in conf[optkey])): for flag in conf[optkey])):
raise YamlLintConfigError( raise YamlLintConfigError(
('invalid config: option "%s" of "%s" should only ' ('invalid config: option "%s" of "%s" should only '

Loading…
Cancel
Save