numtide / treefmt-nix

treefmt nix configuration
https://numtide.github.io/treefmt/
MIT License
213 stars 62 forks source link

Add `packer fmt` formatter #169

Closed tomeon closed 4 months ago

tomeon commented 4 months ago

Due to the fact that packer fmt accepts only a single file or directory as an argument, this PR includes a not-particularly-pretty wrapper script that calls out to packer fmt once per included source file, and a not-particularly-robust mechanism for distinguishing included source files from packer fmt options (basically, trying to plop a bare -- between options and source file arguments).

Also includes some updates to the "Adding new formatters" section of the README; would be happy to spin these changes into a separate PR if that's preferable.

Thanks in advance!

tomeon commented 4 months ago

Do you mind also contacting upstream so it eventually gets fixed?

Done: hashicorp/packer#12883.

dawidd6 commented 4 months ago

Isn't this the same as hclfmt though?

zimbatm commented 4 months ago

probably. I would use hclfmt as it follows the treefmt spec. But I haven't used Packer for a while, maybe there is some extra semantic that packer fmt understands?

tomeon commented 4 months ago

[M]aybe there is some extra semantic that packer fmt understands?

Allegedly several of the <hashicorp-tool> fmt subcommands, including packer fmt, have tool-specific behavior, according to Hashicorp employees/contributors here and here. Such that running hclfmt after packer fmt is (or should be) idempotent, but running packer fmt after hclfmt isn't.