From 918f15b68d022d7a667534ec7e34fd6831880583 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Verg=C3=A9?= Date: Fri, 15 Jan 2016 18:39:52 +0100 Subject: [PATCH] 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. --- yamllint/__init__.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/yamllint/__init__.py b/yamllint/__init__.py index 887c840..a2812f9 100644 --- a/yamllint/__init__.py +++ b/yamllint/__init__.py @@ -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