Comments (12)
don't give up @layus ! the format is definitely up for discussion
from nixpkgs-fmt.
This is sort of intentional, see #46.
The problem with placing first parameter after {
is that it forces parameters to align to {
, which doesn't work to well in cases like this:
{
f = { x
, y
}: body
}
from nixpkgs-fmt.
Fair point indeed.
That being said, top-level functions are a bit different and could be handled differently, because this example looks like an unfinished tetris game. The curly bracket is itching to fall one square below ;-).
But this has already been discussed, so closing for now.
{
foo
, bar
, baz
}:
foo + bar
Okay examples
{
foo,
bar,
baz
}:
foo + bar
{ foo
, bar
, baz
}:
foo + bar
{
f = { x
, y
, z
}: body;
}
{
f = {
x,
y,
z,
}: body;
}
Not okay examples
{
foo
, bar
, baz
}:
foo + bar
{
f = {
x
, y
, z
}: body;
}
from nixpkgs-fmt.
This is the hardest problem we've had with the nix format, making it work in the top-level and deeper levels. We haven't found a solution that keep the rules simple.
I guess an alternative would be to force the deeper level to be on multiple lines like that:
{
f =
{ x
, y
, z
}: body;
}
from nixpkgs-fmt.
I guess an alternative would be to force the deeper level to be on multiple lines like that:
{ f = { x , y , z }: body; }
That's definitely an option, and it looks quite nice to me. Especially given that nested functions that receive an attrset as argument do not look too frequent in nixpkgs.
from nixpkgs-fmt.
Function parameters are hard, because they have no opening and closing symbols. We could use λ a: b: c: 1
for the sake of reasoning. then an argument list is just like a normal list. See the simmilarity between these two ?
{
f = λ
{ x, y, z}:
foo:
{ a, b, c}:
bar:
body;
}
{
f = [
{ x, y, z}
foo
{ a, b, c}
bar
];
}
So either the arguments are on the same line, or they are on separate lines, with a leading newline. That rule is easy to state, and somewhat alleviates our current issue.
Fully expanded ;-):
{
f =
{ x
, y
, z
}:
foo:
{ a
, b
, c
}:
bar:
body;
}
[Edit] replace tabs with spaces
from nixpkgs-fmt.
Why are foo:
and bar:
indented once more in your example? The array argument should dictate that all the function arguments would be aligned on the same indent?
from nixpkgs-fmt.
they say a figure is better than a thousand words ;-), so here it comes:
{
f =
set1:
foo:
set2:
bar:
body;
}
{
f =
{
x,
y,
z
}:
foo:
{
a,
b,
c
}:
bar:
body;
}
from nixpkgs-fmt.
Why are
foo:
andbar:
indented once more in your example? The array argument should dictate that all the function arguments would be aligned on the same indent?
They are not. Could it be a tab vs spaces issue ? I edited my previous comment to fix that.
from nixpkgs-fmt.
Okay that makes more sense now with the indent fixed :)
I think the body will have to be on the same level as the argument to avoid too much movement:
single-line:
{
f = a: b: c:
body;
}
multi-line:
{
f =
a:
b:
c:
body;
}
If the body is really large it will create a lot of whitespace diff otherwise.
from nixpkgs-fmt.
And if that's applied then we can keep the comma-first notation for the function arguments. This notation is quite pervasive in nixpkgs:
{ foo
, bar
, baz
}:
from nixpkgs-fmt.
What we do in canonix is to format top-level differently than inline.
from nixpkgs-fmt.
Related Issues (20)
- `error: input 'nixpkgs-fmt/fenix/naersk' follows a non-existent input 'naersk'` HOT 8
- Peculiar indentation choice HOT 1
- Wrong indentation on multi line if/then/else expression HOT 4
- Full line comment wrongfully converted to same line comment
- Stop enforcing a space in empty containers? HOT 7
- "#dontformat" directive HOT 4
- sample: list of floats formatted surpised me HOT 3
- improve CLI ergonomics when parsing errors occur when using parse flag HOT 1
- [Security] Make formatted expression free from CVE-2021-42574 (Trojan Source) HOT 5
- Misaligned lists of attribute sets HOT 1
- sample: List after in has no indentation
- Second comment line is indented after let … in
- Multi-line strings in let/in-expressions are wrongly indented
- Add a binary to Releases
- Re-release for security updates HOT 2
- Wrong indention for attr set as parameter
- Space removed before comments in multi-line inherit expressions HOT 1
- Add option to choose indention style HOT 2
- Confusing attset merging
- Shell completions HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nixpkgs-fmt.