ESLint Plugin for MDX that enables linting and validation of MDX content with comprehensive support for JavaScript/JSX syntax and Markdown formatting.
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
ESLint processors for handling MDX file parsing and code block extraction. The remark processor provides core MDX parsing with configurable options for code block linting and language mapping.
The main processor for handling MDX files, providing parsing and code block extraction functionality.
declare const remark: Linter.Processor;The remark processor includes:
Factory function for creating customized remark processors with specific options.
function createRemarkProcessor(options?: ProcessorOptions): Linter.Processor;
// From eslint-mdx
interface SyncOptions {
ignoreRemarkConfig?: boolean;
remarkConfigPath?: string;
extensions?: string[];
markdownExtensions?: string[];
}
interface ProcessorOptions extends SyncOptions {
lintCodeBlocks?: boolean;
languageMapper?: Record<string, string> | false;
}Usage Examples:
import { createRemarkProcessor } from "eslint-plugin-mdx";
// Basic processor
const processor = createRemarkProcessor();
// Custom processor with options
const customProcessor = createRemarkProcessor({
lintCodeBlocks: true,
languageMapper: {
"js": "javascript",
"ts": "typescript"
},
ignoreRemarkConfig: false
});
// Flat config usage
export default [
{
files: ["**/*.mdx"],
processor: customProcessor
}
];Utilities for mapping code block languages to file extensions for proper linting.
declare const DEFAULT_LANGUAGE_MAPPER: {
readonly ecmascript: "js";
readonly javascript: "js";
readonly javascriptreact: "jsx";
readonly typescript: "ts";
readonly typescriptreact: "tsx";
readonly markdown: "md";
readonly markdownjsx: "mdx";
readonly markdownreact: "mdx";
readonly mdown: "md";
readonly mkdn: "md";
};
function getShortLang(
filename: string,
languageMapper?: Record<string, string> | false
): string;The getShortLang function:
languageMapper to falseGlobal processor options configuration object.
declare const processorOptions: ProcessorOptions;This constant provides default processor options that can be used for configuration reference or as a starting point for custom processors.
All processors are available through a unified export object.
interface ProcessorsExport {
remark: Linter.Processor;
}
declare const processors: ProcessorsExport;interface ESLintMdxSettings {
'mdx/code-blocks'?: boolean;
'mdx/language-mapper'?: Record<string, string> | false;
'mdx/ignore-remark-config'?: boolean;
'mdx/remark-config-path'?: string;
}
interface RangeMap {
indent: number;
js: number;
md: number;
}
interface CodeBlock extends Code {
baseIndentText: string;
comments: string[];
rangeMap: RangeMap[];
}
// From mdast
interface Code {
type: 'code';
lang?: string;
meta?: string;
value: string;
position?: Position;
}
interface Position {
start: Point;
end: Point;
}
interface Point {
line: number;
column: number;
offset?: number;
}The processors integrate with ESLint's processing pipeline:
Configuration Example:
// .eslintrc.js
module.exports = {
settings: {
"mdx/code-blocks": true, // Enable code block linting
"mdx/language-mapper": { // Custom language mapping
"js": "javascript",
"ts": "typescript"
}
},
overrides: [
{
files: ["*.mdx"],
processor: "mdx/remark"
}
]
};