Skip to content

prefer-number-isnan: autofix for provably-numeric args, drop misleading caveat#43515

Closed
pelikhan with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-prefer-number-isnan-rule
Closed

prefer-number-isnan: autofix for provably-numeric args, drop misleading caveat#43515
pelikhan with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-prefer-number-isnan-rule

Conversation

Copilot AI commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

The rule always emitted a suggest-only fix with a "review whether to wrap with Number(...)" caveat — but every one of the 51 live isNaN() call sites in actions/setup/js passes an already-numeric argument (parseInt(...), parseFloat(...), Date#getTime(), etc.), making that caveat wrong and the replacement un---fix-able.

Rule changes

  • isProvablyNumeric(arg) — new helper that returns true for: calls to parseInt / parseFloat / Number / Number.parseInt / Number.parseFloat; method calls to getTime / getTimezoneOffset / valueOf; numeric literals.
  • report() now branches on isProvablyNumeric:
    • Provably-numeric → real fix (applied by --fix), no caveat message.
    • Unknown arg → unchanged suggest-only + "review whether to wrap with Number(...)" caveat.
  • Added fixable: "code" to rule meta.

Behavior comparison

// Before: suggest-only, misleading "review Number(...)" caveat on every case
isNaN(parseInt(x, 10));   // ← manual suggestion only
isNaN(process.env.PORT);  // ← manual suggestion only

// After: autofix for proven-numeric, suggest-only preserved for unknown args
isNaN(parseInt(x, 10));   // ← auto-fixed to Number.isNaN(parseInt(x, 10))
isNaN(process.env.PORT);  // ← unchanged: suggest-only + caveat

Tests

Added a new test group with 9 invalid cases covering every provably-numeric pattern, each asserting the output after autofix. Existing suggestion-only cases are unchanged.


Generated by 👨‍🍳 PR Sous Chef · 8.37 AIC · ⌖ 7.92 AIC · ⊞ 3.7K ·
Comment /souschef to run again

- Add isProvablyNumeric() to detect parseInt/parseFloat/Number/
  Number.parseInt/Number.parseFloat calls, getTime/getTimezoneOffset/
  valueOf method calls, and numeric literals as provably-numeric args
- Add fixable: "code" to rule meta so --fix can apply the replacement
- Branch report(): provably-numeric → real fix (no misleading caveat);
  unknown arg → unchanged suggest-only + "review Number(...)" caveat
- Add 9 test cases asserting autofix output for all provably-numeric
  patterns; existing suggestion-only tests unchanged

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix misleading caveat in prefer-number-isnan rule prefer-number-isnan: autofix for provably-numeric args, drop misleading caveat Jul 5, 2026
Copilot AI requested a review from pelikhan July 5, 2026 09:34
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Hey @Copilot 👋 — great work on the prefer-number-isnan rule improvement! The isProvablyNumeric helper is an elegant solution for distinguishing call sites where an autofix is unambiguously safe from those that require human judgment.

This PR ticks all the boxes: the implementation is tightly scoped to a single rule, test coverage spans every provably-numeric pattern the helper recognises (9 new invalid cases each asserting post-autofix output), existing suggest-only behaviour is preserved, and the PR description clearly explains the motivation and before/after semantics. Looks ready for review! 🎉

Generated by ✅ Contribution Check · 364.6 AIC · ⌖ 23.4 AIC · ⊞ 6.2K ·

@pelikhan pelikhan marked this pull request as ready for review July 5, 2026 10:19
Copilot AI review requested due to automatic review settings July 5, 2026 10:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the prefer-number-isnan ESLint rule to provide a true autofix (--fix) when the argument to isNaN(...) is deemed “provably numeric”, while keeping suggestion-only behavior (with the existing caveat message) for unknown inputs.

Changes:

  • Added fixable: "code" and a new isProvablyNumeric(...) helper to decide when an autofix is safe.
  • Split report() behavior: autofix for “provably numeric” args; suggestions-only for everything else.
  • Added a new test block asserting autofix outputs for several “provably numeric” patterns.
Show a summary per file
File Description
eslint-factory/src/rules/prefer-number-isnan.ts Adds provably-numeric detection and enables real autofixes for certain isNaN(...) call sites.
eslint-factory/src/rules/prefer-number-isnan.test.ts Adds invalid cases asserting the new autofix outputs for provably-numeric argument patterns.

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: Low

Comment on lines +77 to +91
// parseInt(x), parseFloat(x), Number(x)
if (callee.type === "Identifier" && NUMERIC_CALL_NAMES.has(callee.name)) {
return true;
}
// Number.parseInt(x), Number.parseFloat(x)
if (
callee.type === "MemberExpression" &&
!callee.computed &&
callee.object.type === "Identifier" &&
callee.object.name === "Number" &&
callee.property.type === "Identifier" &&
(callee.property.name === "parseInt" || callee.property.name === "parseFloat")
) {
return true;
}
Comment on lines +92 to +95
// x.getTime(), x.getTimezoneOffset(), x.valueOf()
if (callee.type === "MemberExpression" && !callee.computed && callee.property.type === "Identifier" && NUMERIC_METHOD_NAMES.has(callee.property.name)) {
return true;
}
Comment on lines +134 to +149
// Date method results
{
code: `isNaN(d.getTime());`,
output: `Number.isNaN(d.getTime());`,
errors: [{ messageId: "preferNumberIsNaN" }],
},
{
code: `isNaN(d.getTimezoneOffset());`,
output: `Number.isNaN(d.getTimezoneOffset());`,
errors: [{ messageId: "preferNumberIsNaN" }],
},
{
code: `isNaN(x.valueOf());`,
output: `Number.isNaN(x.valueOf());`,
errors: [{ messageId: "preferNumberIsNaN" }],
},
@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot please run the pr-finisher skill, address any unresolved review feedback, ensure the branch is up to date with the base branch, and rerun checks.

Generated by 👨‍🍳 PR Sous Chef · 8.37 AIC · ⌖ 7.92 AIC · ⊞ 3.7K ·
Comment /souschef to run again

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>

Copilot AI commented Jul 5, 2026

Copy link
Copy Markdown
Contributor Author

@copilot please run the pr-finisher skill, address any unresolved review feedback, ensure the branch is up to date with the base branch, and rerun checks.

...

Addressed unresolved review feedback in 308d3b1.

  • Tightened prefer-number-isnan autofix safety: provably-numeric now requires unshadowed global parseInt/parseFloat/Number bindings.
  • Removed method-name-based autofix assumptions (getTime/getTimezoneOffset/valueOf) so those remain suggestion-only.
  • Updated tests accordingly, including shadowed-binding suggestion-only coverage.

I also fetched origin/main and confirmed this branch is not behind base. I reran local checks (make fmt, make lint, rule tests, make recompile; make test-unit/make test still show the same pre-existing TestPRSousChefWorkflowAddCommentTargetContract failure). CI on this new head will need a maintainer-triggered rerun.

Copilot AI requested a review from gh-aw-bot July 5, 2026 12:17
@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

🤖 PR Triage — Run §28741077056

Field Value
Category bug
Risk 🟢 Low
Priority Score 40/100 — impact:20 urgency:8 quality:12
Action 📦 batch_review
Batch pr-batch:eslint-isnan

Rationale: Promotes prefer-number-isnan from suggest-only to autofixable for provably-numeric args. Review together with #43500 (ESM import shadow companion fix). 1× COMMENTED only.

Generated by 🔧 PR Triage Agent · 91.2 AIC · ⌖ 11.9 AIC · ⊞ 5.5K ·

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot please run the pr-finisher skill, address unresolved review comments, and rerun checks once the branch is up to date.

Generated by 👨‍🍳 PR Sous Chef · 8.12 AIC · ⌖ 9.29 AIC · ⊞ 3.7K ·
Comment /souschef to run again

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

Projects

None yet

4 participants