diff --git a/tests/rules/test_comments.py b/tests/rules/test_comments.py index 4f64a97..e6468f1 100644 --- a/tests/rules/test_comments.py +++ b/tests/rules/test_comments.py @@ -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) diff --git a/yamllint/rules/comments.py b/yamllint/rules/comments.py index c2ec209..854755e 100644 --- a/yamllint/rules/comments.py +++ b/yamllint/rules/comments.py @@ -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