Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@putout/plugin-remove-useless-variables

coderaiser44.2kMIT12.6.1

🐊Putout plugin adds ability to find and remove useless

putout, putout-plugin, putout-plugin-remove, plugin, remove, useless, variables, for-of

readme

@putout/plugin-remove-useless-variables NPM version

🐊Putout plugin adds ability to find and remove useless variables.

Install

npm i @putout/plugin-remove-useless-variables -D

Rules

Config

{
    "rules": {
        "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"
    }
}

rename

❌ Example of incorrect code

function hi(a) {
    const b = a;
}

✅ Example of correct code

function hi(b) {}

destruct

❌ Example of incorrect code

function hi(c) {
    const {a, b} = c;
}

✅ Example of correct code

function hi({a, b}) {}

remove

❌ Example of incorrect code

const child_process = require('node:child_process');

const {exec, spawn} = child_process;

✅ Example of correct code

const {exec, spawn} = require('node:child_process');

remove

Check it out in 🐊Putout Editor.

❌ Example of incorrect code

const a = 5;
const b = a;

const c = 5;

d = c;

✅ Example of correct code

const b = 5;

d = 5;

declaration

Check it out in 🐊Putout Editor.

❌ Example of incorrect code

function x() {
    const a = 5;
    return a;
}

const z = b.c.replace('x', 'y');

b.c = z;

✅ Example of correct code

function x() {
    return 5;
}

b.c = b.c.replace('x', 'y');

duplicate

Check it out in 🐊Putout Editor.

❌ Example of incorrect code

const DestructuringErrors = function DestructuringErrors(a, b) {
    return [a, b];
};

✅ Example of correct code

function DestructuringErrors(a, b) {
    return [a, b];
}

bc = b.c.replace('x', 'y');

License

MIT