nix-community / nixpkgs-fmt

Nix code formatter for nixpkgs [maintainer=@zimbatm]
https://nix-community.github.io/nixpkgs-fmt/
Apache License 2.0
581 stars 34 forks source link

Add '--write' argument #252

Closed andyrichardson closed 3 years ago

andyrichardson commented 3 years ago

Is your feature request related to a problem? Please describe. It would be great if formatting could optionally be written to files on execution.

Tools such as prettier and eslint take a --write or --fix argument to opt-in to writing to the file.

Describe the solution you'd like

When running the following command

fmt --write flake.nix

The formatted file content would be written to the file rather than outputted to the console.

Describe alternatives you've considered

Maybe add something to the readme to make it easy for users to have this functionality (less ideal).

Something like (not tested)

find nix | grep .nix | xargs -L 1 -I {} bash -c "fmt {} > {}"  

Additional context

N/A

zimbatm commented 3 years ago

This is already the default. Just use nixpkgs-fmt flake.nix

andyrichardson commented 3 years ago

Thanks @zimbatm - looks like I was using fmt rather than nixpkgs-fmt