feat: Add --yaml-compact-seq-indent / -c flag for compact sequence indentation (#2583)

Adds a new CLI flag that enables compact sequence indentation where '- ' is
considered part of the indentation. This leverages the CompactSeqIndent()
method from the underlying go.yaml.in/yaml/v4 library.

Example output with --yaml-compact-seq-indent:
  parent:
    items:
    - one
    - two

Instead of the default:
  parent:
    items:
      - one
      - two

Closes #1841
This commit is contained in:
jfenal
2026-01-31 14:50:01 +11:00
committed by GitHub
parent c4f4e6d416
commit 78192a915b
3 changed files with 7 additions and 0 deletions
+3
View File
@@ -52,6 +52,9 @@ func (ye *yamlEncoder) Encode(writer io.Writer, node *CandidateNode) error {
var encoder = yaml.NewEncoder(destination)
encoder.SetIndent(ye.prefs.Indent)
if ye.prefs.CompactSequenceIndent {
encoder.CompactSeqIndent()
}
target, err := node.MarshalYAML()
+3
View File
@@ -8,6 +8,7 @@ type YamlPreferences struct {
UnwrapScalar bool
EvaluateTogether bool
FixMergeAnchorToSpec bool
CompactSequenceIndent bool
}
func NewDefaultYamlPreferences() YamlPreferences {
@@ -19,6 +20,7 @@ func NewDefaultYamlPreferences() YamlPreferences {
UnwrapScalar: true,
EvaluateTogether: false,
FixMergeAnchorToSpec: false,
CompactSequenceIndent: false,
}
}
@@ -31,6 +33,7 @@ func (p *YamlPreferences) Copy() YamlPreferences {
UnwrapScalar: p.UnwrapScalar,
EvaluateTogether: p.EvaluateTogether,
FixMergeAnchorToSpec: p.FixMergeAnchorToSpec,
CompactSequenceIndent: p.CompactSequenceIndent,
}
}