Rules: indentation: Add the 'indent-sequences' option
Using either 'yes', 'no' or 'whatever', the user will be able to choose whether to force block sequence items to be indented, to force them not to be indented, or don't care, respectively.
This commit is contained in:
@@ -31,7 +31,7 @@ rules:
|
||||
max-spaces-after: 1
|
||||
indentation:
|
||||
spaces: 2
|
||||
# indent-sequences: no
|
||||
indent-sequences: yes
|
||||
line-length:
|
||||
max: 80
|
||||
new-line-at-end-of-file: {level: error}
|
||||
|
||||
@@ -22,7 +22,8 @@ from yamllint.rules.common import is_explicit_key
|
||||
|
||||
ID = 'indentation'
|
||||
TYPE = 'token'
|
||||
CONF = {'spaces': int}
|
||||
CONF = {'spaces': int,
|
||||
'indent-sequences': (True, False, 'whatever')}
|
||||
|
||||
ROOT, MAP, B_SEQ, F_SEQ, KEY, VAL = range(6)
|
||||
|
||||
@@ -164,16 +165,21 @@ def check(conf, token, prev, next, context):
|
||||
# yaml.scan()ning this:
|
||||
# '- lib:\n'
|
||||
# ' - var\n'
|
||||
if next.start_mark.column == context['stack'][-1].indent:
|
||||
# key:
|
||||
# - e1
|
||||
# - e2
|
||||
if conf['indent-sequences'] is False:
|
||||
indent = context['stack'][-1].indent
|
||||
else:
|
||||
# key:
|
||||
# - e1
|
||||
# - e2
|
||||
elif conf['indent-sequences'] is True:
|
||||
indent = context['stack'][-1].indent + conf['spaces']
|
||||
else: # 'whatever'
|
||||
if next.start_mark.column == context['stack'][-1].indent:
|
||||
# key:
|
||||
# - e1
|
||||
# - e2
|
||||
indent = context['stack'][-1].indent
|
||||
else:
|
||||
# key:
|
||||
# - e1
|
||||
# - e2
|
||||
indent = context['stack'][-1].indent + conf['spaces']
|
||||
else:
|
||||
# k:
|
||||
# value
|
||||
|
||||
Reference in New Issue
Block a user