|
|
@ -25,39 +25,46 @@ CONF = {'spaces': int}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def check(conf, token, prev, next):
|
|
|
|
def check(conf, token, prev, next):
|
|
|
|
if isinstance(token, yaml.StreamEndToken):
|
|
|
|
if isinstance(token, (yaml.StreamStartToken, yaml.StreamEndToken)):
|
|
|
|
return
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
if (prev is None or isinstance(prev, yaml.StreamStartToken) or
|
|
|
|
# Check if first token in line
|
|
|
|
isinstance(prev, yaml.DirectiveToken) or
|
|
|
|
if (not isinstance(prev, (yaml.StreamStartToken, yaml.DirectiveToken)) and
|
|
|
|
isinstance(prev, yaml.DocumentStartToken)):
|
|
|
|
token.start_mark.line == prev.end_mark.line):
|
|
|
|
if token.start_mark.column != 0:
|
|
|
|
|
|
|
|
yield LintProblem(
|
|
|
|
|
|
|
|
token.end_mark.line + 1, token.start_mark.column + 1,
|
|
|
|
|
|
|
|
'found indentation of %d instead of %d' %
|
|
|
|
|
|
|
|
(token.start_mark.column, 0))
|
|
|
|
|
|
|
|
return
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
if token.start_mark.line > prev.end_mark.line:
|
|
|
|
if token.start_mark.column % conf['spaces'] != 0:
|
|
|
|
buffer = prev.end_mark.buffer
|
|
|
|
yield LintProblem(
|
|
|
|
|
|
|
|
token.end_mark.line + 1, token.start_mark.column + 1,
|
|
|
|
|
|
|
|
'indentation is not a multiple of %d' % conf['spaces'])
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if isinstance(prev, (yaml.StreamStartToken,
|
|
|
|
|
|
|
|
yaml.DirectiveToken,
|
|
|
|
|
|
|
|
yaml.DocumentStartToken,
|
|
|
|
|
|
|
|
yaml.DocumentEndToken)):
|
|
|
|
|
|
|
|
indent = 0
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
buffer = prev.end_mark.buffer
|
|
|
|
start = buffer.rfind('\n', 0, prev.end_mark.pointer) + 1
|
|
|
|
start = buffer.rfind('\n', 0, prev.end_mark.pointer) + 1
|
|
|
|
prev_indent = 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# YAML recognizes two white space characters: space and tab.
|
|
|
|
indent = 0
|
|
|
|
# http://yaml.org/spec/1.2/spec.html#id2775170
|
|
|
|
while buffer[start + indent] == ' ':
|
|
|
|
while buffer[start + prev_indent] in ' \t':
|
|
|
|
indent += 1
|
|
|
|
prev_indent += 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Discard any leading '- '
|
|
|
|
if token.start_mark.column > indent:
|
|
|
|
if (buffer[start + prev_indent:start + prev_indent + 2] == '- '):
|
|
|
|
if not isinstance(prev, (yaml.BlockSequenceStartToken,
|
|
|
|
prev_indent += 2
|
|
|
|
yaml.BlockMappingStartToken,
|
|
|
|
while buffer[start + prev_indent] in ' \t':
|
|
|
|
yaml.FlowSequenceStartToken,
|
|
|
|
prev_indent += 1
|
|
|
|
yaml.FlowMappingStartToken,
|
|
|
|
|
|
|
|
yaml.KeyToken,
|
|
|
|
|
|
|
|
yaml.ValueToken)):
|
|
|
|
|
|
|
|
yield LintProblem(
|
|
|
|
|
|
|
|
token.end_mark.line + 1, token.start_mark.column + 1,
|
|
|
|
|
|
|
|
'unexpected indentation')
|
|
|
|
|
|
|
|
|
|
|
|
if (token.start_mark.column > prev_indent and
|
|
|
|
elif token.start_mark.column != indent + conf['spaces']:
|
|
|
|
token.start_mark.column != prev_indent + conf['spaces']):
|
|
|
|
|
|
|
|
yield LintProblem(
|
|
|
|
yield LintProblem(
|
|
|
|
token.end_mark.line + 1, token.start_mark.column + 1,
|
|
|
|
token.end_mark.line + 1, token.start_mark.column + 1,
|
|
|
|
'found indentation of %d instead of %d' %
|
|
|
|
'found indentation of %d instead of %d' %
|
|
|
|
(token.start_mark.column, prev_indent + conf['spaces']))
|
|
|
|
(token.start_mark.column, indent + conf['spaces']))
|
|
|
|