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:
@@ -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}
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user