From 4410bc3e23aa4f89751382b78e8a4c7adbc5cf17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Verg=C3=A9?= Date: Mon, 25 Jan 2016 11:01:42 +0100 Subject: [PATCH] Rules: indentation: Fix check-multi-line-strings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For strings that continue on next line at a lower indentation level: Blaise Pascal: Je vous écris une longue lettre parce que je n'ai pas le temps d'en écrire une courte. --- tests/rules/test_indentation.py | 26 ++++++++++++++------------ yamllint/rules/indentation.py | 21 +++++++++++++++------ 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/tests/rules/test_indentation.py b/tests/rules/test_indentation.py index dfe0816..f4a8e34 100644 --- a/tests/rules/test_indentation.py +++ b/tests/rules/test_indentation.py @@ -507,7 +507,7 @@ class ScalarIndentationTestCase(RuleTestCase): self.check('a key: multi\n' ' line\n', conf) self.check('a key: multi\n' - ' line\n', conf, problem=(2, 3)) + ' line\n', conf) self.check('a key: multi\n' ' line\n', conf) self.check('a key:\n' @@ -528,6 +528,8 @@ class ScalarIndentationTestCase(RuleTestCase): ' line\n', conf, problem=(2, 2)) self.check('- multi\n' ' line\n', conf, problem=(2, 4)) + self.check('a key: multi\n' + ' line\n', conf, problem=(2, 3)) self.check('a key: multi\n' ' line\n', conf, problem=(2, 9)) self.check('a key:\n' @@ -546,24 +548,13 @@ class ScalarIndentationTestCase(RuleTestCase): 'document-start: disable\n') self.check('"multi\n' ' line"\n', conf) - self.check('"multi\n' - 'line"\n', conf, problem=(2, 1)) self.check('- "multi\n' ' line"\n', conf) - self.check('- "multi\n' - ' line"\n', conf, problem=(2, 3)) self.check('a key: "multi\n' ' line"\n', conf) - self.check('a key: "multi\n' - ' line"\n', conf, problem=(2, 3)) - self.check('a key: "multi\n' - ' line"\n', conf, problem=(2, 8)) self.check('a key:\n' ' "multi\n' ' line"\n', conf) - self.check('a key:\n' - ' "multi\n' - ' line"\n', conf, problem=(3, 3)) self.check('- jinja2: "{% if ansible is defined %}\n' ' {{ ansible }}\n' ' {% else %}\n' @@ -580,11 +571,22 @@ class ScalarIndentationTestCase(RuleTestCase): conf = ('indentation: {spaces: 2, check-multi-line-strings: yes}\n' 'document-start: disable\n') self.check('"multi\n' + 'line"\n', conf, problem=(2, 1)) + self.check('"multi\n' + ' line"\n', conf, problem=(2, 3)) + self.check('- "multi\n' ' line"\n', conf, problem=(2, 3)) self.check('- "multi\n' ' line"\n', conf, problem=(2, 5)) + self.check('a key: "multi\n' + ' line"\n', conf, problem=(2, 3)) + self.check('a key: "multi\n' + ' line"\n', conf, problem=(2, 8)) self.check('a key: "multi\n' ' line"\n', conf, problem=(2, 10)) + self.check('a key:\n' + ' "multi\n' + ' line"\n', conf, problem=(3, 3)) self.check('a key:\n' ' "multi\n' ' line"\n', conf, problem=(3, 5)) diff --git a/yamllint/rules/indentation.py b/yamllint/rules/indentation.py index e51255f..44ec786 100644 --- a/yamllint/rules/indentation.py +++ b/yamllint/rules/indentation.py @@ -113,6 +113,18 @@ Use this rule to control the indentation. Je vous écris une longue lettre parce que je n'ai pas le temps d'en écrire une courte. + the following code snippet would **PASS**: + :: + + Blaise Pascal: Je vous écris une longue lettre parce que + je n'ai pas le temps d'en écrire une courte. + + the following code snippet would **FAIL**: + :: + + Blaise Pascal: Je vous écris une longue lettre parce que + je n'ai pas le temps d'en écrire une courte. + the following code snippet would **FAIL**: :: @@ -212,11 +224,7 @@ def check_scalar_indentation(conf, token, context): if token.start_mark.buffer[line_start + indent] == '\n': continue - 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: + if indent != expected_indent: yield LintProblem(line_no, indent + 1, 'wrong indentation: expected %d but found %d' % (expected_indent, indent)) @@ -252,7 +260,8 @@ def check(conf, token, prev, next, context): 'wrong indentation: expected %d but found %d' % (expected, found_indentation)) - if isinstance(token, yaml.ScalarToken): + if (isinstance(token, yaml.ScalarToken) and + conf['check-multi-line-strings']): for problem in check_scalar_indentation(conf, token, context): yield problem