Giter VIP home page Giter VIP logo

eslint-mdx's Introduction

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. And also can be integrated with remark-lint plugins to lint markdown syntaxes.

TOC

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.4.0, just add:

      {
        "extends": ["plugin:mdx/recommended"]
      }
    2. If you're using eslint >=6.0.0 and <6.4.0, add as following because it does not support overrides from npm pkg:

      {
        "extends": ["plugin:mdx/recommended"],
        "overrides": [
          {
            "files": ["*.md"],
            "rules": {
              "prettier/prettier": [
                2,
                {
                  // unnecessary if you're not using `eslint-plugin-prettier`, but required if you are
                  "parser": "markdown"
                }
              ]
            }
          },
          {
            "files": ["*.mdx"],
            "extends": ["plugin:mdx/overrides"]
          }
        ]
      }
    3. 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')
      
      module.exports = {
        extends: ['plugin:mdx/recommended'],
        overrides: [
          {
            files: ['*.md'],
            rules: {
              'prettier/prettier': [
                2,
                {
                  // unnecessary if you're not using `eslint-plugin-prettier`, but required if you are
                  parser: 'markdown',
                },
              ],
            },
          },
          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.

  3. 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.

Rules

mdx/no-jsx-html-comments

Fixable: 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.

mdx/remark

possible fixable depends on your remark plugins:

Integration with remark-lint plugins, it will read remark's configuration automatically via cosmiconfig. But .remarkignore will not be respected, you should use .eslintignore instead.

Prettier Integration

If you're using remark-lint feature with Prettier both together, you can try remark-preset-prettier which helps you to turn off all rules that are unnecessary or might conflict with Prettier.

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

Changelog

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

License

MIT © JounQin@1stG.me

eslint-mdx's People

Contributors

jjoselv avatar jounqin avatar nd0ut avatar renovate-bot avatar renovate[bot] avatar wooorm avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.