Skip to content

Commit e8a2be0

Browse files
authored
feat: split markdown messages in postprocess (#303)
eslint/markdown#183 (comment)
1 parent 9ca50d0 commit e8a2be0

File tree

3 files changed

+35
-39
lines changed

3 files changed

+35
-39
lines changed

packages/eslint-plugin-mdx/src/processors/markdown.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -367,14 +367,7 @@ function postprocess(
367367
// eslint-disable-next-line unicorn/prefer-spread
368368
return ([] as Linter.LintMessage[]).concat(
369369
...messages.map((group, i) => {
370-
const block = blocks[i]
371-
372-
// non code block message, parsed by `eslint-mdx` for example
373-
if (!block) {
374-
return group
375-
}
376-
377-
const adjust = adjustBlock(block)
370+
const adjust = adjustBlock(blocks[i])
378371

379372
return group.map(adjust).filter(excludeUnsatisfiableRules)
380373
}),

packages/eslint-plugin-mdx/src/processors/remark.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,21 @@ export const remark: ESLintProcessor = {
1515
}
1616

1717
return [
18+
text,
1819
...markdown.preprocess(text, filename).map(({ text, filename }) => ({
1920
text,
2021
filename:
2122
filename.slice(0, filename.lastIndexOf('.')) +
2223
'.' +
2324
getShortLang(filename, processorOptions.languageMapper),
2425
})),
25-
text,
2626
]
2727
},
28-
postprocess(lintMessages, filename) {
29-
return markdown.postprocess(lintMessages, filename).map(lintMessage => {
28+
postprocess([mdxMessages, ...markdownMessages], filename) {
29+
return [
30+
...mdxMessages,
31+
...markdown.postprocess(markdownMessages, filename),
32+
].map(lintMessage => {
3033
const {
3134
message,
3235
ruleId: eslintRuleId,

test/__snapshots__/fixtures.test.ts.snap

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ Array [
55
Object {
66
"column": 1,
77
"endColumn": 6,
8-
"endLine": 36,
8+
"endLine": 3,
99
"fix": Object {
1010
"range": Array [
11-
406,
12-
411,
11+
7,
12+
12,
1313
],
1414
"text": "# abc",
1515
},
16-
"line": 36,
16+
"line": 3,
1717
"message": "Do not use headings with similar content (1:1)",
1818
"nodeType": "Program",
1919
"ruleId": "remark-lint-no-duplicate-headings",
@@ -22,15 +22,15 @@ Array [
2222
Object {
2323
"column": 1,
2424
"endColumn": 6,
25-
"endLine": 36,
25+
"endLine": 3,
2626
"fix": Object {
2727
"range": Array [
28-
406,
29-
411,
28+
7,
29+
12,
3030
],
3131
"text": "# abc",
3232
},
33-
"line": 36,
33+
"line": 3,
3434
"message": "Don’t use multiple top level headings (1:1)",
3535
"nodeType": "Program",
3636
"ruleId": "remark-lint-no-multiple-toplevel-headings",
@@ -39,67 +39,67 @@ Array [
3939
Object {
4040
"column": 1,
4141
"endColumn": 6,
42-
"endLine": 46,
42+
"endLine": 36,
4343
"fix": Object {
4444
"range": Array [
45-
472,
46-
477,
45+
406,
46+
411,
4747
],
4848
"text": "# abc",
4949
},
50-
"line": 46,
51-
"message": "Do not use headings with similar content (3:1)",
50+
"line": 36,
51+
"message": "Do not use headings with similar content (1:1)",
5252
"nodeType": "Program",
5353
"ruleId": "remark-lint-no-duplicate-headings",
5454
"severity": 2,
5555
},
5656
Object {
5757
"column": 1,
5858
"endColumn": 6,
59-
"endLine": 46,
59+
"endLine": 36,
6060
"fix": Object {
6161
"range": Array [
62-
472,
63-
477,
62+
406,
63+
411,
6464
],
6565
"text": "# abc",
6666
},
67-
"line": 46,
68-
"message": "Don’t use multiple top level headings (3:1)",
67+
"line": 36,
68+
"message": "Don’t use multiple top level headings (1:1)",
6969
"nodeType": "Program",
7070
"ruleId": "remark-lint-no-multiple-toplevel-headings",
7171
"severity": 1,
7272
},
7373
Object {
7474
"column": 1,
7575
"endColumn": 6,
76-
"endLine": 3,
76+
"endLine": 46,
7777
"fix": Object {
7878
"range": Array [
79-
7,
80-
12,
79+
472,
80+
477,
8181
],
8282
"text": "# abc",
8383
},
84-
"line": 3,
85-
"message": "Do not use headings with similar content (1:1)",
84+
"line": 46,
85+
"message": "Do not use headings with similar content (3:1)",
8686
"nodeType": "Program",
8787
"ruleId": "remark-lint-no-duplicate-headings",
8888
"severity": 2,
8989
},
9090
Object {
9191
"column": 1,
9292
"endColumn": 6,
93-
"endLine": 3,
93+
"endLine": 46,
9494
"fix": Object {
9595
"range": Array [
96-
7,
97-
12,
96+
472,
97+
477,
9898
],
9999
"text": "# abc",
100100
},
101-
"line": 3,
102-
"message": "Don’t use multiple top level headings (1:1)",
101+
"line": 46,
102+
"message": "Don’t use multiple top level headings (3:1)",
103103
"nodeType": "Program",
104104
"ruleId": "remark-lint-no-multiple-toplevel-headings",
105105
"severity": 1,

0 commit comments

Comments
 (0)