[WIP] Fix false positives in require-nan-check rule - #50556
Conversation
…nv-numeric-parse Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Extends NaN-validation detection for environment-derived numeric parsing.
Changes:
- Recognizes finite checks and direct truthiness guards.
- Updates diagnostics and adds grounded valid-case tests.
Show a summary per file
| File | Description |
|---|---|
require-nan-check-after-env-numeric-parse.ts |
Expands validation detection. |
require-nan-check-after-env-numeric-parse.test.ts |
Tests finite and truthiness guards. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Suppressed comments (2)
eslint-factory/src/rules/require-nan-check-after-env-numeric-parse.ts:131
- Validation is recorded by identifier text rather than by the tracked binding. A truthiness check on a same-named parameter or local in another scope can therefore clear the diagnostic for the parsed value—for example,
const port = parseInt(process.env.PORT, 10); function f(port) { if (port) use(port); } use(port);. Resolve the test identifier to its scope variable/declarator and mark only that tracked binding as validated.
if (expr.type === "Identifier") {
validated.add(expr.name);
eslint-factory/src/rules/require-nan-check-after-env-numeric-parse.ts:113
Number.isFiniteis also accepted whenNumberis a locally shadowed object, so code such asconst Number = { isFinite: () => true }; const n = parseInt(process.env.N, 10); Number.isFinite(n);incorrectly marksnvalidated. RequireNumberto resolve to the unshadowed global before accepting this call.
callee.object.type === "Identifier" &&
callee.object.name === "Number" &&
!callee.computed &&
callee.property.type === "Identifier" &&
(callee.property.name === "isNaN" || callee.property.name === "isFinite")
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Balanced
| // Global isNaN(x) | ||
| if (callee.type === "Identifier" && callee.name === "isNaN") { | ||
| // Global isNaN(x) / isFinite(x) | ||
| if (callee.type === "Identifier" && (callee.name === "isNaN" || callee.name === "isFinite")) { |
|
Great work on fixing the false positives in the This PR successfully extends validation detection to recognize The diff is focused, the tests are comprehensive, and the PR message clearly describes the work done. Ready for merge! ✨ Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
To allow these domains, add them to the network:
allowed:
- defaults
- "patchdiff.githubusercontent.com"See Network Configuration for more information.
|
|
🎉 This pull request is included in a new release. Release: |
Number.isFinite(x)/isFinite(x)as validatingif (x),if (!x), ternary test) on the tracked identifier as validating