From b7fcc105e263b53bc271d64f850f327662c76a56 Mon Sep 17 00:00:00 2001 From: Mathieu Rul Date: Fri, 16 Jun 2023 15:21:01 +0200 Subject: [PATCH] Fix null rule for syntax error Signed-off-by: Mathieu Rul --- tests/common.py | 5 +---- tests/test_syntax_errors.py | 2 +- yamllint/linter.py | 3 ++- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/common.py b/tests/common.py index 65af63b..9546c77 100644 --- a/tests/common.py +++ b/tests/common.py @@ -40,10 +40,7 @@ class RuleTestCase(unittest.TestCase): 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] + rule_id = kwargs[key][2] else: rule_id = self.rule_id expected_problems.append(linter.LintProblem( diff --git a/tests/test_syntax_errors.py b/tests/test_syntax_errors.py index 507ab5a..ece4474 100644 --- a/tests/test_syntax_errors.py +++ b/tests/test_syntax_errors.py @@ -17,7 +17,7 @@ from tests.common import RuleTestCase class YamlLintTestCase(RuleTestCase): - rule_id = None # syntax error + rule_id = 'syntax' # syntax error def test_syntax_errors(self): self.check('---\n' diff --git a/yamllint/linter.py b/yamllint/linter.py index 5501bb5..3dc7888 100644 --- a/yamllint/linter.py +++ b/yamllint/linter.py @@ -180,7 +180,8 @@ def get_syntax_error(buffer): except yaml.error.MarkedYAMLError as e: problem = LintProblem(e.problem_mark.line + 1, e.problem_mark.column + 1, - 'syntax error: ' + e.problem + ' (syntax)') + 'syntax error: ' + e.problem, + 'syntax') problem.level = 'error' return problem