diff --git a/tests/rules/common.py b/tests/rules/common.py index 0d31550..cf5ff07 100644 --- a/tests/rules/common.py +++ b/tests/rules/common.py @@ -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))) diff --git a/tests/rules/test_document_start.py b/tests/rules/test_document_start.py index 29a6dc0..b19dc8f 100644 --- a/tests/rules/test_document_start.py +++ b/tests/rules/test_document_start.py @@ -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}' diff --git a/tests/rules/test_indentation.py b/tests/rules/test_indentation.py index cdebdf7..e71fdc9 100644 --- a/tests/rules/test_indentation.py +++ b/tests/rules/test_indentation.py @@ -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' diff --git a/tests/rules/test_trailing_spaces.py b/tests/rules/test_trailing_spaces.py index 75ffe3d..9bbfbfd 100644 --- a/tests/rules/test_trailing_spaces.py +++ b/tests/rules/test_trailing_spaces.py @@ -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' diff --git a/yamllint/__init__.py b/yamllint/__init__.py index 4595133..1bb1a54 100644 --- a/yamllint/__init__.py +++ b/yamllint/__init__.py @@ -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