Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change formatting for ++, + and // #284

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

Sereja313
Copy link
Member

This commit implements a new formatting style for ++, + and //, like described in proposal 2 in the comment #228 (comment)

This commit implements a new formatting style for `++`, `+` and `//`, like
described in proposal 2 in the comment #228 (comment)
Copy link

github-actions bot commented Feb 18, 2025

Nixpkgs diff processing..

Will be available here

@infinisil
Copy link
Member

(reviewed together with @Sereja313 in the meeting)

Problematic cases that are valid with the PR:

{
  foo = aaaaaaaaaaaaaaaaaaaaaaaaa
  + bbbbbbbbbbbbbbbbbbbbbbbbbbbbb
  + ccccccccccccccccccccccccccccc
  + ddddddddddddddddddddddddddddd;

  bar = "aaaaaaaaaaaaaaaaaaaaaaaa"
    + bbbbbbbbbbbbbbbbbbbbbbbbbbb
    + ccccccccccccccccccccccccccc
    + ddddddddddddddddddddddddddd;
}
{
  boot.kernelParams = [ aaaaaaaaaaaaaa ]
    ++ optionals config.boot.vesa [
      "vga=0x317"
      "nomodeset"
    ];
}
{
  foo = [ bar ]
    ++ baz;
}

Should address these, can use the above as tests.

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/formatting-team-meeting-2025-02-18/60511/1

@infinisil
Copy link
Member

Oh and forgot to mention, we also need to update the standard document with this change.

@Sereja313 Sereja313 marked this pull request as draft March 17, 2025 13:36
@Sereja313 Sereja313 force-pushed the sereja313/228-optionals branch from 9272590 to 7d36f5e Compare March 18, 2025 16:20
-- If none of these failed, put together and return
return (preRendered ++ prioRendered ++ postRendered)
where
-- Special case where list concatenation doesn't fit one line we need to replace space with newline
fixListConcat (Spacing Space : xs@(Text _ _ _ "++" : _)) = newline <> xs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't. This is a strong violation of layers and really should be fixed earlier in the data flow

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it doesn't work anyway

@piegamesde
Copy link
Member

piegamesde commented Mar 18, 2025

If you want to remove the indentation, you need to move the nest calls wrapping absorbRHS into absorbRHS so that you can skip it for certain operations

To add context, your current code only works for cases where the first term gets absorbed into the line of the =, because then the nesting gets canceled. However, and I don't think those cases are currently sufficiently tested, you (probably?) also want stuff like this without indentation:

foo =
some function application that kinda is long
++ [
  a
  list
];

Also, don't forget to test cases where the = is indented, like

some.long.attribute # with a comment
  = [ stuff ]
  ++ more stuff;

@infinisil
Copy link
Member

infinisil commented Mar 18, 2025

A bit messy notes from the meeting today:

{
  # PR
  # This example has additional indentation, so likely also has larger git diffs
  boot.kernelParams = [ aaaaaaaaaaaaaa ]
    ++ optionals config.boot.vesa [
      "vga=0x317"
      "nomodeset"
    ];

  # Base:
  boot.kernelParams = [ aaaaaaaaaaaaaa ];
  boot.kernelParams = [
    aaaaaaaaaaaaaa
    bbbbbbbbbbbbbb
  ];

  # Current
  # This example does not minimise git diff
  boot.kernelParams =
    [ aaaaaaaaaaaaaa ]
    ++ optionals config.boot.vesa [
      "vga=0x317"
      "nomodeset"
    ];
    
  # Alternative
  # This example minimises git diff
  boot.kernelParams = [
    aaaaaaaaaaaaaa
  ]
  ++ optionals config.boot.vesa [
    bbbbbbbbbbbbbb
  ];
}
  • @MattSturgeon: The latter would be preferred for smaller diffs
  • @infinisil: Can also be future work, as long as the PR doesn't make formatting worse, can merge it
  • (doesn't block the treewide)
  • @piegamesde can help out

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/formatting-team-meeting-2025-03-18/61868/1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

4 participants