{"id":19818,"library":"eslint-plugin-listeners","title":"eslint-plugin-listeners","description":"ESLint plugin that provides rules to prevent memory leaks caused by event listeners that are not removed. Current stable version is 1.5.1, with infrequent releases. It checks for missing removeEventListener calls, mismatched add/remove listener functions, and inline function listeners. Unlike generic linting approaches, this plugin is purpose-built for event listener hygiene in JavaScript/TypeScript projects.","status":"active","version":"1.5.1","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/foad/eslint-plugin-listeners","tags":["javascript","eslint","eslint-plugin","eslintplugin","event","listeners","event-listeners"],"install":[{"cmd":"npm install eslint-plugin-listeners","lang":"bash","label":"npm"},{"cmd":"yarn add eslint-plugin-listeners","lang":"bash","label":"yarn"},{"cmd":"pnpm add eslint-plugin-listeners","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"In ESLint config, prefix the rule name with 'listeners/' not 'eslint-plugin-listeners/'.","wrong":"{\n  \"rules\": {\n    \"eslint-plugin-listeners/no-missing-remove-event-listener\": \"error\"\n  }\n}","symbol":"no-missing-remove-event-listener","correct":"{\n  \"rules\": {\n    \"listeners/no-missing-remove-event-listener\": \"error\"\n  }\n}"},{"note":"When using the plugin, rules must be prefixed with 'listeners/'.","wrong":"{\n  \"rules\": {\n    \"matching-remove-event-listener\": \"error\"\n  }\n}","symbol":"matching-remove-event-listener","correct":"{\n  \"rules\": {\n    \"listeners/matching-remove-event-listener\": \"error\"\n  }\n}"},{"note":"Must include the 'plugin:' prefix when extending a config from an ESLint plugin.","wrong":"{\n  \"extends\": [\"listeners/recommended\"]\n}","symbol":"plugin:listeners/recommended","correct":"{\n  \"extends\": [\"plugin:listeners/recommended\"]\n}"}],"quickstart":{"code":"// Install:\n// npm install --save-dev eslint eslint-plugin-listeners\n\n// .eslintrc.json:\n{\n  \"plugins\": [\"listeners\"],\n  \"extends\": [\"plugin:listeners/recommended\"],\n  \"rules\": {\n    \"listeners/no-inline-function-event-listener\": \"error\"\n  }\n}\n\n// Example code that flags:\ndocument.addEventListener('click', function() { // inline function\n  console.log('clicked');\n});","lang":"javascript","description":"Quickstart showing installation, configuration, and a rule violation detection using the plugin."},"warnings":[{"fix":"Ensure addEventListener and removeEventListener calls are in the same function scope or use proper references.","message":"Rule 'no-missing-remove-event-listener' requires add and remove functions to be called within the same scope. Cross-scope patterns (e.g., storing listener reference) may be missed.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use the 'removeAllListeners' option in rule configuration to include removeAllListeners calls.","message":"The plugin does not detect removals via removeAllListeners by default. Ensure to configure custom remove functions if using removeAllListeners.","severity":"gotcha","affected_versions":">=1.5.0"},{"fix":"Upgrade to >=1.4.0 for proper TypeScript support.","message":"Version 1.4.0 introduced TypeScript support via TSESLint. If using an older version, TypeScript AST may not be fully supported.","severity":"gotcha","affected_versions":"<1.4.0"},{"fix":"Use static function references whenever possible; manually review dynamic cases.","message":"The plugin relies on ESLint's AST analysis and may not catch all dynamic listener additions/removals (e.g., using variables for function references).","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run `npm install --save-dev eslint-plugin-listeners` in the project directory.","cause":"The plugin is not installed or is installed globally while ESLint is local (or vice versa).","error":"Error: Failed to load plugin 'listeners' declared in '.eslintrc.json': Cannot find module 'eslint-plugin-listeners'"},{"fix":"Check rule configuration in .eslintrc; ensure it's an object with severity string (e.g., 'error') or array with options.","cause":"Rule configuration missing required options or using an unsupported format.","error":"TypeError: Cannot read property 'map' of undefined (eslint-plugin-listeners)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}