unicorn/no-for-loop
eslint-plugin-unicorn
Safe autofix
eslint.config.js
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/no-for-loop": "error",
},
},
];for (let index = 0; index < array.length; index++) {
const element = array[index];
console.log(index, element);
}for (let index = 0; index < array.length; index++) {
const element = array[index];
console.log(element);
}for (const [index, element] of array.entries()) {
console.log(index, element);
}for (const element of array) {
console.log(element);
}Examples from the ESLint documentation.
unicorn/no-for-loop
eslint-plugin-unicorn
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/no-for-loop": "error",
},
},
];Oxlint does not have this rule.
style/useForOf
style · since 1.5.0
{
"linter": {
"rules": {
"style": {
"useForOf": "error"
}
}
}
}Enforce consistent labels on tuple type elements.
Disallow checking a Map key before accessing a different key.
Enforce consistent JSON file reads before JSON.parse().
Disallow simple recursive function calls that can be replaced with a loop.
Enforce consistent naming for boolean names.
Prefer early continues over conditionals wrapping the remainder of the loop body.