eslint-plugin-easy-loops
v1.0.1eslint-plugin-easy-loops
Use this plugin if you'd like to restrict the use of loops to simple, single-expression loop bodies
👎 Bad
for (let i = 0, i < 10, i++) {
doSomething(i);
console.log('i is', i);
otherArr.push(i);
}
for (const child of this.children) {
const name = child.name;
const value = child.value;
elements.push({ name, value });
}
👍 Good
for (const child of this.children)
this.registerOnChild(child);
while (node !== document.body)
leaveBreadCrumb(node)
Installation
npm install --save-dev eslint-plugin-easy-loops
Usage
In your .eslintrc
:
{
"plugins": [
"easy-loops"
],
"rules": {
"easy-loops/easy-loops": "warn"
}
}
Rule
Disallow use of for
and do while
loops, Restrict use of loops for-in
, while
, and for-of
loops to simple, single-expression loop bodies.
Why
But, OTOH, sometimes you don't need the syntactic noise of a .forEach
;
This is essentially a more lenient version of no-loops
npm i eslint-plugin-easy-loops
Metadata
- MIT
- Whatever
- Benny Powers
- released 9/27/2020