This package has been deprecated

Author message:

Since the coming of ESLint flat config file, you can specify local rules without the need of this package. For running ESLint rule unit tests, use eslint-rule-tester instead

eslint-plugin-local
TypeScript icon, indicating that this package has built-in type declarations

6.0.0 • Public • Published

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([...]),
      }
    }
  }
}

Readme

Keywords

none

Package Sidebar

Install

npm i eslint-plugin-local

Weekly Downloads

140,039

Version

6.0.0

License

MIT

Unpacked Size

12.6 kB

Total Files

7

Last publish

Collaborators

  • rebasecop