|
| 1 | +<p align="center"> |
| 2 | + <a href="https://eslint.org"> |
| 3 | + <img src="https://eslint.org/assets/img/logo.svg" height="50"> |
| 4 | + </a> |
| 5 | + <a href="#readme"> |
| 6 | + <img src="https://rx-ts.github.io/assets/heart.svg" height="50"> |
| 7 | + </a> |
| 8 | + <a href="https://github.com/mdx-js/mdx"> |
| 9 | + <img src="https://mdx-logo.now.sh" height="50"> |
| 10 | + </a> |
| 11 | +</p> |
| 12 | + |
| 13 | +[](https://travis-ci.com/rx-ts/eslint-mdx) |
| 14 | +[](https://codecov.io/gh/rx-ts/eslint-mdx) |
| 15 | +[](https://github.com/rx-ts/eslint-mdx/releases) |
| 16 | +[](https://conventionalcommits.org) |
| 17 | +[](https://github.com/prettier/prettier) |
| 18 | +[](https://lerna.js.org) |
| 19 | + |
| 20 | +> [ESLint] Parser/Plugin for [MDX], helps you lint all ES syntaxes excluding `code` block of course. |
| 21 | +> Work perfectly with `eslint-plugin-import`, `eslint-plugin-prettier` or any other eslint plugins. |
| 22 | +
|
| 23 | +## Packages |
| 24 | + |
| 25 | +This repository is a monorepo managed by Lerna what means we actually publish several packages to npm from the same codebase, including: |
| 26 | + |
| 27 | +| Package | Version | Dependencies Status | Description | |
| 28 | +| -------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------- | |
| 29 | +| [`eslint-mdx`](/packages/eslint-mdx) | [](https://www.npmjs.com/package/eslint-mdx) | [](https://david-dm.org/rx-ts/eslint-mdx?path=packages/eslint-mdx&type=peer) [](https://david-dm.org/rx-ts/eslint-mdx?path=packages/eslint-mdx) | ESLint Parser for MDX | |
| 30 | +| [`@rxts/eslint-plugin-mdx`](/packages/eslint-plugin-mdx) | [](https://www.npmjs.com/package/@rxts/eslint-plugin-mdx) | [](https://david-dm.org/rx-ts/eslint-mdx?path=packages/eslint-plugin-mdx&type=peer) [](https://david-dm.org/rx-ts/eslint-mdx?path=packages/eslint-plugin-mdx) | ESLint Plugin, Configuration and Rules for MDX | |
| 31 | + |
| 32 | +## Install |
| 33 | + |
| 34 | +```sh |
| 35 | +# yarn |
| 36 | +yarn add -D @rxts/eslint-plugin-mdx |
| 37 | + |
| 38 | +# npm |
| 39 | +npm i -D @rxts/eslint-plugin-mdx |
| 40 | +``` |
| 41 | + |
| 42 | +## Usage |
| 43 | + |
| 44 | +1. In your ESLint config file: |
| 45 | + |
| 46 | + 1. If you're using `eslint >= 6.0.0`, add: |
| 47 | + |
| 48 | + ```json |
| 49 | + { |
| 50 | + "extends": ["plugin:@rxts/mdx/recommended"], |
| 51 | + "overrides": [ |
| 52 | + { |
| 53 | + "files": ["*.mdx"], |
| 54 | + "extends": ["plugin:@rxts/mdx/overrides"] |
| 55 | + } |
| 56 | + ] |
| 57 | + } |
| 58 | + ``` |
| 59 | + |
| 60 | + 2. If you're using `eslint@^5.0.0`, you need to enable this parse/plugin manually, because `eslint@5` does not support `extends` for `overrides` property in its configuration: |
| 61 | + |
| 62 | + ```json |
| 63 | + { |
| 64 | + "extends": ["plugin:@rxts/mdx/recommended"], |
| 65 | + "overrides": [ |
| 66 | + { |
| 67 | + "files": ["*.mdx"], |
| 68 | + "globals": { |
| 69 | + "React": false |
| 70 | + }, |
| 71 | + "rules": { |
| 72 | + "lines-between-class-members": 0, |
| 73 | + "react/react-in-jsx-scope": 0 |
| 74 | + } |
| 75 | + } |
| 76 | + ] |
| 77 | + } |
| 78 | + ``` |
| 79 | + |
| 80 | +2. Make sure ESLint knows to run on `.mdx` files: |
| 81 | + |
| 82 | + ```sh |
| 83 | + eslint . --ext js,mdx |
| 84 | + ``` |
| 85 | + |
| 86 | +## Parser Options |
| 87 | + |
| 88 | +1. `parser` (`string | Function`): 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 do this: |
| 89 | + |
| 90 | + ```json |
| 91 | + { |
| 92 | + "extends": ["plugin:@rxts/mdx/recommended"], |
| 93 | + "parserOptions": { |
| 94 | + "parser": "babel-eslint" |
| 95 | + } |
| 96 | + } |
| 97 | + ``` |
| 98 | + |
| 99 | +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. |
| 100 | + |
| 101 | +## Rules |
| 102 | + |
| 103 | +### @rxts/mdx/no-jsx-html-comments |
| 104 | + |
| 105 | +HTML style comments in jsx block is invalid, this rule will help you to fix it by transforming it to JSX style comments. |
| 106 | + |
| 107 | +### @rxts/mdx/no-unescaped-entities |
| 108 | + |
| 109 | +Inline JSX like `Inline <Component />` is supported by [MDX], but rule `react/no-unescaped-entities` from [eslint-plugin-react] is incompatible with it, `@rxts/mdx/no-unescaped-entities` is the replacement. |
| 110 | + |
| 111 | +### @rxts/mdx/no-unused-expressions |
| 112 | + |
| 113 | +[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. |
| 114 | + |
| 115 | +## Limitation |
| 116 | + |
| 117 | +> This parser/plugin can only handle ES syntaxes for you, markdown related syntaxes will just be ignored, you can use [markdownlint] or [remake-lint] to lint that part. |
| 118 | +
|
| 119 | +I have a very preliminary idea to integrate with [remake-lint]. |
| 120 | + |
| 121 | +## Changelog |
| 122 | + |
| 123 | +Detailed changes for each release are documented in [CHANGELOG.md](./CHANGELOG.md). |
| 124 | + |
| 125 | +## License |
| 126 | + |
| 127 | +[MIT] |
| 128 | + |
| 129 | +[eslint]: https://eslint.org |
| 130 | +[eslint-plugin-react]: https://github.com/yannickcr/eslint-plugin-react |
| 131 | +[mdx]: https://github.com/mdx-js/mdx |
| 132 | +[mit]: http://opensource.org/licenses/MIT |
| 133 | +[markdownlint]: https://github.com/markdownlint/markdownlint |
| 134 | +[remake-lint]: https://github.com/remarkjs/remark-lint |
0 commit comments