mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-21 22:43:01 +00:00
CONTRIBUTING.md: Mention nixfmt instead of manual formatting rules
This commit is contained in:
parent
ca4a5e1f20
commit
8121f5a4bd
127
CONTRIBUTING.md
127
CONTRIBUTING.md
@ -561,132 +561,7 @@ Names of files and directories should be in lowercase, with dashes between words
|
||||
|
||||
- Use `lowerCamelCase` for variable names, not `UpperCamelCase`. Note, this rule does not apply to package attribute names, which instead follow the rules in [package naming](./pkgs/README.md#package-naming).
|
||||
|
||||
- Function calls with attribute set arguments are written as
|
||||
|
||||
```nix
|
||||
foo {
|
||||
arg = <...>;
|
||||
}
|
||||
```
|
||||
|
||||
not
|
||||
|
||||
```nix
|
||||
foo
|
||||
{
|
||||
arg = <...>;
|
||||
}
|
||||
```
|
||||
|
||||
Also fine is
|
||||
|
||||
```nix
|
||||
foo { arg = <...>; }
|
||||
```
|
||||
|
||||
if it's a short call.
|
||||
|
||||
- In attribute sets or lists that span multiple lines, the attribute names or list elements should be aligned:
|
||||
|
||||
```nix
|
||||
{
|
||||
# A long list.
|
||||
list = [
|
||||
elem1
|
||||
elem2
|
||||
elem3
|
||||
];
|
||||
|
||||
# A long attribute set.
|
||||
attrs = {
|
||||
attr1 = short_expr;
|
||||
attr2 =
|
||||
if true then big_expr else big_expr;
|
||||
};
|
||||
|
||||
# Combined
|
||||
listOfAttrs = [
|
||||
{
|
||||
attr1 = 3;
|
||||
attr2 = "fff";
|
||||
}
|
||||
{
|
||||
attr1 = 5;
|
||||
attr2 = "ggg";
|
||||
}
|
||||
];
|
||||
}
|
||||
```
|
||||
|
||||
- Short lists or attribute sets can be written on one line:
|
||||
|
||||
```nix
|
||||
{
|
||||
# A short list.
|
||||
list = [ elem1 elem2 elem3 ];
|
||||
|
||||
# A short set.
|
||||
attrs = { x = 1280; y = 1024; };
|
||||
}
|
||||
```
|
||||
|
||||
- Breaking in the middle of a function argument can give hard-to-read code, like
|
||||
|
||||
```nix
|
||||
someFunction { x = 1280;
|
||||
y = 1024; } otherArg
|
||||
yetAnotherArg
|
||||
```
|
||||
|
||||
(especially if the argument is very large, spanning multiple lines).
|
||||
|
||||
Better:
|
||||
|
||||
```nix
|
||||
someFunction
|
||||
{ x = 1280; y = 1024; }
|
||||
otherArg
|
||||
yetAnotherArg
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```nix
|
||||
let res = { x = 1280; y = 1024; };
|
||||
in someFunction res otherArg yetAnotherArg
|
||||
```
|
||||
|
||||
- The bodies of functions, asserts, and withs are not indented to prevent a lot of superfluous indentation levels, i.e.
|
||||
|
||||
```nix
|
||||
{ arg1, arg2 }:
|
||||
assert system == "i686-linux";
|
||||
stdenv.mkDerivation { /* ... */ }
|
||||
```
|
||||
|
||||
not
|
||||
|
||||
```nix
|
||||
{ arg1, arg2 }:
|
||||
assert system == "i686-linux";
|
||||
stdenv.mkDerivation { /* ... */ }
|
||||
```
|
||||
|
||||
- Function formal arguments are written as:
|
||||
|
||||
```nix
|
||||
{ arg1, arg2, arg3 }: { /* ... */ }
|
||||
```
|
||||
|
||||
but if they don't fit on one line they're written as:
|
||||
|
||||
```nix
|
||||
{ arg1, arg2, arg3
|
||||
, arg4
|
||||
# Some comment...
|
||||
, argN
|
||||
}: { }
|
||||
```
|
||||
- New files must be formatted by entering the `nix-shell` from the repository root and running `nixfmt`.
|
||||
|
||||
- Functions should list their expected arguments as precisely as possible. That is, write
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user