Skip to content

fix: allow typedef returns that may be void#1699

Merged
brettz9 merged 4 commits into
gajus:mainfrom
StantonMatt:codex/require-returns-typedef-void
Jun 6, 2026
Merged

fix: allow typedef returns that may be void#1699
brettz9 merged 4 commits into
gajus:mainfrom
StantonMatt:codex/require-returns-typedef-void

Conversation

@StantonMatt

@StantonMatt StantonMatt commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Fixes #1390.

This updates require-returns-check so a @returns tag whose type resolves to a same-file @typedef is treated as potentially undefined when that typedef includes void or undefined. That prevents the rule from reporting a missing return expression for patterns like:

/**
 * @typedef {{ loadTime: number; runTime: number; totalTime: number } | void} PerfResult
 * @returns {PerfResult}
 */

I also added generated docs coverage for the new valid case.

Verification:

  • pnpm run test-index --rule require-returns-check
  • pnpm exec eslint src/rules/requireReturnsCheck.js test/rules/assertions/requireReturnsCheck.js
  • pnpm run tsc
  • pnpm run check-docs
  • pnpm run build
  • git diff --check

@brettz9

brettz9 commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator

Thank you for this PR. However, I'm not sure how common it is that the typedef would be defined on the block itself. I was hoping any PR could search the document for typedefs (as does jsdoc/no-undefined-types. That may get complicated, but it would catch other typedefs within the same document...

Signed-off-by: Matthew Stanton <stantonmatthewj@gmail.com>
@StantonMatt StantonMatt force-pushed the codex/require-returns-typedef-void branch from c54051f to 99dfe01 Compare June 4, 2026 00:15
@StantonMatt

StantonMatt commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

Updated in 99dfe01b. The rule now scans the source file's JSDoc comments for typedef-defining tags using the same filtering shape as no-undefined-types, so typedefs before or after the function comment are considered.

I added coverage for separate-block typedefs before and after the function, plus a non-void typedef case that still reports. Local checks: pnpm build, pnpm lint, and pnpm test (3118 passing). The fork workflow was still approval-gated when I pushed the update.

@brettz9

brettz9 commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator

Thanks! This looks good, but may take me maybe a few days to get to it to review.

Signed-off-by: Matthew Stanton <stantonmatthewj@gmail.com>

@brettz9 brettz9 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looking good.

See the comments. My example code needs to be tested--just what I think it will probably look like.

Comment thread test/rules/assertions/requireReturnsCheck.js
Comment thread src/rules/requireReturnsCheck.js
Comment thread src/rules/requireReturnsCheck.js
Signed-off-by: Matthew Stanton <stantonmatthewj@gmail.com>
@StantonMatt

StantonMatt commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by the later 839ae3ef update below; editing this earlier note to avoid leaving a stale head SHA in the thread. The current PR head is 839ae3ef, and the GitHub workflow is green across Build, Lint, and the three Node/ESLint test jobs.

Signed-off-by: Matthew Stanton <stantonmatthewj@gmail.com>
@StantonMatt StantonMatt force-pushed the codex/require-returns-typedef-void branch from 932470e to 839ae3e Compare June 4, 2026 10:34
@StantonMatt

Copy link
Copy Markdown
Contributor Author

Updated in 839ae3ef.

  • moved the document-wide namepath/typedef scan into jsdocUtils and reused it from no-undefined-types
  • changed require-returns-check to parse/traverse the return type so typedef references in unions, return-level void/undefined, and parenthesized cases are handled
  • dropped the explicit TypeScript settings from the new fixtures and synced the generated docs examples

Local checks: focused require-returns-check and no-undefined-types suites, pnpm test, pnpm run build, and pnpm run lint.

GitHub checks are also green on the pushed head: Build, Lint, and the three Test matrix jobs.

@brettz9 brettz9 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looking very good to me, thanks!

@brettz9 brettz9 merged commit 319e84b into gajus:main Jun 6, 2026
5 checks passed
@github-actions

github-actions Bot commented Jun 6, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 63.0.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[require-returns-check] false postive with a typedef with a union including void

2 participants