-
-
Notifications
You must be signed in to change notification settings - Fork 32
Trailing commas #248
Comments
I agree with the reasoning but I think this ship has sailed already. Most of the nixpkgs default.nix use the comma-first notation. |
I would not say it is too late. Many (most?) nixpkgs packages still use the multiple-attributes-per-line style so they will need to be reformatted anyway. If we consider this reasonable, the upcoming nixpkgs reformatting would be a great opportunity. |
I prefer the style proposed here, and it would be a great time to do it. Another option is to remove the final |
I am open to introducing the change, but I don't think it should be holding back the upstream effort. nixpkgs-fmt 1.0 has been released on Aug 17, 2020, so it's not like the hasn't been plenty of time to discover this. |
I started using nixpkgs-fmt integration for my editor a few days ago, but this issue is the reason I will disable it again.
There doesn't seem to be any option to disable this behavior. Or is there?
Why has the ship sailed? There is no enforced formatting in nixpkgs AFAIK and right now there is still a lot of chaos. I see all kinds of different formatting styles in nixpkgs. It doesn't seem like anything will get worse by introducing this change.
What needs to be done to make it happen? |
I personally prefer the way it is now, so if anything happens I'd like it to be configurable. Of course not in nixpkgs but for other projects. |
Could you explain why you prefer the current style over the one that is proposed by the current issue? |
I may have some motivation to take a shot at this. Would somebody familiar with the code base please give me some directions for a head start? |
I like the current implementation. After initial confusion (why would anyone do that?!?) I came to prefer that style even when writing code myself. It just looks nicer to me and is more consistent (within itself). I see that it isn't consistent with attrsets but that isn't an issue for me personally. |
I'm not so sure but I think the proposed style also has the advantage that merging different code (potentially with conflicts) is easier as you can just remove the conflict markers / remove one part in the case that the { foo # first line
, bar
,
} is removed and another one is added or similar changes. |
It's interesting, and not surprising to see people having different preferences. There is not really a way to solve that without issuing a vote to all NixOS contributors. If we were to make this change, it should go into a 2.x release as it would be very backwards-incompatible. |
I think the leading comma is fine, and it's a pattern I do in other languages as well. I'm not sure I would directly correlate this with regular attribute sets and That said, I don't think everyone is going to agree one way or another on this. I would say, in this case, to go with what most packages in nixpkgs already do, which is the leading |
I think we should optimize the style for practicality, not personal preferences.
Could you please explain what you mean, maybe with an example? In what way is it more consistent if the first element starts with a
I don't really see why this is a hard decision to make. Multiple points have been brought up, demonstrating practical downsides of the current style, but basically no arguments other than |
@DavHau, I'm not sure if I can provide a compelling objective argument honestly. To me, this is just one of those things that boils down to preference. I also think the difficulties you mentioned are dependant on the editor you use. I have been in the two situations you mentioned myself, but didn't really find the difficulty you described in kakoune. All I can say is that having the comma on the starting line makes the deliniation trivially clear to my eyes. Also, for your second point in particular, it seems this would be an issue with either style. The only real way to simplify that would be if we forced a newline after the first |
As far as I can tell that's what the issue creation comment does. |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/the-uncompromising-nix-code-formatter/17385/26 |
Describe the bug
I would like to use trailing commas in attrset pattern matches in function arguments to be consistent with regular attrsets (which have trailing semicolons):
Currently, the trailing commas are moved to the next row, looking really ugly:
Would also help with the dilemma where to place a comma with regards to the argument comments by @Mindavi and @asymmetric.
To Reproduce
Expected behavior
The function argument would keep commas at the same line when a trailing comma for the final attr is detected.
System information
nixpkgs-fmt --version
nixpkgs-fmt 1.2.0The text was updated successfully, but these errors were encountered: