quoted-strings: Fix broken rule for list items

The rule worked for values like:

    flow-map: {a: foo, b: "bar"}
    block-map:
      a: foo
      b: "bar"

But not for:

    flow-seq: [foo, "bar"]
    block-seq:
      - foo
      - "bar"

Also add tests to make sure there will be no regression.

Fixes: #208.
This commit is contained in:
Adrien Vergé
2020-04-10 19:06:59 +02:00
parent e284d74be1
commit 2d8639c3a1
2 changed files with 61 additions and 17 deletions

View File

@@ -89,7 +89,10 @@ def quote_match(quote_type, token_style):
def check(conf, token, prev, next, nextnext, context):
if not (isinstance(token, yaml.tokens.ScalarToken) and
isinstance(prev, (yaml.ValueToken, yaml.TagToken))):
isinstance(prev, (yaml.BlockEntryToken, yaml.FlowEntryToken,
yaml.FlowSequenceStartToken, yaml.TagToken,
yaml.ValueToken))):
return
# Ignore explicit types, e.g. !!str testtest or !!int 42