Skip to main content

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 Markdown
  • eslint-plugin-vue - Vue single-file components
  • eslint-plugin-html - HTML script tags

Processor Structure

A processor is an object with preprocess() and postprocess() methods:

Processor Methods

preprocess(text, filename)
function
required
Extracts JavaScript code blocks from the fileParameters:
  • text (string): File contents
  • filename (string): File path
Returns: Array of code blocks, each with:
  • text (string): JavaScript code to lint
  • filename (string): Virtual filename (should include extension)
postprocess(messages, filename)
function
required
Adjusts lint message locations and aggregates resultsParameters:
  • messages (Message[][]): Two-dimensional array of messages
  • filename (string): File path
Returns: Flat array of adjusted messages
supportsAutofix
boolean
Set to true to enable automatic fixes
When supportsAutofix is true, postprocess() must also transform the fix property of messages to reference the original file locations.

Message 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
Virtual FilenamesESLint uses the filename from preprocessed blocks to match configuration. Use patterns like **/*.md/*.js to target extracted code.

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

Processors run on every file. Optimize performance:
  • Cache regex patterns - Compile once, use many times
  • Minimize string operations - Avoid unnecessary slicing/splitting
  • Use efficient parsing - Consider parser libraries for complex formats
  • Limit regex backtracking - Use possessive quantifiers

Optimized Extraction

Common Pitfalls

Always calculate line offsets based on the original file:
postprocess() receives a 2D array but must return a 1D array:
If you want fixes to work, set supportsAutofix: true and adjust fix ranges in postprocess().
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