nixvim icon indicating copy to clipboard operation
nixvim copied to clipboard

TEST: reformat with latest nixfmt

Open MattSturgeon opened this issue 1 year ago • 4 comments

Just to satisfy my curiosity, this is what the repo looks like when running

nix run github:nixos/nixfmt -- **/*.nix

Note: some of the new formatting uses input-formatting-based heuristics, so if you (for example) wanted to reformat the following, it may require manual intervention.

# from
mkRenamedOptionModule
  [
    "plugins"
    "hello"
    "foo"
  ]
  [
    "plugins"
    "goodbye"
    "bar"
  ]
# to
mkRenamedOptionModule [ "plugins" "hello" "foo" ] [ "plugins" "goodbye" "bar" ]
# or
mkRenamedOptionModule
  [ "plugins" "hello" "foo" ]
  [ "plugins" "goodbye" "bar" ]

We can experiment with additional commits on this branch, manually modifying input formatting and re-running nixfmt to see what it now permits.

MattSturgeon avatar Sep 09 '24 16:09 MattSturgeon

mkRenamedOptionModule
  [ "plugins" "hello" "foo" ]
  [ "plugins" "goodbye" "bar" ]

This one looks cleanest to me

khaneliman avatar Sep 09 '24 16:09 khaneliman

Tried playing with some mkRenameOptionModules, I was really hoping https://github.com/NixOS/nixfmt/pull/233 would clean these up (as above). So far I'm kinda disappointed:

(mkRenamedOptionModule [ "foo" "bar" ] [
  "hello"
  "world"
])
(mkRenamedOptionModule [ "foo" "bar" ] (
  foo
  ++ [
    "hello"
    "world"
  ]
))
(mkRenamedOptionModule
  (
    foo
    ++ [
      "bar"
      "baz"
    ]
  )
  [
    "hello"
    "world"
  ]
)

The final argument is always expanded to multiple lines, even if the line length would remain short.

Additionally, any concatenation changes the semantics as far as nixfmt is concerned. Concatenation no longer qualifies as a "list used as a function argument"; instead it is treated as "part of a concatenation expression". It is therefore always expanded to multiple lines :sob:

This isn't the best place to discuss nix formatting; we should probably raise this as feedback in the nixfmt repo I guess. Although there's already https://github.com/NixOS/nixfmt/issues/206 and https://github.com/NixOS/nixfmt/issues/228, which are related.

For now I'll just cc some of the formatting team: @infinisil @piegamesde @emilazy

MattSturgeon avatar Sep 09 '24 18:09 MattSturgeon

I'm not a member of the formatting team :) though I play one on TV.

emilazy avatar Sep 09 '24 18:09 emilazy

I'm not a member of the formatting team :) though I play one on TV.

I was going to try blaming you when I saw you tagged but then saw you weren't the one who did the commit :P

khaneliman avatar Sep 09 '24 18:09 khaneliman

With https://github.com/NixOS/nixfmt/pull/257 this is fixed now! Though be aware of https://github.com/NixOS/nixfmt/pull/224

infinisil avatar Nov 29 '24 14:11 infinisil