Rules: indentation: Do not crash on unexpected token
Previously, when the indentation rule blocked on an unexpected token,
the program crashed with something like:
File "/usr/lib/python3/dist-packages/yamllint/rules/indentation.py",
line 434, in check
assert context['stack'][-1].type == KEY
AssertionError
Instead, we prefer report the error as a regular `LintProblem` and
continue processing.
Fixes: #3
This commit is contained in:
@@ -295,7 +295,7 @@ def check_scalar_indentation(conf, token, context):
|
||||
(expected_indent, indent))
|
||||
|
||||
|
||||
def check(conf, token, prev, next, nextnext, context):
|
||||
def _check(conf, token, prev, next, nextnext, context):
|
||||
if 'stack' not in context:
|
||||
context['stack'] = [Parent(ROOT, 0)]
|
||||
context['cur_line'] = -1
|
||||
@@ -541,3 +541,13 @@ def check(conf, token, prev, next, nextnext, context):
|
||||
|
||||
else:
|
||||
break
|
||||
|
||||
|
||||
def check(conf, token, prev, next, nextnext, context):
|
||||
try:
|
||||
for problem in _check(conf, token, prev, next, nextnext, context):
|
||||
yield problem
|
||||
except AssertionError:
|
||||
yield LintProblem(token.start_mark.line + 1,
|
||||
token.start_mark.column + 1,
|
||||
'cannot infer indentation: unexpected token')
|
||||
|
||||
Reference in New Issue
Block a user