Extension modules that add custom rules and configurations to ESLint
Core Idea: ESLint plugins are packages that extend ESLint's core functionality with additional rules, configurations, processors, and environments tailored to specific frameworks, libraries, or coding patterns.
Key Elements
-
Key Functions:
- Add specialized linting rules beyond ESLint core
- Provide framework-specific code analysis
- Enable linting for non-JavaScript files
- Add shareable configurations for specific technologies
- Create custom environments with global variables
-
Plugin Components:
- Rules: Custom linting rules specific to the plugin's focus
- Configs: Shareable configurations that can be extended
- Processors: Tools to extract JavaScript from other file types
- Environments: Predefined global variables for specific contexts
- Utils: Helper functions for rule implementations
-
Popular Plugins:
eslint-plugin-react
: React-specific rules and best practiceseslint-plugin-jsx-a11y
: Accessibility checks for JSX@typescript-eslint/eslint-plugin
: TypeScript-specific ruleseslint-plugin-import
: Rules for proper import/export syntaxeslint-plugin-prettier
: Prettier integrationeslint-plugin-vue
: Vue.js-specific ruleseslint-plugin-jest
: Testing-specific rules for Jest
-
Implementation Example:
// In .eslintrc.js module.exports = { plugins: [ 'react', 'jsx-a11y', '@typescript-eslint', 'import' ], extends: [ 'plugin:react/recommended', 'plugin:jsx-a11y/recommended', 'plugin:@typescript-eslint/recommended', 'plugin:import/errors', 'plugin:import/typescript' ], rules: { // Override specific plugin rules 'react/jsx-filename-extension': ['error', { extensions: ['.tsx'] }], 'import/order': ['error', { groups: ['builtin', 'external', 'internal'], 'newlines-between': 'always' }] } };
- **Creating Custom Plugins**:
- Plugins follow a naming convention: `eslint-plugin-{name}`
- Can be published to npm or used locally
- Must export an object with rules and/or configurations
- Can implement custom AST traversal logic
- Should include documentation and tests
## Connections
- **Related Concepts**: ESLint (the base tool), ESLint Rules (components of plugins), ESLint Configurations (often provided by plugins)
- **Broader Context**: Static Code Analysis (ecosystem of code analysis tools)
- **Applications**: Framework-Specific Linting (specialized rules for frameworks)
- **Components**: Abstract Syntax Tree (AST) (foundation for rule implementation)
## References
1. ESLint Plugins Documentation: https://eslint.org/docs/latest/extend/plugins
2. "Creating Custom ESLint Plugins" by Nicholas C. Zakas
3. "ESLint Plugin Development Guide" by ESLint Team
#eslint #javascript #typescript #plugins #code-quality #static-analysis
---
**Connections:**
-
---
**Sources:**
- From: Syntax - Lint como un desarrollador senior con eslint + husky + lint staged + acciones de github