Skip to content

Commit

Permalink
fix: parse comment correctly - close #205
Browse files Browse the repository at this point in the history
so that it could be used to disable the rule
  • Loading branch information
JounQin committed May 30, 2020
1 parent 8e34db8 commit 909651f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/eslint-mdx/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,12 +323,20 @@ export class Parser {

const value = node.value as string

const { loc, start, end } = normalizePosition(node.position)

// fix #4
if (isComment(value)) {
const comment = COMMENT_CONTENT_REGEX.exec(value)[2]
this._ast.comments.push({
type: 'Block',
value: comment,
loc,
range: [start, end],
})
return
}

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

let program: AST.Program
Expand Down
2 changes: 2 additions & 0 deletions test/__snapshots__/fixtures.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,6 @@ Header <header>
"
`;
exports[`fixtures should match all snapshots: remark.md 1`] = `undefined`;
exports[`fixtures should match all snapshots: remark.mdx 1`] = `undefined`;
7 changes: 7 additions & 0 deletions test/fixtures/remark.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
_Hello_, **world**!

<!--lint disable no-literal-urls-->

### Code Splitting

This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
6 changes: 6 additions & 0 deletions test/fixtures/remark.mdx
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
_Hello_, **world**!

### Code Splitting

<!-- eslint-disable mdx/remark -->

This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting

0 comments on commit 909651f

Please sign in to comment.