Rules: Keep a persistent context for token rules
This will be needed to build a clean indentation checking algorithm.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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'],
|
||||
|
||||
@@ -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'],
|
||||
|
||||
@@ -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'],
|
||||
|
||||
@@ -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'],
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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'],
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user