Skip to main content

Creating Plugins

Plugins are the primary way to extend ESLint with custom functionality. A plugin can bundle rules, processors, parsers, and configurations into a single, reusable package.

What is a Plugin?

An ESLint plugin is a JavaScript object that exports:
  • Rules - Custom linting rules
  • Processors - Transform non-JavaScript files
  • Configs - Shareable configurations
  • Parsers - Custom syntax support
Popular Plugins:
  • @typescript-eslint/eslint-plugin - TypeScript rules
  • eslint-plugin-react - React-specific rules
  • eslint-plugin-vue - Vue.js support
  • eslint-plugin-import - Import/export validation

Plugin Structure

A plugin is an object with specific properties:

Plugin Metadata

Provide metadata for better debugging and caching:
meta.name
string
required
Plugin name (should match npm package name)
meta.version
string
required
Plugin version (should match npm package version)
meta.namespace
string
required
Default namespace for accessing plugin features
Read metadata from package.json:

Adding Rules

Export rules in the rules object:
Rule ID Naming: Rule IDs should not contain / characters. Use kebab-case: no-foo, enforce-pattern.

Using Plugin Rules

eslint.config.js

Adding Processors

Export processors for non-JavaScript files:

Using Plugin Processors

eslint.config.js

Adding Configurations

Bundle recommended configurations:
Config Format: Configs should be arrays of configuration objects (flat config format). You can also export a single object if there’s only one configuration.

Using Plugin Configs

eslint.config.js

Complete Plugin Example

Here’s a full plugin with rules, configs, and metadata:
index.js

Plugin Naming Conventions

Follow these naming conventions for better discoverability:Unscoped packages:
  • Start with eslint-plugin-
  • Example: eslint-plugin-myproject
Scoped packages:
  • Format: @scope/eslint-plugin or @scope/eslint-plugin-name
  • Examples: @company/eslint-plugin, @company/eslint-plugin-custom

Project Structure

Organize your plugin project:

Organizing Rules

lib/rules/no-foo.js
index.js

Creating Your Plugin

1

Initialize Project

2

Install Dependencies

3

Create Plugin File

index.js
4

Add Rules

Create rules following the custom rules guide.
5

Test Locally

Link plugin for local testing:
In test project:

Testing Plugins

Test rules using RuleTester:
tests/rules/no-foo.test.js

Integration Tests

Test the complete plugin:
tests/plugin.test.js

Publishing Your Plugin

1

Update package.json

package.json
2

Add README

Document:
  • Installation instructions
  • Available rules
  • Configuration examples
  • Rule options
3

Publish to npm

4

Install in Projects

Configure:
eslint.config.js

Legacy Config Support

Support both flat and legacy configs:

Linting Your Plugin

Lint plugin code with recommended configs:
eslint.config.js
Recommended Linting:
  • eslint - Core linting
  • eslint-plugin-eslint-plugin - Plugin-specific rules
  • eslint-plugin-n - Node.js best practices

Distribution Checklist

1

Documentation

  • Comprehensive README
  • Rule documentation with examples
  • Configuration examples
  • Migration guide (if applicable)
2

Testing

  • Unit tests for all rules
  • Integration tests
  • Test edge cases
  • CI/CD setup
3

Metadata

  • Correct peer dependencies
  • Appropriate keywords
  • License file
  • Changelog
4

Quality

  • Lint your plugin code
  • Format consistently
  • Document all options
  • Provide TypeScript types (if applicable)

Best Practices

Follow these guidelines:
  1. Use clear rule names - Descriptive, kebab-case IDs
  2. Provide good error messages - Help users understand issues
  3. Document thoroughly - Examples for valid/invalid code
  4. Test comprehensively - Cover edge cases
  5. Version carefully - Follow semver strictly
  6. Maintain backwards compatibility - Deprecate before removing

Rule Documentation Template

Real-World Examples

@typescript-eslint/eslint-plugin

Comprehensive TypeScript plugin

eslint-plugin-react

React-specific rules and configs

eslint-plugin-vue

Vue.js plugin with processor

eslint-plugin-import

Import/export validation

Next Steps

Custom Rules

Learn to create powerful rules

Custom Processors

Add processor support

Shareable Configs

Create standalone config packages