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.
npm install eslint-rule-extenderVerified import paths — ran on the pinned version, not inferred.
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.
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`.
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.
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.
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.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.