{"id":14562,"library":"eslint-rule-extender","title":"ESLint Rule Extender Utility","description":"eslint-rule-extender is a utility library designed to facilitate the extension and modification of existing ESLint rules without needing to rewrite them entirely. It provides a programmatic API to override aspects of an `ESLintRule` object, allowing developers to customize `meta` properties, add new AST visitors, or modify the reporting behavior of a rule. This can be particularly useful for creating highly specific linting rules based on established ones, or for adapting third-party rules to fit unique project requirements. As of version 0.0.1, it focuses on core functionality, offering a lean approach to rule customization. Its release cadence is not explicitly defined, but as a utility, updates would likely follow ESLint API changes or community-driven feature requests. A key differentiator is its focus on *extending* rather than *composing* rules, providing granular control over specific aspects.","status":"active","version":"0.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/kaicataldo/eslint-rule-extender","tags":["javascript","eslint","custom","rule","rules","plugin","plugins"],"install":[{"cmd":"npm install eslint-rule-extender","lang":"bash","label":"npm"},{"cmd":"yarn add eslint-rule-extender","lang":"bash","label":"yarn"},{"cmd":"pnpm add eslint-rule-extender","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency for any ESLint utility, as it operates on ESLint rule objects and context.","package":"eslint","optional":false}],"imports":[{"note":"Primary CommonJS import pattern. Given the 0.0.1 version, CommonJS is the expected module system.","symbol":"ruleExtender","correct":"const ruleExtender = require('eslint-rule-extender');"},{"note":"ESM import for `ruleExtender`. The package at 0.0.1 likely doesn't have explicit ESM exports, so this might require bundler configuration or be unsupported. It's a default export.","wrong":"import { ruleExtender } from 'eslint-rule-extender';","symbol":"ruleExtender","correct":"import ruleExtender from 'eslint-rule-extender';"}],"quickstart":{"code":"const ruleExtender = require('eslint-rule-extender');\nconst { originalRule } = require('eslint-plugin-example'); // Replace with a real ESLint rule import\n\n// Example: Define a placeholder originalRule for demonstration\nconst mockOriginalRule = {\n  meta: {\n    type: 'problem',\n    docs: {\n      description: 'Disallow direct use of ThisExpression (mock)',\n      category: 'Possible Problems',\n      recommended: true\n    },\n    schema: [],\n    messages: {\n      defaultMessage: 'Avoid ThisExpression.'\n    }\n  },\n  create(context) {\n    return {\n      ThisExpression(node) {\n        context.report({\n          node,\n          messageId: 'defaultMessage'\n        });\n      }\n    };\n  }\n};\n\n// In a real scenario, you'd import an actual rule, e.g., from 'eslint/lib/rules/no-console'\n// const originalRule = require('eslint/lib/rules/no-console');\n\nconst extendedRule = ruleExtender(mockOriginalRule, {\n  metaOverrides: {\n    type: 'suggestion',\n    fixable: false,\n    messages: {\n        anAdditionalSuggestion: 'Arrow functions are fine here!',\n        ...mockOriginalRule.meta.messages\n    }\n  },\n  createAdditionalVisitors(context) {\n    return {\n      ArrowFunctionExpression(node) {\n        context.report({ node, messageId: 'anAdditionalSuggestion' });\n      }\n    };\n  },\n  reportOverrides(meta) {\n    // Only report if the node type is NOT 'ThisExpression'\n    return meta.node.type !== 'ThisExpression';\n  }\n});\n\n// To use this extended rule, you would typically export it from an ESLint plugin:\n// module.exports = {\n//   rules: {\n//     'my-extended-rule': extendedRule\n//   }\n// };\n\nconsole.log('Extended Rule Meta:', extendedRule.meta);\n// Simulate a rule execution for demonstration (not how ESLint actually runs it)\n// In a real ESLint setup, this rule would be applied to source code.\n// For now, we just show it's configured.\n","lang":"javascript","description":"This example demonstrates how to use `eslint-rule-extender` to customize an existing rule by overriding its `meta` properties, adding new visitor callbacks, and conditionally suppressing reports."},"warnings":[{"fix":"Review the package's GitHub repository for the latest status and any new releases before integrating into production systems. Pin the exact version in `package.json`.","message":"The package is at version 0.0.1, indicating early development. API stability is not guaranteed, and future versions may introduce breaking changes without a major version bump.","severity":"gotcha","affected_versions":"0.0.1"},{"fix":"If using in an ESM-only Node.js project, test `import ruleExtender from 'eslint-rule-extender';` thoroughly. You might need to add `\"type\": \"module\"` to your `package.json` or consult the package's repository for ESM support plans.","message":"The README examples use `require()`, suggesting primary support for CommonJS. While bundlers might handle ESM `import` statements, direct Node.js ESM environments might require explicit configuration or may not be supported at this early version.","severity":"gotcha","affected_versions":"0.0.1"},{"fix":"Use the spread operator (`...originalRule.meta.messages`) when defining `metaOverrides.messages` to ensure all original message IDs are available alongside new ones, or explicitly define all required messages.","message":"When overriding `meta` properties, ensure that the original rule's messages are preserved or correctly merged if you intend to still use them. The `metaOverrides` will fully replace properties, so careful merging is necessary for objects like `messages`.","severity":"gotcha","affected_versions":"0.0.1"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Replace `require('eslint-plugin-example')` with an actual ESLint rule import, for example, `require('eslint/lib/rules/no-debugger')` for a built-in rule, or the path to a rule from an installed plugin.","cause":"The quickstart example uses `eslint-plugin-example` as a placeholder for an original rule. This plugin does not actually exist on npm.","error":"Error: Cannot find module 'eslint-plugin-example'"},{"fix":"Ensure that `originalRule` is correctly imported and is a valid ESLint rule object with at least a `meta` property, or that the path to the rule is correct.","cause":"The `originalRule` passed to `ruleExtender` is undefined or not a valid ESLint rule object, which typically has a `meta` property.","error":"TypeError: Cannot read properties of undefined (reading 'meta')"}],"ecosystem":"npm"}