-
Notifications
You must be signed in to change notification settings - Fork 62
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
[FR] option to ignore code blocks by meta string #208
Comments
I did some digging to figure out how to approach the proposed solution and stumbled upon this: Apparently ESLint calls the preprocessor, which produces a list of blocks. ESLint then iterates over those blocks and (among other things) checks whether to lint each block or not based file path/extension. Here is the corresponding function, which blindly allows all Perhaps changing the preprocessor to not pass certain code blocks (based on meta info?) back to ESLint would be a viable alternative. |
I'm excited you're thinking of using this for MDN! This is the same problem we encountered when we tried to lint our own docs: unlike most published code, so many of our code blocks are intentionally invalid. Right now, there are two ways to avoid linting code blocks:
There should be a third way by explicitly ignoring a virtual file path, but as @lionralfs discovered, that currently has a bug that is tracked in eslint/eslint#15949. I have three ideas:
|
RE:
I'd certainly be willing to 😄 If there isn't a way to make it a core feature we can certainly maintain our fork. RE: "anything can go there", my goal with this FR is to make it an opt-in feature and users have to explicitly say "skip code with meta containing X". I think that's generalizable enough.
Yeah, we'd prefer to not use any kind of comment but stick with meta string.
That's unfortunate. I'll admit I don't know much about ESLint core APIs beyond developing rules... So if I understand correctly—the Markdown processor is not configurable in any way, and metadata format must be hardcoded (e.g. In this case, I think we can consider forking it since we can do other useful things—we have a lot of tricky code block usage that's hard to analyze. |
Sorry for the long delay here. When I wrote my previous comment about processor options being the ideal way to do this without forking, I had forgotten about an already-accepted RFC that would make options accessible to processors! There was a PR to implement it, but it was never finished. I've opened a new issue to track the implementation of that RFC. If anyone's interested in picking up that work, we'd be able to add an option like |
Hi, we at MDN are considering adopting ESLint for our code examples.
We have got some initial success at fixing thousands of syntax errors / stylistic issues. However, we have some code blocks that intentionally demonstrate bad syntax:
We decided to not use
eslint-skip
anywhere (or at least as sparsely as possible), so that external contributors don't get confused. On top of that, we don't want to duplicate metadata: sinceexample-bad
is already used by the platform to render a code block with a cross, we think the linter should accommodate that convention.Therefore, I want to propose a feature that ignores code blocks by meta string—currently, the parser takes advantage of glob patterns to differentiate code blocks, so adding a Markdown-specific option could be tricky. I don't have a solid API design on top of my head, but maybe we can add the meta string as part of the language extension (e.g.
*.example-bad.js
)?The text was updated successfully, but these errors were encountered: