Package Exports
- no-dead-code
- no-dead-code/dist/index.js
- no-dead-code/dist/index.mjs
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (no-dead-code) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Dead code search tool
Reports unused exports in JS/TS files.
Supports both ES and CommonJS modules out of the box.
Only relative import paths are supported at the moment.
Usage
In a project's root, run:
$ npx no-dead-code
Example output
src/client/util/common.js: Unused exports: colors, CONFIG_NAME
src/client/pages/FeedbackTarget/tabs/Results/QuestionResults/utils.js: Unused exports: countAverage, countStandardDeviation, countMedian
Options
--extensions
(-e
)
Specify which extensions are included.
Default: cjs js ts tsx jsx
--ignore
(-i
)
Specify which paths are ignored.
By default, node_modules
, .git
, dist
, build
, migrations
are always ignored. Values passed to -i
are added to these.
--no-default-ignore
Turn off the default ignores node_modules
, .git
, dist
, build
, migrations
.
Caveats
no-dead-code is far from complete, that's why its "best effort". The goal is to cover most typical coding standards, but it will inevitably output false positives and miss unused exports.
ES modules
Import and export declarations work pretty well. Dynamic imports are considered to import just everything.
CommonJS
Tracking all require-calls and module.exports assignments is a lot of effort, so only typical use cases are covered.
The following are seen by no-dead-code:
module.exports = foo // sees "default" exported.
module.exports = { // "foo" and "bar" are seen exported
foo,
bar,
}
const foo = require('./foo') // everything imported from './foo'
const {
foo,
bar,
} = require('./foo') // "foo" and "bar" imported from './foo'
require('./foo')() // everything imported from './foo'
someFunction(require('./foo')) // everything imported from './foo'
Absolute paths
For absolute paths, the closest parent package.json and js/tsconfig are searched to resolve external dependencies and compilerOptions.baseUrl
.
Path aliases
TODO
Todo
- Formatted & colored output
- Deeper usage search