Rules: comments: Fix bug when multi-line scalar

YAML content like the following one produced an error, because the
ScalarToken associated whose value is "this is plain text" ends at the
beginning of the 5th line (the one with the comment):

    ---
    string: >
      this is plain text

    # comment
pull/4/head
Adrien Vergé 9 years ago
parent 6a24781f96
commit 847f7e3fff

@ -131,3 +131,19 @@ class CommentsTestCase(RuleTestCase):
' require-starting-space: yes\n' ' require-starting-space: yes\n'
' min-spaces-from-content: 2\n') ' min-spaces-from-content: 2\n')
self.check('# comment\n', conf) self.check('# comment\n', conf)
def test_multi_line_scalar(self):
conf = ('comments:\n'
' require-starting-space: yes\n'
' min-spaces-from-content: 2\n'
'trailing-spaces: disable\n')
self.check('---\n'
'string: >\n'
' this is plain text\n'
'\n'
'# comment\n', conf)
self.check('---\n'
'- string: >\n'
' this is plain text\n'
' \n'
' # comment\n', conf)

@ -30,8 +30,10 @@ def check(conf, token, prev, next, context):
for comment in get_comments_between_tokens(token, next): for comment in get_comments_between_tokens(token, next):
if (conf['min-spaces-from-content'] != -1 and if (conf['min-spaces-from-content'] != -1 and
not isinstance(token, yaml.StreamStartToken) and not isinstance(token, yaml.StreamStartToken) and
comment.line == token.end_mark.line + 1 and comment.line == token.end_mark.line + 1):
comment.pointer - token.end_mark.pointer < # Sometimes token end marks are on the next line
if token.end_mark.buffer[token.end_mark.pointer - 1] != '\n':
if (comment.pointer - token.end_mark.pointer <
conf['min-spaces-from-content']): conf['min-spaces-from-content']):
yield LintProblem(comment.line, comment.column, yield LintProblem(comment.line, comment.column,
'too few spaces before comment') 'too few spaces before comment')

Loading…
Cancel
Save