Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/steelbrain/babel-plugin-remove-unused-vars
Babel plugin to remove unused variables and imports (Babel autofix for ESLint's no-unused-vars)
https://github.com/steelbrain/babel-plugin-remove-unused-vars
Last synced: 10 days ago
JSON representation
Babel plugin to remove unused variables and imports (Babel autofix for ESLint's no-unused-vars)
- Host: GitHub
- URL: https://github.com/steelbrain/babel-plugin-remove-unused-vars
- Owner: steelbrain
- License: mit
- Created: 2019-05-06T05:17:45.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-07-22T13:57:54.000Z (over 5 years ago)
- Last Synced: 2024-08-09T21:13:50.012Z (3 months ago)
- Language: TypeScript
- Size: 410 KB
- Stars: 18
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
Babel Plugin Remove Unused Vars
-------------------------------Babel plugin to remove unused variables and imports (Babel autofix for ESLint's no-unused-vars).
### Installation
```
npm install --save-dev babel-plugin-remove-unused-vars
```### Usage
```
npx babel --no-babelrc --retain-lines --plugins babel-plugin-remove-unused-vars --out-dir src-2/ src/
```This plugin is intended for source-to-source conversions. You can then replace original source
with output source, and have a quick look over at git diff to see what was changed and revert any
unwanted changes.### Features
Removes
- Unused imports
- Unused function arguments
- Unused results of function calls (ie. requires, or any others.)
- Unused variables (even destructured ones)### Caveats
This plugin is **NOT** perfect. It'll have false-positives and remove used variables or sometimes keep unused variables around. It's highly rare but still something you have to keep in mind, if you experience this behavior please open a bug report with steps to reproduce.
One case that has been intentionally not handled for code simplicity and maintainer sanity is deep assignment expressions, this plugin retains the right side statement if it's an assignment and is used and left side is unused, but if the assignment is somewhere deep inside, it'll treat it as a normal expression and not keep it around if left side is unused.
Explanation by example:
```
const a = b = something();
// ^ If a is unused, output:
b = something();
```
```
const a = something(b = jing());
// ^ If a is unused, output:
// - nothing.
```It's a rare case, and a highly discouraged practice by most linters so support for it will not be added.
### License
This project is licensed under the terms of MIT License. See the LICENSE file for more info.