Skip to content

Commit

Permalink
[document-end] adds min/max empty lines before
Browse files Browse the repository at this point in the history
  • Loading branch information
wookietreiber committed Jul 14, 2021
1 parent 493e662 commit 8d31c7d
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions yamllint/rules/document_end.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
* Set ``present`` to ``true`` when the document end marker is required, or to
``false`` when it is forbidden.
* ``min-empty-lines-before`` defines the minimal number of empty lines before
the document end marker.
* ``max-empty-lines-before`` defines the maximal number of empty lines before
the document end marker.
.. rubric:: Default values (when enabled)
Expand Down Expand Up @@ -89,8 +93,12 @@

ID = 'document-end'
TYPE = 'token'
CONF = {'present': bool}
DEFAULT = {'present': True}
CONF = {'present': bool,
'max-empty-lines-before': int,
'min-empty-lines-before': int}
DEFAULT = {'present': True,
'max-empty-lines-before': -1,
'min-empty-lines-before': 0}


def check(conf, token, prev, next, nextnext, context):
Expand All @@ -108,6 +116,21 @@ def check(conf, token, prev, next, nextnext, context):
yield LintProblem(token.start_mark.line + 1, 1,
'missing document end "..."')

if isinstance(next, yaml.DocumentEndToken):
empty_lines = next.start_mark.line - token.start_mark.line - 1

if (conf['max-empty-lines-before'] >= 0 and
empty_lines > conf['max-empty-lines-before']):
yield LintProblem(token.start_mark.line + 1,
token.start_mark.column + 1,
'too many empty lines before document end')

if (conf['min-empty-lines-before'] > 0 and
empty_lines < conf['min-empty-lines-before']):
yield LintProblem(token.start_mark.line + 1,
token.start_mark.column + 1,
'too few empty lines before document end')

else:
if isinstance(token, yaml.DocumentEndToken):
yield LintProblem(token.start_mark.line + 1,
Expand Down

0 comments on commit 8d31c7d

Please sign in to comment.