Scan Nix files for dead code
Go to file
2021-12-09 17:29:31 +01:00
.github/workflows .github/workflows/checks.yml: split cargo build --release 2021-12-09 17:29:31 +01:00
src add rustfmt, apply suggestions 2021-12-09 15:55:22 +01:00
.gitignore PoC 2021-12-06 00:04:52 +01:00
Cargo.lock main: find .nix files recursively 2021-12-08 19:17:09 +01:00
Cargo.toml main: find .nix files recursively 2021-12-08 19:17:09 +01:00
flake.lock flake.nix: switch from mozillapkgs to fenix 2021-12-09 16:44:31 +01:00
flake.nix flake.nix: switch from mozillapkgs to fenix 2021-12-09 16:44:31 +01:00
LICENSE LICENSE: add 2021-12-06 00:13:14 +01:00
README.md README: to boldly go where no evaluation has gone before 2021-12-08 01:37:23 +01:00
test.nix implement no_lambda_arg+no_underscore options 2021-12-07 22:10:44 +01:00

deadnix

Scan .nix files for dead code (unused variable bindings).

Usage with Nix Flakes

Help

$ nix run github:astro/deadnix -- --help
USAGE:
    deadnix [FLAGS] [FILE_PATHS]...

FLAGS:
    -e, --edit             Remove unused code and write to source file
    -l, --no-lambda-arg    Don't check lambda parameter arguments
    -_, --no-underscore    Don't check any bindings that start with a _
    -q, --quiet            Don't print dead code report
    -h, --help             Prints help information
    -V, --version          Prints version information

ARGS:
    <FILE_PATHS>...    .nix files

Scan for unused code

$ nix run github:astro/deadnix test.nix
test.nix:1:
> unusedArgs@{ unusedArg, usedArg, ... }:
> ^^^^^^^^^^   ^^^^^^^^^
> |            |
> |            Unused lambda pattern: unusedArg
> Unused lambda pattern: unusedArgs
test.nix:3:
>   inherit (builtins) unused_inherit;
>                      ^^^^^^^^^^^^^^
>                      |
>                      Unused let binding: unused_inherit
test.nix:5:
>   unused = "fnord";
>   ^^^^^^
>   |
>   Unused let binding: unused
test.nix:10:
>   shadowed = 42;
>   ^^^^^^^^
>   |
>   Unused let binding: shadowed
test.nix:11:
>   _unused = unused: false;
>   ^^^^^^^   ^^^^^^
>   |         |
>   |         Unused lambda argument: unused
>   Unused let binding: _unused
test.nix:13:
>   x = { unusedArg2, x ? args.y, ... }@args: used1 + x;
>         ^^^^^^^^^^
>         |
>         Unused lambda pattern: unusedArg2

Remove unused code automatically

Do commit your changes into version control before!

$ nix run github:astro/deadnix -- -eq test.nix

What if the produced reports are wrong?

Please open an issue. Do not forget to include the .nix code that produces incorrect results.

Commercial Support

The author can be hired to implement the features that you wish, or to integrate this tool into your toolchain.