Config: Allow 'enable' keyword for rules
In the same manner as 'disable', 'enable' allows setting a rule on without worrying about its options.
This commit is contained in:
@@ -49,7 +49,7 @@ class CommentsIndentationTestCase(RuleTestCase):
|
|||||||
'...\n', conf)
|
'...\n', conf)
|
||||||
|
|
||||||
def test_enabled(self):
|
def test_enabled(self):
|
||||||
conf = 'comments-indentation: {}'
|
conf = 'comments-indentation: enable'
|
||||||
self.check('---\n'
|
self.check('---\n'
|
||||||
'# line 1\n'
|
'# line 1\n'
|
||||||
'# line 2\n', conf)
|
'# line 2\n', conf)
|
||||||
@@ -123,18 +123,18 @@ class CommentsIndentationTestCase(RuleTestCase):
|
|||||||
'...\n', conf)
|
'...\n', conf)
|
||||||
|
|
||||||
def test_first_line(self):
|
def test_first_line(self):
|
||||||
conf = 'comments-indentation: {}'
|
conf = 'comments-indentation: enable'
|
||||||
self.check('# comment\n', conf)
|
self.check('# comment\n', conf)
|
||||||
self.check(' # comment\n', conf, problem=(1, 3))
|
self.check(' # comment\n', conf, problem=(1, 3))
|
||||||
|
|
||||||
def test_no_newline_at_end(self):
|
def test_no_newline_at_end(self):
|
||||||
conf = ('comments-indentation: {}\n'
|
conf = ('comments-indentation: enable\n'
|
||||||
'new-line-at-end-of-file: disable\n')
|
'new-line-at-end-of-file: disable\n')
|
||||||
self.check('# comment', conf)
|
self.check('# comment', conf)
|
||||||
self.check(' # comment', conf, problem=(1, 3))
|
self.check(' # comment', conf, problem=(1, 3))
|
||||||
|
|
||||||
def test_empty_comment(self):
|
def test_empty_comment(self):
|
||||||
conf = 'comments-indentation: {}'
|
conf = 'comments-indentation: enable'
|
||||||
self.check('---\n'
|
self.check('---\n'
|
||||||
'# hey\n'
|
'# hey\n'
|
||||||
'# normal\n'
|
'# normal\n'
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ class KeyDuplicatesTestCase(RuleTestCase):
|
|||||||
': 1\n', conf)
|
': 1\n', conf)
|
||||||
|
|
||||||
def test_enabled(self):
|
def test_enabled(self):
|
||||||
conf = 'key-duplicates: {}'
|
conf = 'key-duplicates: enable'
|
||||||
self.check('---\n'
|
self.check('---\n'
|
||||||
'block mapping:\n'
|
'block mapping:\n'
|
||||||
' key: a\n'
|
' key: a\n'
|
||||||
@@ -149,7 +149,7 @@ class KeyDuplicatesTestCase(RuleTestCase):
|
|||||||
problem4=(7, 3))
|
problem4=(7, 3))
|
||||||
|
|
||||||
def test_key_tokens_in_flow_sequences(self):
|
def test_key_tokens_in_flow_sequences(self):
|
||||||
conf = 'key-duplicates: {}'
|
conf = 'key-duplicates: enable'
|
||||||
self.check('---\n'
|
self.check('---\n'
|
||||||
'[\n'
|
'[\n'
|
||||||
' flow: sequence, with, key: value, mappings\n'
|
' flow: sequence, with, key: value, mappings\n'
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ class NewLineAtEndOfFileTestCase(RuleTestCase):
|
|||||||
self.check('Sentence.\n', conf)
|
self.check('Sentence.\n', conf)
|
||||||
|
|
||||||
def test_enabled(self):
|
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'
|
'empty-lines: disable\n'
|
||||||
'document-start: disable\n')
|
'document-start: disable\n')
|
||||||
self.check('', conf)
|
self.check('', conf)
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ class TrailingSpacesTestCase(RuleTestCase):
|
|||||||
'some: text \n', conf)
|
'some: text \n', conf)
|
||||||
|
|
||||||
def test_enabled(self):
|
def test_enabled(self):
|
||||||
conf = 'trailing-spaces: {}'
|
conf = 'trailing-spaces: enable'
|
||||||
self.check('', conf)
|
self.check('', conf)
|
||||||
self.check('\n', conf)
|
self.check('\n', conf)
|
||||||
self.check(' \n', conf, problem=(1, 1))
|
self.check(' \n', conf, problem=(1, 1))
|
||||||
@@ -40,7 +40,7 @@ class TrailingSpacesTestCase(RuleTestCase):
|
|||||||
'some: text\t\n', conf, problem=(2, 11, 'syntax'))
|
'some: text\t\n', conf, problem=(2, 11, 'syntax'))
|
||||||
|
|
||||||
def test_with_dos_new_lines(self):
|
def test_with_dos_new_lines(self):
|
||||||
conf = ('trailing-spaces: {}\n'
|
conf = ('trailing-spaces: enable\n'
|
||||||
'new-lines: {type: dos}\n')
|
'new-lines: {type: dos}\n')
|
||||||
self.check('---\r\n'
|
self.check('---\r\n'
|
||||||
'some: text\r\n', conf)
|
'some: text\r\n', conf)
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ class SimpleConfigTestCase(unittest.TestCase):
|
|||||||
config.YamlLintConfigError,
|
config.YamlLintConfigError,
|
||||||
'invalid config: no such rule: "this-one-does-not-exist"'):
|
'invalid config: no such rule: "this-one-does-not-exist"'):
|
||||||
config.YamlLintConfig('rules:\n'
|
config.YamlLintConfig('rules:\n'
|
||||||
' this-one-does-not-exist: {}\n')
|
' this-one-does-not-exist: enable\n')
|
||||||
|
|
||||||
def test_missing_option(self):
|
def test_missing_option(self):
|
||||||
with self.assertRaisesRegexp(
|
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, False), False)
|
||||||
self.assertEqual(config.validate_rule_conf(Rule, 'disable'), 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': 'error'})
|
||||||
config.validate_rule_conf(Rule, {'level': 'warning'})
|
config.validate_rule_conf(Rule, {'level': 'warning'})
|
||||||
self.assertRaises(config.YamlLintConfigError,
|
self.assertRaises(config.YamlLintConfigError,
|
||||||
|
|||||||
@@ -34,11 +34,11 @@ rules:
|
|||||||
spaces: 2
|
spaces: 2
|
||||||
indent-sequences: yes
|
indent-sequences: yes
|
||||||
check-multi-line-strings: no
|
check-multi-line-strings: no
|
||||||
key-duplicates: {}
|
key-duplicates: enable
|
||||||
line-length:
|
line-length:
|
||||||
max: 80
|
max: 80
|
||||||
allow-non-breakable-words: yes
|
allow-non-breakable-words: yes
|
||||||
new-line-at-end-of-file: {level: error}
|
new-line-at-end-of-file: enable
|
||||||
new-lines:
|
new-lines:
|
||||||
type: unix
|
type: unix
|
||||||
trailing-spaces: {}
|
trailing-spaces: enable
|
||||||
|
|||||||
@@ -83,6 +83,8 @@ class YamlLintConfig(object):
|
|||||||
def validate_rule_conf(rule, conf):
|
def validate_rule_conf(rule, conf):
|
||||||
if conf is False or conf == 'disable':
|
if conf is False or conf == 'disable':
|
||||||
return False
|
return False
|
||||||
|
elif conf == 'enable':
|
||||||
|
conf = {}
|
||||||
|
|
||||||
if type(conf) == dict:
|
if type(conf) == dict:
|
||||||
if 'level' not in conf:
|
if 'level' not in conf:
|
||||||
@@ -117,7 +119,8 @@ def validate_rule_conf(rule, conf):
|
|||||||
(optkey, rule.ID))
|
(optkey, rule.ID))
|
||||||
else:
|
else:
|
||||||
raise YamlLintConfigError(('invalid config: rule "%s": should be '
|
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
|
return conf
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user