Skip to content

Add option to emit compact mappings in block sequences #142

Description

@ian-buse

Hi, first off, thanks for the work on SharpYaml. I’ve been experimenting with it for a user-editable CLI config file, and it’s been a great fit overall.

One thing I ran into is the formatting of mappings inside block sequences.

Given a model like this:

contexts:
  - name: default
    target: localhost
    credential: localhost-admin

SharpYaml currently emits:

contexts:
  -
    name: default
    target: localhost
    credential: localhost-admin

As far as I understand it, this is valid YAML, so I don’t think this is a correctness bug. It just looks a little odd for a hand-editable config file. Most config files I’ve seen tend to put the first mapping key on the same line as the dash when possible.

Would you be open to adding an option for this style?

Something along the lines of:

new YamlSerializerOptions
{
    CompactSequenceMappings = true
}

or whatever name fits the existing API better.

This is mostly about readability for files that users may open and edit by hand. I realize the current output is valid YAML, so I’d consider this a formatting enhancement rather than a bug.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions