nixfmt
nixfmt copied to clipboard
Ignore symlinks when formatting
Before this, symlinks were replaced with a formatted file rather than
formatting the file behind the symlink. The choice was between ignoring
symlinks and following them. Following symlinks means potentially
formatting files in an unexpected location which seems much worse than
needing to wrap the arguments in a readlink -f when symlinks are
otherwise ignored.
Fixes #56.
Ah, whoops, I broke nixfmt without arguments.
That should fix that.
One option might be to add -L option to follow symlinks, but, I’d say, that’s too much trouble. Instead, we can just add an example of an invocation that would follow symlinks (find, xargs, readlink, something like this...).
I agree with using safe-exceptions and adding an example like nixfmt $(readlink -f $(find -name '*.nix')). Don't have time for it right now though, feel free to fix them and ask for my review.
We plan to deprecate the directory mode directly in nixfmt and instead encourage use of treefmt.
This pull request has been mentioned on NixOS Discourse. There might be relevant details there:
https://discourse.nixos.org/t/formatting-team-meeting-2024-05-28/46126/1