mirror of
https://github.com/adrienverge/yamllint.git
synced 2025-02-25 18:55:20 -06:00
Make syntax errors prevail over all yamllint problems
This commit is contained in:
parent
effb4db3b4
commit
222f7a27c1
@ -37,8 +37,15 @@ class RuleTestCase(unittest.TestCase):
|
||||
expected_problems = []
|
||||
for key in kwargs:
|
||||
assert key.startswith('problem')
|
||||
if len(kwargs[key]) > 2:
|
||||
if kwargs[key][2] == 'syntax':
|
||||
rule_id = None
|
||||
else:
|
||||
rule_id = kwargs[key][2]
|
||||
else:
|
||||
rule_id = self.rule_id
|
||||
expected_problems.append(
|
||||
LintProblem(kwargs[key][0], kwargs[key][1], rule=self.rule_id))
|
||||
LintProblem(kwargs[key][0], kwargs[key][1], rule=rule_id))
|
||||
expected_problems.sort()
|
||||
|
||||
real_problems = list(lint(source, self.build_fake_config(conf)))
|
||||
|
@ -82,7 +82,7 @@ class DocumentStartTestCase(RuleTestCase):
|
||||
'...\n'
|
||||
'second: document\n'
|
||||
'---\n'
|
||||
'third: document\n', conf, problem=(4, 1))
|
||||
'third: document\n', conf, problem=(4, 1, 'syntax'))
|
||||
|
||||
def test_directives(self):
|
||||
conf = 'document-start: {present: yes}'
|
||||
|
@ -163,7 +163,7 @@ class IndentationTestCase(RuleTestCase):
|
||||
self.check('---\n'
|
||||
'- o:\n'
|
||||
' k1: v1\n'
|
||||
'...\n', conf, problem=(3, 2))
|
||||
'...\n', conf, problem=(3, 2, 'syntax'))
|
||||
self.check('---\n'
|
||||
'- o:\n'
|
||||
' k1: v1\n'
|
||||
@ -192,18 +192,18 @@ class IndentationTestCase(RuleTestCase):
|
||||
' f:\n'
|
||||
'g:\n'
|
||||
'...\n', None)
|
||||
# self.check('---\n'
|
||||
# 'a:\n'
|
||||
# ' b:\n'
|
||||
# ' c:\n'
|
||||
# ' d:\n'
|
||||
# '...\n', None, problem=(5, 5))
|
||||
# self.check('---\n'
|
||||
# 'a:\n'
|
||||
# ' b:\n'
|
||||
# ' c:\n'
|
||||
# ' d:\n'
|
||||
# '...\n', None, problem=(5, 2))
|
||||
self.check('---\n'
|
||||
'a:\n'
|
||||
' b:\n'
|
||||
' c:\n'
|
||||
' d:\n'
|
||||
'...\n', None, problem=(5, 4, 'syntax'))
|
||||
self.check('---\n'
|
||||
'a:\n'
|
||||
' b:\n'
|
||||
' c:\n'
|
||||
' d:\n'
|
||||
'...\n', None, problem=(5, 2, 'syntax'))
|
||||
|
||||
def test_first_line(self):
|
||||
conf = ('indentation: {spaces: 2}\n'
|
||||
|
@ -33,11 +33,11 @@ class TrailingSpacesTestCase(RuleTestCase):
|
||||
self.check('', conf)
|
||||
self.check('\n', conf)
|
||||
self.check(' \n', conf, problem=(1, 1))
|
||||
self.check('\t\t\t\n', conf, problem=(1, 1))
|
||||
self.check('\t\t\t\n', conf, problem=(1, 1, 'syntax'))
|
||||
self.check('---\n'
|
||||
'some: text \n', conf, problem=(2, 11))
|
||||
self.check('---\n'
|
||||
'some: text\t\n', conf, problem=(2, 11))
|
||||
'some: text\t\n', conf, problem=(2, 11, 'syntax'))
|
||||
|
||||
def test_with_dos_new_lines(self):
|
||||
conf = ('trailing-spaces: {}\n'
|
||||
|
@ -81,15 +81,16 @@ def _lint(buffer, conf):
|
||||
# Insert the syntax error (if any) at the right place...
|
||||
if (syntax_error and syntax_error.line <= problem.line and
|
||||
syntax_error.column <= problem.column):
|
||||
# ... unless there is already a yamllint error at the same place,
|
||||
# in which case the syntax error is probably redundant.
|
||||
# In such a case, the yamllint problem is preferred, except if its
|
||||
# level is not 'error' (because the script needs to exit with a
|
||||
# failure status, the syntax error is preferred here).
|
||||
if (syntax_error.line != problem.line or
|
||||
syntax_error.column != problem.column or
|
||||
problem.level != 'error'):
|
||||
yield syntax_error
|
||||
yield syntax_error
|
||||
|
||||
# If there is already a yamllint error at the same place, discard
|
||||
# it as it is probably redundant (and maybe it's just a 'warning',
|
||||
# in which case the script won't even exit with a failure status).
|
||||
if (syntax_error.line == problem.line and
|
||||
syntax_error.column == problem.column):
|
||||
syntax_error = None
|
||||
continue
|
||||
|
||||
syntax_error = None
|
||||
|
||||
yield problem
|
||||
|
Loading…
Reference in New Issue
Block a user