Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

eslint-rule-extender

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-rule-extender

Utility to extend existing ESLint rules

  • 0.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

eslint-rule-extender

npm node

A utility to extend existing ESLint rules.

Installation

npm install eslint-rule-extender

or

yarn add eslint-rule-extender

Usage

The default export is a function that takes two arguments and returns the modified rule.

API

ruleExtender(originalRule: ESLintRule, options: Object) => ESLintRule;
  • originalRule - The original rule to extend
  • options - An object with the desired overrides (options can be viewed below)

Example Usage

const ruleExtender = require('eslint-rule-extender');
const { originalRule } = require('eslint-plugin-example');

const extendedRule = ruleExtender(originalRule, options);

module.exports = {
  extendedRule,
};

Options

metaOverrides

Overrides for the original rule's meta property. The properties of the meta object can be found here.Options

const extendedRule = ruleExtender(originalRule, {
  metaOverrides: {
    type: 'suggestion',
    fixable: false,
  },
});

createAdditionalVisitors

A function that has the same signature as ESLint rules' create method. It is passed the context object and should return a object of visitor callbacks. See the official ESLint docs for more details!

Example Usage

const extendedRule = ruleExtender(originalRule, {
  createAdditionalVisitors(context) {
    return {
      ArrowFunctionExpression(node) {
        context.report({ node, messageId: 'anAdditionalSuggestion' });
      },
    };
  },
});

reportOverrides

A function that is called with the report metadata of the original rule's context.report() calls. The return value of this function is a trinary with the following behavior:

  • true: report with original metadata (unchanged)
  • false: do not report
  • modified report metadata object: report with this metadata instead

Example Usage

const extendedRule = ruleExtender(originalRule, {
  reportOverrides(meta) {
    return meta.node.type !== 'ThisExpression';
  },
});

Putting It All Together

const ruleExtender = require('eslint-rule-extender');
const { originalRule } = require('eslint-plugin-example');

const extendedRule = ruleExtender(originalRule, {
  metaOverrides: {
    type: 'suggestion',
    fixable: false,
  },
  createAdditionalVisitors(context) {
    return {
      ArrowFunctionExpression(node) {
        context.report({ node, messageId: 'anAdditionalSuggestion' });
      },
    };
  },
  reportOverrides(meta) {
    return meta.node.type !== 'ThisExpression';
  },
});

module.exports = {
  extendedRule,
};

Prior art

Keywords

FAQs

Package last updated on 16 Oct 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc