Skip to content

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.

RuleSettingFilesWhat it checksWhy
for-directionerrorJS + TSEnforce for loop update clause moving the counter in the right direction—
no-unreachable-looperrorJS + TSDisallow loops with a body that allows only one iteration—
guard-for-inwarnJS + TSRequire for-in loops to include an if statement—
no-continueinfoJS + TSDisallow continue statements—
no-extra-labeloffJS + TSDisallow unnecessary labelsOff: labels are forbidden by no-labels.
no-iteratorerrorJS + TSDisallow the use of the __iterator__ property—
no-label-varoffJS + TSDisallow labels that share a name with a variableOff: labels are forbidden by no-labels.
no-labelswarnJS + TSDisallow labeled statements—
no-loop-funcwarnJS + TSDisallow function declarations that contain unsafe references inside loop statements—
no-unused-labelserrorJS + TSDisallow unused labels—
sonarjs/too-many-break-or-continue-in-loopoffJS + TSLoops should not contain more than a single "break" or "continue" statementOff: not in the Sonar way profile of SonarQube.
sonarjs/constructor-for-side-effectsoffJS + TSObjects should not be created to be dropped immediately without being usedOff: duplicate of no-new.
sonarjs/function-inside-loopoffJS + TSFunctions should not be defined inside loopsOff: duplicate of no-loop-func.
sonarjs/label-positionoffJS + TSOnly "while", "do", "for" and "switch" statements should be labelledOff: duplicate of no-labels.
sonarjs/no-labelsoffJS + TSLabels should not be usedOff: duplicate of no-labels.
sonarjs/for-inoffJS + TS"for...in" loops should filter properties before acting on themOff: not in the Sonar way profile of SonarQube.
sonarjs/for-loop-increment-signerrorJS + TSA "for" loop update clause should move the counter in the right direction—
sonarjs/misplaced-loop-counterwarnJS + TS"for" loop increment clauses should modify the loops' counters—
sonarjs/no-for-in-iterableoffJS + TS"for in" should not be used with iterablesOff: not in the Sonar way profile of SonarQube.
sonarjs/prefer-whileerrorJS + TSA "while" loop should be used instead of a "for" loop—
sonarjs/updated-loop-counterwarnJS + TSLoop counters should not be assigned within the loop body—
@typescript-eslint/no-for-in-arrayerrorTSDisallow iterating over an array with a for-in loop—
@typescript-eslint/no-loop-funcoffTSDisallow function declarations that contain unsafe references inside loop statementsDeprecated: the core rule supports TypeScript.
@typescript-eslint/prefer-for-ofinfoTSEnforce the use of for-of loop over the standard for loop where possible—

Generated from the JSDoc of the sources.