Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/rules/no-reversed-media-syntax.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,12 @@ export default {
const matchIndex = match.index;
const matchLength = reversedSyntax.length;

if (isInCodeSpan(matchIndex, codeSpans)) {
if (
isInCodeSpan(
matchIndex + node.position.start.offset,
codeSpans,
)
) {
continue;
}

Expand Down
9 changes: 9 additions & 0 deletions tests/rules/no-reversed-media-syntax.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ ruleTester.run("no-reversed-media-syntax", rule, {
\`\`\`
`,
"`myobj.getFiles(test)[0]`",
dedent`
# Heading,
\`myobj.getFiles(test)[0]\`,
`,
dedent`
foo
# Heading,
\`myobj.getFiles(test)[0]\`,
`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks 👍

Interestingly, the current test cases don’t detect the changed logic properly, since the matchIndex is ignored by the range of the InlineCode node by chance!

Image

So even if we revert this change, the test cases still pass 😄


Suggested change
dedent`
# Heading,
\`myobj.getFiles(test)[0]\`,
`,
dedent`
foo
# Heading,
\`myobj.getFiles(test)[0]\`,
`,
dedent`
# Heading
\`(test)[0]\`
`,
dedent`
foo
# Heading
\`(test)[0]\`
`,

Would it be possible to use the above test cases instead? If we modify them, the tests wouldn’t pass if we reverted this change.

Also, it’s not a technical issue, but I think the comma (,) was added by mistake. If it wasn’t intentional, it would be great if you could remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right that it did not actuall test the change 😅 .
I removed the unnecessary first test case and added more text in the next.

"(reversed)[link]",
"a ) a ( a )[a]~",
"a<pre>&rpar; a &lpar; a &rpar;[a]~</pre>",
Expand Down
Loading