mirror of
https://github.com/adrienverge/yamllint.git
synced 2025-02-25 18:55:20 -06:00
Rules: Fix spaces_before when prev is multi-line scalar
YAML content like the following one produced an error, because the
multi-line ScalarToken ends at the beginning of the 4th line (the one
with the value):
? >
multi-line
key
: value
This commit is contained in:
@@ -118,7 +118,7 @@ class ColonTestCase(RuleTestCase):
|
|||||||
'...\n', conf, problem=(3, 8))
|
'...\n', conf, problem=(3, 8))
|
||||||
|
|
||||||
def test_before_with_explicit_block_mappings(self):
|
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'
|
self.check('---\n'
|
||||||
'object:\n'
|
'object:\n'
|
||||||
' ? key\n'
|
' ? key\n'
|
||||||
@@ -129,6 +129,30 @@ class ColonTestCase(RuleTestCase):
|
|||||||
' ? key\n'
|
' ? key\n'
|
||||||
' : value\n'
|
' : value\n'
|
||||||
'...\n', conf, problem=(2, 7))
|
'...\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):
|
def test_after_enabled(self):
|
||||||
conf = 'colons: {max-spaces-before: -1, max-spaces-after: 1}'
|
conf = 'colons: {max-spaces-before: -1, max-spaces-after: 1}'
|
||||||
|
|||||||
@@ -33,7 +33,10 @@ def spaces_after(token, prev, next, min=-1, max=-1,
|
|||||||
|
|
||||||
def spaces_before(token, prev, next, min=-1, max=-1,
|
def spaces_before(token, prev, next, min=-1, max=-1,
|
||||||
min_desc=None, max_desc=None):
|
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
|
spaces = token.start_mark.pointer - prev.end_mark.pointer
|
||||||
if max != - 1 and spaces > max:
|
if max != - 1 and spaces > max:
|
||||||
return LintProblem(token.start_mark.line + 1,
|
return LintProblem(token.start_mark.line + 1,
|
||||||
|
|||||||
Reference in New Issue
Block a user