Skip to content

basic formatter: add option to prefer unquoted strings when safe #311

Description

@pygarap

Please add a basic formatter setting that can force and check for plain string values when it is safe, especially inside flow arrays. This would let users keep CLI args readable without quotes.

Problem

force_array_style: flow can produce flow arrays, but there is no way to require unquoted strings inside them. force_quote_style only chooses single or double quotes for nodes that are already quoted.

Example

Config:

formatter:
  type: basic
  force_array_style: flow
  # proposed new option, name is up to you:
  prefer_unquoted_strings: true

Input:

args: ["--output=line", "--minAlertLevel=error"]

Expected output:

args: [--output=line, --minAlertLevel=error]

Safety rules

Only remove quotes when:

  • the output remains valid YAML
  • the parsed value stays a string (do not change types)

So values like yes, no, on, off, null, numbers, etc should remain quoted.

Acceptance criteria

  • With the option enabled, yamlfmt rewrites quoted strings to unquoted form when safe.
  • When not safe, yamlfmt keeps quotes.
  • The option works consistently alongside force_array_style: flow.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions