Skip to content

Builtins.tofu fix adds a newline to empty .tf files that tofu fmt accepts #1873

Closed

Description

@mfroembgen

What were you trying to do when you hit this?

Run hk fix --all in an OpenTofu repository that uses Builtins.tofu. The repository has a few intentionally empty .tf files.

What you ran

mise.toml:

[tools]
hk = "2.13.0"
opentofu = "1.11.5"

hk.pkl:

amends "package://github.com/jdx/hk/releases/download/v2.13.0/hk@2.13.0#/Config.pkl"
import "package://github.com/jdx/hk/releases/download/v2.13.0/hk@2.13.0#/Builtins.pkl"

steps {
  ["tofu"] = Builtins.tofu
}
git init && : > empty.tf && git add -A
hk check --all        # exit 0
tofu fmt -check empty.tf   # exit 0
hk fix --all          # exit 0
xxd empty.tf

What happened

00000000: 0a                                       .

hk fix writes a single newline into the empty file, although hk check and tofu fmt -check both accept it, and tofu fmt empty.tf leaves it empty. The builtin's check_diff runs tofu fmt -, which turns empty input into "\n", and hk applies that diff.

Expected: hk fix leaves files alone that tofu fmt leaves alone.

Version

hk 2.13.0, OpenTofu 1.11.5

Activity

  1. added a commit that references this issue on Nov 19, 2026
    704b141
  2. github-actions commented on Nov 23, 2026

    @github-actions
    Contributor

    Fixed in v2.14.0 by #1874.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions