salts
v1.1.0
Published
Detect unused functions and methods in TypeScript projects
Downloads
183
Maintainers
Readme
Salts
A TypeScript dead code detector that finds unused functions and methods using Babel AST analysis.

Features
- Detects unused functions, methods, and arrow functions
- Handles alias resolution (variable assignments, imports, exports)
- Supports JSX callback detection
- Optional React function component detection (
--jsx-components) - Tracks transitive usage through assignment chains
- Configurable export handling
Installation
npm install saltsFrom Source
npm install
npm run buildUsage
# Analyze a directory
npx salts ./src
# Include exported functions in the report
npx salts ./src --include-exports
# Count React component usage as function usage
npx salts ./src --jsx-components
# Ignore additional patterns
npx salts ./src --ignore "**/*.test.ts" --ignore "**/fixtures/**"Options
| Option | Description |
|--------|-------------|
| --include-exports | Include exported functions in dead code report (by default, exports are considered "used") |
| --jsx-components | Count JSX component usage (e.g., <MyComponent />) as function usage |
| --ignore <patterns> | Additional glob patterns to exclude from analysis |
How It Works
What's Detected as a Function Declaration
- Named functions:
function foo() {} - Class methods:
class X { method() {} } - Arrow functions:
const foo = () => {} - Function expressions:
const foo = function() {}
What Counts as Usage
A function is considered "used" if it is:
- Called directly:
myFunc() - Called as a method:
obj.myFunc(),this.myFunc(),obj['myFunc']() - Passed as a callback:
arr.map(myFunc) - Used in JSX:
<Button onClick={myFunc} /> - Assigned and the assignment is used:
const x = myFunc; x() - Imported with alias:
import { func as alias }wherealiasis used - Exported with alias:
export { func as alias }wherealiasis used - Used as a JSX component:
<MyComponent />(requires--jsx-componentsflag)
Alias Resolution
Assignment chains are followed transitively:
const x = myFunc;
const y = x;
y(); // myFunc is marked as usedDefault Ignored Patterns
**/node_modules/****/dist/****/build/****/*.d.ts**/.git/**
Development
# Build the project
npm run build
# Watch mode
npm run dev
# Run tests
npm test
# Run tests with coverage
npm run test:coverageLicense
MIT
