Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ESLint Parser/Plugin for MDX

License

NotificationsYou must be signed in to change notification settings

mdx-js/eslint-mdx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub Actions Workflow StatusCodecovtype-coverageGitHub release

Renovate enabledConventional Commitscode style: prettierchangesets

ESLint Parser/Plugin forMDX, helps you lint all ES syntaxes.Lintingcode blocks can be enabled withmdx/code-blocks setting too!Work perfectly witheslint-plugin-import,eslint-plugin-prettier or any other eslint plugins.And also can be integrated withremark-lint plugins to lint markdown syntaxes.

TOC

VSCode Extension

Visual Studio Marketplace Version

VSCode MDX: Integrates withVSCode ESLint, syntaxes highlighting and error reporting.

Packages

This repository is a monorepo managed bychangesets what means we actually publish several packages to npm from same codebase, including:

PackageDescriptionVersion
eslint-mdxESLint Parser for MDXnpm
eslint-plugin-mdxESLint Plugin, Configuration and Rules for MDXnpm

Install

# yarnyarn add -D eslint-plugin-mdx# npmnpm i -D eslint-plugin-mdx

Notice

  1. If you're using multi languages,js/jsx/ts/tsx/vue, etc for example, you'd better to always useoverrides (Classic Config) orfiles (Flag Config) feature of ESLint, because configs may be overridden by following configs.

    See#251 for more details.

  2. If you're using{/* eslint-disable-line mdx/remark */} withprettier, this won't work becauseprettier will add a blank line after the comment, which makes it invalid. You can use{/* eslint-disable mdx/remark */} paired with{/* eslint-enable mdx/remark */} instead:

    {/* eslint-disable mdx/remark*/}#Heading{/* eslint-enable mdx/remark*/}

Usage

Classic Config

.eslintrc file:

{"extends": ["plugin:mdx/recommended"],// optional, if you want to lint code blocks at the same time"settings": {"mdx/code-blocks":true,// optional, if you want to disable language mapper, set it to `false`// if you want to override the default language mapper inside, you can provide your own"mdx/language-mapper": {},// optional, same as the `parserOptions.ignoreRemarkConfig`, you have to specify it twice unfortunately"mdx/ignore-remark-config":true,// optional, same as the `parserOptions.remarkConfigPath`, you have to specify it twice unfortunately"mdx/remark-config-path":"path/to/your/remarkrc",  },}

Flat Config

eslint.config.js file:

import*asmdxfrom'eslint-plugin-mdx'exportdefault[{    ...mdx.flat,// optional, if you want to lint code blocks at the sameprocessor:mdx.createRemarkProcessor({lintCodeBlocks:true,// optional, if you want to disable language mapper, set it to `false`// if you want to override the default language mapper inside, you can provide your ownlanguageMapper:{},// optional, same as the `parserOptions.ignoreRemarkConfig`, you have to specify it twice unfortunatelyignoreRemarkConfig:true,// optional, same as the `parserOptions.remarkConfigPath`, you have to specify it twice unfortunatelyremarkConfigPath:'path/to/your/remarkrc',}),},{    ...mdx.flatCodeBlocks,rules:{      ...mdx.flatCodeBlocks.rules,// if you want to override some rules for code blocks'no-var':'error','prefer-const':'error',},},]

Then, make sure ESLint knows to run on.md or.mdx files:

eslint. --ext js,md,mdx

Parser Options

  1. extensions (string | string[]):eslint-mdx will only resolve.mdx files by default, if you want to resolve other extensions as like.mdx, you can use this option.

  2. markdownExtensions (string | string[]):eslint-mdx will only treat.md files as plain markdown by default, and will lint them via remark plugins. If you want to resolve other extensions as like.md, you can use this option.

  3. ignoreRemarkConfig (boolean): Ignore theremark configuration defined in the project.

  4. remarkConfigPath (string): Specify the path to theremark configuration file, could be relative toCWD or absolute path.

Parser API

MDXCode

A newMDXCode estree node type is exported fromeslint-mdx which represents code blocks inmdx like the following:

<div>```jsexportfunctionfoo() {return'bar'  }```</div>

See alsohttps://github.com/syntax-tree/mdast#code

MDXHeading

A newMDXHeading estree node type is exported fromeslint-mdx which represents markdown heading inmdx like the following:

<div>#Here's a text gradient short code!</div>

See alsohttps://github.com/syntax-tree/mdast#heading

Typings

importtype{BaseNode}from'estree'importtype{JSXElement}from'estree-jsx'exportinterfaceMDXCodeextendsBaseNode{type:'MDXCode'value:stringlang?:string|nullmeta?:string|null}exporttypeHeadingDepth=1|2|3|4|5|6exportinterfaceMDXHeadingextendsBaseNode{type:'MDXHeading'depth:HeadingDepthchildren:JSXElement['children']}

Rules

mdx/remark

possible fixable depends on your remark plugins:

Integration withremark-lint plugins, it will readremark's configuration automatically viaunified-engine. But.remarkignore will not be respected, you should use.eslintignore instead.

If you want to disable or change severity of some related rules, it won't work by setting rules in eslint config like'remark-lint-no-duplicate-headings': 0, you should change your remark config instead like following:

{"plugins": ["@1stg/remark-config",// change to error severity, notice `[]` is required    ["lint-no-duplicate-headings", [2]],// disable following plugin    ["lint-no-multiple-toplevel-headings",      [0],// or false    ],  ],}

Prettier Integration

If you're usingremark-lint feature withPrettier both together, you can tryremark-preset-prettier which helps you toturn off all rules that are unnecessary or might conflict withPrettier.

{"plugins": ["preset-lint-consistent","preset-lint-recommended","preset-lint-markdown-style-guide","preset-prettier"  ]}

Sponsors and Backers

Sponsors

Sponsors

1stGRxTSUnRSUnTS
1stG Open Collective sponsorsRxTS Open Collective sponsorsUnRS Open Collective sponsorsUnTS Open Collective sponsors

unified Open Collective backers and sponsors

Backers

1stGRxTSUnRSUnTS
1stG Open Collective backersRxTS Open Collective backersUnRS Open Collective backersUnTS Open Collective backers

unified Open Collective backers and sponsors

Changelog

Detailed changes for each release are documented inCHANGELOG.md.

License

MIT ©JounQin@1stG.me

Packages

No packages published

Contributors18


[8]ページ先頭

©2009-2025 Movatter.jp