eslint/rules/loops
Loops: for, while, iteration and labels: the right loop for the job, no mutation of what is iterated. Rules of ESLint, typescript-eslint and SonarJS (the Sonar way profile of SonarQube) on this subject, every rule listed; the TypeScript rules apply to TypeScript files only.
24 rules, 14 on. Source: lint/eslint/rules/loops.mjs.
| Rule | Setting | Files | What it checks | Why |
|---|---|---|---|---|
for-direction | error | JS + TS | Enforce for loop update clause moving the counter in the right direction | — |
no-unreachable-loop | error | JS + TS | Disallow loops with a body that allows only one iteration | — |
guard-for-in | warn | JS + TS | Require for-in loops to include an if statement | — |
no-continue | info | JS + TS | Disallow continue statements | — |
no-extra-label | off | JS + TS | Disallow unnecessary labels | Off: labels are forbidden by no-labels. |
no-iterator | error | JS + TS | Disallow the use of the __iterator__ property | — |
no-label-var | off | JS + TS | Disallow labels that share a name with a variable | Off: labels are forbidden by no-labels. |
no-labels | warn | JS + TS | Disallow labeled statements | — |
no-loop-func | warn | JS + TS | Disallow function declarations that contain unsafe references inside loop statements | — |
no-unused-labels | error | JS + TS | Disallow unused labels | — |
sonarjs/too-many-break-or-continue-in-loop | off | JS + TS | Loops should not contain more than a single "break" or "continue" statement | Off: not in the Sonar way profile of SonarQube. |
sonarjs/constructor-for-side-effects | off | JS + TS | Objects should not be created to be dropped immediately without being used | Off: duplicate of no-new. |
sonarjs/function-inside-loop | off | JS + TS | Functions should not be defined inside loops | Off: duplicate of no-loop-func. |
sonarjs/label-position | off | JS + TS | Only "while", "do", "for" and "switch" statements should be labelled | Off: duplicate of no-labels. |
sonarjs/no-labels | off | JS + TS | Labels should not be used | Off: duplicate of no-labels. |
sonarjs/for-in | off | JS + TS | "for...in" loops should filter properties before acting on them | Off: not in the Sonar way profile of SonarQube. |
sonarjs/for-loop-increment-sign | error | JS + TS | A "for" loop update clause should move the counter in the right direction | — |
sonarjs/misplaced-loop-counter | warn | JS + TS | "for" loop increment clauses should modify the loops' counters | — |
sonarjs/no-for-in-iterable | off | JS + TS | "for in" should not be used with iterables | Off: not in the Sonar way profile of SonarQube. |
sonarjs/prefer-while | error | JS + TS | A "while" loop should be used instead of a "for" loop | — |
sonarjs/updated-loop-counter | warn | JS + TS | Loop counters should not be assigned within the loop body | — |
@typescript-eslint/no-for-in-array | error | TS | Disallow iterating over an array with a for-in loop | — |
@typescript-eslint/no-loop-func | off | TS | Disallow function declarations that contain unsafe references inside loop statements | Deprecated: the core rule supports TypeScript. |
@typescript-eslint/prefer-for-of | info | TS | Enforce the use of for-of loop over the standard for loop where possible | — |