Skip to content
ESLint Parser/Plugin for MDX
TypeScript JavaScript
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
packages build: bump dependencies, use union @1stG configs, integrate with codacy Aug 20, 2019
test build: bump dependencies, use union @1stG configs, integrate with codacy Aug 20, 2019
.editorconfig first blood, no support for parser, yet Jul 29, 2019
.eslintrc.js build: bump dependencies, use union @1stG configs, integrate with codacy Aug 20, 2019
.gitignore chore: add type-coverage and codechecks support (#39) Aug 12, 2019
.huskyrc.js build: bump dependencies, use union @1stG configs, integrate with codacy Aug 20, 2019
.lintstagedrc.js build: bump dependencies, use union @1stG configs, integrate with codacy Aug 20, 2019
.prettierignore fix: options unchangeable issue for default parser Aug 5, 2019
.travis.yml build: bump dependencies, use union @1stG configs, integrate with codacy Aug 20, 2019
CHANGELOG.md chore(release): v0.11.2 Aug 13, 2019
LICENSE Initial commit Jul 29, 2019
README.md build: bump dependencies, use union @1stG configs, integrate with codacy Aug 20, 2019
codechecks.yml feat: rename plugin to `eslint-plugin-mdx`, thanks to @azz (#42) Aug 14, 2019
lerna.json
package.json build: bump dependencies, use union @1stG configs, integrate with codacy Aug 20, 2019
tsconfig.base.json build: bump dependencies, use union @1stG configs, integrate with codacy Aug 20, 2019
tsconfig.json build: bump dependencies, use union @1stG configs, integrate with codacy Aug 20, 2019
yarn.lock build: bump dependencies, use union @1stG configs, integrate with codacy Aug 20, 2019

README.md

Travis Codacy Grade Codecov type-coverage GitHub release David Dev

Conventional Commits code style: prettier lerna codechecks.io

ESLint Parser/Plugin for MDX, helps you lint all ES syntaxes excluding code block of course. Work perfectly with eslint-plugin-import, eslint-plugin-prettier or any other eslint plugins.

VSCode Extension Visual Studio Marketplace Version

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

Packages

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

Package Description Version Peer Dependencies Dependencies
eslint-mdx ESLint Parser for MDX npm David Peer David
eslint-plugin-mdx ESLint Plugin, Configuration and Rules for MDX npm David Peer David

Install

# yarn
yarn add -D eslint-plugin-mdx

# npm
npm i -D eslint-plugin-mdx

Usage

  1. In your ESLint config file:

    1. If you're using eslint >= 6.0.0, add:

      {
        "extends": ["plugin:mdx/recommended"],
        "overrides": [
          {
            "files": ["*.mdx"],
            "extends": ["plugin:mdx/overrides"]
          }
        ]
      }
    2. If you're using eslint@^5.0.0, you need to enable this parser/plugin manually, because eslint@5 does not support extends for overrides property in its configuration:

      const { configs } = require('eslint-plugin-mdx')
      const rebass = require('rebass')
      
      module.exports = {
        extends: ['plugin:mdx/recommended'],
        overrides: [
          Object.assign(
            {
              files: ['*.mdx'],
            },
            configs.overrides,
          ),
        ],
      }
  2. Make sure ESLint knows to run on .mdx files:

    eslint . --ext js,mdx

Parser Options

  1. parser (string | ParserConfig | ParserFn): Custom parser for ES syntax is supported, although @typescript-eslint/parser or babel-eslint will be detected automatically what means you actually do not need to do this:

    {
      "extends": ["plugin:mdx/recommended"],
      "parserOptions": {
        "parser": "babel-eslint"
      }
    }
  2. extensions (string | string[]): eslint-mdx will only resolve .mdx files by default, files with other extensions will be resolved by the parser option. If you want to resolve other extensions as like .mdx, you can use this option.

Rules

mdx/no-jsx-html-comments

HTML style comments in jsx block is invalid, this rule will help you to fix it by transforming it to JSX style comments.

mdx/no-unescaped-entities

Inline JSX like Inline <Component /> is supported by MDX, but rule react/no-unescaped-entities from eslint-plugin-react is incompatible with it, mdx/no-unescaped-entities is the replacement.

mdx/no-unused-expressions

MDX can render jsx block automatically without exporting them, but ESLint will report no-unused-expressions issue which could be unexpected, this rule is a replacement of it, so make sure that you've turned off the original no-unused-expressions rule.

Limitation

This parser/plugin can only handle ES syntaxes for you, markdown related syntaxes will just be ignored, you can use markdownlint or remark-lint to lint that part.

I have a very preliminary idea to integrate with remark-lint.

Changelog

Detailed changes for each release are documented in CHANGELOG.md.

License

MIT © JounQin@1stG

You can’t perform that action at this time.