kamadorueda / alejandra

The Uncompromising Nix Code Formatter
https://kamadorueda.github.io/alejandra/
The Unlicense
843 stars 41 forks source link

function arguments, operator chains and lists surpassing line 80 are ignored #349

Open adrian-gierakowski opened 2 years ago

adrian-gierakowski commented 2 years ago
> alejandra --version
Alejandra 3.0.0

function args and operator chains

input 1

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: bbbbbbbbbbbbbbbbddddddddd: cccccccccccccccccccccccccccc: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbddddddddd + cccccccccccccccccccccccccccc

output 1

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: bbbbbbbbbbbbbbbbddddddddd: cccccccccccccccccccccccccccc: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbddddddddd + cccccccccccccccccccccccccccc

expected output 1

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: 
bbbbbbbbbbbbbbbbddddddddd: 
cccccccccccccccccccccccccccc:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 
+ bbbbbbbbbbbbbbbbddddddddd
+ cccccccccccccccccccccccccccc

input 2

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:
bbbbbbbbbbbbbbbbddddddddd:
cccccccccccccccccccccccccccc:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbddddddddd + cccccccccccccccccccccccccccc

output 2: same as 1

expected output 2: same as 1

NOTE: replacing + with any other operator (at least the few that I tried) yields the same results

lists

input 3

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: bbbbbbbbbbbbbbbbddddddddd: cccccccccccccccccccccccccccc: [aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbddddddddd cccccccccccccccccccccccccccc]

output 3

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: bbbbbbbbbbbbbbbbddddddddd: cccccccccccccccccccccccccccc: [aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbddddddddd cccccccccccccccccccccccccccc]

expected output 3

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: 
bbbbbbbbbbbbbbbbddddddddd: 
cccccccccccccccccccccccccccc: [  
  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 
  bbbbbbbbbbbbbbbbddddddddd
  cccccccccccccccccccccccccccc
]

input 4

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: bbbbbbbbbbbbbbbbddddddddd: cccccccccccccccccccccccccccc:
[aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbddddddddd cccccccccccccccccccccccccccc]

output 4: same as 3

expected output 4: same as 3

Additional thoughts

This seems inconsistent with how attrsets are treated, which are always split accross multiple lines, regardless of line length

input 5

{ a, b, c }: { a = 1; b = 2; c = 3; }

output 5

{
  a,
  b,
  c,
}: {
  a = 1;
  b = 2;
  c = 3;
}

Also, note that in the case of operator chains and lists, developer can nudge the formatter to split into multiple lines by inserting at least on newline in between the elements of the expression:

input 6

a: b: c: [
  a b c]

output 6

a: b: c: [
  a
  b
  c
]

input 7

a: b: c: a
+ b + c

output 7

a: b: c:
a
+ b
+ c

I understand this as giving the developer an option to choose between keeping things on one line vs multiple. I believe that this is good as long as the expression doesn't violate max acceptable line length. However this optionality is not given to the developer in case ow function arguments (which are always collapsed onto a single line) and attrsets with more than 1 element (which are always expanded into multiple lines).

adrian-gierakowski commented 2 years ago

related https://github.com/kamadorueda/alejandra/issues/271#issue-1192005471

adrian-gierakowski commented 2 years ago

related https://github.com/kamadorueda/alejandra/issues/271