Skip to content

Commit ec1d9b4

Browse files
authored
feat!: experimentally support remark-mdx@2 (#284)
drop `parser` option support, please use `overrides` of ESLint config instead
1 parent 16c5934 commit ec1d9b4

Some content is hidden

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

48 files changed

+6528
-5811
lines changed

.eslintrc.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ module.exports = {
44
rules: {
55
// `strictNullChecks` is required
66
'@typescript-eslint/no-unnecessary-condition': 0,
7+
'unicorn/prefer-export-from': [
8+
2,
9+
{
10+
ignoreUsedVariables: true,
11+
},
12+
],
713
},
814
overrides: [
915
{

CONTRIBUTING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,9 @@ This project is a [lerna][] monorepo, so packages releasing is controlled by [le
1414
2. You need a GitHub token with a `public_repo` scope as `GH_TOKEN` in the environment to publish
1515
3. Run `yarn release` simply, or `GH_TOKEN=xxx yarn release` to export `GH_TOKEN` at one time.
1616

17+
### Release a bete next version
18+
19+
Run `yarn release-next`
20+
1721
[contributing]: https://mdxjs.com/contributing
1822
[lerna]: https://github.com/lerna/lerna

README.md

Lines changed: 17 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
- [Usage](#usage)
3535
- [Parser Options](#parser-options)
3636
- [Rules](#rules)
37-
- [mdx/no-jsx-html-comments](#mdxno-jsx-html-comments)
38-
- [mdx/no-unused-expressions](#mdxno-unused-expressions)
3937
- [mdx/remark](#mdxremark)
4038
- [Prettier Integration](#prettier-integration)
4139
- [Changelog](#changelog)
@@ -74,133 +72,36 @@ See [#251](https://github.com/mdx-js/eslint-mdx/issues/251#issuecomment-73613922
7472

7573
## Usage
7674

77-
1. In your ESLint config file:
78-
79-
1. If you're using `eslint >= 6.4.0`, just add:
80-
81-
```jsonc
82-
{
83-
"extends": ["plugin:mdx/recommended"],
84-
// optional, if you want to lint code blocks at the same time
85-
"settings": {
86-
"mdx/code-blocks": true,
87-
// optional, if you want to disable language mapper, set it to `false`
88-
// if you want to override the default language mapper inside, you can provide your own
89-
"mdx/language-mapper": {}
90-
}
91-
}
92-
```
93-
94-
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:
95-
96-
```jsonc
97-
{
98-
"extends": ["plugin:mdx/recommended"],
99-
// optional, if you want to lint code blocks at the same time
100-
"settings": {
101-
"mdx/code-blocks": true,
102-
// optional, if you want to disable language mapper, set it to `false`
103-
// if you want to override the default language mapper inside, you can provide your own
104-
"mdx/language-mapper": {}
105-
},
106-
"overrides": [
107-
{
108-
"files": ["*.md"],
109-
"rules": {
110-
"prettier/prettier": [
111-
2,
112-
{
113-
// unnecessary if you're not using `eslint-plugin-prettier`, but required if you are
114-
"parser": "markdown"
115-
}
116-
]
117-
}
118-
},
119-
{
120-
"files": ["*.mdx"],
121-
"extends": ["plugin:mdx/overrides"]
122-
},
123-
{
124-
"files": "**/*.{md,mdx}/**",
125-
"extends": "plugin:mdx/code-blocks"
126-
}
127-
]
128-
}
129-
```
130-
131-
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:
132-
133-
```js
134-
const configs = require('eslint-plugin-mdx/lib/configs')
135-
136-
module.exports = {
137-
extends: ['plugin:mdx/recommended'],
138-
// optional, if you want to lint code blocks at the same time
139-
settings: {
140-
'mdx/code-blocks': true,
141-
// optional, if you want to disable language mapper, set it to `false`
142-
// if you want to override the default language mapper inside, you can provide your own
143-
'mdx/language-mapper': {},
144-
},
145-
overrides: [
146-
{
147-
files: ['*.md'],
148-
rules: {
149-
'prettier/prettier': [
150-
2,
151-
{
152-
// unnecessary if you're not using `eslint-plugin-prettier`, but required if you are
153-
parser: 'markdown',
154-
},
155-
],
156-
},
157-
},
158-
{
159-
files: ['*.mdx'],
160-
...configs.overrides,
161-
},
162-
{
163-
files: '**/*.{md,mdx}/**',
164-
...configs.codeBlocks,
165-
},
166-
],
167-
}
168-
```
75+
1. In your ESLint 8+ config file, just add:
16976

170-
2. Make sure ESLint knows to run on `.md` or `.mdx` files:
171-
172-
```sh
173-
eslint . --ext js,md,mdx
174-
```
175-
176-
## Parser Options
177-
178-
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:
179-
180-
```json
77+
```jsonc
18178
{
18279
"extends": ["plugin:mdx/recommended"],
183-
"parserOptions": {
184-
"parser": "babel-eslint"
80+
// optional, if you want to lint code blocks at the same time
81+
"settings": {
82+
"mdx/code-blocks": true,
83+
// optional, if you want to disable language mapper, set it to `false`
84+
// if you want to override the default language mapper inside, you can provide your own
85+
"mdx/language-mapper": {}
18586
}
18687
}
18788
```
18889

189-
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.
190-
191-
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.
90+
2. Make sure ESLint knows to run on `.md` or `.mdx` files:
19291

193-
4. `ignoreRemarkConfig` (`boolean`): Ignore the `remark` configuration defined in the project.
92+
```sh
93+
eslint . --ext js,md,mdx
94+
```
19495

195-
## Rules
96+
## Parser Options
19697

197-
### mdx/no-jsx-html-comments
98+
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.
19899

199-
_Fixable_: HTML style comments in jsx block is invalid, this rule will help you to fix it by transforming it to JSX style comments.
100+
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.
200101

201-
### mdx/no-unused-expressions
102+
3. `ignoreRemarkConfig` (`boolean`): Ignore the `remark` configuration defined in the project.
202103

203-
[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.
104+
## Rules
204105

205106
### mdx/remark
206107

@@ -225,8 +126,6 @@ If you want to disable or change severity of some related rules, it won't work b
225126
}
226127
```
227128

228-
Some plugins are ESM and eslint don't supports them. So, a workaround is to set `ignoreRemarkConfig` to `true` and execute `remark-lint` through the terminal before running eslint. For example: `remark **/*.mdx --no-stdout && eslint . --fix --ext .mdx`.
229-
230129
## Prettier Integration
231130

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

lerna.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
"command": {
1414
"version": {
1515
"allowBranch": [
16-
"develop",
17-
"master"
16+
"master",
17+
"next"
1818
]
1919
},
2020
"publish": {

package.json

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -21,36 +21,34 @@
2121
"prelint": "yarn build",
2222
"prerelease": "yarn build",
2323
"release": "lerna publish --conventional-commits --create-release github --yes",
24+
"release-next": "lerna publish --conventional-prerelease --preid next --pre-dist-tag next --yes",
2425
"test": "jest",
2526
"typecov": "type-coverage"
2627
},
2728
"devDependencies": {
28-
"@1stg/lib-config": "^4.1.2",
29-
"@types/eslint": "^7.29.0",
29+
"@1stg/lib-config": "^5.2.0",
30+
"@types/eslint": "^8.4.1",
3031
"@types/eslint-plugin-markdown": "^2.0.0",
3132
"@types/jest": "^27.4.1",
32-
"@types/node": "^16.10.9",
33-
"@types/react": "^17.0.39",
33+
"@types/node": "^17.0.23",
34+
"@types/react": "^17.0.43",
3435
"@types/unist": "^2.0.6",
3536
"lerna": "^4.0.0",
36-
"npm-run-all": "^4.1.5",
3737
"react": "^17.0.2",
38-
"remark-frontmatter": "2",
39-
"remark-validate-links": "^10.0.4",
40-
"ts-jest": "^27.1.3",
41-
"ts-node": "^10.4.0",
42-
"type-coverage": "^2.18.2",
43-
"typescript": "^4.4.4",
44-
"yarn-deduplicate": "^3.1.0"
38+
"remark-frontmatter": "4.0.1",
39+
"remark-lint": "^9.1.1",
40+
"remark-preset-lint-consistent": "^5.1.1",
41+
"remark-preset-lint-markdown-style-guide": "^5.1.2",
42+
"remark-preset-lint-recommended": "^6.1.2",
43+
"remark-preset-prettier": "^1.0.0",
44+
"remark-validate-links": "^11.0.2",
45+
"ts-jest": "^27.1.4",
46+
"ts-node": "^10.7.0",
47+
"type-coverage": "^2.21.1",
48+
"typescript": "^4.6.3"
4549
},
4650
"resolutions": {
47-
"@typescript-eslint/eslint-plugin": "^5.0.0",
48-
"@typescript-eslint/eslint-plugin-tslint": "^5.0.0",
49-
"@typescript-eslint/experimental-utils": "^5.0.0",
50-
"@typescript-eslint/parser": "^5.0.0",
51-
"eslint": "^8.0.1",
52-
"eslint-plugin-unicorn": "^37.0.1",
53-
"prettier": "^2.5.1"
51+
"prettier": "^2.6.1"
5452
},
5553
"commitlint": {
5654
"extends": [
@@ -76,8 +74,8 @@
7674
"collectCoverage": true,
7775
"coverageThreshold": {
7876
"global": {
79-
"branches": 100,
80-
"functions": 95,
77+
"branches": 98,
78+
"functions": 100,
8179
"lines": 100,
8280
"statements": 100
8381
}
@@ -86,19 +84,18 @@
8684
},
8785
"prettier": "@1stg/prettier-config",
8886
"remarkConfig": {
87+
"settings": {
88+
"emphasis": "_",
89+
"strong": "*"
90+
},
8991
"plugins": [
90-
"remark-frontmatter",
91-
"@1stg/remark-config",
92-
[
93-
"lint-no-duplicate-headings",
94-
[
95-
2
96-
]
97-
],
98-
[
99-
"validate-links",
100-
true
101-
]
92+
"frontmatter",
93+
"lint",
94+
"preset-lint-consistent",
95+
"preset-lint-markdown-style-guide",
96+
"preset-lint-recommended",
97+
"preset-prettier",
98+
"validate-links"
10299
]
103100
},
104101
"renovate": {
@@ -107,7 +104,7 @@
107104
]
108105
},
109106
"typeCoverage": {
110-
"atLeast": 99.92,
107+
"atLeast": 99.93,
111108
"cache": true,
112109
"detail": true,
113110
"ignoreAsAssertion": true,

0 commit comments

Comments
 (0)