Config: Allow 'enable' keyword for rules

In the same manner as 'disable', 'enable' allows setting a rule on
without worrying about its options.
pull/4/head
Adrien Vergé 9 years ago
parent 69ef9a7272
commit 8fca8a7a33

@ -49,7 +49,7 @@ class CommentsIndentationTestCase(RuleTestCase):
'...\n', conf)
def test_enabled(self):
conf = 'comments-indentation: {}'
conf = 'comments-indentation: enable'
self.check('---\n'
'# line 1\n'
'# line 2\n', conf)
@ -123,18 +123,18 @@ class CommentsIndentationTestCase(RuleTestCase):
'...\n', conf)
def test_first_line(self):
conf = 'comments-indentation: {}'
conf = 'comments-indentation: enable'
self.check('# comment\n', conf)
self.check(' # comment\n', conf, problem=(1, 3))
def test_no_newline_at_end(self):
conf = ('comments-indentation: {}\n'
conf = ('comments-indentation: enable\n'
'new-line-at-end-of-file: disable\n')
self.check('# comment', conf)
self.check(' # comment', conf, problem=(1, 3))
def test_empty_comment(self):
conf = 'comments-indentation: {}'
conf = 'comments-indentation: enable'
self.check('---\n'
'# hey\n'
'# normal\n'

@ -80,7 +80,7 @@ class KeyDuplicatesTestCase(RuleTestCase):
': 1\n', conf)
def test_enabled(self):
conf = 'key-duplicates: {}'
conf = 'key-duplicates: enable'
self.check('---\n'
'block mapping:\n'
' key: a\n'
@ -149,7 +149,7 @@ class KeyDuplicatesTestCase(RuleTestCase):
problem4=(7, 3))
def test_key_tokens_in_flow_sequences(self):
conf = 'key-duplicates: {}'
conf = 'key-duplicates: enable'
self.check('---\n'
'[\n'
' flow: sequence, with, key: value, mappings\n'

@ -30,7 +30,7 @@ class NewLineAtEndOfFileTestCase(RuleTestCase):
self.check('Sentence.\n', conf)
def test_enabled(self):
conf = ('new-line-at-end-of-file: {}\n'
conf = ('new-line-at-end-of-file: enable\n'
'empty-lines: disable\n'
'document-start: disable\n')
self.check('', conf)

@ -29,7 +29,7 @@ class TrailingSpacesTestCase(RuleTestCase):
'some: text \n', conf)
def test_enabled(self):
conf = 'trailing-spaces: {}'
conf = 'trailing-spaces: enable'
self.check('', conf)
self.check('\n', conf)
self.check(' \n', conf, problem=(1, 1))
@ -40,7 +40,7 @@ class TrailingSpacesTestCase(RuleTestCase):
'some: text\t\n', conf, problem=(2, 11, 'syntax'))
def test_with_dos_new_lines(self):
conf = ('trailing-spaces: {}\n'
conf = ('trailing-spaces: enable\n'
'new-lines: {type: dos}\n')
self.check('---\r\n'
'some: text\r\n', conf)

@ -37,7 +37,7 @@ class SimpleConfigTestCase(unittest.TestCase):
config.YamlLintConfigError,
'invalid config: no such rule: "this-one-does-not-exist"'):
config.YamlLintConfig('rules:\n'
' this-one-does-not-exist: {}\n')
' this-one-does-not-exist: enable\n')
def test_missing_option(self):
with self.assertRaisesRegexp(
@ -65,6 +65,11 @@ class SimpleConfigTestCase(unittest.TestCase):
self.assertEqual(config.validate_rule_conf(Rule, False), False)
self.assertEqual(config.validate_rule_conf(Rule, 'disable'), False)
self.assertEqual(config.validate_rule_conf(Rule, {}),
{'level': 'error'})
self.assertEqual(config.validate_rule_conf(Rule, 'enable'),
{'level': 'error'})
config.validate_rule_conf(Rule, {'level': 'error'})
config.validate_rule_conf(Rule, {'level': 'warning'})
self.assertRaises(config.YamlLintConfigError,

@ -34,11 +34,11 @@ rules:
spaces: 2
indent-sequences: yes
check-multi-line-strings: no
key-duplicates: {}
key-duplicates: enable
line-length:
max: 80
allow-non-breakable-words: yes
new-line-at-end-of-file: {level: error}
new-line-at-end-of-file: enable
new-lines:
type: unix
trailing-spaces: {}
trailing-spaces: enable

@ -83,6 +83,8 @@ class YamlLintConfig(object):
def validate_rule_conf(rule, conf):
if conf is False or conf == 'disable':
return False
elif conf == 'enable':
conf = {}
if type(conf) == dict:
if 'level' not in conf:
@ -117,7 +119,8 @@ def validate_rule_conf(rule, conf):
(optkey, rule.ID))
else:
raise YamlLintConfigError(('invalid config: rule "%s": should be '
'either "disable" or a dict') % rule.ID)
'either "enable", "disable" or a dict')
% rule.ID)
return conf

Loading…
Cancel
Save