Skip to content

YAML inconsistent indent and offset values #154

@fmigneault

Description

@fmigneault

Considering the following valid YAML (this is the result I would like to achieve after auto-fix by pretty-format-yaml):

services:
  svc:
    image: "..."
    volumes:
      - "/tmp:/tmp"

Using

--indent=4
--offset=2

causes the auto-fix of the file to be over-indented as follows:

services:
    svc:  # all nested mappings over-indented
        image: "..."
        volumes:
          - "/tmp:/tmp"  # indent as expected here

while

--indent=2
--offset=0

results in:

services:
  svc:  # nesting indents preserved
    image: "..."
    volumes:
    - "/tmp:/tmp"   # de-indented

It seems that the following should be valid:

--indent=2
--offset=2

but it is blocked by the following check:

if args.indent < args.offset + 2:
print(
"Indent should be at least 2 more than offset. \n"
"Invalid output could be resulting otherwise. \n"
"indent={}, offset={}".format(args.indent, args.offset)
)
return 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions