diff --git a/yamllint/rules/document_end.py b/yamllint/rules/document_end.py index 4e3302f89..0ade4a2be 100644 --- a/yamllint/rules/document_end.py +++ b/yamllint/rules/document_end.py @@ -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) @@ -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): @@ -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,