Skip to content

Commit abe30cb

Browse files
authored
feat: use eslint-plugin-markdown as processor! (#283)
1 parent 5052eb8 commit abe30cb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1310
-434
lines changed

.eslintrc.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,35 @@ module.exports = {
99
// `strictNullChecks` is required
1010
'@typescript-eslint/no-unnecessary-condition': 0,
1111
},
12+
settings: {
13+
node: {
14+
allowModules: ['@babel/types', 'estree', 'unist'],
15+
},
16+
},
17+
overrides: [
18+
{
19+
files: '*.ts',
20+
rules: {
21+
'@typescript-eslint/consistent-type-imports': 2,
22+
},
23+
},
24+
{
25+
files: '**/*.{md,mdx}/**',
26+
rules: {
27+
'prettier/prettier': 0,
28+
'unicorn/filename-case': 0,
29+
},
30+
},
31+
{
32+
files: '*.{md,mdx}',
33+
// related to https://github.com/eslint/eslint/issues/14207
34+
rules: {
35+
'prettier/prettier': 0,
36+
'unicorn/filename-case': 0,
37+
},
38+
settings: {
39+
'mdx/code-blocks': true,
40+
},
41+
},
42+
],
1243
}

README.md

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
[![lerna](https://img.shields.io/badge/maintained%20with-lerna-cc00ff.svg)](https://lerna.js.org)
2323
[![codechecks.io](https://raw.githubusercontent.com/codechecks/docs/master/images/badges/badge-default.svg?sanitize=true)](https://codechecks.io)
2424

25-
> [ESLint][] Parser/Plugin for [MDX][], helps you lint all ES syntaxes excluding `code` block of course.
25+
> [ESLint][] Parser/Plugin for [MDX][], helps you lint all ES syntaxes.
26+
> Linting `code` blocks can be enabled with `mdx/code-blocks` setting too!
2627
> Work perfectly with `eslint-plugin-import`, `eslint-plugin-prettier` or any other eslint plugins.
2728
> And also can be integrated with [remark-lint][] plugins to lint markdown syntaxes.
2829
@@ -73,9 +74,13 @@ npm i -D eslint-plugin-mdx
7374

7475
1. If you're using `eslint >= 6.4.0`, just add:
7576

76-
```json
77+
```jsonc
7778
{
78-
"extends": ["plugin:mdx/recommended"]
79+
"extends": ["plugin:mdx/recommended"],
80+
// optional, if you want to lint code blocks at the same time
81+
"settings": {
82+
"mdx/code-blocks": true
83+
}
7984
}
8085
```
8186

@@ -84,6 +89,10 @@ npm i -D eslint-plugin-mdx
8489
```jsonc
8590
{
8691
"extends": ["plugin:mdx/recommended"],
92+
// optional, if you want to lint code blocks at the same time
93+
"settings": {
94+
"mdx/code-blocks": true
95+
},
8796
"overrides": [
8897
{
8998
"files": ["*.md"],
@@ -100,6 +109,10 @@ npm i -D eslint-plugin-mdx
100109
{
101110
"files": ["*.mdx"],
102111
"extends": ["plugin:mdx/overrides"]
112+
},
113+
{
114+
"files": "**/*.{md,mdx}/**",
115+
"extends": "plugin:mdx/code-blocks"
103116
}
104117
]
105118
}
@@ -112,6 +125,10 @@ npm i -D eslint-plugin-mdx
112125
113126
module.exports = {
114127
extends: ['plugin:mdx/recommended'],
128+
// optional, if you want to lint code blocks at the same time
129+
settings: {
130+
'mdx/code-blocks': true,
131+
},
115132
overrides: [
116133
{
117134
files: ['*.md'],
@@ -125,25 +142,27 @@ npm i -D eslint-plugin-mdx
125142
],
126143
},
127144
},
128-
Object.assign(
129-
{
130-
files: ['*.mdx'],
131-
},
132-
configs.overrides,
133-
),
145+
{
146+
files: ['*.mdx'],
147+
...configs.overrides,
148+
},
149+
{
150+
files: '**/*.{md,mdx}/**',
151+
...configs.codeBlocks,
152+
},
134153
],
135154
}
136155
```
137156

138-
2. Make sure ESLint knows to run on `.mdx` files:
157+
2. Make sure ESLint knows to run on `.md` or `.mdx` files:
139158

140159
```sh
141-
eslint . --ext js,mdx
160+
eslint . --ext js,md,mdx
142161
```
143162

144163
## Parser Options
145164

146-
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:
165+
1. `parser` (`string | ParserConfig | ParserFn`): Custom parser for ES syntax is supported, although `@typescript-eslint/parser` or `@babel/eslint-parser` or `babel-eslint` will be detected automatically what means you actually do not need to do this:
147166

148167
```json
149168
{
@@ -166,18 +185,35 @@ _Fixable_: HTML style comments in jsx block is invalid, this rule will help you
166185

167186
### mdx/no-unescaped-entities
168187

169-
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.
188+
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, so make sure that you've turned off the original `no-unescaped-entities` rule.
170189
171190
### mdx/no-unused-expressions
172191
173-
[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.
192+
[MDX][] can render `jsx` block automatically without exporting them, but [ESLint][] will report `no-unused-expressions` issue which could be unexpected, this rule is the replacement, so make sure that you've turned off the original `no-unused-expressions` rule.
174193

175194
### mdx/remark
176195

177196
_possible fixable depends on your remark plugins_:
178197

179198
Integration with [remark-lint][] plugins, it will read [remark's configuration](https://github.com/remarkjs/remark/tree/master/packages/remark-cli#remark-cli) automatically via [cosmiconfig][]. But `.remarkignore` will not be respected, you should use `.eslintignore` instead.
180199
200+
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:
201+
202+
```jsonc
203+
{
204+
"plugins": [
205+
"@1stg/remark-config",
206+
// change to error severity, notice `[]` is required
207+
["lint-no-duplicate-headings", [2]],
208+
// disable following plugin
209+
[
210+
"lint-no-multiple-toplevel-headings",
211+
[0] // or false
212+
]
213+
]
214+
}
215+
```
216+
181217
## Prettier Integration
182218

183219
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][]_.

package.json

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"build": "run-p build:*",
1414
"build:r": "r -p",
1515
"build:ts": "tsc -b",
16+
"clean": "rimraf packages/*/{lib,*.tsbuildinfo} node_modules/@1stg/eslint-config/node_modules",
1617
"lint": "run-p lint:*",
1718
"lint:es": "cross-env PARSER_NO_WATCH=true eslint . --cache --ext js,md,ts -f friendly",
1819
"lint:ts": "tslint -p . -t stylish",
@@ -23,11 +24,11 @@
2324
"typecov": "type-coverage"
2425
},
2526
"devDependencies": {
26-
"@1stg/lib-config": "^1.1.9",
27-
"@1stg/tslint-config": "^1.1.0",
27+
"@1stg/lib-config": "^1.2.0",
28+
"@1stg/tslint-config": "^1.2.0",
2829
"@types/eslint": "^7.2.7",
2930
"@types/jest": "^26.0.20",
30-
"@types/node": "^14.14.33",
31+
"@types/node": "^14.14.34",
3132
"@types/react": "^17.0.3",
3233
"@types/rebass": "^4.0.8",
3334
"@types/unist": "^2.0.3",
@@ -54,13 +55,16 @@
5455
]
5556
},
5657
"eslintIgnore": [
57-
"**/fixtures/**",
5858
"coverage",
59+
"fixtures",
5960
"lib",
6061
"CHANGELOG.md",
6162
"!/.*.js"
6263
],
6364
"jest": {
65+
"setupFiles": [
66+
"eslint/lib/linter/linter"
67+
],
6468
"collectCoverage": true,
6569
"coverageThreshold": {
6670
"global": {
@@ -90,7 +94,7 @@
9094
]
9195
},
9296
"typeCoverage": {
93-
"atLeast": 99.76,
97+
"atLeast": 99.7,
9498
"cache": true,
9599
"detail": true,
96100
"ignoreAsAssertion": true,

packages/eslint-mdx/README.md

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
[![lerna](https://img.shields.io/badge/maintained%20with-lerna-cc00ff.svg)](https://lerna.js.org)
2323
[![codechecks.io](https://raw.githubusercontent.com/codechecks/docs/master/images/badges/badge-default.svg?sanitize=true)](https://codechecks.io)
2424

25-
> [ESLint][] Parser/Plugin for [MDX][], helps you lint all ES syntaxes excluding `code` block of course.
25+
> [ESLint][] Parser/Plugin for [MDX][], helps you lint all ES syntaxes.
26+
> Linting `code` blocks can be enabled with `mdx/code-blocks` setting too!
2627
> Work perfectly with `eslint-plugin-import`, `eslint-plugin-prettier` or any other eslint plugins.
2728
> And also can be integrated with [remark-lint][] plugins to lint markdown syntaxes.
2829
@@ -73,9 +74,13 @@ npm i -D eslint-plugin-mdx
7374

7475
1. If you're using `eslint >= 6.4.0`, just add:
7576

76-
```json
77+
```jsonc
7778
{
78-
"extends": ["plugin:mdx/recommended"]
79+
"extends": ["plugin:mdx/recommended"],
80+
// optional, if you want to lint code blocks at the same time
81+
"settings": {
82+
"mdx/code-blocks": true
83+
}
7984
}
8085
```
8186

@@ -84,6 +89,10 @@ npm i -D eslint-plugin-mdx
8489
```jsonc
8590
{
8691
"extends": ["plugin:mdx/recommended"],
92+
// optional, if you want to lint code blocks at the same time
93+
"settings": {
94+
"mdx/code-blocks": true
95+
},
8796
"overrides": [
8897
{
8998
"files": ["*.md"],
@@ -100,6 +109,10 @@ npm i -D eslint-plugin-mdx
100109
{
101110
"files": ["*.mdx"],
102111
"extends": ["plugin:mdx/overrides"]
112+
},
113+
{
114+
"files": "**/*.{md,mdx}/**",
115+
"extends": "plugin:mdx/code-blocks"
103116
}
104117
]
105118
}
@@ -112,6 +125,10 @@ npm i -D eslint-plugin-mdx
112125
113126
module.exports = {
114127
extends: ['plugin:mdx/recommended'],
128+
// optional, if you want to lint code blocks at the same time
129+
settings: {
130+
'mdx/code-blocks': true,
131+
},
115132
overrides: [
116133
{
117134
files: ['*.md'],
@@ -125,25 +142,27 @@ npm i -D eslint-plugin-mdx
125142
],
126143
},
127144
},
128-
Object.assign(
129-
{
130-
files: ['*.mdx'],
131-
},
132-
configs.overrides,
133-
),
145+
{
146+
files: ['*.mdx'],
147+
...configs.overrides,
148+
},
149+
{
150+
files: '**/*.{md,mdx}/**',
151+
...configs.codeBlocks,
152+
},
134153
],
135154
}
136155
```
137156

138-
2. Make sure ESLint knows to run on `.mdx` files:
157+
2. Make sure ESLint knows to run on `.md` or `.mdx` files:
139158

140159
```sh
141-
eslint . --ext js,mdx
160+
eslint . --ext js,md,mdx
142161
```
143162

144163
## Parser Options
145164

146-
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:
165+
1. `parser` (`string | ParserConfig | ParserFn`): Custom parser for ES syntax is supported, although `@typescript-eslint/parser` or `@babel/eslint-parser` or `babel-eslint` will be detected automatically what means you actually do not need to do this:
147166

148167
```json
149168
{
@@ -166,18 +185,35 @@ _Fixable_: HTML style comments in jsx block is invalid, this rule will help you
166185

167186
### mdx/no-unescaped-entities
168187

169-
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.
188+
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, so make sure that you've turned off the original `no-unescaped-entities` rule.
170189
171190
### mdx/no-unused-expressions
172191
173-
[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.
192+
[MDX][] can render `jsx` block automatically without exporting them, but [ESLint][] will report `no-unused-expressions` issue which could be unexpected, this rule is the replacement, so make sure that you've turned off the original `no-unused-expressions` rule.
174193

175194
### mdx/remark
176195

177196
_possible fixable depends on your remark plugins_:
178197

179198
Integration with [remark-lint][] plugins, it will read [remark's configuration](https://github.com/remarkjs/remark/tree/master/packages/remark-cli#remark-cli) automatically via [cosmiconfig][]. But `.remarkignore` will not be respected, you should use `.eslintignore` instead.
180199
200+
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:
201+
202+
```jsonc
203+
{
204+
"plugins": [
205+
"@1stg/remark-config",
206+
// change to error severity, notice `[]` is required
207+
["lint-no-duplicate-headings", [2]],
208+
// disable following plugin
209+
[
210+
"lint-no-multiple-toplevel-headings",
211+
[0] // or false
212+
]
213+
]
214+
}
215+
```
216+
181217
## Prettier Integration
182218

183219
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][]_.

packages/eslint-mdx/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
"eslint": ">=5.0.0"
3434
},
3535
"dependencies": {
36-
"espree": "^7.3.1",
3736
"remark-mdx": "^1.6.22",
3837
"remark-parse": "^8.0.3",
3938
"tslib": "^2.1.0",

0 commit comments

Comments
 (0)