astro / deadnix

Scan Nix files for dead code
GNU General Public License v3.0
512 stars 13 forks source link

Incorrect formatting when removing let binding #7

Closed siraben closed 2 years ago

siraben commented 2 years ago

While testing https://github.com/NixOS/nixpkgs/pull/149892, the following file pkgs/pkgs-lib/tests/default.nix gets formatted incorrectly:

# Call nix-build on this file to run all tests in this directory
{ pkgs ? import ../../.. {} }:
let
  formats = import ./formats.nix { inherit pkgs; };
in pkgs.linkFarm "nixpkgs-pkgs-lib-tests" [
  { name = "formats"; path = import ./formats.nix { inherit pkgs; }; }
]

deadnix produces

# Call nix-build on this file to run all tests in this directory
{ pkgs ? import ../../.. {} }:pkgs.linkFarm "nixpkgs-pkgs-lib-tests" [
  { name = "formats"; path = import ./formats.nix { inherit pkgs; }; }
]

while maybe something like this is more appropriate

# Call nix-build on this file to run all tests in this directory
{ pkgs ? import ../../.. {} }:
pkgs.linkFarm "nixpkgs-pkgs-lib-tests" [
  { name = "formats"; path = import ./formats.nix { inherit pkgs; }; }
]
astro commented 2 years ago

very interesting, thank you for reporting.

astro commented 2 years ago

fixed and released in 0.1.2