Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

treefmt 2+ no longer formats gitignored files passed explicitly as arguments #435

Closed
jfly opened this issue Oct 11, 2024 · 1 comment · Fixed by #438
Closed

treefmt 2+ no longer formats gitignored files passed explicitly as arguments #435

jfly opened this issue Oct 11, 2024 · 1 comment · Fixed by #438
Labels
bug Something isn't working

Comments

@jfly
Copy link
Collaborator

jfly commented Oct 11, 2024

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: #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 invoking nix 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.

@jfly jfly added the bug Something isn't working label Oct 11, 2024
brianmcgee added a commit that referenced this issue Oct 12, 2024
Changes how we handle paths which are provided as arguments:

- if it's a file, we attempt to format it based on the matching options
- if it's a directory, we traverse it using the provided walk type

This is more consistent with what a user expects and makes it easier to integrate with tools such as `none-ls`.

Close #435
@jfly
Copy link
Collaborator Author

jfly commented Oct 12, 2024

Thanks, @brianmcgee! Unfortunately, it turns out that none-ls passes absolute paths to the formatter, which doesn't seem to work. I filed #442 and put out #445 with a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant