@putout/plugin-remove-useless-conditions

3.0.1 • Public • Published

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

The if statement executes a statement if a specified condition is truthy. If the condition is falsy, another statement can be executed.

(c) MDN

🐊Putout plugin adds ability to remove useless conditions. Merged to @putout/plugin-conditions.

Install

npm i @putout/plugin-remove-useless-conditions

Rule

{
    "rules": {
        "remove-useless-conditions/evaluate": "on",
        "remove-useless-conditions/simplify": "on"
    }
}

Evaluate

Example of incorrect code

const a = [];
const c = a;

if (a) {
    console.log(a);
}

Example of correct code

const a = [];
const c = a;

console.log(a);

Simplify

Example of incorrect code

if (zone?.tooltipCallback) {
    zone.tooltipCallback(e);
}

if (a)
    alert('hello');
else
    alert('hello');

Example of correct code

zone?.tooltipCallback(e);

alert('hello');

License

MIT

Dependencies (0)

    Dev Dependencies (5)

    Package Sidebar

    Install

    npm i @putout/plugin-remove-useless-conditions

    Weekly Downloads

    10,351

    Version

    3.0.1

    License

    MIT

    Unpacked Size

    4.87 kB

    Total Files

    6

    Last publish

    Collaborators

    • coderaiser