Skip to content

Conversation

@som-sm
Copy link
Collaborator

@som-sm som-sm commented Nov 20, 2025

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 interface instead of type
    image

  • Incosistent spacing
    image

  • Incorrect quotes
    image

  • Use of T[] for non-simple types.

    image
  • Missing semicolon
    image

  • Use of spaces instead of tabs

    image

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.

@som-sm som-sm force-pushed the feat/lint-jsdoc-codeblocks branch from bd88f98 to e2b0e03 Compare November 20, 2025 14:06
@som-sm som-sm force-pushed the feat/lint-jsdoc-codeblocks branch from 883dc5c to b7695d7 Compare November 20, 2025 14:50
@som-sm som-sm force-pushed the feat/lint-jsdoc-codeblocks branch from 3c54c0c to 61ef5f3 Compare November 20, 2025 15:50
Repository owner deleted a comment from claude bot Nov 26, 2025
Repository owner deleted a comment from claude bot Nov 26, 2025
Repository owner deleted a comment from claude bot Nov 26, 2025
Repository owner deleted a comment from claude bot Nov 26, 2025
Repository owner deleted a comment from claude bot Nov 26, 2025
Repository owner deleted a comment from claude bot Nov 26, 2025
Repository owner deleted a comment from claude bot Nov 26, 2025
Repository owner deleted a comment from claude bot Nov 26, 2025
Repository owner deleted a comment from claude bot Nov 26, 2025
Repository owner deleted a comment from claude bot Nov 26, 2025
- run: npm install
- run: npm install typescript@${{ matrix.typescript-version }}
- run: npx tsc
- run: NODE_OPTIONS="--max-old-space-size=5120" npx tsc
Copy link
Collaborator Author

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 # 839

If 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 # 514

Copy link
Collaborator Author

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);
Copy link
Collaborator Author

@som-sm som-sm Nov 27, 2025

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.

Copy link
Collaborator Author

@som-sm som-sm left a 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.

Repository owner deleted a comment from claude bot Nov 27, 2025
@som-sm som-sm marked this pull request as ready for review November 27, 2025 11:07
@som-sm
Copy link
Collaborator Author

som-sm commented Nov 27, 2025

@sindresorhus This PR is ready for review now!

  • All the changes within the source directory are inside JSDoc example codeblocks only. Most of these changes were auto-fixable, and the ones that weren't are captured separately in this commit.
  • Unlike the validate-codeblocks lint rule, this processor applies the lint rules to all JSDoc codeblocks, not just the exported ones. This seems fine and makes sense, since it's nice to catch lint errors even in non-exported JSDoc codeblocks.

@som-sm som-sm requested a review from sindresorhus November 27, 2025 11:09
@sindresorhus sindresorhus merged commit 2702882 into main Nov 29, 2025
6 checks passed
@sindresorhus sindresorhus deleted the feat/lint-jsdoc-codeblocks branch November 29, 2025 21:44
@sindresorhus
Copy link
Owner

Yay! So nice to have this automatically enforced too 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants