From ca540c113bfc4e49b550b6b980b278c9f8d9c85c Mon Sep 17 00:00:00 2001 From: Tim Wade Date: Mon, 16 Oct 2017 12:17:49 -0700 Subject: [PATCH] Fix indentation rule for key following empty list If a key-value pair follows an empty list, i.e.: ```yaml a: - b: c ``` yamllint will complain: ``` warning wrong indentation: expected 2 but found 0 (indentation) ``` This is because it is expecting the second key to be a continuation of the block entry above: ```yaml a: - b: c ``` However, both are perfectly valid, though structurally different. --- tests/rules/test_indentation.py | 3 +++ yamllint/rules/indentation.py | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/tests/rules/test_indentation.py b/tests/rules/test_indentation.py index 2733ea7..7d2f966 100644 --- a/tests/rules/test_indentation.py +++ b/tests/rules/test_indentation.py @@ -589,6 +589,9 @@ class IndentationTestCase(RuleTestCase): ' date: 1969\n' ' - name: Linux\n' ' date: 1991\n' + ' k4:\n' + ' -\n' + ' k5: v3\n' '...\n', conf) conf = 'indentation: {spaces: 2, indent-sequences: true}' self.check('---\n' diff --git a/yamllint/rules/indentation.py b/yamllint/rules/indentation.py index 432c23c..fb14faf 100644 --- a/yamllint/rules/indentation.py +++ b/yamllint/rules/indentation.py @@ -399,6 +399,10 @@ def _check(conf, token, prev, next, nextnext, context): # - item 1 # - item 2 indent = next.start_mark.column + elif next.start_mark.column == token.start_mark.column: + # - + # key: value + indent = next.start_mark.column else: # - # item 1