@putout/plugin-apply-early-return

3.0.0 • Public • Published

@putout/plugin-apply-early-return NPM version

In short, an early return provides functionality so the result of a conditional statement can be returned as soon as a result is available, rather than wait until the rest of the function is run.

(c) dev.to

🐊Putout plugin adds ability to apply early return.

Install

npm i @putout/plugin-apply-early-return

Rule

{
    "rules": {
        "apply-early-return": "on"
    }
}

Example of incorrect code

function get(a) {
    let b = 0;
    
    if (a > 0)
        b = 5;
    else
        b = 7;
    
    return b;
}

Example of correct code

function get(a) {
    if (a > 0)
        return 5;
    
    return 7;
}

License

MIT

Package Sidebar

Install

npm i @putout/plugin-apply-early-return

Weekly Downloads

4,029

Version

3.0.0

License

MIT

Unpacked Size

4.29 kB

Total Files

4

Last publish

Collaborators

  • coderaiser