Skip to content

Commit

Permalink
document-end: Fix spurious "missing document end"
Browse files Browse the repository at this point in the history
DocumentStartToken is preceded by DirectiveToken.
  • Loading branch information
DimitriPapadopoulos authored and adrienverge committed Jun 27, 2023
1 parent 7f2c071 commit a68c3aa
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
19 changes: 19 additions & 0 deletions tests/rules/test_document_end.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,22 @@ def test_multiple_documents(self):
'---\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)
4 changes: 3 additions & 1 deletion yamllint/rules/document_end.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "..."')

Expand Down

0 comments on commit a68c3aa

Please sign in to comment.