Make syntax errors prevail over yamllint 'warnings'

When both a syntax error (unability to parse a document) and a cosmetic
yamllint problem are found at the same place, the yamllint problem had
the priority -- and the syntax error was not displayed.

This had the following problem: if a rule is at the 'warning' level, its
problems will not make the `yamllint` script return a failure return
code (`!= 0`), even when it should (because there was a syntax error,
precisely).

This commit changes this behavior by preferring yamllint problems only
when they have the 'error' level.
pull/4/head
Adrien Vergé 9 years ago
parent 97e2210ec9
commit 918f15b68d

@ -76,10 +76,14 @@ 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, in which case the
# syntax error is probably redundant.
# ... 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):
syntax_error.column != problem.column or
problem.level != 'error'):
yield syntax_error
syntax_error = None

Loading…
Cancel
Save