mirror of
https://github.com/adrienverge/yamllint.git
synced 2025-02-16 13:04:45 -06:00
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
This commit is contained in:
parent
6a24781f96
commit
847f7e3fff
@ -131,3 +131,19 @@ class CommentsTestCase(RuleTestCase):
|
||||
' require-starting-space: yes\n'
|
||||
' min-spaces-from-content: 2\n')
|
||||
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,11 +30,13 @@ def check(conf, token, prev, next, context):
|
||||
for comment in get_comments_between_tokens(token, next):
|
||||
if (conf['min-spaces-from-content'] != -1 and
|
||||
not isinstance(token, yaml.StreamStartToken) and
|
||||
comment.line == token.end_mark.line + 1 and
|
||||
comment.pointer - token.end_mark.pointer <
|
||||
conf['min-spaces-from-content']):
|
||||
yield LintProblem(comment.line, comment.column,
|
||||
'too few spaces before comment')
|
||||
comment.line == token.end_mark.line + 1):
|
||||
# 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']):
|
||||
yield LintProblem(comment.line, comment.column,
|
||||
'too few spaces before comment')
|
||||
|
||||
if (conf['require-starting-space'] and
|
||||
comment.pointer + 1 < len(comment.buffer) and
|
||||
|
Loading…
Reference in New Issue
Block a user