-
-
Notifications
You must be signed in to change notification settings - Fork 461
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: use eslint-plugin-mdx
for md
/mdx
files
#353
base: main
Are you sure you want to change the base?
Conversation
3b1f334
to
8a3bd14
Compare
8a3bd14
to
dd8d570
Compare
dd8d570
to
336e453
Compare
@@ -1,32 +1,33 @@ | |||
# @antfu/eslint-config | |||
@antfu/eslint-config |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think they're removed unexpectedly.
const patchedParser: Linter.ParserModule = { | ||
...mdxParser, | ||
parse(text, options) { | ||
// @ts-expect-error cast | ||
const result = mdxParser.parseForESLint!(text, options) | ||
const body = result.ast.body | ||
|
||
function predicate(token: { start: number, end: number }) { | ||
for (const node of body) { | ||
if (node.start <= token.start! && node.end >= token.end!) | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
// `eslint-mdx` produces extra tokens that are not presented in the AST, causing rules like `indent` to fail | ||
result.ast.tokens = result.ast.tokens.filter(predicate) | ||
result.ast.comments = result.ast.comments.filter(predicate) | ||
|
||
return result | ||
}, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to eslint-stylistic/eslint-stylistic#215
This patch is the closest thing I could fix, but the formatting for mdx is still not ideal.
I think I have spent too much time on working around it. I rather not have it or something in a broken state. I am giving it up at this moment, but I am open to revisiting it later if the compatibility gets better in the future.
Thanks for your effort!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand, why not just disable indent
temporarily for .md/.mdx
files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this commit, even the tests are passing, you see that mdx is basically not formatted at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because prettier does not support mdx v2/v3 well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just raised mdx-js/eslint-mdx#491 for tracking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, looking forward to see it get fixed! 👍
I am okay with keeping this PR open for future reference, or feel free to close it. |
Description
Enable
eslint-plugin-mdx
to replace simpleeslint-plugin-markdown
Linked Issues
N/A
Additional context