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

set nixfmt as the default formatter for nix #11001

Conversation

notnmeyer
Copy link

sets the default formatter for nix to nixfmt and enables auto-formatting.

closes #10803

@poliorcetics
Copy link
Contributor

Is it stable yet ? I agree that using what is going to be the official formatter is nice but it's still in < 1.0 so I'm afraid they'll do breaking changes yet and we'll get issues with people complaining helix is changing all the formatting because of two different versions of nixfmt on two machines

@notnmeyer
Copy link
Author

notnmeyer commented Jun 21, 2024

could they... use nix to avoid that? joking aside, if this a concern a practical solution would just be disable auto-format as a default. i think the scenario where different tooling versions "fight" over the correct formatting style can apply to a lot of tools and different configuration settings. personally, i don't think its that big of deal.

@kirawi kirawi added the A-language-support Area: Support for programming/text languages label Jun 21, 2024
@poliorcetics
Copy link
Contributor

could they... use nix to avoid that

I must admit I laughed 😁

And really my comment was a question for you. I settled on "nixpkgs-fmt" a long time ago for nix formatting because I didn't want to depend on something that, at the time, was still only a project and not actual working code, but if the situation has changed and stabilized, adding out of the box support in helix is certainly something I'll agree with.

I have not followed evolutions though, so I genuinely don't know 😅

@notnmeyer
Copy link
Author

notnmeyer commented Jun 24, 2024

the current RFC style is packaged in nixfmt-rfc-style (which still installs a nixfmt binary) and i believe the intention is to eventually just have the nixfmt package be the source of truth. i cant comment on how "stable" the formatter is, but ive been using it myself and it works fine.

the main points here:

  1. the style rfc has been adopted
  2. the formatter is packaged and available

@the-mikedavis
Copy link
Member

Yeah let's keep auto-format off for now by default. We should only enable auto-format for languages where formatting is ubiquitous like Rust - otherwise it can unexpectedly reformat older code. Eventually if formatting becomes very popular for Nix we can enable it but where the RFC was accepted recently I think it's too soon.

Super ideally though we wouldn't need to set up a formatter binary for this. Ideally the language servers would depend-on/use nixfmt. External formatters are fairly wasteful since we need to spawn them and send the whole document through them and figure out the diff ourself per-save while with language servers we have incremental document sync and text edits to describe the changes. Maybe for now we could just recommend formatter.command = "nixfmt" in the documentation since I assume language servers will follow the RFC in the (near?) future.

@notnmeyer
Copy link
Author

notnmeyer commented Jun 27, 2024

or now we could just recommend formatter.command = "nixfmt" in the documentation

works for me, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-language-support Area: Support for programming/text languages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add nixfmt as default formatter for nix
4 participants