Skip to content

Commit 0d01b19

Browse files
authored
docs: add migration docs (#559)
* docs: add migration docs This change adds a new migration.md file where details about major migrations can be documented. The first section is details about migrating from the previous implementation `eslint-plugin-markdown`. * address lint errors * add additional package managers and fix important notices * update config section * add link to README * address feedback
1 parent 6d1bd73 commit 0d01b19

File tree

2 files changed

+169
-2
lines changed

2 files changed

+169
-2
lines changed

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,13 @@ import { defineConfig } from "eslint/config";
5252
import markdown from "@eslint/markdown";
5353

5454
export default defineConfig([
55-
markdown.configs.recommended,
56-
55+
{
56+
files: ["**/*.md"],
57+
plugins: {
58+
markdown,
59+
},
60+
extends: ["markdown/recommended"],
61+
},
5762
// your other configs here
5863
]);
5964
```
@@ -220,6 +225,10 @@ export default defineConfig([
220225
| ------------------------------------------- | ----------------------------------------------------------------------------------- |
221226
| [`markdown`](./docs/processors/markdown.md) | Extract fenced code blocks from the Markdown code so they can be linted separately. |
222227

228+
## Migration from `eslint-plugin-markdown`
229+
230+
See [Migration](./docs/migration.md#from-eslint-plugin-markdown).
231+
223232
## Editor Integrations
224233

225234
### VSCode

docs/migration.md

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
# Migration
2+
3+
## From `eslint-plugin-markdown`
4+
5+
Starting with v6, `@eslint/markdown` officially replaced `eslint-plugin-markdown`.
6+
You can take the following steps to migrate from the old package.
7+
8+
<!-- eslint-disable-next-line markdown/no-missing-label-refs -- This should be fixed in https://github.com/eslint/markdown/issues/294 -->
9+
> [!NOTE]
10+
> `@eslint/markdown` requires that you're on at least ESLint v9.15.0.
11+
12+
### Update dependencies
13+
14+
- `npm remove eslint-plugin-markdown`
15+
- `npm add -D @eslint/markdown`
16+
17+
### Update `eslint.config.js/ts`
18+
19+
Make the following updates to your config, based on how you're currently using `eslint-plugin-markdown`.
20+
21+
#### Configs
22+
23+
```diff
24+
// eslint.config.js
25+
import { defineConfig } from "eslint/config";
26+
- import markdown from "eslint-plugin-markdown";
27+
+ import markdown from "@eslint/markdown";
28+
29+
export default defineConfig([
30+
- ...markdown.configs.recommended,
31+
+ {
32+
+ name: "your-project/markdown-rules",
33+
+ files: ["**/*.md"],
34+
+ plugins: {
35+
+ markdown
36+
+ },
37+
+ extends: ["markdown/recommended"]
38+
},
39+
40+
// your other configs
41+
]);
42+
43+
```
44+
45+
<!-- eslint-disable-next-line markdown/no-missing-label-refs -- This should be fixed in https://github.com/eslint/markdown/issues/294 -->
46+
> [!IMPORTANT]
47+
> Because this plugin uses a new language to power its linting, you may need to update the other configs you're using so that you limit those to only apply to `js / ts` files.
48+
> Otherwise, those rules will be applied to markdown files now, too, which can lead to unexpected failures.
49+
50+
```js
51+
// eslint.config.js
52+
import { defineConfig } from "eslint/config";
53+
import js from "@eslint/js";
54+
import markdown from "@eslint/markdown";
55+
56+
export default defineConfig([
57+
{
58+
name: "your-project/recommended-rules",
59+
files: ["**/*.js"],
60+
plugins: {
61+
js,
62+
},
63+
extends: ["js/recommended"],
64+
},
65+
{
66+
name: "your-project/markdown-rules",
67+
files: ["**/*.md"],
68+
plugins: {
69+
markdown
70+
},
71+
extends: ["markdown/recommended"]
72+
},
73+
]);
74+
```
75+
76+
If you were previously applying rules from other languages to code blocks within your markdown files, you can use this plugin's `processor` config to still allow for that.
77+
78+
```js
79+
// eslint.config.js
80+
import { defineConfig } from "eslint/config";
81+
import markdown from "@eslint/markdown";
82+
83+
export default defineConfig([
84+
{
85+
name: "your-project/markdown-processor",
86+
files: ["**/*.md"],
87+
plugins: {
88+
markdown
89+
},
90+
extends: ["markdown/processor"]
91+
},
92+
// your other configs
93+
]);
94+
```
95+
96+
<!-- eslint-disable-next-line markdown/no-missing-label-refs -- This should be fixed in https://github.com/eslint/markdown/issues/294 -->
97+
> [!WARNING]
98+
> It is not currently possible to use both the language-based `recommended` config and the processor-based `processor` config, due to a limitation in ESLint core.
99+
> We hope at some point in the future the core will have a solution for this.
100+
101+
#### Rules Only
102+
103+
`@eslint/markdown` is significantly different in its architecture than `eslint-plugin-markdown`, and uses the language feature of `ESLint`, rather than using a processor.
104+
As a result, if you want to configure rules directly (instead of using the recommended config), you'll have to set up the language instead of the processor.
105+
106+
```diff
107+
// eslint.config.js
108+
import { defineConfig } from "eslint/config";
109+
- import markdown from "eslint-plugin-markdown";
110+
+ import markdown from "@eslint/markdown";
111+
112+
export default defineConfig([
113+
{
114+
files: ["**/*.md"],
115+
plugins: {
116+
markdown,
117+
},
118+
- processor: "markdown/markdown"
119+
+ language: "markdown/commonmark",
120+
rules: {
121+
"markdown/no-html": "error",
122+
},
123+
},
124+
]);
125+
126+
```
127+
<!-- eslint-disable-next-line markdown/no-missing-label-refs -- This should be fixed in https://github.com/eslint/markdown/issues/294 -->
128+
> [!IMPORTANT]
129+
> Because this plugin uses a new language to power its linting, you may need to update the other configs you're using so that you limit those to only apply to `js / ts` files.
130+
> Otherwise, those rules will be applied to markdown files now, too, which can lead to unexpected failures.
131+
132+
```js
133+
// eslint.config.js
134+
import { defineConfig } from "eslint/config";
135+
import js from "@eslint/js";
136+
import markdown from "@eslint/markdown";
137+
138+
export default defineConfig([
139+
{
140+
name: "your-project/recommended-rules",
141+
files: ["**/*.js"],
142+
plugins: {
143+
js,
144+
},
145+
extends: ["js/recommended"],
146+
},
147+
{
148+
files: ["**/*.md"],
149+
plugins: {
150+
markdown,
151+
},
152+
language: "markdown/commonmark",
153+
rules: {
154+
"markdown/no-html": "error",
155+
},
156+
},
157+
]);
158+
```

0 commit comments

Comments
 (0)