Skip to content

Ignore import() in JSDoc examples#1844

Merged
webpro merged 2 commits into
webpro-nl:mainfrom
cyphercodes:fix-jsdoc-example-import
Jul 1, 2026
Merged

Ignore import() in JSDoc examples#1844
webpro merged 2 commits into
webpro-nl:mainfrom
cyphercodes:fix-jsdoc-example-import

Conversation

@cyphercodes

Copy link
Copy Markdown
Contributor

Summary

  • Restrict JSDoc import() extraction to type-expression tags so code shown in @example blocks is not analyzed as a real import.
  • Add fixture coverage for an object-literal @example containing import('./Foo').

Fixes #1842

Tests

  • pnpm exec oxfmt --check packages/knip/src/typescript/comments.ts packages/knip/test/language/jsdoc.test.ts packages/knip/fixtures/language/jsdoc/index.ts
  • pnpm exec oxlint packages/knip/src/typescript/comments.ts packages/knip/test/language/jsdoc.test.ts packages/knip/fixtures/language/jsdoc/index.ts
  • node --test test/language/jsdoc.test.ts test/language/svelte-script-jsdoc-import.test.ts
  • pnpm build
  • node packages/knip/src/cli.ts --directory /tmp/oss-pr-pipeline/repro-jsdoc --include unresolved --reporter compact

@pkg-pr-new

pkg-pr-new Bot commented Jul 1, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/knip@1844
npm i https://pkg.pr.new/@knip/language-server@1844
npm i https://pkg.pr.new/@knip/mcp@1844

commit: f8ed26a

@const, @constant, @member, @var, @namespace and @module also hold type
expressions, so keep extracting import() specifiers from them.
@webpro

webpro commented Jul 1, 2026

Copy link
Copy Markdown
Member

Thanks Rayan!

@webpro
webpro merged commit 6f090f9 into webpro-nl:main Jul 1, 2026
27 of 30 checks passed
@webpro

webpro commented Jul 2, 2026

Copy link
Copy Markdown
Member

🚀 This pull request is included in v6.24.0. See Release 6.24.0 for release notes.

Using Knip in a commercial project? Please consider becoming a sponsor.

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.

🐛 import() inside a JSDoc @example comment is reported as an unresolved import

2 participants