Skip to content

Commit

Permalink
Rules: indentation: Handle sets
Browse files Browse the repository at this point in the history
Sets are like mappings, that do not contain values. Example:

    set:
      ? key one
      ? key two
      ? [non, scalar, key]
  • Loading branch information
adrienverge committed Feb 1, 2016
1 parent 431a379 commit 68618be
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
3 changes: 1 addition & 2 deletions tests/test_spec_examples.py
Expand Up @@ -110,6 +110,7 @@ class SpecificationTestCase(RuleTestCase):
'example-8.9': ('empty-lines: {max-end: 1}\n'),
'example-8.14': ('colons: {max-spaces-before: 1}\n'),
'example-8.16': ('indentation: {spaces: 1}\n'),
'example-8.17': ('indentation: disable\n'),
}

files = os.listdir('tests/yaml-1.2-spec-examples')
Expand All @@ -125,9 +126,7 @@ def test(self):
# The following tests are blacklisted because they contain rarely-used formats
# that yamllint does not handle yet.
tmp_blacklist = (
'example-2.25',
'example-7.16',
'example-8.17',
'example-8.20',
'example-8.22',
'example-10.1',
Expand Down
17 changes: 17 additions & 0 deletions tests/test_syntax_errors.py
Expand Up @@ -75,3 +75,20 @@ def test_mapping_between_sequences(self):
' Atlanta Braves]\n'
': [2001-07-02, 2001-08-12,\n'
' 2001-08-14]\n', None)

def test_sets(self):
self.check('---\n'
'? key one\n'
'? key two\n'
'? [non, scalar, key]\n'
'? key with value\n'
': value\n'
'...\n', None)
self.check('---\n'
'? - multi\n'
' - line\n'
' - keys\n'
'? in:\n'
' a:\n'
' set\n'
'...\n', None)
9 changes: 9 additions & 0 deletions yamllint/rules/indentation.py
Expand Up @@ -413,3 +413,12 @@ def check(conf, token, prev, next, context):
indent = context['stack'][-1].indent + conf['spaces']

context['stack'].append(Parent(VAL, indent))

if (context['stack'][-1].type == KEY and
isinstance(next, (yaml.BlockEndToken,
yaml.FlowMappingEndToken,
yaml.FlowSequenceEndToken,
yaml.KeyToken))):
# A key without a value: it's part of a set. Let's drop this key
# and leave room for the next one.
context['stack'].pop()

0 comments on commit 68618be

Please sign in to comment.