1.0.1 • Published 4 years ago

eslint-plugin-easy-loops v1.0.1

Weekly downloads
21
License
MIT
Repository
github
Last release
4 years ago

eslint-plugin-easy-loops

CI npm

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

You don't need them.

But, OTOH, sometimes you don't need the syntactic noise of a .forEach;

This is essentially a more lenient version of no-loops