astro / deadnix

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

unused args are not detected #24

Closed Artturin closed 2 years ago

Artturin commented 2 years ago

examples from https://github.com/NixOS/nixpkgs/pull/166605 ./pkgs/applications/blockchains/bisq-desktop/default.nix ./pkgs/applications/audio/caudec/default.nix

gnutar was removed from bisq and bash from caudec

$ deadnix ./pkgs/applications/blockchains/bisq-desktop/default.nix
<no output>
$ deadnix ./pkgs/applications/audio/caudec/default.nix
<no output>
astro commented 2 years ago

The corresponding attrset lambda patterns don't have an ellipsis ({ ... }:). Deleting those identifiers changes code semantically, for example when used with eg. callPackage. That's just an explanation why I chose to ignore them if the ellipsis is missing. This might need some more thought...

On the other hand there is already --no-lambda-pattern-names so we could start ignoring the ellipsis altogether.

astro commented 2 years ago

@supersandro2000 proposes that we should ignore attrset destructuring in absence of ... when there is an { }@args alias

astro commented 2 years ago

@Artturin Do you have an opinion ignoring only when there's an @alias to the lambda arg? That would replace the current check for ....

So far deadnix does what's intuitive for the language. I agree that we need to acknowledge the callPackage practise in nixpkgs as it is very common.

astro commented 2 years ago

@Artturin I have changed the behaviour to check all lambda attrset args. Could you please evaluate deadnix' main branch, checking that it won't generate too many false positives?

SuperSandro2000 commented 2 years ago

I used it a couple of times in the last days and so far did not encounter any bugs. Maybe some more complex situations could be buggy but we can only test that if more people would use it.

Artturin commented 2 years ago

i've been using it in my editor with https://github.com/jose-elias-alvarez/null-ls.nvim/blob/main/doc/BUILTINS.md#deadnix for ~3 days now and it has worked well