From 0ba193331b8e066218c3c5f3417c214904c23e3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Verg=C3=A9?= Date: Thu, 6 Jun 2019 11:05:33 +0200 Subject: [PATCH] truthy: Validate options passed to 'allowed-values' Make sure values passed in allowed values are correct ones. This is possible thanks to previous commit, and should prevent users from writing incorrect configurations. --- tests/rules/test_truthy.py | 14 -------------- yamllint/rules/truthy.py | 10 ++++++---- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/tests/rules/test_truthy.py b/tests/rules/test_truthy.py index 796f3c7..82e4f6c 100644 --- a/tests/rules/test_truthy.py +++ b/tests/rules/test_truthy.py @@ -97,20 +97,6 @@ class TruthyTestCase(RuleTestCase): problem1=(2, 7), problem2=(3, 7), problem3=(4, 7), problem4=(5, 7)) - def test_empty_string_allowed_values(self): - conf = ('truthy:\n' - ' allowed-values: ["", ""]\n') - self.check('---\n' - 'key1: foo\n' - 'key2: bar\n', conf) - self.check('---\n' - 'key1: true\n' - 'key2: yes\n' - 'key3: false\n' - 'key4: no\n', conf, - problem1=(2, 7), problem2=(3, 7), - problem3=(4, 7), problem4=(5, 7)) - def test_explicit_types(self): conf = 'truthy: enable\n' self.check('---\n' diff --git a/yamllint/rules/truthy.py b/yamllint/rules/truthy.py index 1648b51..3cf058b 100644 --- a/yamllint/rules/truthy.py +++ b/yamllint/rules/truthy.py @@ -98,10 +98,6 @@ import yaml from yamllint.linter import LintProblem -ID = 'truthy' -TYPE = 'token' -CONF = {'allowed-values': list} -DEFAULT = {'allowed-values': ['true', 'false']} TRUTHY = ['YES', 'Yes', 'yes', 'NO', 'No', 'no', @@ -111,6 +107,12 @@ TRUTHY = ['YES', 'Yes', 'yes', 'OFF', 'Off', 'off'] +ID = 'truthy' +TYPE = 'token' +CONF = {'allowed-values': list(TRUTHY)} +DEFAULT = {'allowed-values': ['true', 'false']} + + def check(conf, token, prev, next, nextnext, context): if prev and isinstance(prev, yaml.tokens.TagToken): return