Skip to content

Commit a867a5c

Browse files
infinisilpiegamesde
authored andcommitted
Redo and explain operator special case
Also remove the special case for non-chainable operators, barely any benefit in Nixpkgs
1 parent 404688c commit a867a5c

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

rfcs/0166-nix-formatting.md

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -566,12 +566,7 @@ If an operator chain does not fit onto one line, it is expanded such that every
566566
- If the operand can also fit on the same line as the operator, it's put there
567567
- Otherwise, the operand usually starts indented on a new line, with special handling for parenthesis, brackets, braces, function applications
568568

569-
Binary operators (which cannot be chained) may use a more compact representation,
570-
where the operator is not required to start a new line even when the operands span multiple lines.
571-
572-
The `//` operator is special cased to such a more compact representation too,
573-
even though this results in multiple violations of the style guidelines.
574-
The motivation for this is that it is often used in places that are very sensitive to the indentation of large attribute sets.
569+
Operator chains in bindings may be compacted as long as all lines between the first and last one are indented.
575570

576571
**Examples**
577572

@@ -607,6 +602,25 @@ foo
607602
echo hi
608603
''
609604
test
605+
606+
{
607+
# In a binding, we can use a more compact form as long as all inbetween lines are indented
608+
foo = bar // {
609+
x = 10;
610+
y = 20;
611+
} // baz;
612+
}
613+
614+
{
615+
# Bad, we can't use the more compact form because an intermediate line is not indented.
616+
foo = {
617+
x = 10;
618+
y = 20;
619+
} // foo // {
620+
z = 30;
621+
w = 40;
622+
};
623+
}
610624
```
611625

612626
### if

0 commit comments

Comments
 (0)