Rules: colons: Apply to '?' also

This commit is contained in:
Adrien Vergé
2016-01-19 19:45:13 +01:00
parent 9d8b0d4d2c
commit 8288a6f331
4 changed files with 37 additions and 11 deletions

View File

@@ -16,7 +16,7 @@
import yaml
from yamllint.rules.common import spaces_after, spaces_before
from yamllint.rules.common import spaces_after, spaces_before, is_explicit_key
ID = 'colons'
@@ -38,3 +38,10 @@ def check(conf, token, prev, next, context):
max_desc='too many spaces after colon')
if problem is not None:
yield problem
if isinstance(token, yaml.KeyToken) and is_explicit_key(token):
problem = spaces_after(token, prev, next,
max=conf['max-spaces-after'],
max_desc='too many spaces after question mark')
if problem is not None:
yield problem

View File

@@ -101,3 +101,15 @@ def get_comments_between_tokens(token1, token2, skip_first_line=False):
pointer += len(line) + 1
line_no += 1
column_no = 1
def is_explicit_key(token):
# explicit key:
# ? key
# : v
# or
# ?
# key
# : v
return (token.start_mark.pointer < token.end_mark.pointer and
token.start_mark.buffer[token.start_mark.pointer] == '?')

View File

@@ -17,6 +17,7 @@
import yaml
from yamllint.errors import LintProblem
from yamllint.rules.common import is_explicit_key
ID = 'indentation'
@@ -128,16 +129,7 @@ def check(conf, token, prev, next, context):
context['stack'].append(Parent(KEY, indent))
# explicit key:
# ? key
# : v
# or
# ?
# key
# : v
context['stack'][-1].explicit_key = (
token.start_mark.pointer < token.end_mark.pointer and
token.start_mark.buffer[token.start_mark.pointer] == '?')
context['stack'][-1].explicit_key = is_explicit_key(token)
if context['stack'][-1].type == VAL:
context['stack'].pop()