From 3989a09d32369e723fddb7d9df1f1f280063ee32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Verg=C3=A9?= Date: Thu, 14 Jan 2016 19:56:10 +0100 Subject: [PATCH] Rules: comments: Allow empty comments --- tests/rules/test_comments.py | 12 ++++++++++++ yamllint/rules/comments.py | 3 ++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/rules/test_comments.py b/tests/rules/test_comments.py index 9d247bc..42ac733 100644 --- a/tests/rules/test_comments.py +++ b/tests/rules/test_comments.py @@ -163,3 +163,15 @@ class CommentsTestCase(RuleTestCase): problem5=(9, 2), problem6=(10, 4), problem7=(13, 30)) + + def test_empty_comment(self): + conf = ('comments:\n' + ' require-starting-space: yes\n' + ' min-spaces-from-content: 2\n') + self.check('---\n' + '# This is paragraph 1.\n' + '#\n' + '# This is paragraph 2.\n', conf) + self.check('---\n' + 'inline: comment #\n' + '\n', conf) diff --git a/yamllint/rules/comments.py b/yamllint/rules/comments.py index 120fd13..4a8d83c 100644 --- a/yamllint/rules/comments.py +++ b/yamllint/rules/comments.py @@ -79,6 +79,7 @@ def check(conf, token, prev, next): if (conf['require-starting-space'] and comment.pointer + 1 < len(comment.buffer) and - comment.buffer[comment.pointer + 1] != ' '): + comment.buffer[comment.pointer + 1] != ' ' and + comment.buffer[comment.pointer + 1] != '\n'): yield LintProblem(comment.line, comment.column + 1, 'missing starting space in comment')