nixfmt icon indicating copy to clipboard operation
nixfmt copied to clipboard

Ignore symlinks when formatting

Open Lucus16 opened this issue 5 years ago • 6 comments

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.

Lucus16 avatar Feb 14 '20 00:02 Lucus16

Ah, whoops, I broke nixfmt without arguments.

Lucus16 avatar Feb 15 '20 10:02 Lucus16

That should fix that.

Lucus16 avatar Feb 15 '20 11:02 Lucus16

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...).

kirelagin avatar Feb 15 '20 16:02 kirelagin

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.

Lucus16 avatar Feb 17 '20 22:02 Lucus16

We plan to deprecate the directory mode directly in nixfmt and instead encourage use of treefmt.

tomberek avatar May 28 '24 18:05 tomberek

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

nixos-discourse avatar May 28 '24 19:05 nixos-discourse