diff --git a/yamllint/__init__.py b/yamllint/__init__.py index 9e2b89e..4595133 100644 --- a/yamllint/__init__.py +++ b/yamllint/__init__.py @@ -38,12 +38,17 @@ def get_costemic_problems(buffer, conf): token_rules = [r for r in rules if r.TYPE == 'token'] line_rules = [r for r in rules if r.TYPE == 'line'] + context = {} + for rule in token_rules: + context[rule.ID] = {} + for elem in parser.token_or_line_generator(buffer): if isinstance(elem, parser.Token): for rule in token_rules: rule_conf = conf[rule.ID] for problem in rule.check(rule_conf, - elem.curr, elem.prev, elem.next): + elem.curr, elem.prev, elem.next, + context[rule.ID]): problem.rule = rule.ID problem.level = rule_conf['level'] yield problem diff --git a/yamllint/rules/braces.py b/yamllint/rules/braces.py index f21278e..2aa2e1d 100644 --- a/yamllint/rules/braces.py +++ b/yamllint/rules/braces.py @@ -25,7 +25,7 @@ CONF = {'min-spaces-inside': int, 'max-spaces-inside': int} -def check(conf, token, prev, next): +def check(conf, token, prev, next, 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 d40f4aa..e27a3bc 100644 --- a/yamllint/rules/brackets.py +++ b/yamllint/rules/brackets.py @@ -25,7 +25,7 @@ CONF = {'min-spaces-inside': int, 'max-spaces-inside': int} -def check(conf, token, prev, next): +def check(conf, token, prev, next, 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 d73c3ad..d20f453 100644 --- a/yamllint/rules/colons.py +++ b/yamllint/rules/colons.py @@ -25,7 +25,7 @@ CONF = {'max-spaces-before': int, 'max-spaces-after': int} -def check(conf, token, prev, next): +def check(conf, token, prev, next, 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 152c2d0..5cdb5de 100644 --- a/yamllint/rules/commas.py +++ b/yamllint/rules/commas.py @@ -25,7 +25,7 @@ CONF = {'max-spaces-before': int, 'max-spaces-after': int} -def check(conf, token, prev, next): +def check(conf, token, prev, next, context): if isinstance(token, yaml.FlowEntryToken): problem = spaces_before(token, prev, next, max=conf['max-spaces-before'], diff --git a/yamllint/rules/comments.py b/yamllint/rules/comments.py index 2b88d1a..c2ec209 100644 --- a/yamllint/rules/comments.py +++ b/yamllint/rules/comments.py @@ -26,7 +26,7 @@ CONF = {'require-starting-space': bool, 'min-spaces-from-content': int} -def check(conf, token, prev, next): +def check(conf, token, prev, next, 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 f256043..3a44252 100644 --- a/yamllint/rules/comments_indentation.py +++ b/yamllint/rules/comments_indentation.py @@ -37,7 +37,7 @@ TYPE = 'token' # # commented line 2 # current: line -def check(conf, token, prev, next): +def check(conf, token, prev, next, context): if prev is None: return diff --git a/yamllint/rules/document_end.py b/yamllint/rules/document_end.py index 7850619..0336eb7 100644 --- a/yamllint/rules/document_end.py +++ b/yamllint/rules/document_end.py @@ -24,7 +24,7 @@ TYPE = 'token' CONF = {'present': bool} -def check(conf, token, prev, next): +def check(conf, token, prev, next, 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 54cd418..476488f 100644 --- a/yamllint/rules/document_start.py +++ b/yamllint/rules/document_start.py @@ -24,7 +24,7 @@ TYPE = 'token' CONF = {'present': bool} -def check(conf, token, prev, next): +def check(conf, token, prev, next, context): if conf['present']: if (isinstance(prev, (yaml.StreamStartToken, yaml.DocumentEndToken, diff --git a/yamllint/rules/hyphens.py b/yamllint/rules/hyphens.py index 99ee968..1702c50 100644 --- a/yamllint/rules/hyphens.py +++ b/yamllint/rules/hyphens.py @@ -24,7 +24,7 @@ TYPE = 'token' CONF = {'max-spaces-after': int} -def check(conf, token, prev, next): +def check(conf, token, prev, next, 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 06a731f..320742c 100644 --- a/yamllint/rules/indentation.py +++ b/yamllint/rules/indentation.py @@ -24,7 +24,7 @@ TYPE = 'token' CONF = {'spaces': int} -def check(conf, token, prev, next): +def check(conf, token, prev, next, context): if isinstance(token, (yaml.StreamStartToken, yaml.StreamEndToken)): return