6.0.0 • Published 10 months ago

eslint-plugin-local v6.0.0

Weekly downloads
26,167
License
MIT
Repository
github
Last release
10 months ago

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

10 months ago

5.0.1

12 months ago

5.0.0

12 months ago

4.2.2

1 year ago

4.2.1

1 year ago

4.2.0

1 year ago

4.1.0

1 year ago

4.1.1

1 year ago

4.0.0

1 year ago

3.2.1

1 year ago

3.1.3

1 year ago

3.1.2

1 year ago

3.2.0

1 year ago

3.1.6

1 year ago

3.1.5

1 year ago

3.1.4

1 year ago

3.1.1

1 year ago

3.1.0

1 year ago

3.0.1

1 year ago

3.0.0

1 year ago

2.0.0

1 year ago

1.0.0

8 years ago