unicorn/no-late-event-control
eslint-plugin-unicorn
No autofix
eslint.config.js
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/no-late-event-control": "error",
},
},
];Disallow event-control method calls after the synchronous event dispatch has finished.
element.addEventListener('click', async event => {
await save();
event.preventDefault();
});element.addEventListener('click', event => {
setTimeout(() => {
event.stopPropagation();
});
});element.addEventListener('click', async event => {
event.preventDefault();
await save();
});element.addEventListener('click', event => {
event.stopPropagation();
setTimeout(() => {
update();
});
});function prevent(event) {
event.preventDefault();
}
element.addEventListener('click', event => {
setTimeout(prevent, 1, event);
});Examples from the ESLint documentation.
unicorn/no-late-event-control
eslint-plugin-unicorn
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/no-late-event-control": "error",
},
},
];Oxlint does not have this rule.
nursery/noLateEventControl
nursery · since 2.6.5
{
"linter": {
"rules": {
"nursery": {
"noLateEventControl": "error"
}
}
}
}Disallow accessing event.currentTarget after the synchronous event dispatch has finished.
Disallow using the return value of Array#push() and Array#unshift().
Disallow .map() and .filter() in for…of and for await…of loop headers.
Disallow Array#splice() when simpler alternatives exist.
Disallow confusing uses of Array#{splice,toSpliced}().
Prefer putting the condition in the while statement.