πPutout plugin adds ability to find and remove useless variables
npm install @putout/plugin-remove-useless-variables[NPMIMGURL]: https://img.shields.io/npm/v/@putout/plugin-remove-useless-variables.svg?style=flat&longCache=true
[NPMURL]: https://npmjs.org/package/@putout/plugin-remove-useless-variables "npm"
πPutout plugin adds ability to find and remove useless variables. Renamed to @putout/plugin-variables.
```
npm i @putout/plugin-remove-useless-variables -D
- β
assignment;
- β
declaration;
- β
destruct;
- β
duplicate;
- β
remove;
- β
rename;
`json`
{
"rules": {
"remove-useless-variables/assignment": "on",
"remove-useless-variables/rename": "on",
"remove-useless-variables/remove": "on",
"remove-useless-variables/destruct": "on",
"remove-useless-variables/declaration": ["on", {
"maxLength": 20
}],
"remove-useless-variables/duplicate": "on"
}
}
Checkout in πPutout Editor.
`js`
while (!(files = readDirectory(parentDir)).length) {}
`js`
while (!readDirectory(parentDir).length) {}
`js`
function hi(a) {
const b = a;
}
`js`
function hi(b) {}
`js`
function hi(c) {
const {a, b} = c;
}
`js`
function hi({a, b}) {}
`js
const child_process = require('node:child_process');
const {exec, spawn} = child_process;
`
`js`
const {exec, spawn} = require('node:child_process');
Check it out in πPutout Editor.
`js
const a = 5;
const b = a;
const c = 5;
d = c;
`
`js
const b = 5;
d = 5;
`
Check it out in πPutout Editor.
`js
function x() {
const a = 5;
return a;
}
const z = b.c.replace('x', 'y');
b.c = z;
`
`js
function x() {
return 5;
}
b.c = b.c.replace('x', 'y');
`
Check it out in πPutout Editor.
`js`
const DestructuringErrors = function DestructuringErrors(a, b) {
return [a, b];
};
`js
function DestructuringErrors(a, b) {
return [a, b];
}
bc = b.c.replace('x', 'y');
``
MIT