unicorn/no-duplicate-loops
eslint-plugin-unicorn
No autofix
eslint.config.js
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/no-duplicate-loops": "error",
},
},
];Disallow .map() and .filter() in for…of and for await…of loop headers.
for (const value of values.map(value => value.property)) {
console.log(value);
}for (const value of values.filter(value => value.isEnabled)) {
console.log(value);
}for (const value of values) {
console.log(value.property);
}for (const value of values) {
if (value.isEnabled) {
console.log(value);
}
}Examples from the ESLint documentation.
unicorn/no-duplicate-loops
eslint-plugin-unicorn
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/no-duplicate-loops": "error",
},
},
];Oxlint does not have this rule.
nursery/noEagerArrayMethodsInLoops
nursery · since 2.6.3
{
"linter": {
"rules": {
"nursery": {
"noEagerArrayMethodsInLoops": "error"
}
}
}
}Disallow confusing uses of Array#{splice,toSpliced}().
Disallow accessing event.currentTarget after the synchronous event dispatch has finished.
Prefer putting the condition in the while statement.
Disallow event-control method calls after the synchronous event dispatch has finished.
Prefer the unary minus operator over multiplying or dividing by -1.
Disallow using the return value of Array#push() and Array#unshift().