-
-
Notifications
You must be signed in to change notification settings - Fork 653
Add lint rule to validate JSDoc codeblocks using TS compiler #1265
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
base: main
Are you sure you want to change the base?
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
c641bf8 to
89b14c8
Compare
This comment was marked as outdated.
This comment was marked as outdated.
|
@sindresorhus This PR is still a WIP, because there are still a lot of code blocks that have errors in them, but would appreciate if you could give an early feedback on this. Couple of questions:
|
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
Should be fairly fast now, the env creation happens only once now! Now, the only task left is to fix the remaining 214 errors 😪 |
186f9e2 to
d974efa
Compare
No, it can't run just once.
The env creation now happens per file instead of the initial per file per code block setup. So, it now takes around a min. Refer #d974efa. |
|
This is a very useful rule 🙌 |
I think we should just ignore the internal types. Many will eventually be exposed and then they can be fixed then.
👍
Doesn't ESLint cache things? Maybe something is not working with the cache. Alternatively, we could only run this rule in CI. |
My bad, I didn't mean types within the Lines 82 to 93 in 72f491f
But, I guess it's fine to not lint those codeblocks, because those are anyways not publicly accessible. I'll update this.
Umm… not too sure about this. Is there some built-in caching that ESLint does?
Umm...but it's fast enough in the editor (refer the video in #1265 (comment)). It only takes time when it has to lint all files together. |


This PR introduces a lint rule that extracts example code blocks from JSDoc comments and validates them using
@typescript/vfs. It then reports any errors at their corresponding locations.The errors and their locations are identical to normal TS errors, so the experience feels just like editing a regular TS file.
The lint rule surfaced around 400 errors, so this PR also fixes/improves multiple JSDoc code examples. Some common errors that it catches:
Missing

importstatementsFloating examples

References to hypothetical functions/variables

Duplicate identifiers

Syntax errors
