unicorn/prefer-continue
eslint-plugin-unicorn
Safe autofix
eslint.config.js
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/prefer-continue": "error",
},
},
];Prefer early continues over conditionals wrapping the remainder of the loop body.
for (const item of items) {
doSomethingBefore();
if (item.isActive) {
process(item);
save(item);
}
}for (const item of items) {
doSomethingBefore();
if (!item.isActive) {
continue;
}
process(item);
save(item);
}for (const item of items) {
if (item.isActive) {
process(item);
}
}for (const item of items) {
if (item.isActive) {
process(item);
save(item);
}
finish(item);
}Examples from the ESLint documentation.
unicorn/prefer-continue
eslint-plugin-unicorn
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/prefer-continue": "error",
},
},
];Oxlint does not have this rule.
nursery/useEarlyContinue
nursery · since 2.6.9
{
"linter": {
"rules": {
"nursery": {
"useEarlyContinue": "error"
}
}
}
}Disallow simple recursive function calls that can be replaced with a loop.
Prefer Iterator.zip() over parallel-array indexing.
Disallow checking a Map key before accessing a different key.
Enforce consistent class references in static methods.
Do not use a for loop that can be replaced with a for-of loop.
Enforce consistent class member order.