-
-
Notifications
You must be signed in to change notification settings - Fork 661
Add custom processor to lint JSDoc codeblocks #1300
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
Conversation
bd88f98 to
e2b0e03
Compare
883dc5c to
b7695d7
Compare
3c54c0c to
61ef5f3
Compare
| - run: npm install | ||
| - run: npm install typescript@${{ matrix.typescript-version }} | ||
| - run: npx tsc | ||
| - run: NODE_OPTIONS="--max-old-space-size=5120" npx tsc |
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.
This bump is needed because the number of files in the TS program has increased from 792 to 839. The default limit seems to be 4GB, and increasing it by 1GB works fine.
The extra files come from the new typescript-eslint package added in this PR.
# main
npx tsc --listFilesOnly | wc -l # 792# feat/lint-jsdoc-codeblocks
npx tsc --listFilesOnly | wc -l # 839If this is a problem, we can disable allowJS in tsconfig.json for now, which will bring down the files to 514 and then come back to this separately.
# "allowJS": false
npx tsc --listFilesOnly | wc -l # 514There 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.
This config file is used to lint the test cases. And, this is present inside the repo instead of the temp directory because it needs certain imports.
| } | ||
|
|
||
| const resultsFixed = await eslintFixed.lintFiles([fileName]); | ||
| t.assert.strictEqual(resultsFixed[0].output, output); |
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.
It would have been cleaner if this were done using snapshot testing, it would have moved the outputs to a separate snapshot file. But t.assert.snapshot is not available in Node 20, and we currently run the tests on Node 20.
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.
Added comments wherever I felt it needed some explanation.
|
@sindresorhus This PR is ready for review now!
|
|
Yay! So nice to have this automatically enforced too 🎉 |
A common task when reviewing PRs is manually checking JSDoc codeblocks for issues like missing semicolons, broken indentation, use of double quotes etc. This PR addresses that by adding linting to JSDoc codeblocks. They will now be linted just like our regular TS files, so any lint errors in JSDoc codeblocks will be caught automatically, and auto-fixable errors can be fixed just like regular auto-fixable errors.
demo.mov
Common lint errors:
Use of

interfaceinstead oftypeIncosistent spacing

Incorrect quotes

Use of
T[]for non-simple types.Missing semicolon

Use of spaces instead of tabs
These are just a few examples. Otherwise, all the rules (except the ones explicitly disabled) that apply to our TS source files apply to JSDoc codeblocks as well.