fix(useAwaitThenable): treat unresolved call expressions as uninferred#8997
Conversation
TypeofExpression types that survive the flattening phase represent type computations that could not be resolved (e.g., cross-module function calls to Node.js builtins or npm packages). These should not be treated as "inferred" since their actual type is unknown. Added Self::TypeofExpression(_) => false to TypeData::is_inferred() to prevent false positives on unresolvable call expressions. Fixes biomejs#8476
🦋 Changeset detectedLatest commit: e9a1657 The changes in this PR will be included in the next version bump. This PR includes changesets to release 13 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
WalkthroughThis patch fixes false positives in the Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 3 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Merging this PR will not alter performance
Comparing Footnotes
|
Summary
Fixes #8476.
useAwaitThenablereports false positives whenawaitis used on call expressions whose return type cannot be resolved — e.g.,await fsPromises.readFile(...),await response.json(), or any cross-module call where the callee type comes from an external module (Node.js builtins, npm packages).The root cause is in
TypeData::is_inferred(). Call expressions are stored asTypeofExpression(Call { ... })during local inference. When the flattening phase cannot resolve the callee (because Biome doesn't parse.d.tsfromnode_modules), theTypeofExpressionsurvives unflattened.is_inferred()returnstruefor these via the_ => truecatch-all, so the rule fires:ty.is_inferred() && !ty.is_promise_instance()→true && true→ false positive.This PR adds
Self::TypeofExpression(_) => falsetois_inferred(). UnflattenedTypeofExpressiontypes represent failed type computations — their actual type is unknown, so they should not be considered "inferred."Changes
type_data.rs: AddedSelf::TypeofExpression(_) => falsetoTypeData::is_inferred()valid.js: Added test cases for cross-module calls (import fs from "node:fs/promises", external packages)Test Plan
cargo test -p biome_js_analyze -- use_await_thenable— bothvalid_jsandinvalid_jspassChildProcess, notPromise) still correctly caughtDocs
No documentation changes needed — this is a bug fix to an existing nursery rule.
This PR was written with the assistance of Claude Code.