nixfmt icon indicating copy to clipboard operation
nixfmt copied to clipboard

Function parameter attrset block formatting is not optimal to read

Open tfc opened this issue 4 years ago • 1 comments

Description

Function parameter set blocks with default arguments are most clear and most pretty to read when the parameters are presented each on one line (and i tend to like it when they're sorted alphabetically, but i consider that optional).

nixfmt does generally produce really nice output and i would like to use it, but it seems suboptimal that it squashes such function parameter blocks to less readable format.

Small example input

foo = {
  bar ? bla function call [] foobar {},
  quux ? something very long,
  baz ? []
}: builtins.toJSON {
  # ...
}

Expected output

foo = {
    bar ? bla function call [] foobar {},
  , quux ? something very long,
  , baz ? []
  }: 
  builtins.toJSON {
  # ...
}

Actual output

foo = 
  { bar ? bla function call [] foobar {}, quux ? something very long,  baz ? []}: 
  builtins.toJSON {
    # ...
  }

(please only look at the attrset parameter block, i don't care about the rest formatting, as nixfmt does that well)

tfc avatar Oct 26 '19 11:10 tfc

This is especially bad when default parameters span multiple lines, like here:

{ haskellNix ? import (builtins.fetchTarball {
  url =
    "https://github.com/vitalbio/haskell.nix/archive/06435647a5a02a2bcf20ec156894e910721c8497.tar.gz"; # vital
  sha256 = "190j32spzkf1cmwfsyyp996qkbfgj23blg2hwmi0xd9swj701c26";
}) { }, nixpkgsSrc ? haskellNix.sources.nixpkgs-2009 }:

_

It would be much nicer to indent the attrset passed to fetchTarball to the level of haskellNix

expipiplus1 avatar Nov 08 '20 02:11 expipiplus1

The RFC format is completely different on this, and should not have this readability issue.

piegamesde avatar Mar 14 '24 20:03 piegamesde