Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if conf['require-starting-space']:
text_start = comment.pointer + 1
while (comment.buffer[text_start] == '#' and
text_start < len(comment.buffer)):
text_start += 1
if text_start < len(comment.buffer):
if (conf['ignore-shebangs'] and
comment.line_no == 1 and
comment.column_no == 1 and
re.match(r'^!\S', comment.buffer[text_start:])):
return
# We can test for both \r and \r\n just by checking first char
# \r itself is a valid newline on some older OS.
elif comment.buffer[text_start] not in {' ', '\n', '\r', '\x00'}:
column = comment.column_no + text_start - comment.pointer
yield LintProblem(comment.line_no,
column,
'missing starting space in comment')
def spaces_after(token, prev, next, min=-1, max=-1,
min_desc=None, max_desc=None):
if next is not None and token.end_mark.line == next.start_mark.line:
spaces = next.start_mark.pointer - token.end_mark.pointer
if max != - 1 and spaces > max:
return LintProblem(token.start_mark.line + 1,
next.start_mark.column, max_desc)
elif min != - 1 and spaces < min:
return LintProblem(token.start_mark.line + 1,
next.start_mark.column + 1, min_desc)
def check(conf, token, prev, next, nextnext, context):
if prev and isinstance(prev, yaml.tokens.TagToken):
return
if (not conf['check-keys'] and isinstance(prev, yaml.tokens.KeyToken) and
isinstance(token, yaml.tokens.ScalarToken)):
return
if isinstance(token, yaml.tokens.ScalarToken):
if (token.value in (set(TRUTHY) - set(conf['allowed-values'])) and
token.style is None):
yield LintProblem(token.start_mark.line + 1,
token.start_mark.column + 1,
"truthy value should be one of [" +
", ".join(sorted(conf['allowed-values'])) + "]")
elif isinstance(token, (yaml.BlockSequenceStartToken,
yaml.FlowSequenceStartToken)):
context['stack'].append(Parent(SEQ))
elif isinstance(token, (yaml.BlockEndToken,
yaml.FlowMappingEndToken,
yaml.FlowSequenceEndToken)):
context['stack'].pop()
elif (isinstance(token, yaml.KeyToken) and
isinstance(next, yaml.ScalarToken)):
# This check is done because KeyTokens can be found inside flow
# sequences... strange, but allowed.
if len(context['stack']) > 0 and context['stack'][-1].type == MAP:
if (next.value in context['stack'][-1].keys and
# `<<` is "merge key", see http://yaml.org/type/merge.html
next.value != '<<'):
yield LintProblem(
next.start_mark.line + 1, next.start_mark.column + 1,
'duplication of key "%s" in mapping' % next.value)
else:
context['stack'][-1].keys.append(next.value)
def check(conf, token, prev, next, nextnext, context):
if conf['present']:
if (isinstance(prev, (yaml.StreamStartToken,
yaml.DocumentEndToken,
yaml.DirectiveToken)) and
not isinstance(token, (yaml.DocumentStartToken,
yaml.DirectiveToken,
yaml.StreamEndToken))):
yield LintProblem(token.start_mark.line + 1, 1,
'missing document start "---"')
else:
if isinstance(token, yaml.DocumentStartToken):
yield LintProblem(token.start_mark.line + 1,
token.start_mark.column + 1,
'found forbidden document start "---"')
def check(conf, line):
if line.start == 0 and len(line.buffer) > line.end:
if conf['type'] == 'dos':
if (line.end + 2 > len(line.buffer) or
line.buffer[line.end:line.end + 2] != '\r\n'):
yield LintProblem(1, line.end - line.start + 1,
'wrong new line character: expected \\r\\n')
else:
if line.buffer[line.end] == '\r':
yield LintProblem(1, line.end - line.start + 1,
'wrong new line character: expected \\n')
def check(conf, token, prev, next, nextnext, context):
if conf['present']:
is_stream_end = isinstance(token, yaml.StreamEndToken)
is_start = isinstance(token, yaml.DocumentStartToken)
prev_is_end_or_stream_start = isinstance(
prev, (yaml.DocumentEndToken, yaml.StreamStartToken)
)
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:
yield LintProblem(token.start_mark.line + 1, 1,
'missing document end "..."')
else:
if isinstance(token, yaml.DocumentEndToken):
yield LintProblem(token.start_mark.line + 1,
token.start_mark.column + 1,
'found forbidden document end "..."')
start = line.start
while start < line.end and line.buffer[start] == ' ':
start += 1
if start != line.end:
if line.buffer[start] in ('#', '-'):
start += 2
if line.buffer.find(' ', start, line.end) == -1:
return
if (conf['allow-non-breakable-inline-mappings'] and
check_inline_mapping(line)):
return
yield LintProblem(line.line_no, conf['max'] + 1,
'line too long (%d > %d characters)' %
(line.end - line.start, conf['max']))
def spaces_after(token, prev, next, min=-1, max=-1,
min_desc=None, max_desc=None):
if next is not None and token.end_mark.line == next.start_mark.line:
spaces = next.start_mark.pointer - token.end_mark.pointer
if max != - 1 and spaces > max:
return LintProblem(token.start_mark.line + 1,
next.start_mark.column, max_desc)
elif min != - 1 and spaces < min:
return LintProblem(token.start_mark.line + 1,
next.start_mark.column + 1, min_desc)