Skip to content

Add YAML formatting options: compact array indent and document start marker#2167

Open
snarlysodboxer wants to merge 2 commits intogetsops:mainfrom
snarlysodboxer:amick/fix-yaml-formatting
Open

Add YAML formatting options: compact array indent and document start marker#2167
snarlysodboxer wants to merge 2 commits intogetsops:mainfrom
snarlysodboxer:amick/fix-yaml-formatting

Conversation

@snarlysodboxer
Copy link
Copy Markdown

Add two new YAML store configuration options that address long-standing formatting requests:

  • compact_array_indent - Treats the - array indicator as part of the indentation. With indent: 2, this produces arrays flush with their parent key, matching the style used by
    Kubernetes manifests and common YAML linters. Exposes yaml.v3's CompactSeqIndent() encoder setting.

  • document_start_marker - Prepends --- to YAML output. SOPS currently strips this during encryption, which often breaks linting tools that need/want it, like yamlfmt, yamllint, and ytt.

Both options can be set via .sops.yaml or CLI flags:

stores:
    yaml:
        compact_array_indent: true
        document_start_marker: true

--compact-array-indent
--document-start-marker

Closes #514, closes #864, closes #1066, closes #1158

Added tests for:

  • Compact array indent: default indent (4), indent 2, and disabled
  • Document start marker: single doc, multi-doc, and disabled

Expose the Go yaml.v3 CompactSeqIndent() encoder setting,
which treats '- ' as part of the indentation. With indent: 2,
this produces sequences flush with their parent key, matching
the style expected by yamlfmt and yamllint.

Configurable via .sops.yaml or --compact-sequence-indent flag.

Refs getsops#514, getsops#864, getsops#1066

Signed-off-by: david amick <david@davidamick.com>
Prepend '---' to YAML output when enabled, addressing tools like
yamllint and ytt that often expect the document start marker.

Configurable via .sops.yaml or --document-start-marker flag.

Refs getsops#1158

Signed-off-by: david amick <david@davidamick.com>
@snarlysodboxer snarlysodboxer force-pushed the amick/fix-yaml-formatting branch from 01780a3 to b298cc0 Compare May 4, 2026 21:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

2 participants