diff --git a/tests/rules/test_indentation.py b/tests/rules/test_indentation.py index af8e5da..e9f2069 100644 --- a/tests/rules/test_indentation.py +++ b/tests/rules/test_indentation.py @@ -39,7 +39,8 @@ class IndentationStackTestCase(RuleTestCase): context = {} output = '' for elem in token_generator(source): - list(check(conf, elem.curr, elem.prev, elem.next, context)) + list(check(conf, elem.curr, elem.prev, elem.next, elem.nextnext, + context)) token_type = (elem.curr.__class__.__name__ .replace('Token', '') diff --git a/yamllint/linter.py b/yamllint/linter.py index 414438e..65dc9e9 100644 --- a/yamllint/linter.py +++ b/yamllint/linter.py @@ -68,6 +68,7 @@ def get_costemic_problems(buffer, conf): rule_conf = conf.rules[rule.ID] for problem in rule.check(rule_conf, elem.curr, elem.prev, elem.next, + elem.nextnext, context[rule.ID]): problem.rule = rule.ID problem.level = rule_conf['level'] diff --git a/yamllint/parser.py b/yamllint/parser.py index 57fc934..eccfb42 100644 --- a/yamllint/parser.py +++ b/yamllint/parser.py @@ -30,11 +30,12 @@ class Line(object): class Token(object): - def __init__(self, line_no, curr, prev, next): + def __init__(self, line_no, curr, prev, next, nextnext): self.line_no = line_no self.curr = curr self.prev = prev self.next = next + self.nextnext = nextnext def line_generator(buffer): @@ -55,14 +56,16 @@ def token_generator(buffer): try: prev = None - next = yaml_loader.peek_token() - while next is not None: - curr = yaml_loader.get_token() - next = yaml_loader.peek_token() + curr = yaml_loader.get_token() + while curr is not None: + next = yaml_loader.get_token() + nextnext = yaml_loader.peek_token() - yield Token(curr.start_mark.line + 1, curr, prev, next) + yield Token(curr.start_mark.line + 1, curr, prev, next, nextnext) prev = curr + curr = next + except yaml.scanner.ScannerError: pass diff --git a/yamllint/rules/braces.py b/yamllint/rules/braces.py index 78464c3..55f465e 100644 --- a/yamllint/rules/braces.py +++ b/yamllint/rules/braces.py @@ -73,7 +73,7 @@ CONF = {'min-spaces-inside': int, 'max-spaces-inside': int} -def check(conf, token, prev, next, context): +def check(conf, token, prev, next, nextnext, context): if isinstance(token, yaml.FlowMappingStartToken): problem = spaces_after(token, prev, next, min=conf['min-spaces-inside'], diff --git a/yamllint/rules/brackets.py b/yamllint/rules/brackets.py index b2a94e3..ae0e744 100644 --- a/yamllint/rules/brackets.py +++ b/yamllint/rules/brackets.py @@ -74,7 +74,7 @@ CONF = {'min-spaces-inside': int, 'max-spaces-inside': int} -def check(conf, token, prev, next, context): +def check(conf, token, prev, next, nextnext, context): if isinstance(token, yaml.FlowSequenceStartToken): problem = spaces_after(token, prev, next, min=conf['min-spaces-inside'], diff --git a/yamllint/rules/colons.py b/yamllint/rules/colons.py index 9bfdd14..8d386b8 100644 --- a/yamllint/rules/colons.py +++ b/yamllint/rules/colons.py @@ -81,7 +81,7 @@ CONF = {'max-spaces-before': int, 'max-spaces-after': int} -def check(conf, token, prev, next, context): +def check(conf, token, prev, next, nextnext, context): if isinstance(token, yaml.ValueToken): problem = spaces_before(token, prev, next, max=conf['max-spaces-before'], diff --git a/yamllint/rules/commas.py b/yamllint/rules/commas.py index 386e6cb..ba42373 100644 --- a/yamllint/rules/commas.py +++ b/yamllint/rules/commas.py @@ -105,7 +105,7 @@ CONF = {'max-spaces-before': int, 'max-spaces-after': int} -def check(conf, token, prev, next, context): +def check(conf, token, prev, next, nextnext, context): if isinstance(token, yaml.FlowEntryToken): if (prev is not None and conf['max-spaces-before'] != -1 and prev.end_mark.line < token.start_mark.line): diff --git a/yamllint/rules/comments.py b/yamllint/rules/comments.py index 112f658..af58de8 100644 --- a/yamllint/rules/comments.py +++ b/yamllint/rules/comments.py @@ -67,7 +67,7 @@ CONF = {'require-starting-space': bool, 'min-spaces-from-content': int} -def check(conf, token, prev, next, context): +def check(conf, token, prev, next, nextnext, context): for comment in get_comments_between_tokens(token, next): if (conf['min-spaces-from-content'] != -1 and not isinstance(token, yaml.StreamStartToken) and diff --git a/yamllint/rules/comments_indentation.py b/yamllint/rules/comments_indentation.py index 8bd0c56..52923dc 100644 --- a/yamllint/rules/comments_indentation.py +++ b/yamllint/rules/comments_indentation.py @@ -98,7 +98,7 @@ TYPE = 'token' # # commented line 2 # current: line -def check(conf, token, prev, next, context): +def check(conf, token, prev, next, nextnext, context): if prev is None: return diff --git a/yamllint/rules/document_end.py b/yamllint/rules/document_end.py index ee62b67..c6e7356 100644 --- a/yamllint/rules/document_end.py +++ b/yamllint/rules/document_end.py @@ -84,7 +84,7 @@ TYPE = 'token' CONF = {'present': bool} -def check(conf, token, prev, next, context): +def check(conf, token, prev, next, nextnext, context): if conf['present']: if (isinstance(token, yaml.StreamEndToken) and not (isinstance(prev, yaml.DocumentEndToken) or diff --git a/yamllint/rules/document_start.py b/yamllint/rules/document_start.py index 70f511f..5955a7f 100644 --- a/yamllint/rules/document_start.py +++ b/yamllint/rules/document_start.py @@ -74,7 +74,7 @@ TYPE = 'token' CONF = {'present': bool} -def check(conf, token, prev, next, context): +def check(conf, token, prev, next, nextnext, context): if conf['present']: if (isinstance(prev, (yaml.StreamStartToken, yaml.DocumentEndToken, diff --git a/yamllint/rules/hyphens.py b/yamllint/rules/hyphens.py index 1d3702d..1d5a1a4 100644 --- a/yamllint/rules/hyphens.py +++ b/yamllint/rules/hyphens.py @@ -78,7 +78,7 @@ TYPE = 'token' CONF = {'max-spaces-after': int} -def check(conf, token, prev, next, context): +def check(conf, token, prev, next, nextnext, context): if isinstance(token, yaml.BlockEntryToken): problem = spaces_after(token, prev, next, max=conf['max-spaces-after'], diff --git a/yamllint/rules/indentation.py b/yamllint/rules/indentation.py index 35c9679..e889594 100644 --- a/yamllint/rules/indentation.py +++ b/yamllint/rules/indentation.py @@ -236,7 +236,7 @@ def check_scalar_indentation(conf, token, context): (expected_indent, indent)) -def check(conf, token, prev, next, context): +def check(conf, token, prev, next, nextnext, context): if 'stack' not in context: context['stack'] = [Parent(ROOT, 0)] context['cur_line'] = -1 diff --git a/yamllint/rules/key_duplicates.py b/yamllint/rules/key_duplicates.py index 9f879f0..12d6e09 100644 --- a/yamllint/rules/key_duplicates.py +++ b/yamllint/rules/key_duplicates.py @@ -72,7 +72,7 @@ class Parent(object): self.keys = [] -def check(conf, token, prev, next, context): +def check(conf, token, prev, next, nextnext, context): if 'stack' not in context: context['stack'] = []