Rules: indentation: Handle sets
Sets are like mappings, that do not contain values. Example:
set:
? key one
? key two
? [non, scalar, key]
This commit is contained in:
@@ -110,6 +110,7 @@ conf_overrides = {
|
|||||||
'example-8.9': ('empty-lines: {max-end: 1}\n'),
|
'example-8.9': ('empty-lines: {max-end: 1}\n'),
|
||||||
'example-8.14': ('colons: {max-spaces-before: 1}\n'),
|
'example-8.14': ('colons: {max-spaces-before: 1}\n'),
|
||||||
'example-8.16': ('indentation: {spaces: 1}\n'),
|
'example-8.16': ('indentation: {spaces: 1}\n'),
|
||||||
|
'example-8.17': ('indentation: disable\n'),
|
||||||
}
|
}
|
||||||
|
|
||||||
files = os.listdir('tests/yaml-1.2-spec-examples')
|
files = os.listdir('tests/yaml-1.2-spec-examples')
|
||||||
@@ -125,9 +126,7 @@ def _gen_test(buffer, conf):
|
|||||||
# The following tests are blacklisted because they contain rarely-used formats
|
# The following tests are blacklisted because they contain rarely-used formats
|
||||||
# that yamllint does not handle yet.
|
# that yamllint does not handle yet.
|
||||||
tmp_blacklist = (
|
tmp_blacklist = (
|
||||||
'example-2.25',
|
|
||||||
'example-7.16',
|
'example-7.16',
|
||||||
'example-8.17',
|
|
||||||
'example-8.20',
|
'example-8.20',
|
||||||
'example-8.22',
|
'example-8.22',
|
||||||
'example-10.1',
|
'example-10.1',
|
||||||
|
|||||||
@@ -75,3 +75,20 @@ class YamlLintTestCase(RuleTestCase):
|
|||||||
' Atlanta Braves]\n'
|
' Atlanta Braves]\n'
|
||||||
': [2001-07-02, 2001-08-12,\n'
|
': [2001-07-02, 2001-08-12,\n'
|
||||||
' 2001-08-14]\n', None)
|
' 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)
|
||||||
|
|||||||
@@ -413,3 +413,12 @@ def check(conf, token, prev, next, context):
|
|||||||
indent = context['stack'][-1].indent + conf['spaces']
|
indent = context['stack'][-1].indent + conf['spaces']
|
||||||
|
|
||||||
context['stack'].append(Parent(VAL, indent))
|
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()
|
||||||
|
|||||||
Reference in New Issue
Block a user