Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dca3a54e63 | ||
|
|
2dcfbd7e0d | ||
|
|
73d7a608e8 | ||
|
|
1c0f164fbf | ||
|
|
46e9108419 | ||
|
|
2f9e3cc71b | ||
|
|
b13a03815a | ||
|
|
9a7eec34b1 | ||
|
|
5b62548ece | ||
|
|
8fca8a7a33 | ||
|
|
69ef9a7272 |
@@ -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'
|
||||
|
||||
@@ -615,10 +615,60 @@ class IndentationTestCase(RuleTestCase):
|
||||
'- b\n'
|
||||
'- c\n', conf, problem=(6, 1, 'syntax'))
|
||||
|
||||
def test_indent_sequences_consistent(self):
|
||||
conf = 'indentation: {spaces: 4, indent-sequences: consistent}'
|
||||
self.check('---\n'
|
||||
'list one:\n'
|
||||
'- 1\n'
|
||||
'- 2\n'
|
||||
'- 3\n'
|
||||
'list:\n'
|
||||
' two:\n'
|
||||
' - a\n'
|
||||
' - b\n'
|
||||
' - c\n', conf)
|
||||
self.check('---\n'
|
||||
'list one:\n'
|
||||
' - 1\n'
|
||||
' - 2\n'
|
||||
' - 3\n'
|
||||
'list:\n'
|
||||
' two:\n'
|
||||
' - a\n'
|
||||
' - b\n'
|
||||
' - c\n', conf)
|
||||
self.check('---\n'
|
||||
'list one:\n'
|
||||
'- 1\n'
|
||||
'- 2\n'
|
||||
'- 3\n'
|
||||
'list two:\n'
|
||||
' - a\n'
|
||||
' - b\n'
|
||||
' - c\n', conf, problem=(7, 5))
|
||||
self.check('---\n'
|
||||
'list one:\n'
|
||||
' - 1\n'
|
||||
' - 2\n'
|
||||
' - 3\n'
|
||||
'list two:\n'
|
||||
'- a\n'
|
||||
'- b\n'
|
||||
'- c\n', conf, problem=(7, 1))
|
||||
self.check('---\n'
|
||||
'list one:\n'
|
||||
' - 1\n'
|
||||
' - 2\n'
|
||||
' - 3\n'
|
||||
'list two:\n'
|
||||
'- a\n'
|
||||
'- b\n'
|
||||
'- c\n', conf, problem1=(3, 2), problem2=(7, 1))
|
||||
|
||||
def test_direct_flows(self):
|
||||
# flow: [ ...
|
||||
# ]
|
||||
conf = 'indentation: {spaces: 2}'
|
||||
conf = 'indentation: {spaces: consistent}'
|
||||
self.check('---\n'
|
||||
'a: {x: 1,\n'
|
||||
' y,\n'
|
||||
@@ -670,7 +720,7 @@ class IndentationTestCase(RuleTestCase):
|
||||
# flow: [
|
||||
# ...
|
||||
# ]
|
||||
conf = 'indentation: {spaces: 2}'
|
||||
conf = 'indentation: {spaces: consistent}'
|
||||
self.check('---\n'
|
||||
'a: {\n'
|
||||
' x: 1,\n'
|
||||
@@ -684,7 +734,7 @@ class IndentationTestCase(RuleTestCase):
|
||||
'a: {\n'
|
||||
' x: 1,\n'
|
||||
' y, z: 1\n'
|
||||
'}\n', conf, problem=(3, 4))
|
||||
'}\n', conf, problem=(4, 3))
|
||||
self.check('---\n'
|
||||
'a: {\n'
|
||||
' x: 1,\n'
|
||||
@@ -703,7 +753,7 @@ class IndentationTestCase(RuleTestCase):
|
||||
'a: [\n'
|
||||
' x,\n'
|
||||
' y, z\n'
|
||||
']\n', conf, problem=(3, 4))
|
||||
']\n', conf, problem=(4, 3))
|
||||
self.check('---\n'
|
||||
'a: [\n'
|
||||
' x,\n'
|
||||
@@ -752,13 +802,24 @@ class IndentationTestCase(RuleTestCase):
|
||||
' foo: 1,\n'
|
||||
' bar: 2\n'
|
||||
' }\n', conf, problem1=(7, 7), problem2=(11, 3))
|
||||
conf = 'indentation: {spaces: 2}'
|
||||
self.check('---\n'
|
||||
'a: {\n'
|
||||
' x: 1,\n'
|
||||
' y, z: 1\n'
|
||||
'}\n', conf, problem=(3, 4))
|
||||
self.check('---\n'
|
||||
'a: [\n'
|
||||
' x,\n'
|
||||
' y, z\n'
|
||||
']\n', conf, problem=(3, 4))
|
||||
|
||||
def test_cleared_flows(self):
|
||||
# flow:
|
||||
# [
|
||||
# ...
|
||||
# ]
|
||||
conf = 'indentation: {spaces: 2}'
|
||||
conf = 'indentation: {spaces: consistent}'
|
||||
self.check('---\n'
|
||||
'top:\n'
|
||||
' rules:\n'
|
||||
@@ -808,7 +869,7 @@ class IndentationTestCase(RuleTestCase):
|
||||
'top:\n'
|
||||
' [\n'
|
||||
' a, b, c\n'
|
||||
' ]\n', conf, problem=(3, 4))
|
||||
' ]\n', conf, problem=(4, 6))
|
||||
self.check('---\n'
|
||||
'top:\n'
|
||||
' [\n'
|
||||
@@ -843,7 +904,7 @@ class IndentationTestCase(RuleTestCase):
|
||||
problem3=(9, 9), problem4=(11, 7), problem5=(13, 1))
|
||||
|
||||
def test_under_indented(self):
|
||||
conf = 'indentation: {spaces: 2, indent-sequences: yes}'
|
||||
conf = 'indentation: {spaces: 2, indent-sequences: consistent}'
|
||||
self.check('---\n'
|
||||
'object:\n'
|
||||
' val: 1\n'
|
||||
@@ -859,7 +920,7 @@ class IndentationTestCase(RuleTestCase):
|
||||
' - name: Unix\n'
|
||||
' date: 1969\n'
|
||||
'...\n', conf, problem=(5, 6, 'syntax'))
|
||||
conf = 'indentation: {spaces: 4, indent-sequences: yes}'
|
||||
conf = 'indentation: {spaces: 4, indent-sequences: consistent}'
|
||||
self.check('---\n'
|
||||
'object:\n'
|
||||
' val: 1\n'
|
||||
@@ -877,7 +938,7 @@ class IndentationTestCase(RuleTestCase):
|
||||
'...\n', conf, problem=(5, 10, 'syntax'))
|
||||
|
||||
def test_over_indented(self):
|
||||
conf = 'indentation: {spaces: 2, indent-sequences: yes}'
|
||||
conf = 'indentation: {spaces: 2, indent-sequences: consistent}'
|
||||
self.check('---\n'
|
||||
'object:\n'
|
||||
' val: 1\n'
|
||||
@@ -893,7 +954,7 @@ class IndentationTestCase(RuleTestCase):
|
||||
' - name: Unix\n'
|
||||
' date: 1969\n'
|
||||
'...\n', conf, problem=(5, 12, 'syntax'))
|
||||
conf = 'indentation: {spaces: 4, indent-sequences: yes}'
|
||||
conf = 'indentation: {spaces: 4, indent-sequences: consistent}'
|
||||
self.check('---\n'
|
||||
'object:\n'
|
||||
' val: 1\n'
|
||||
@@ -933,7 +994,7 @@ class IndentationTestCase(RuleTestCase):
|
||||
problem=(2, 3))
|
||||
|
||||
def test_multi_lines(self):
|
||||
conf = 'indentation: {spaces: 2, indent-sequences: yes}'
|
||||
conf = 'indentation: {spaces: consistent, indent-sequences: yes}'
|
||||
self.check('---\n'
|
||||
'long_string: >\n'
|
||||
' bla bla blah\n'
|
||||
@@ -952,7 +1013,7 @@ class IndentationTestCase(RuleTestCase):
|
||||
'...\n', conf)
|
||||
|
||||
def test_empty_value(self):
|
||||
conf = 'indentation: {spaces: 2}'
|
||||
conf = 'indentation: {spaces: consistent}'
|
||||
self.check('---\n'
|
||||
'key1:\n'
|
||||
'key2: not empty\n'
|
||||
@@ -1007,7 +1068,7 @@ class IndentationTestCase(RuleTestCase):
|
||||
'...\n', conf, problem=(2, 2))
|
||||
|
||||
def test_return(self):
|
||||
conf = 'indentation: {spaces: 2}'
|
||||
conf = 'indentation: {spaces: consistent}'
|
||||
self.check('---\n'
|
||||
'a:\n'
|
||||
' b:\n'
|
||||
@@ -1031,12 +1092,12 @@ class IndentationTestCase(RuleTestCase):
|
||||
'...\n', conf, problem=(5, 2, 'syntax'))
|
||||
|
||||
def test_first_line(self):
|
||||
conf = ('indentation: {spaces: 2}\n'
|
||||
conf = ('indentation: {spaces: consistent}\n'
|
||||
'document-start: disable\n')
|
||||
self.check(' a: 1\n', conf, problem=(1, 3))
|
||||
|
||||
def test_explicit_block_mappings(self):
|
||||
conf = 'indentation: {spaces: 4}'
|
||||
conf = 'indentation: {spaces: consistent}'
|
||||
self.check('---\n'
|
||||
'object:\n'
|
||||
' ? key\n'
|
||||
@@ -1072,7 +1133,7 @@ class IndentationTestCase(RuleTestCase):
|
||||
'...\n', conf, problem1=(4, 10), problem2=(6, 8))
|
||||
|
||||
def test_clear_sequence_item(self):
|
||||
conf = 'indentation: {spaces: 2}'
|
||||
conf = 'indentation: {spaces: consistent}'
|
||||
self.check('---\n'
|
||||
'-\n'
|
||||
' string\n'
|
||||
@@ -1087,6 +1148,35 @@ class IndentationTestCase(RuleTestCase):
|
||||
' multi\n'
|
||||
' line\n'
|
||||
'...\n', conf)
|
||||
self.check('---\n'
|
||||
'-\n'
|
||||
' string\n'
|
||||
'-\n'
|
||||
' string\n', conf, problem=(5, 4))
|
||||
self.check('---\n'
|
||||
'-\n'
|
||||
' map: ping\n'
|
||||
'-\n'
|
||||
' map: ping\n', conf, problem=(5, 4))
|
||||
self.check('---\n'
|
||||
'-\n'
|
||||
' - sequence\n'
|
||||
'-\n'
|
||||
' - sequence\n', conf, problem=(5, 4))
|
||||
self.check('---\n'
|
||||
'-\n'
|
||||
' -\n'
|
||||
' nested\n'
|
||||
' -\n'
|
||||
' nested\n', conf, problem1=(4, 4), problem2=(6, 6))
|
||||
self.check('---\n'
|
||||
'-\n'
|
||||
' -\n'
|
||||
' >\n'
|
||||
' multi\n'
|
||||
' line\n'
|
||||
'...\n', conf, problem=(4, 6))
|
||||
conf = 'indentation: {spaces: 2}'
|
||||
self.check('---\n'
|
||||
'-\n'
|
||||
' string\n'
|
||||
@@ -1108,16 +1198,9 @@ class IndentationTestCase(RuleTestCase):
|
||||
' nested\n'
|
||||
' -\n'
|
||||
' nested\n', conf, problem1=(4, 4), problem2=(6, 6))
|
||||
self.check('---\n'
|
||||
'-\n'
|
||||
' -\n'
|
||||
' >\n'
|
||||
' multi\n'
|
||||
' line\n'
|
||||
'...\n', conf, problem=(4, 6))
|
||||
|
||||
def test_anchors(self):
|
||||
conf = 'indentation: {spaces: 2}'
|
||||
conf = 'indentation: {spaces: consistent}'
|
||||
self.check('---\n'
|
||||
'key: &anchor value\n', conf)
|
||||
self.check('---\n'
|
||||
@@ -1177,7 +1260,7 @@ class IndentationTestCase(RuleTestCase):
|
||||
' - k: *a\n', conf)
|
||||
|
||||
def test_tags(self):
|
||||
conf = 'indentation: {spaces: 2}'
|
||||
conf = 'indentation: {spaces: consistent}'
|
||||
self.check('---\n'
|
||||
'-\n'
|
||||
' "flow in block"\n'
|
||||
@@ -1186,7 +1269,7 @@ class IndentationTestCase(RuleTestCase):
|
||||
'- !!map # Block collection\n'
|
||||
' foo: bar\n', conf)
|
||||
|
||||
conf = 'indentation: {spaces: 2, indent-sequences: no}'
|
||||
conf = 'indentation: {spaces: consistent, indent-sequences: no}'
|
||||
self.check('---\n'
|
||||
'sequence: !!seq\n'
|
||||
'- entry\n'
|
||||
@@ -1210,7 +1293,8 @@ class ScalarIndentationTestCase(RuleTestCase):
|
||||
rule_id = 'indentation'
|
||||
|
||||
def test_basics_plain(self):
|
||||
conf = ('indentation: {spaces: 2, check-multi-line-strings: no}\n'
|
||||
conf = ('indentation: {spaces: consistent,\n'
|
||||
' check-multi-line-strings: no}\n'
|
||||
'document-start: disable\n')
|
||||
self.check('multi\n'
|
||||
'line\n', conf)
|
||||
@@ -1238,7 +1322,8 @@ class ScalarIndentationTestCase(RuleTestCase):
|
||||
' }\n', conf)
|
||||
|
||||
def test_check_multi_line_plain(self):
|
||||
conf = ('indentation: {spaces: 2, check-multi-line-strings: yes}\n'
|
||||
conf = ('indentation: {spaces: consistent,\n'
|
||||
' check-multi-line-strings: yes}\n'
|
||||
'document-start: disable\n')
|
||||
self.check('multi\n'
|
||||
' line\n', conf, problem=(2, 2))
|
||||
@@ -1260,7 +1345,8 @@ class ScalarIndentationTestCase(RuleTestCase):
|
||||
' }\n', conf, problem=(3, 9))
|
||||
|
||||
def test_basics_quoted(self):
|
||||
conf = ('indentation: {spaces: 2, check-multi-line-strings: no}\n'
|
||||
conf = ('indentation: {spaces: consistent,\n'
|
||||
' check-multi-line-strings: no}\n'
|
||||
'document-start: disable\n')
|
||||
self.check('"multi\n'
|
||||
' line"\n', conf)
|
||||
@@ -1290,7 +1376,8 @@ class ScalarIndentationTestCase(RuleTestCase):
|
||||
' line 2"]\n', conf)
|
||||
|
||||
def test_check_multi_line_quoted(self):
|
||||
conf = ('indentation: {spaces: 2, check-multi-line-strings: yes}\n'
|
||||
conf = ('indentation: {spaces: consistent,\n'
|
||||
' check-multi-line-strings: yes}\n'
|
||||
'document-start: disable\n')
|
||||
self.check('"multi\n'
|
||||
'line"\n', conf, problem=(2, 1))
|
||||
@@ -1345,7 +1432,8 @@ class ScalarIndentationTestCase(RuleTestCase):
|
||||
' line 2"]\n', conf, problem=(3, 14))
|
||||
|
||||
def test_basics_folded_style(self):
|
||||
conf = ('indentation: {spaces: 2, check-multi-line-strings: no}\n'
|
||||
conf = ('indentation: {spaces: consistent,\n'
|
||||
' check-multi-line-strings: no}\n'
|
||||
'document-start: disable\n')
|
||||
self.check('>\n'
|
||||
' multi\n'
|
||||
@@ -1382,7 +1470,8 @@ class ScalarIndentationTestCase(RuleTestCase):
|
||||
' {% endif %}\n', conf)
|
||||
|
||||
def test_check_multi_line_folded_style(self):
|
||||
conf = ('indentation: {spaces: 2, check-multi-line-strings: yes}\n'
|
||||
conf = ('indentation: {spaces: consistent,\n'
|
||||
' check-multi-line-strings: yes}\n'
|
||||
'document-start: disable\n')
|
||||
self.check('>\n'
|
||||
' multi\n'
|
||||
@@ -1422,7 +1511,8 @@ class ScalarIndentationTestCase(RuleTestCase):
|
||||
problem1=(3, 7), problem2=(5, 7))
|
||||
|
||||
def test_basics_literal_style(self):
|
||||
conf = ('indentation: {spaces: 2, check-multi-line-strings: no}\n'
|
||||
conf = ('indentation: {spaces: consistent,\n'
|
||||
' check-multi-line-strings: no}\n'
|
||||
'document-start: disable\n')
|
||||
self.check('|\n'
|
||||
' multi\n'
|
||||
@@ -1459,7 +1549,8 @@ class ScalarIndentationTestCase(RuleTestCase):
|
||||
' {% endif %}\n', conf)
|
||||
|
||||
def test_check_multi_line_literal_style(self):
|
||||
conf = ('indentation: {spaces: 2, check-multi-line-strings: yes}\n'
|
||||
conf = ('indentation: {spaces: consistent,\n'
|
||||
' check-multi-line-strings: yes}\n'
|
||||
'document-start: disable\n')
|
||||
self.check('|\n'
|
||||
' multi\n'
|
||||
@@ -1502,7 +1593,8 @@ class ScalarIndentationTestCase(RuleTestCase):
|
||||
# http://stackoverflow.com/questions/3790454/in-yaml-how-do-i-break-a-string-over-multiple-lines
|
||||
|
||||
def test_paragraph_plain(self):
|
||||
conf = ('indentation: {spaces: 2, check-multi-line-strings: yes}\n'
|
||||
conf = ('indentation: {spaces: consistent,\n'
|
||||
' check-multi-line-strings: yes}\n'
|
||||
'document-start: disable\n')
|
||||
self.check('- long text: very "long"\n'
|
||||
' \'string\' with\n'
|
||||
@@ -1523,7 +1615,8 @@ class ScalarIndentationTestCase(RuleTestCase):
|
||||
' spaces.\n', conf)
|
||||
|
||||
def test_paragraph_double_quoted(self):
|
||||
conf = ('indentation: {spaces: 2, check-multi-line-strings: yes}\n'
|
||||
conf = ('indentation: {spaces: consistent,\n'
|
||||
' check-multi-line-strings: yes}\n'
|
||||
'document-start: disable\n')
|
||||
self.check('- long text: "very \\"long\\"\n'
|
||||
' \'string\' with\n'
|
||||
@@ -1550,7 +1643,8 @@ class ScalarIndentationTestCase(RuleTestCase):
|
||||
' spaces."\n', conf)
|
||||
|
||||
def test_paragraph_single_quoted(self):
|
||||
conf = ('indentation: {spaces: 2, check-multi-line-strings: yes}\n'
|
||||
conf = ('indentation: {spaces: consistent,\n'
|
||||
' check-multi-line-strings: yes}\n'
|
||||
'document-start: disable\n')
|
||||
self.check('- long text: \'very "long"\n'
|
||||
' \'\'string\'\' with\n'
|
||||
@@ -1577,7 +1671,8 @@ class ScalarIndentationTestCase(RuleTestCase):
|
||||
' spaces.\'\n', conf)
|
||||
|
||||
def test_paragraph_folded(self):
|
||||
conf = ('indentation: {spaces: 2, check-multi-line-strings: yes}\n'
|
||||
conf = ('indentation: {spaces: consistent,\n'
|
||||
' check-multi-line-strings: yes}\n'
|
||||
'document-start: disable\n')
|
||||
self.check('- long text: >\n'
|
||||
' very "long"\n'
|
||||
@@ -1594,7 +1689,8 @@ class ScalarIndentationTestCase(RuleTestCase):
|
||||
problem1=(3, 6), problem2=(5, 7), problem3=(6, 8))
|
||||
|
||||
def test_paragraph_literal(self):
|
||||
conf = ('indentation: {spaces: 2, check-multi-line-strings: yes}\n'
|
||||
conf = ('indentation: {spaces: consistent,\n'
|
||||
' check-multi-line-strings: yes}\n'
|
||||
'document-start: disable\n')
|
||||
self.check('- long text: |\n'
|
||||
' very "long"\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,
|
||||
|
||||
@@ -22,7 +22,7 @@ indentation, etc."""
|
||||
|
||||
|
||||
APP_NAME = 'yamllint'
|
||||
APP_VERSION = '1.1.0'
|
||||
APP_VERSION = '1.2.0'
|
||||
APP_DESCRIPTION = __doc__
|
||||
|
||||
__author__ = u'Adrien Vergé'
|
||||
|
||||
@@ -31,14 +31,14 @@ rules:
|
||||
hyphens:
|
||||
max-spaces-after: 1
|
||||
indentation:
|
||||
spaces: 2
|
||||
spaces: consistent
|
||||
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
|
||||
|
||||
@@ -15,15 +15,13 @@ rules:
|
||||
level: warning
|
||||
comments: disable
|
||||
comments-indentation: disable
|
||||
document-end: disable
|
||||
document-start: disable
|
||||
empty-lines:
|
||||
level: warning
|
||||
hyphens: disable
|
||||
hyphens:
|
||||
level: warning
|
||||
indentation:
|
||||
spaces: consistent
|
||||
indent-sequences: whatever
|
||||
check-multi-line-strings: no
|
||||
level: warning
|
||||
indent-sequences: consistent
|
||||
line-length:
|
||||
level: warning
|
||||
max: 100
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -26,8 +26,9 @@ Use this rule to control the indentation.
|
||||
* ``indent-sequences`` defines whether block sequences should be indented or
|
||||
not (when in a mapping, this indentation is not mandatory -- some people
|
||||
perceive the ``-`` as part of the indentation). Possible values: ``yes``,
|
||||
``no`` and ``whatever`` (the latter means either indenting or not indenting
|
||||
block sequences is OK.
|
||||
``no``, ``whatever`` and ``consistent``. ``consistent`` requires either all
|
||||
block sequences to be indented, or none to be. ``whatever`` means either
|
||||
indenting or not indenting individual block sequences is OK.
|
||||
* ``check-multi-line-strings`` defines whether to lint indentation in
|
||||
multi-line strings. Set to ``yes`` to enable, ``no`` to disable.
|
||||
|
||||
@@ -129,6 +130,28 @@ Use this rule to control the indentation.
|
||||
- spaghetti
|
||||
- sauce
|
||||
|
||||
#. With ``indentation: {spaces: 2, indent-sequences: consistent}``
|
||||
|
||||
the following code snippet would **PASS**:
|
||||
::
|
||||
|
||||
- flying:
|
||||
- spaghetti
|
||||
- monster
|
||||
- not flying:
|
||||
- spaghetti
|
||||
- sauce
|
||||
|
||||
the following code snippet would **FAIL**:
|
||||
::
|
||||
|
||||
- flying:
|
||||
- spaghetti
|
||||
- monster
|
||||
- not flying:
|
||||
- spaghetti
|
||||
- sauce
|
||||
|
||||
#. With ``indentation: {spaces: 4, check-multi-line-strings: yes}``
|
||||
|
||||
the following code snippet would **PASS**:
|
||||
@@ -176,7 +199,7 @@ from yamllint.rules.common import is_explicit_key, get_real_end_line
|
||||
ID = 'indentation'
|
||||
TYPE = 'token'
|
||||
CONF = {'spaces': (int, 'consistent'),
|
||||
'indent-sequences': (True, False, 'whatever'),
|
||||
'indent-sequences': (bool, 'whatever', 'consistent'),
|
||||
'check-multi-line-strings': bool}
|
||||
|
||||
ROOT, B_MAP, F_MAP, B_SEQ, F_SEQ, B_ENT, KEY, VAL = range(8)
|
||||
@@ -277,6 +300,7 @@ def check(conf, token, prev, next, nextnext, context):
|
||||
context['stack'] = [Parent(ROOT, 0)]
|
||||
context['cur_line'] = -1
|
||||
context['spaces'] = conf['spaces']
|
||||
context['indent-sequences'] = conf['indent-sequences']
|
||||
|
||||
# Step 1: Lint
|
||||
|
||||
@@ -287,11 +311,10 @@ def check(conf, token, prev, next, nextnext, context):
|
||||
first_in_line = (is_visible and
|
||||
token.start_mark.line + 1 > context['cur_line'])
|
||||
|
||||
def detect_indent(next):
|
||||
def detect_indent(base_indent, next):
|
||||
if type(context['spaces']) is not int:
|
||||
context['spaces'] = (next.start_mark.column -
|
||||
context['stack'][-1].indent)
|
||||
return context['spaces']
|
||||
context['spaces'] = next.start_mark.column - base_indent
|
||||
return base_indent + context['spaces']
|
||||
|
||||
if first_in_line:
|
||||
found_indentation = token.start_mark.column
|
||||
@@ -303,7 +326,7 @@ def check(conf, token, prev, next, nextnext, context):
|
||||
elif (context['stack'][-1].type == KEY and
|
||||
context['stack'][-1].explicit_key and
|
||||
not isinstance(token, yaml.ValueToken)):
|
||||
expected += detect_indent(token)
|
||||
expected = detect_indent(expected, token)
|
||||
|
||||
if found_indentation != expected:
|
||||
yield LintProblem(token.start_mark.line + 1, found_indentation + 1,
|
||||
@@ -337,7 +360,7 @@ def check(conf, token, prev, next, nextnext, context):
|
||||
# - ?
|
||||
# a
|
||||
# : 1
|
||||
indent = token.start_mark.column + detect_indent(next)
|
||||
indent = detect_indent(token.start_mark.column, next)
|
||||
|
||||
context['stack'].append(Parent(B_MAP, indent))
|
||||
|
||||
@@ -349,7 +372,7 @@ def check(conf, token, prev, next, nextnext, context):
|
||||
# - {
|
||||
# a: 1, b: 2
|
||||
# }
|
||||
indent = context['cur_line_indent'] + detect_indent(next)
|
||||
indent = detect_indent(context['cur_line_indent'], next)
|
||||
|
||||
context['stack'].append(Parent(F_MAP, indent,
|
||||
line_indent=context['cur_line_indent']))
|
||||
@@ -383,7 +406,7 @@ def check(conf, token, prev, next, nextnext, context):
|
||||
# -
|
||||
# key:
|
||||
# value
|
||||
indent = token.start_mark.column + detect_indent(next)
|
||||
indent = detect_indent(token.start_mark.column, next)
|
||||
|
||||
context['stack'].append(Parent(B_ENT, indent))
|
||||
|
||||
@@ -395,7 +418,7 @@ def check(conf, token, prev, next, nextnext, context):
|
||||
# - [
|
||||
# a, b
|
||||
# ]
|
||||
indent = context['cur_line_indent'] + detect_indent(next)
|
||||
indent = detect_indent(context['cur_line_indent'], next)
|
||||
|
||||
context['stack'].append(Parent(F_SEQ, indent,
|
||||
line_indent=context['cur_line_indent']))
|
||||
@@ -433,7 +456,7 @@ def check(conf, token, prev, next, nextnext, context):
|
||||
# ? k
|
||||
# :
|
||||
# value
|
||||
indent = context['stack'][-1].indent + detect_indent(next)
|
||||
indent = detect_indent(context['stack'][-1].indent, next)
|
||||
elif next.start_mark.line == prev.start_mark.line:
|
||||
# k: value
|
||||
indent = next.start_mark.column
|
||||
@@ -444,26 +467,30 @@ def check(conf, token, prev, next, nextnext, context):
|
||||
# yaml.scan()ning this:
|
||||
# '- lib:\n'
|
||||
# ' - var\n'
|
||||
if conf['indent-sequences'] is False:
|
||||
if context['indent-sequences'] is False:
|
||||
indent = context['stack'][-1].indent
|
||||
elif conf['indent-sequences'] is True:
|
||||
indent = context['stack'][-1].indent + detect_indent(next)
|
||||
else: # 'whatever'
|
||||
elif context['indent-sequences'] is True:
|
||||
indent = detect_indent(context['stack'][-1].indent, next)
|
||||
else: # 'whatever' or 'consistent'
|
||||
if next.start_mark.column == context['stack'][-1].indent:
|
||||
# key:
|
||||
# - e1
|
||||
# - e2
|
||||
if context['indent-sequences'] == 'consistent':
|
||||
context['indent-sequences'] = False
|
||||
indent = context['stack'][-1].indent
|
||||
else:
|
||||
if context['indent-sequences'] == 'consistent':
|
||||
context['indent-sequences'] = True
|
||||
# key:
|
||||
# - e1
|
||||
# - e2
|
||||
indent = (context['stack'][-1].indent +
|
||||
detect_indent(next))
|
||||
indent = detect_indent(context['stack'][-1].indent,
|
||||
next)
|
||||
else:
|
||||
# k:
|
||||
# value
|
||||
indent = context['stack'][-1].indent + detect_indent(next)
|
||||
indent = detect_indent(context['stack'][-1].indent, next)
|
||||
|
||||
context['stack'].append(Parent(VAL, indent))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user