Custom Processors
Processors enable ESLint to extract and lint JavaScript from non-JavaScript files. They’re perfect for Markdown code blocks, HTML script tags, or framework-specific file formats.When to Use Processors
Create a processor when you need to:- Lint JavaScript in Markdown code blocks
- Extract scripts from HTML files
- Process framework-specific files (Vue, Svelte)
- Handle template languages
- Transform files before linting
Popular Processors:
@eslint/markdown- Lint JavaScript in Markdowneslint-plugin-vue- Vue single-file componentseslint-plugin-html- HTML script tags
Processor Structure
A processor is an object withpreprocess() and postprocess() methods:
Processor Methods
Extracts JavaScript code blocks from the fileParameters:
text(string): File contentsfilename(string): File path
text(string): JavaScript code to lintfilename(string): Virtual filename (should include extension)
Adjusts lint message locations and aggregates resultsParameters:
messages(Message[][]): Two-dimensional array of messagesfilename(string): File path
Set to
true to enable automatic fixesMessage Structure
Lint messages have this structure:Example: Markdown Processor
Extract JavaScript from Markdown code blocks:Example: HTML Processor
Extract JavaScript from HTML script tags:Supporting Autofixes
To support automatic fixes, transform fix ranges to original file positions:Metadata Objects
Plugin Meta
Define at plugin level:Processor Meta
Define for each processor:Why Both Meta Objects?The plugin meta is used when the processor is referenced by string (e.g.,
"example/processor-name"). The processor meta is used when the processor object is passed directly in configuration.Creating Your Processor
1
Identify Code Blocks
Determine how to extract JavaScript from your file format:
2
Implement Preprocess
Extract and return code blocks:
3
Implement Postprocess
Adjust message locations:
4
Test Thoroughly
Test with various code block configurations:
Using Processors in Configuration
Configure ESLint to use your processor:eslint.config.js
Advanced Patterns
Multiple File Types
Handle different file types with one plugin:Conditional Processing
Process only certain code blocks:Preserving Indentation
Maintain original indentation in extracted code:Testing Processors
Unit Tests
Integration Tests
Performance Tips
Optimized Extraction
Common Pitfalls
Incorrect Line Number Adjustments
Incorrect Line Number Adjustments
Always calculate line offsets based on the original file:
Forgetting to Flatten Messages
Forgetting to Flatten Messages
postprocess() receives a 2D array but must return a 1D array:Not Setting supportsAutofix
Not Setting supportsAutofix
If you want fixes to work, set
supportsAutofix: true and adjust fix ranges in postprocess().Losing Message Properties
Losing Message Properties
Preserve all message properties when adjusting:
Real-World Examples
@eslint/markdown
Official Markdown processor
eslint-plugin-vue
Vue single-file component processor
eslint-plugin-html
HTML script tag processor
eslint-plugin-svelte
Svelte component processor
Next Steps
Create a Plugin
Package your processor for distribution
Configure Processors
Learn how users configure processors