Skip to content

Commit 909651f

Browse files
committed
fix: parse comment correctly - close #205
so that it could be used to disable the rule
1 parent 8e34db8 commit 909651f

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

packages/eslint-mdx/src/parser.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -323,12 +323,20 @@ export class Parser {
323323

324324
const value = node.value as string
325325

326+
const { loc, start, end } = normalizePosition(node.position)
327+
326328
// fix #4
327329
if (isComment(value)) {
330+
const comment = COMMENT_CONTENT_REGEX.exec(value)[2]
331+
this._ast.comments.push({
332+
type: 'Block',
333+
value: comment,
334+
loc,
335+
range: [start, end],
336+
})
328337
return
329338
}
330339

331-
const { loc, start } = normalizePosition(node.position)
332340
const startLine = loc.start.line - 1 // ! line is 1-indexed, change to 0-indexed to simplify usage
333341

334342
let program: AST.Program

test/__snapshots__/fixtures.test.ts.snap

+2
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,6 @@ Header <header>
116116
"
117117
`;
118118
119+
exports[`fixtures should match all snapshots: remark.md 1`] = `undefined`;
120+
119121
exports[`fixtures should match all snapshots: remark.mdx 1`] = `undefined`;

test/fixtures/remark.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
_Hello_, **world**!
2+
3+
<!--lint disable no-literal-urls-->
4+
5+
### Code Splitting
6+
7+
This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting

test/fixtures/remark.mdx

+6
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
11
_Hello_, **world**!
2+
3+
### Code Splitting
4+
5+
<!-- eslint-disable mdx/remark -->
6+
7+
This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting

0 commit comments

Comments
 (0)