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

formatting/general code style guidelines #23

Closed
getchoo opened this issue Apr 16, 2023 · 4 comments
Closed

formatting/general code style guidelines #23

getchoo opened this issue Apr 16, 2023 · 4 comments
Assignees
Milestone

Comments

@getchoo
Copy link
Member

getchoo commented Apr 16, 2023

we've talked about this a lot, so i think it might be a good time to actually figure out what formatter we're going to use, and what (if any) code style guidelines we would want to put in CONTRIBUTING.md. a good example of how we could approach this is found here in the home-manager manual

@getchoo
Copy link
Member Author

getchoo commented Apr 16, 2023

the three most popular formatters are

alejandra

i'm personally a fan of alejandra and it's what i use in my nix stuff since it can make things look pretty good and it's aggressive enough with formatting so that the output is very consistent. it has some opinionated styling though, such as lists and attrs being formatted like this:

_: {
  list = [1 2  3 4];
  attr = {foo = bar;};
}

nixfmt

nixfmt is probably the most traditional one, but in my experience it doesn't really format much at all. i feel like this is good for personal projects since it helps you clean up your own unique style, but maybe not the best for collaborative project. a lot of it's formatting lets personal style bleed through and it's easily the most conservative of the three.

nixpkgs-fmt

nixpkgs-fmt is the closest we have to a "standard" formatter since it's in nix-community and has seen pretty wide adoption by projects inside and outside of that group -- and like alejandra, it formats a lot of stuff sometimes. it's style is similar to nixfmt, though with the exception of some small things such as arguments being formatted like this:

{ pkgs
, config
, lib
, ...
}:
{}

imo, nixpkgs-fmt or alejandra would be the best for this project since they create the most uniform code (plus they just look a bit better most of the time)

@Stonks3141
Copy link
Member

I’m leaning toward nixpkgs-fmt just since it’s more standard in the community, so I’ll add it to CI. I’m still open to arguments for alejandra though.

@Stonks3141 Stonks3141 added this to the 1.0.0 milestone Apr 16, 2023
@Stonks3141 Stonks3141 self-assigned this Apr 16, 2023
@getchoo
Copy link
Member Author

getchoo commented Apr 18, 2023

i like alejandra, but yeah i agree nixpkgs-fmt would be best for a collaborative project (plus it's just a formatter :p)

@Stonks3141
Copy link
Member

Closed by #31

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