Rules: commas: Don't allow a comma on a new line

Forbid such constructions:

    [ a, b, c
      , d, e ]
This commit is contained in:
Adrien Vergé
2016-01-19 18:38:37 +01:00
parent 39c878c819
commit 9d8b0d4d2c
2 changed files with 44 additions and 5 deletions

View File

@@ -16,6 +16,7 @@
import yaml
from yamllint.errors import LintProblem
from yamllint.rules.common import spaces_after, spaces_before
@@ -27,11 +28,16 @@ CONF = {'max-spaces-before': int,
def check(conf, token, prev, next, context):
if isinstance(token, yaml.FlowEntryToken):
problem = spaces_before(token, prev, next,
max=conf['max-spaces-before'],
max_desc='too many spaces before comma')
if problem is not None:
yield problem
if prev is not None and prev.end_mark.line < token.start_mark.line:
yield LintProblem(token.start_mark.line + 1,
max(1, token.start_mark.column),
'too many spaces before comma')
else:
problem = spaces_before(token, prev, next,
max=conf['max-spaces-before'],
max_desc='too many spaces before comma')
if problem is not None:
yield problem
problem = spaces_after(token, prev, next,
max=conf['max-spaces-after'],