dead-code-analyser
v1.0.0
Published
A tool to detect dead code, unused exports, and zombies in your project 🧟
Maintainers
Readme
Dead Code Analyser 🧟
A powerful tool to detect dead code, unused exports, and zombies in your project.
Dead Code Analyser scans your TypeScript/JavaScript codebase to find unused files, exports, and dependencies. It helps you keep your project clean and maintainable by identifying "zombie" code that is no longer being used.
Features
- 💀 Orphan Files: Detects files that are never imported.
- ⚰️ Dead Exports: Identifies exported functions, classes, or variables that are never used in other files.
- 🖼️ Unused Assets: Finds images or other assets that are not referenced in your code.
- 📦 Unused Dependencies: Checks for dependencies in
package.jsonthat are not imported in your code. - 🚀 Fast & Efficient: Uses AST parsing for accurate results.
Installation
You can run it directly using npx or install it globally.
Using npx (Recommended)
npx dead-code-analyser .Global Installation
npm install -g dead-code-analyserUsage
Run the tool in your project root:
dead-code-analyser [directory] [options]Arguments
[directory]: The directory to scan. Defaults to current directory (.).
Options
-i, --ignore <patterns...>: Specify glob patterns to ignore.- Default ignores:
**/node_modules/**,**/dist/**,**/build/**
- Default ignores:
Examples
Scan the current directory:
dead-code-analyser .Scan a specific src directory:
dead-code-analyser ./srcIgnore specific folders (e.g., tests and coverage):
dead-code-analyser . --ignore "**/tests/**" "**/coverage/**"How it Works
- Scanning: The tool scans all files in the specified directory based on extensions (
.js,.ts,.jsx,.tsx). - Parsing: It parses each file to extract imports and exports using Babel parser.
- Graph Building: It builds a dependency graph linking files and their exports.
- Analysis: It traverses the graph to find nodes (files/exports) that have no incoming edges (usages).
Output Explanation
- Orphan Files: Files that exist in your project but are not imported by any other file.
- Dead Exports: Specific named exports (e.g.,
export const foo = ...) that are not imported by any other file. - Unused Assets: Non-code files (images, css, etc.) that are not imported.
- Unused Dependencies: Packages listed in
dependenciesthat are never imported.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
ISC
