google / google/yamlfmt

basic formatter: add option to prefer unquoted strings when safe

Open
#311 0 comments 12 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
1.8k
Forks
75
PR merge metrics
No merged PRs in 30d

Description

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:
```yaml
formatter:
type: basic
force_array_style: flow
# proposed new option, name is up to you:
prefer_unquoted_strings: true
````

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

Expected output:
```yaml
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`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.