The easiest is to go to the online formatter and submit code samples when you see something not formatted right. Or if you like to write Rust code your contribution is also welcome.
What’s next?
The goal right now is to have as many people as possible test it an be exposed to the format. The hope is to reach consensus and have a majority of happy users. nixpkgs-fmt’s output is quite close to the format used in nixpkgs so hopefully it won’t be too controversial. Reach 1.0 before 19.09.
After the 19.09 release I am hoping to add hooks to nixpkgs to start formatting the code. We need to discuss how to do that but I think this can be quite gradual.
Another thing I would like to explore is how to create rules that can be language-agnostic by emitting and parsing back a JSON representation of the AST tree. This would make it easy for example to rewrite all the URLs to strings with a simple python/ruby/bash script.
Thanks
Thanks a lot to @matklad who implemented most of nixpkgs-fmt. He also invented the rowan lossless parsing library upon which this project is based.
Thanks also to @jD91mZM2 who wrote the rnix library and was responsive to our pull-requests.
I just tried running some code through it, and I don’t like this particular output decision, but I’m also not sure just what the relevant rules should be either.
Input:
meta = (oldAttrs.meta or {}) // {
platforms = pkgs.rustc.meta.platforms;
};
Output:
meta = (oldAttrs.meta or {})
// {
platforms = pkgs.rustc.meta.platforms;
}
;
In this particular case I think my original formatting is best, because it’s structurally similar to just
meta = {
platforms = pkgs.rustc.meta.platforms;
};
but overlaid on the existing attrset. Given a rule of “operator should be on the new line” I wouldn’t be opposed to an output of
meta = (oldAttrs.meta or {})
// { platforms = pkgs.rustc.meta.pltforms; };
given that the new attrset is a single field with a relatively short value, though I don’t think this is a good as the input.
Edit: I just noticed this decision too, which strikes me as non-idiomatic based on nixpkgs code I’ve seen.
Thanks for the feedback! Until we hit 1.0 any parts of the format is open for discussion and change.
The best thing to do is to submit those code samples to the issue tracker so that we can discuss them individually if you don’t mind. And also keep a centralized history of the decision making.
Thank you @zimbatm. I look forward to this feature! Just a JSON representation to and from nixpkgs-fmt is great for other tools to bootstrap off of the work that nixpkgs-fmt does. I will be writting several nixpkgs transformers once this is available.
I think that the command run git ls-files | grep -e ".nix$" | xargs nixpkgs-fmt could be improved to deal with the files in parallel with GNU parallel or parallel (the Rust one).
Anyway, amazing work ! I will gladly use it ! I will see if I can make myself useful with your codebase.
Oh great ! Did not had the time take a look at the code yet and as I saw xargs I thought it was a good opportunity to parallelize the calls to nixpkgs-fmt. But given the timings you have and your comment it was a bit premature, excuse my mindless comment