Skip to content

fix(queries): allow complex types in type linking regex#814

Merged
avivkeller merged 3 commits into
nodejs:mainfrom
moshams272:fix/allow-generics-in-queries
Jun 2, 2026
Merged

fix(queries): allow complex types in type linking regex#814
avivkeller merged 3 commits into
nodejs:mainfrom
moshams272:fix/allow-generics-in-queries

Conversation

@moshams272

Copy link
Copy Markdown
Contributor

Description

Currently, doc-kit fails to parse and link complex JSDoc types that contain generics, unions and arrow functions.

This happens because the regex in src/utils/queries/index.mjs uses [^<({})>]+, which excludes <, >, (, and ). When the parser encounters these characters, it ignores the entire type block, leaving it unlinked and sometimes causing Markdown parsers (Remark) to see them as HTML tags.

This PR updates the regex exclusion list to [^{}]+.

Validation

Before:
Screenshot from 2026-05-30 15-13-38

After:
Screenshot from 2026-05-30 15-19-35

Related Issues

No related one.

Check List

  • I have read the Contributing Guidelines and made commit messages that follow the guideline.
  • I have run node --run test and all tests passed.
  • I have check code formatting with node --run format & node --run lint.
  • I've covered new added functionality with unit tests if necessary.

@moshams272 moshams272 requested a review from a team as a code owner May 30, 2026 12:29
@vercel

vercel Bot commented May 30, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
api-docs-tooling Ready Ready Preview May 31, 2026 8:08am

Request Review

@cursor

cursor Bot commented May 30, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Small, targeted regex change in doc parsing with new unit tests; possible edge cases around nested {} but scope is limited to type reference matching.

Overview
Fixes JSDoc/API type detection and linking for generics, unions, and parenthesized types by relaxing two regexes in src/utils/queries/index.mjs: normalizeTypes and linksWithTypes now allow <, >, (, and ) inside a type span and only stop at {/} delimiters ([^{}]+ instead of [^<({})>]+).

Adds unit coverage for those patterns (basic types, Readonly<object>, Map<...>, (string|number), and linked generic/union forms). Release bump to 1.3.7 in package.json / lockfile.

Reviewed by Cursor Bugbot for commit 0179459. Bugbot is set up for automated code reviews on this repo. Configure here.

@codecov

codecov Bot commented May 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.93%. Comparing base (bf76f97) to head (0179459).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #814      +/-   ##
==========================================
+ Coverage   82.86%   82.93%   +0.06%     
==========================================
  Files         171      171              
  Lines       14961    15016      +55     
  Branches     1313     1321       +8     
==========================================
+ Hits        12398    12453      +55     
  Misses       2554     2554              
  Partials        9        9              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@avivkeller avivkeller left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you run npm version patch?

@AugustinMauroy AugustinMauroy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGMT ! is there are test for that ?

Added test coverage for normalizeTypes and linksWithTypes to ensure complex JSDoc types (generics, unions) are matched correctly.
@moshams272

Copy link
Copy Markdown
Contributor Author

LGMT ! is there are test for that ?

I initially relied only on screenshots to show it works, but u r right.

@avivkeller avivkeller merged commit 90a908e into nodejs:main Jun 2, 2026
20 of 21 checks passed
@moshams272 moshams272 deleted the fix/allow-generics-in-queries branch June 2, 2026 12:25
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