From a68c3aa69e298ea20bdfb51ac388d5bfc4c347aa Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sat, 24 Jun 2023 15:42:50 +0200 Subject: [PATCH] document-end: Fix spurious "missing document end" DocumentStartToken is preceded by DirectiveToken. --- tests/rules/test_document_end.py | 19 +++++++++++++++++++ yamllint/rules/document_end.py | 4 +++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/tests/rules/test_document_end.py b/tests/rules/test_document_end.py index 927d0a7..8340c6f 100644 --- a/tests/rules/test_document_end.py +++ b/tests/rules/test_document_end.py @@ -71,3 +71,22 @@ class DocumentEndTestCase(RuleTestCase): '---\n' 'third: document\n' '...\n', conf, problem=(6, 1)) + + def test_directives(self): + conf = 'document-end: {present: true}' + self.check('%YAML 1.2\n' + '---\n' + 'document: end\n' + '...\n', conf) + self.check('%YAML 1.2\n' + '%TAG ! tag:clarkevans.com,2002:\n' + '---\n' + 'document: end\n' + '...\n', conf) + self.check('---\n' + 'first: document\n' + '...\n' + '%YAML 1.2\n' + '---\n' + 'second: document\n' + '...\n', conf) diff --git a/yamllint/rules/document_end.py b/yamllint/rules/document_end.py index 3fc14ad..2337484 100644 --- a/yamllint/rules/document_end.py +++ b/yamllint/rules/document_end.py @@ -99,11 +99,13 @@ def check(conf, token, prev, next, nextnext, context): prev_is_end_or_stream_start = isinstance( prev, (yaml.DocumentEndToken, yaml.StreamStartToken) ) + prev_is_directive = isinstance(prev, yaml.DirectiveToken) if is_stream_end and not prev_is_end_or_stream_start: yield LintProblem(token.start_mark.line, 1, 'missing document end "..."') - elif is_start and not prev_is_end_or_stream_start: + elif is_start and not (prev_is_end_or_stream_start + or prev_is_directive): yield LintProblem(token.start_mark.line + 1, 1, 'missing document end "..."')