Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork19
Scan Nix files for dead code
License
astro/deadnix
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Scan.nix files for dead code (unused variable bindings).
nix run github:astro/deadnix -- --helpFind dead code in .nix filesUsage: deadnix [OPTIONS] [FILE_PATHS]...Arguments: [FILE_PATHS]... .nix files, or directories with .nix files inside [default: .]Options: -l, --no-lambda-arg Don't check lambda parameter arguments -L, --no-lambda-pattern-names Don't check lambda attrset pattern names (don't break nixpkgs callPackage) -_, --no-underscore Don't check any bindings that start with a _ -q, --quiet Don't print dead code report -e, --edit Remove unused code and write to source file -h, --hidden Recurse into hidden subdirectories and process hidden .*.nix files --help -f, --fail Exit with 1 if unused code has been found -o, --output-format <OUTPUT_FORMAT> Output format to use [default: human-readable] [possible values: human-readable, json] --exclude <EXCLUDES>... Files to exclude from analysis -V, --version Print version
Reports contain ANSI color escape codes unless the$NO_COLOR environment variable is set.
The--exclude parameter accepts multiple paths. Separate them with-- to pass[FILE_PATHS]....
nix run github:astro/deadnix example.nixWarning: Unused declarations were found. ╭─[example.nix:1:1] 1 │unusedArgs@{ unusedArg, usedArg, ... }: · │ ╰───── Unused lambda pattern: unusedArg · ╰───────────────── Unused lambda pattern: unusedArgs 3 │ inherit (builtins) unused_inherit; · ╰─────── Unused let binding: unused_inherit 5 │ unused = "fnord"; · ╰─── Unused let binding: unused 10 │ shadowed = 42; · ╰──── Unused let binding: shadowed 11 │ _unused = unused: false; · │ ╰─── Unused lambda argument: unused · ╰───────────── Unused let binding: _unused 13 │ x = { unusedArg2, x ? args.y, ... }@args: used1 + x; · ╰───── Unused lambda pattern: unusedArg2
Do commit your changes into version controlbefore!
nix run github:astro/deadnix -- -eq test.nixUsage withpre-commit
Add the following to your project's.pre-commit-config.yaml:
repos: -repo:https://github.com/astro/deadnixrev:ID# frozen: VERSIONhooks: -id:deadnix#args: [--edit] # Uncomment to automatically modify filesstages:[commit]
ReplaceID andVERSION above with the relevant version tag andcommit ID for reference, for example:
rev:da39a3ee5e6b4b0d3255bfef95601890afd80709# frozen: v1.2.3
If you disfavor marking them as unused, use option-l/--no-lambda-arg.
callPackages guesses the packages to inject by the names of apackages' lambda attrset pattern names. Some packages alias these with@args to pass them to anotherimport ...nix args.
As the used args are only named in the imported file they will berecognized as dead in the package source file that is imported bycallPackage, rendering it unable to guess the dependencies to callthe packages with.
Use option-L/--no-lambda-pattern-names in this case.
As of 1.1.0 deadnix supports the following pragma to skip check ofbindings in the following line:
# deadnix: skipPlease open an issue. Do not forget to include the.nix code thatproduces incorrect results.
The author can be hired to implement the features that you wish, or tointegrate this tool into your toolchain.
About
Scan Nix files for dead code
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
Uh oh!
There was an error while loading.Please reload this page.