treefmt icon indicating copy to clipboard operation
treefmt copied to clipboard

`treefmt --stdin` doesn't work if the underlying formatter cares about the real filename

Open MagicRB opened this issue 8 months ago • 11 comments

Describe the bug

So the default behavior of treefmt, is to to not pass the file path to the downstream formatter if formatting via stdin. But that subtly breaks fourmolu, it fails to pull in the active Haskell extensions. So fourmolu -i -c fat-hs/src/MyLib.hs < fat-hs/src/MyLib.hs works, but fourmolu -i -c < fat-hs/src/MyLib.hs doesn't. I don't quite see from the code, where does the path get omitted, https://github.com/numtide/treefmt/blob/9399cd69f9860bf62fd42479591e0ae39a1b7636/format/formatter.go#L80 I was looking there, and I think it comes from files, which is empty in the case of stdin formatting I guess.

To Reproduce

  1. clone my thesis repo https://git.redalder.org/magic_rb/bsc-thesis
  2. try to format fat-hs/src/MyLib.hs using treefmt, so: treefmt --stdin fat-hs/src/MyLib.hs < fat-hs/src/MyLib.hs

Expected behavior

Formatting is consistent between stdin mode and direct mode

System information

NixOS 25.05, exact versions of everything are pinned in https://git.redalder.org/magic_rb/bsc-thesis Additional context

MagicRB avatar Apr 18 '25 10:04 MagicRB