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

Code formatting #4

Open
zupo opened this issue Sep 2, 2019 · 4 comments
Open

Code formatting #4

zupo opened this issue Sep 2, 2019 · 4 comments

Comments

@zupo
Copy link
Owner

zupo commented Sep 2, 2019

https://github.com/hercules-ci/canonix/ and/or https://github.com/nix-community/nixpkgs-fmt.

@infinisil
Copy link

There's also https://nixfmt.serokell.io/ which was announced on discourse

@zupo
Copy link
Owner Author

zupo commented Oct 19, 2019

Has the community converged behind one of these yet? Or it's still up in the air which one will likely prevail?

@infinisil
Copy link

I personally haven't seen anybody use any formatter in a project. People in nixpkgs have been discussing running one for a while now though, which is bound to happen eventually, not sure which formatter we'll end up using.

I like nixfmt because it's simple and made with Haskell, meaning I could contribute to it easily. It uses its own parser and pretty printer code adapted from a well-known package for that, which makes me confident that it does a good job at getting good results. I just tested it a bit and it produces pretty good results. One potential disadvantage is that it tries hard to keep lines below its (adjustable) line width, personally I like that.

I haven't heard about nixpkgs-fmt before, but here's what I think about it after taking a look at it: More complicated but also an extensive test suite, still WIP though. It's based on very direct rules of a generic parser framework, which seems to make it more fragile. It being written in Rust makes it faster than nixfmt for many files though. Tries less hard to enforce a strict style, focuses on not getting in nixpkgs way. While testing it I found some places where certain expressions were formatted incorrectly.

So I'd say nixfmt would be preferred over nixpkgs-fmt.

@zupo
Copy link
Owner Author

zupo commented Oct 22, 2019

I like enforcing line widths and don't care too much about performance, so I'm gonna go with nixfmt! Thanks for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants