README
@putout/plugin-remove-useless-variables
🐊Putout
plugin adds ability to find and remove useless variables
.
Install
npm i @putout/plugin-remove-useless-variables -D
Rule
{
"rules": {
"remove-useless-variables/rename": "on",
"remove-useless-variables/destruct": "on",
"remove-useless-variables/remove": "on",
"remove-useless-variables/await": "on",
"remove-useless-variables/for-of": ["on", {
"maxProperties": 4
}]
}
}
Rename
❌ Incorrect code example
function hi(a) {
const b = a;
}
✅ Correct code Example
function hi(b) {
}
Destruct
❌ Incorrect code example
function hi(c) {
const {a, b} = c;
}
✅ Correct code Example
function hi({a, b}) {
}
Remove
❌ Incorrect code example
const child_process = require('child_process');
const {
exec,
spawn,
} = child_process;
✅ Correct code Example
const {
exec,
spawn,
} = require('child_process');
await
❌ Incorrect code example
async () => {
const result = transformer.transform(
realTransformer,
transformCode,
code,
parser,
);
const result2 = await Promise.resolve(result);
return result2;
};
✅ Correct code Example
async () => {
const result = transformer.transform(
realTransformer,
transformCode,
code,
parser,
);
return result;
};
For-of
❌ Incorrect code example
for (const a of b) {
const {c} = a;
}
✅ Correct code Example
for (const {c} of b) {
}
License
MIT