prefer-number-isnan: autofix provably numeric calls, keep cautionary suggestion for unknown inputs#45064
Conversation
… args Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds safe autofixes for global isNaN calls with apparently numeric arguments while retaining suggestions for unknown inputs.
Changes:
- Detects numeric argument patterns and enables autofixes.
- Splits diagnostics between autofix and cautionary paths.
- Expands rule tests for both paths.
Show a summary per file
| File | Description |
|---|---|
prefer-number-isnan.ts |
Adds numeric detection, messages, and autofixing. |
prefer-number-isnan.test.ts |
Tests autofix and suggestion-only behavior. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 3
- Review effort level: Medium
| const isDirectAccess = !node.computed && property.type === "Identifier" && (property.name === "getTime" || property.name === "getTimezoneOffset" || property.name === "valueOf"); | ||
| const isComputedAccess = node.computed && property.type === "Literal" && (property.value === "getTime" || property.value === "getTimezoneOffset" || property.value === "valueOf"); |
There was a problem hiding this comment.
Fixed in 37862f6: isNumericMethod is removed entirely. Arbitrary member calls (including getTime, valueOf, etc.) now always fall through to the suggestion-only path — no scope-analysis of the receiver is attempted.
| if (node.callee.type === "Identifier" && (node.callee.name === "parseInt" || node.callee.name === "parseFloat" || node.callee.name === "Number")) { | ||
| return true; | ||
| } | ||
|
|
||
| if (node.callee.type === "MemberExpression" && (isNumberParseMethod(node.callee) || isNumericMethod(node.callee))) { | ||
| return true; | ||
| } |
There was a problem hiding this comment.
Fixed in 37862f6: isProvablyNumericArgument now calls hasLocalBinding(node, name) for each of parseInt, parseFloat, and Number before treating the call as provably numeric. A local shadow causes the call to fall through to suggestion-only.
| } | ||
|
|
||
| function report(node: TSESTree.CallExpression): void { | ||
| const hasSingleProvablyNumericArgument = node.arguments.length === 1 && isProvablyNumericArgument(node.arguments[0]); |
There was a problem hiding this comment.
Fixed in 37862f6: report now guards the autofix path with !hasLocalBinding(node, "Number"). When Number is locally bound, the call falls through to the coercion-caveat suggestion path instead.
|
Hey The PR is well-scoped, includes updated tests covering the new autofix cases and the preserve-suggestion path, and the description clearly explains the motivation and mechanics. This looks ready for review! 🚀
|
|
@copilot please run the Run: https://github.com/github/gh-aw/actions/runs/29192100649
|
…l autofix in prefer-number-isnan Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Addressed all three review threads in 37862f6:
Tests updated: removed the |
🤖 PR Triage
CI status unknown. Moderate change (+133/-17). Batch with other eslint/linter rule PRs for review.
|
|
@copilot please run the
Run: https://github.com/github/gh-aw/actions/runs/29197331019
|
All three review threads were already resolved in commit
All three review threads are now marked outdated by GitHub because the lines they pointed to were changed. The threads can be dismissed in the GitHub UI. All 208 unit tests pass locally. |
|
@copilot please run the Run: https://github.com/github/gh-aw/actions/runs/29199165277
|
Actions taken: No code changes needed this iteration; all review feedback was already addressed in the previous commit. |
|
@copilot please run the
|
All three threads were addressed in
All 208 unit tests pass locally. The threads are marked |
|
\n@copilot please run the skill, address any unresolved review feedback, and rerun checks once the branch is up to date.
|
|
@copilot please run the
|
No action needed. All review feedback was addressed in
All 208 unit tests pass locally. The three review threads are marked outdated by GitHub — a maintainer needs to dismiss them in the GitHub UI. PR is
No action needed. All review feedback was addressed in
All 208 unit tests pass locally. The three review threads are marked outdated by GitHub — a maintainer needs to dismiss them in the GitHub UI. PR is |
|
@copilot please run the
|
All review feedback was addressed in
No further action is possible from the agent. This PR is ready for a maintainer to dismiss the outdated threads and merge. |
prefer-number-isnantreated allisNaN(...)calls as equally risky, so it always emitted a caveated suggestion even when the argument was already numeric. This change splits safe numeric cases from unknown-input cases so diagnostics and fix behavior match real semantics.Rule behavior: branch by argument certainty
parseInt(...),parseFloat(...),Number(...)Number.parseInt(...),Number.parseFloat(...)getTime,getTimezoneOffset,valueOf)fix) toNumber.isNaN(...).Diagnostics/messages
Tests
isNaN(parseInt(value, 10))isNaN(parseFloat(value))isNaN(d.getTime())isNaN(process.env.PORT)) as suggest-only with caveat.