config: Allow generic types inside lists

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

    rule:
      foo: [str],
      bar: [int, bool, 'magic'],
This commit is contained in:
Adrien Vergé 2020-04-10 18:26:06 +02:00
parent 851d34b9fd
commit d68022b846

View File

@ -157,11 +157,12 @@ def validate_rule_conf(rule, conf):
raise YamlLintConfigError(
'invalid config: option "%s" of "%s" should be in %s'
% (optkey, rule.ID, options[optkey]))
# Example: CONF = {option: ['flag1', 'flag2']}
# → {option: [flag1]} → {option: [flag1, flag2]}
# Example: CONF = {option: ['flag1', 'flag2', int]}
# → {option: [flag1]} → {option: [42, flag1, flag2]}
elif isinstance(options[optkey], list):
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])):
raise YamlLintConfigError(
('invalid config: option "%s" of "%s" should only '