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 ruleseslint-plugin-react- React-specific ruleseslint-plugin-vue- Vue.js supporteslint-plugin-import- Import/export validation
Plugin Structure
A plugin is an object with specific properties:Plugin Metadata
Provide metadata for better debugging and caching:Plugin name (should match npm package name)
Plugin version (should match npm package version)
Default namespace for accessing plugin features
Adding Rules
Export rules in therules 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
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 usingRuleTester:
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
eslint.config.js
Legacy Config Support
Support both flat and legacy configs:Linting Your Plugin
Lint plugin code with recommended configs:eslint.config.js
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
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