diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 67972d21fd12..8d99e465cc0e 100644 --- a/CONTRIBUTING.md +++ b/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