Skip to content

Conversation

@jrc2139
Copy link

@jrc2139 jrc2139 commented Jan 1, 2026

Summary

Preserve Existing Multiline Flags

If you write:

RUN --mount=type=cache,target=/a \
  --mount=type=cache,target=/b \
  go build

The formatter now preserves your line breaks instead of collapsing them.

Auto-Split Mount Flags (Default: ON)

Single-line mount flags are automatically split for readability:

Before:

RUN --mount=type=cache,target=/a --mount=type=cache,target=/b go build

After:

RUN --mount=type=cache,target=/a \
  --mount=type=cache,target=/b \
  go build

CLI Usage

Default behavior (split mount flags)

dockerfmt Dockerfile

Disable mount flag splitting

dockerfmt --split-mount-flags=false Dockerfile
dockerfmt -m=false Dockerfile

Files Modified

  • lib/format.go - Added extractFlagsFormatted() and formatFlagsWithMountSplit() helpers
  • cmd/root.go - Added --split-mount-flags / -m flag (default: true)
  • dockerfmt_test.go - Enabled SplitMountFlags in test config
  • tests/in/multiline-flags.dockerfile - New test cases
  • tests/out/multiline-flags.dockerfile - Expected outputs
  • tests/out/onbuild.dockerfile - Updated for new behavior

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant