Skip to content

Commit

Permalink
feat: split markdown messages in postprocess
Browse files Browse the repository at this point in the history
  • Loading branch information
JounQin committed Apr 4, 2021
1 parent 9ca50d0 commit 74a8bbc
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 39 deletions.
9 changes: 1 addition & 8 deletions packages/eslint-plugin-mdx/src/processors/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,14 +367,7 @@ function postprocess(
// eslint-disable-next-line unicorn/prefer-spread
return ([] as Linter.LintMessage[]).concat(
...messages.map((group, i) => {
const block = blocks[i]

// non code block message, parsed by `eslint-mdx` for example
if (!block) {
return group
}

const adjust = adjustBlock(block)
const adjust = adjustBlock(blocks[i])

return group.map(adjust).filter(excludeUnsatisfiableRules)
}),
Expand Down
9 changes: 6 additions & 3 deletions packages/eslint-plugin-mdx/src/processors/remark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,21 @@ export const remark: ESLintProcessor = {
}

return [
text,
...markdown.preprocess(text, filename).map(({ text, filename }) => ({
text,
filename:
filename.slice(0, filename.lastIndexOf('.')) +
'.' +
getShortLang(filename, processorOptions.languageMapper),
})),
text,
]
},
postprocess(lintMessages, filename) {
return markdown.postprocess(lintMessages, filename).map(lintMessage => {
postprocess([esMessages, ...markdownMessages], filename) {
return [
...esMessages,
...markdown.postprocess(markdownMessages, filename),
].map(lintMessage => {
const {
message,
ruleId: eslintRuleId,
Expand Down
56 changes: 28 additions & 28 deletions test/__snapshots__/fixtures.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ Array [
Object {
"column": 1,
"endColumn": 6,
"endLine": 36,
"endLine": 3,
"fix": Object {
"range": Array [
406,
411,
7,
12,
],
"text": "# abc",
},
"line": 36,
"line": 3,
"message": "Do not use headings with similar content (1:1)",
"nodeType": "Program",
"ruleId": "remark-lint-no-duplicate-headings",
Expand All @@ -22,15 +22,15 @@ Array [
Object {
"column": 1,
"endColumn": 6,
"endLine": 36,
"endLine": 3,
"fix": Object {
"range": Array [
406,
411,
7,
12,
],
"text": "# abc",
},
"line": 36,
"line": 3,
"message": "Don’t use multiple top level headings (1:1)",
"nodeType": "Program",
"ruleId": "remark-lint-no-multiple-toplevel-headings",
Expand All @@ -39,67 +39,67 @@ Array [
Object {
"column": 1,
"endColumn": 6,
"endLine": 46,
"endLine": 36,
"fix": Object {
"range": Array [
472,
477,
406,
411,
],
"text": "# abc",
},
"line": 46,
"message": "Do not use headings with similar content (3:1)",
"line": 36,
"message": "Do not use headings with similar content (1:1)",
"nodeType": "Program",
"ruleId": "remark-lint-no-duplicate-headings",
"severity": 2,
},
Object {
"column": 1,
"endColumn": 6,
"endLine": 46,
"endLine": 36,
"fix": Object {
"range": Array [
472,
477,
406,
411,
],
"text": "# abc",
},
"line": 46,
"message": "Don’t use multiple top level headings (3:1)",
"line": 36,
"message": "Don’t use multiple top level headings (1:1)",
"nodeType": "Program",
"ruleId": "remark-lint-no-multiple-toplevel-headings",
"severity": 1,
},
Object {
"column": 1,
"endColumn": 6,
"endLine": 3,
"endLine": 46,
"fix": Object {
"range": Array [
7,
12,
472,
477,
],
"text": "# abc",
},
"line": 3,
"message": "Do not use headings with similar content (1:1)",
"line": 46,
"message": "Do not use headings with similar content (3:1)",
"nodeType": "Program",
"ruleId": "remark-lint-no-duplicate-headings",
"severity": 2,
},
Object {
"column": 1,
"endColumn": 6,
"endLine": 3,
"endLine": 46,
"fix": Object {
"range": Array [
7,
12,
472,
477,
],
"text": "# abc",
},
"line": 3,
"message": "Don’t use multiple top level headings (1:1)",
"line": 46,
"message": "Don’t use multiple top level headings (3:1)",
"nodeType": "Program",
"ruleId": "remark-lint-no-multiple-toplevel-headings",
"severity": 1,
Expand Down

0 comments on commit 74a8bbc

Please sign in to comment.