prunr for VS Code
Dead code in a Node.js project, right in the editor:
- unused files, exports and types;
- unused, undeclared or misplaced dependencies;
- circular imports, and the rest of what prunr finds.
prunr follows CommonJS (require, module.exports) as well as ES modules and TypeScript.
The extension starts prunr lsp, prunr's language server. The analysis, the prunr.json and the
findings are the same as prunr check in the terminal or in CI, so what the editor shows is what
CI fails on.
Getting started
Install prunr in the project:
npm i -D @prunr/prunr # or pnpm add -D / yarn add -D / bun add -d
Create a prunr.json:
npx prunr init
It reads the entries from package.json (main, bin, exports, the scripts), and translates
a Knip config when there is one.
Open the project in VS Code. The extension turns on in a workspace with a prunr.json, at the
root or in a folder one level down.
What you get
Diagnostics.
- prunr checks the project when you open or save a file, and each finding is a squiggle on its
line: the export, the import, or the dependency in
package.json.
- An unused file is reported on its first line.
- Findings the
rules of prunr.json set to warn show as warnings, the others as errors.
- They are all listed in the Problems panel (
Ctrl+Shift+M).
Quick fixes. On a finding, open the light bulb (Ctrl+.):
- Fix with prunr applies what
prunr fix would do for that one finding. It removes the
export or the import, deletes the unused file, or edits package.json.
- Ignore with prunr-ignore-next-line (for an export or a type) and Ignore with
prunr-ignore-file (for a file) add the comment that tells prunr to leave it alone.
Why is it unused? Hover a finding about a file, an export or a dependency to see what
prunr why says: the chain of imports from an entry, who uses an export, or why a package counts
as used.
Configuration
The findings are configured in prunr.json, as for the command line. In it, entries, ignore
and rules set the entries, the ignored files and the severity of each finding. See the
configuration guide.
| Setting |
Default |
What it is |
prunr.path |
"" |
The prunr binary. Empty runs the project's prunr with npx prunr lsp. |
Other editors
prunr lsp works with any editor that has a language server client, such as Neovim and Helix.
See Editors.
Development
npm install
npm test # the server command, with node --test
npx vsce package # builds prunr-<version>.vsix