Rules: comments-indentation: Allow two levels
Previously only comments that were indented like the following content
line were allowed, e.g.:
prev: line:
# commented line
current: line
With this change, such new cases are also allowed:
prev: line
# commented line 1
# commented line 2
current: line
This commit is contained in:
@@ -88,15 +88,39 @@ class CommentsIndentationTestCase(RuleTestCase):
|
||||
self.check('---\n'
|
||||
'obj1:\n'
|
||||
' a: 1\n'
|
||||
' # comments\n'
|
||||
' # the following line is disabled\n'
|
||||
' # b: 2\n', conf)
|
||||
self.check('---\n'
|
||||
'obj1:\n'
|
||||
' a: 1\n'
|
||||
' # b: 2\n'
|
||||
'\n'
|
||||
'obj2:\n'
|
||||
' b: 2\n', conf, problem=(4, 3))
|
||||
' b: 2\n', conf)
|
||||
self.check('---\n'
|
||||
'obj1:\n'
|
||||
' a: 1\n'
|
||||
' # b: 2\n'
|
||||
'# this object is useless\n'
|
||||
'obj2: no\n', conf)
|
||||
self.check('---\n'
|
||||
'obj1:\n'
|
||||
' a: 1\n'
|
||||
'# this object is useless\n'
|
||||
' # b: 2\n'
|
||||
'obj2: no\n', conf, problem=(5, 3))
|
||||
self.check('---\n'
|
||||
'obj1:\n'
|
||||
' a: 1\n'
|
||||
' # comments\n'
|
||||
' b: 2\n', conf)
|
||||
self.check('---\n'
|
||||
'mylist:\n'
|
||||
' - todo 1\n'
|
||||
' - todo 2\n'
|
||||
' # commented for now\n'
|
||||
' # - todo 3\n'
|
||||
'...\n', conf)
|
||||
|
||||
def test_first_line(self):
|
||||
conf = 'comments-indentation: {}'
|
||||
|
||||
@@ -18,10 +18,32 @@ import unittest
|
||||
|
||||
import yaml
|
||||
|
||||
from yamllint.rules.common import Comment, get_comments_between_tokens
|
||||
from yamllint.rules.common import (Comment, get_line_indent,
|
||||
get_comments_between_tokens)
|
||||
|
||||
|
||||
class CommonTestCase(unittest.TestCase):
|
||||
def test_get_line_indent(self):
|
||||
tokens = list(yaml.scan('a: 1\n'
|
||||
'b:\n'
|
||||
' - c: [2, 3, {d: 4}]\n'))
|
||||
|
||||
self.assertEqual(tokens[3].value, 'a')
|
||||
self.assertEqual(tokens[5].value, '1')
|
||||
self.assertEqual(tokens[7].value, 'b')
|
||||
self.assertEqual(tokens[13].value, 'c')
|
||||
self.assertEqual(tokens[16].value, '2')
|
||||
self.assertEqual(tokens[18].value, '3')
|
||||
self.assertEqual(tokens[22].value, 'd')
|
||||
self.assertEqual(tokens[24].value, '4')
|
||||
|
||||
for i in (3, 5):
|
||||
self.assertEqual(get_line_indent(tokens[i]), 0)
|
||||
for i in (7,):
|
||||
self.assertEqual(get_line_indent(tokens[i]), 0)
|
||||
for i in (13, 16, 18, 22, 24):
|
||||
self.assertEqual(get_line_indent(tokens[i]), 2)
|
||||
|
||||
def check_comments(self, buffer, *expected):
|
||||
yaml_loader = yaml.BaseLoader(buffer)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user