github reteps/dockerfmt v0.6.0

58 minutes ago

This release is mostly about correctness. dockerfmt could turn a working Dockerfile into one that no longer builds, or one that builds something different. Every known case is fixed, and a new safety check makes that class of bug fail safe.

Highlights

  • dockerfmt no longer changes what your Dockerfile does. After formatting each instruction, dockerfmt parses the result with BuildKit (the parser docker build uses) and checks that it means the same thing as the original. If it doesn't, the instruction is left exactly as written and a warning is printed (Dockerfile:12: left unformatted: ...). Please report these warnings.
  • The RUN formatter was rewritten. Comments and \ separator lines are placed using the shell syntax tree instead of regexes. Output for existing Dockerfiles is unchanged.
  • New --diff / -d flag prints a unified diff of the changes needed and implies --check (#60, #63, thanks @mat813).
  • New Alpine image: ghcr.io/reteps/dockerfmt:alpine (and :<version>-alpine) includes a shell, for CI systems like GitLab CI (#62, thanks @mat813).

Fixes

  • Legacy ENV key value with spaces in the value is now quoted. Before, it became an invalid key=value (#69, #74, thanks @RyoKusnadi).
  • Converting MAINTAINER to LABEL now escapes quotes, backslashes and $ (#70, #75, thanks @RyoKusnadi).
  • COPY/ADD in JSON form keep it when a path contains whitespace (#71).
  • After a SHELL instruction that selects PowerShell or cmd, shell-form bodies are left as written. Before, they were formatted as POSIX shell (#72).
  • CRLF files keep consistent CRLF line endings (#73).
  • Every heredoc in an instruction is kept, not just the first (#76).
  • A blank line inside a RUN continuation no longer splits it into a new instruction (#77).
  • Continuation lines inside quoted ENV/LABEL/ARG values are no longer indented, since indenting them changed the value (#78).
  • CMD/ENTRYPOINT/RUN arguments that aren't valid JSON stay in shell form (#79).
  • Heredocs fed to a non-shell program (RUN <<EOF python3, or a body with a non-shell shebang) are left as written instead of crashing (#80).
  • Non-UTF-8 input (such as UTF-16 written by PowerShell's >) is rejected with an error. Before, it produced an empty file with exit code 0 (#81).
  • Empty continuation lines (\ alone) and comments among RUN flags are preserved (#59, #82).
  • Instructions dockerfmt doesn't recognize (e.g. a misspelled keyword) are kept. Before, they were deleted.
  • COPY/ADD with a heredoc keep their flags. Before, COPY --chmod=755 <<EOF lost --chmod.
  • CMD JSON form keeps its flags, and COPY keeps a -- end-of-flags marker.
  • dockerfmt -i <TAB> completes numbers instead of file names, and positional arguments complete file names (#64, #66).
  • The pre-commit hook no longer overrides indent_size from .editorconfig (#61, #67).

Other changes

  • Dependencies were updated (buildkit v0.33.0, Go 1.26) to pick up CVE fixes (#58, thanks @gw0).
  • The npm package now builds its wasm from the tagged source, so it includes every formatter change. Before, the published wasm was missing every formatter change since v0.5.1, including # dockerfmt-ignore.
  • Library: the new lib.Format(content, config) (string, error) returns errors instead of exiting. FormatFileLines is unchanged.
  • JS: formatting invalid input now rejects with an Error.

Don't miss a new dockerfmt release

NewReleases is sending notifications on new releases.