Closed jfly closed 1 month ago
Thanks, @brianmcgee! Unfortunately, it turns out that none-ls passes absolute paths to the formatter, which doesn't seem to work. I filed https://github.com/numtide/treefmt/issues/442 and put out https://github.com/numtide/treefmt/pull/445/ with a fix.
Context
I believe treefmt 1.x was totally ignorant of VCS/git, and would happily format all files it could find (including stuff the
.git
directory!).It's great that treefmt 2+ doesn't do this: it's default filesystem walker ("auto") detects when we're in a git repo and ignores untracked files.
Describe the bug
The problem is that treefmt no longer formats files that are explicitly passed as arguments.
This breaks my "generic nix fmt" formatter I wrote for null-ls/none-ls. See https://github.com/jfly/snow/blob/835b3765b2fa18768ccebb474b292c061ba47752/pkgs/neovim/vimrc#L332-L342. Much like treefmt itself, under the hood, null-ls generates tempfiles and passes them as command line parameters to the formatter. It expects the formatter to format these files, even though they're not tracked by git.
In other words, null-ls expects formatters to obey treefmt's formatter specification. (On a related note, I've tried to clarify this here: https://github.com/numtide/treefmt/pull/434). I'd argue that treefmt itself doesn't follow its own formatter specification, because it won't format untracked tempfiles.
(I am aware of treefmt's
--walk=filesystem
parameter, but that would require my null-ls plugin to somehow know that it's invoking treefmt, when all it really knows is that it's invokingnix fmt
.)Expected behavior
I'd like for treefmt's default behavior to be to format files passed explicitly on the command line, even if those files are not tracked by git. If folders are passed, or if
--walk=git
is used, it's fine to apply the normal filesystem walking rules.