Skip to content

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

Open
snarlysodboxer wants to merge 2 commits into
getsops: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 into
getsops:mainfrom
snarlysodboxer:amick/fix-yaml-formatting

Conversation

@snarlysodboxer
Copy link
Copy Markdown

@snarlysodboxer snarlysodboxer commented May 2, 2026

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

Refs #514, Refs #864, Refs #1066, Refs #1158

Added tests for:

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

Update: I see docs have been moved to a new repo, I have removed them from here and will follow up with a PR to that repo if this gets merged.

@snarlysodboxer snarlysodboxer force-pushed the amick/fix-yaml-formatting branch from 199728a to 261dcc7 Compare May 2, 2026 19:56
@snarlysodboxer snarlysodboxer force-pushed the amick/fix-yaml-formatting branch 2 times, most recently from 01780a3 to b298cc0 Compare May 4, 2026 21:37
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 b298cc0 to d318c58 Compare May 15, 2026 23:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants