alejandra icon indicating copy to clipboard operation
alejandra copied to clipboard

reconsider placement of semicolons

Open adrian-gierakowski opened this issue 2 years ago • 0 comments

Current formatting

{
  f = a: b: c:
    a 
    || b 
    && c;
}

Proposed:

{
  f = a: b: c:
    a 
    || b 
    && c
  ;
}

Rationale

  1. The semicolon closes a block opened by = so it should be on the same indentation level. It makes it easy to visually parse the span of the block.
  2. Proposed change would make things consistent with how lists and attrsets are formatted:
{
  list = [
    a
    b
  ];
  attrs = {
    a = 1;
    b = 2;
  };
}
  1. Modifying the last line of the scope leads to 2 line diff given current formatting vs 1 line given the proposed one:

current:

     || b
-    && c;
+    && c
+    || a + b;

proposed:

     || b
     && c
+    || a + b
   ;
 }

This is the same argument as used for the choice of comma placement described in alejandra's style guide.

Bonus

Make semicolon placement consistent between multiline assignment and inherit:

Currently we've got:

{
  pkgs =
    import
    <nixpkgs>
    {};
  inherit
    (pgks)
    bash
    lib
    ;
}

I'd like to propose:

{
  pkgs =
    import
    <nixpkgs>
    {}
  ;
  inherit
    (pgks)
    bash
    lib
  ;
}

adrian-gierakowski avatar Aug 28 '22 14:08 adrian-gierakowski