For AI agents: the complete documentation index is available at https://rslint.rs/llms.txt, the full documentation bundle is available at https://rslint.rs/llms-full.txt, and this page is available as Markdown at https://rslint.rs/rules/unicorn/no-invalid-remove-event-listener.md.
close

no-invalid-remove-event-listener

Added in v0.8.2

Configuration

PresetConfigured Value
✅ unicornPlugin.configs.recommended"error"
rslint.config.ts
import { defineConfig, unicornPlugin } from '@rslint/core';

export default defineConfig([
  unicornPlugin.configs.recommended,
  {
    rules: {
      'unicorn/no-invalid-remove-event-listener': 'error',
    },
  },
]);

Rule Details

Prevent calling EventTarget#removeEventListener() with an inline function or the result of an inline .bind() call. removeEventListener() must receive the same function reference that was passed to addEventListener().

Examples of incorrect code for this rule:

window.removeEventListener("click", listener.bind(window));
window.removeEventListener("click", () => {});
window.removeEventListener("click", function () {});

Examples of correct code for this rule:

const listener = () => {};
window.addEventListener("click", listener);
// ...
window.removeEventListener("click", listener);

Original Documentation