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

eslint-plugin-local

Package Overview
Dependencies
Maintainers
0
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-local

This ESLint plugin allows you to implement a custom ESLint plugin including custom rules in your repository without installing them as a dependency.

  • 6.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

This ESLint plugin allows you to implement a custom ESLint plugin including custom rules in your repository without installing them as a dependency.

Originally inspired by cletusw/eslint-plugin-local-rules.

Installation

npm install --save-dev eslint-plugin-local

Usage

The JavaScript file named eslint.local.js or eslint-plugin-local.js or .eslint-plugin-local/index.js must be created at the root of your repository, which the file has the content of an ESLint plugin. The extension .cjs can be used in place of .js in case ES module is not supported. For example:

module.exports = {
  rules: {
    sample: {
      // Optional
      meta: {
        // See https://eslint.org/docs/latest/extend/custom-rules#rule-structure
      },

      // Mandatory
      create: function (context) {
        // Implementation goes here
        // See https://eslint.org/docs/latest/extend/custom-rules
      },

      // Optional
      // Unit test can be triggered by `eslint-plugin-local test` command
      // See https://eslint.org/docs/latest/integrate/nodejs-api#ruletester
      tests: {
        valid: [...],
        invalid: [...],
      }
    }
  }
}

Then add the plugin to your eslint.config.js file:

const local = require('eslint-plugin-local')

module.exports = [{
  plugins: {
    local
  },
  rules: {
    'local/sample': 'error'
  }
}]

Additionally, this package provides eslint-plugin-local test command out of the box, which it scans for tests: { valid: [], invalid: [] } field in each rule and runs RuleTester internally.

To make it easy to debug your test cases, wrap one or more test objects inside the global only() function. Given the example below, only the first test case and every invalid case will be run.

module.exports = {
  rules: {
    sample: {
      tests: {
        valid: [
          only({
            code: 'var foo = 1',
          }),
          {
            code: 'var foo = 2',
          }
        ],
        invalid: only([...]),
      }
    }
  }
}

FAQs

Package last updated on 04 Aug 2024

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