diff --git a/tests/rules/test_colons.py b/tests/rules/test_colons.py index 98a4171..05538a2 100644 --- a/tests/rules/test_colons.py +++ b/tests/rules/test_colons.py @@ -118,7 +118,7 @@ class ColonTestCase(RuleTestCase): '...\n', conf, problem=(3, 8)) def test_before_with_explicit_block_mappings(self): - conf = 'colons: {max-spaces-before: 0, max-spaces-after: -1}' + conf = 'colons: {max-spaces-before: 0, max-spaces-after: 1}' self.check('---\n' 'object:\n' ' ? key\n' @@ -129,6 +129,30 @@ class ColonTestCase(RuleTestCase): ' ? key\n' ' : value\n' '...\n', conf, problem=(2, 7)) + self.check('---\n' + '? >\n' + ' multi-line\n' + ' key\n' + ': >\n' + ' multi-line\n' + ' value\n' + '...\n', conf) + self.check('---\n' + '- ? >\n' + ' multi-line\n' + ' key\n' + ' : >\n' + ' multi-line\n' + ' value\n' + '...\n', conf) + self.check('---\n' + '- ? >\n' + ' multi-line\n' + ' key\n' + ' : >\n' + ' multi-line\n' + ' value\n' + '...\n', conf, problem=(5, 5)) def test_after_enabled(self): conf = 'colons: {max-spaces-before: -1, max-spaces-after: 1}' diff --git a/yamllint/rules/common.py b/yamllint/rules/common.py index 400479c..8de3b33 100644 --- a/yamllint/rules/common.py +++ b/yamllint/rules/common.py @@ -33,7 +33,10 @@ def spaces_after(token, prev, next, min=-1, max=-1, def spaces_before(token, prev, next, min=-1, max=-1, min_desc=None, max_desc=None): - if prev is not None and prev.end_mark.line == token.start_mark.line: + if (prev is not None and prev.end_mark.line == token.start_mark.line and + # Discard tokens (only scalars?) that end at the start of next line + (prev.end_mark.pointer == 0 or + prev.end_mark.buffer[prev.end_mark.pointer - 1] != '\n')): spaces = token.start_mark.pointer - prev.end_mark.pointer if max != - 1 and spaces > max: return LintProblem(token.start_mark.line + 1,