Rules: indentation: Add 'check-multi-line-strings' option

This options allows the user to control whether to lint indentation
inside multi-line scalars or not.

When enabled, such YAML source will be detected as a problem:

    - C code: void main() {
                  printf("foo");
              }

whereas this one would not:

    - C code: void main() {
              printf("foo");
              }
This commit is contained in:
Adrien Vergé
2016-01-22 18:16:52 +01:00
parent 08f99ccc19
commit 1bfd18097a
3 changed files with 176 additions and 22 deletions

View File

@@ -32,6 +32,7 @@ rules:
indentation:
spaces: 2
indent-sequences: yes
check-multi-line-strings: no
line-length:
max: 80
new-line-at-end-of-file: {level: error}

View File

@@ -23,7 +23,8 @@ from yamllint.rules.common import is_explicit_key
ID = 'indentation'
TYPE = 'token'
CONF = {'spaces': int,
'indent-sequences': (True, False, 'whatever')}
'indent-sequences': (True, False, 'whatever'),
'check-multi-line-strings': bool}
ROOT, MAP, B_SEQ, F_SEQ, KEY, VAL = range(6)
@@ -95,7 +96,11 @@ def check_scalar_indentation(conf, token, context):
if token.start_mark.buffer[line_start + indent] == '\n':
continue
if indent != expected_indent:
if indent < expected_indent:
yield LintProblem(line_no, indent + 1,
('wrong indentation: expected at least %d but '
'found %d') % (expected_indent, indent))
elif conf['check-multi-line-strings'] and indent > expected_indent:
yield LintProblem(line_no, indent + 1,
'wrong indentation: expected %d but found %d' %
(expected_indent, indent))