@putout/plugin-apply-early-return
Version:
πPutout plugin adds ability use apply early return
57 lines (40 loc) β’ 1.17 kB
Markdown
# @putout/plugin-apply-early-return [![NPM version][NPMIMGURL]][NPMURL]
[NPMIMGURL]: https://img.shields.io/npm/v/@putout/plugin-apply-early-return.svg?style=flat&longCache=true
[NPMURL]: https://npmjs.org/package/@putout/plugin-apply-early-return"npm"
> 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. Merged with [`@putout/plugin-return`](https://www.npmjs.com/package/@putout/plugin-return).
>
> (c) [dev.to](https://dev.to/jenniferlynparsons/early-returns-in-javascript-5hfb)
π[**Putout**](https://github.com/coderaiser/putout) plugin adds ability to apply **early return**.
## Install
```
npm i @putout/plugin-apply-early-return
```
## Rule
```json
{
"rules": {
"apply-early-return": "on"
}
}
```
## β Example of incorrect code
```js
function get(a) {
let b = 0;
if (a > 0)
b = 5;
else
b = 7;
return b;
}
```
## β
Example of correct code
```js
function get(a) {
if (a > 0)
return 5;
return 7;
}
```
## License
MIT