Skip to content

Commit bee20dd

Browse files
authored
fix: false positives in no-reversed-media-syntax (#521)
* wip * wip * wip * wip: handle `Image` * wip: handle `ImageReference` * wip (error) * wip
1 parent 22bd5e3 commit bee20dd

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

src/rules/no-reversed-media-syntax.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
/**
1111
* @import { SourceRange } from "@eslint/core"
12-
* @import { Heading, Paragraph, TableCell, Html, InlineCode } from "mdast";
12+
* @import { Heading, Paragraph, TableCell, Html, Image, ImageReference, InlineCode, LinkReference } from "mdast";
1313
* @import { MarkdownRuleDefinition } from "../types.js";
1414
* @typedef {"reversedSyntax"} NoReversedMediaSyntaxMessageIds
1515
* @typedef {[]} NoReversedMediaSyntaxOptions
@@ -102,8 +102,8 @@ export default {
102102
}
103103

104104
return {
105-
":matches(heading, paragraph, tableCell) :matches(html, inlineCode)"(
106-
/** @type {Html | InlineCode} */ node,
105+
":matches(heading, paragraph, tableCell) :matches(html, image, imageReference, inlineCode, linkReference)"(
106+
/** @type {Html | Image | ImageReference | InlineCode | LinkReference} */ node,
107107
) {
108108
skipRanges.push(sourceCode.getRange(node));
109109
},

tests/rules/no-reversed-media-syntax.test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@ ruleTester.run("no-reversed-media-syntax", rule, {
7474
// Heading
7575
"# [ESLint](https://eslint.org/)",
7676
"# ![A beautiful sunset](sunset.png)",
77+
// Image
78+
"![()[]](hi)",
79+
"![(hi)[something]](hi)",
80+
"![()[]](https://example.com)",
81+
// ImageReference
82+
"![()[]][ref]\n\n[ref]: https://example.com",
83+
"![(hi)[something]][ref]\n\n[ref]: https://example.com",
84+
// LinkReference
85+
"[()[]][ref]\n\n[ref]: https://example.com",
86+
"[(hi)[something]][ref]\n\n[ref]: https://example.com",
7787
// TableCell
7888
{
7989
code: dedent`
@@ -255,6 +265,20 @@ ruleTester.run("no-reversed-media-syntax", rule, {
255265
},
256266
],
257267
},
268+
{
269+
code: "[^1]: !(Footnote alt)[https://example.com]",
270+
output: "[^1]: ![Footnote alt](https://example.com)",
271+
language: "markdown/gfm",
272+
errors: [
273+
{
274+
messageId: "reversedSyntax",
275+
line: 1,
276+
column: 8,
277+
endLine: 1,
278+
endColumn: 43,
279+
},
280+
],
281+
},
258282
{
259283
code: "[^1]: (Footnote text)[https://example.com]",
260284
output: "[^1]: [Footnote text](https://example.com)",

0 commit comments

Comments
 (0)