feat(eslint-factory): add require-nan-check-after-env-numeric-parse rule - #49962
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
require-nan-check-after-env-numeric-parse rule to ESLint|
@copilot merge main and recompile |
…add-require-nan-check-rule Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Done — merged main and recompiled all 269 workflows (269 succeeded). |
There was a problem hiding this comment.
Pull request overview
Adds an ESLint rule warning when numeric process.env parsing lacks NaN validation.
Changes:
- Implements and tests env numeric-parse detection.
- Registers, enables, and documents the rule.
- Unintentionally removes an agentic-workflow guidance entry.
Show a summary per file
| File | Description |
|---|---|
eslint-factory/src/rules/require-nan-check-after-env-numeric-parse.ts |
Implements detection and validation tracking. |
eslint-factory/src/rules/require-nan-check-after-env-numeric-parse.test.ts |
Adds rule tests. |
eslint-factory/src/index.ts |
Registers the rule. |
eslint-factory/eslint.config.cjs |
Enables the rule as a warning. |
eslint-factory/README.md |
Documents the rule. |
.github/skills/agentic-workflows/SKILL.md |
Removes an unrelated guidance entry. |
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:116
- The rule keys declarations and validations only by identifier text, so distinct bindings are conflated and same-named declarations overwrite each other. For example,
Number.isNaN(count)in one function suppresses an unvalidatedcountparsed in another function. Track the ESLint variable/binding identity and resolve each validation argument to that binding instead.
unvalidated.set(node.id.name, node);
eslint-factory/src/rules/require-nan-check-after-env-numeric-parse.ts:102
- A locally defined
isNaN(or localNumberobject below) is accepted as validation solely by name. A no-op helper such asconst isNaN = () => falsetherefore suppresses the warning even though the parsed value was never checked by the intended built-in. Require these validator callees to resolve to unshadowed globals.
// Global isNaN(x)
if (callee.type === "Identifier" && callee.name === "isNaN") {
return true;
- Files reviewed: 6/6 changed files
- Comments generated: 2
- Review effort level: Balanced
| @@ -71,7 +71,6 @@ Load these files from `github/gh-aw` (they are not available locally). | |||
| - `.github/aw/test-coverage.md` | |||
| - `.github/aw/test-expression.md` | |||
| - `.github/aw/token-optimization-caching-budgets.md` | |||
| // Global parseInt(envExpr, ...) or parseFloat(envExpr) | ||
| if (callee.type === "Identifier" && (callee.name === "parseInt" || callee.name === "parseFloat")) { |
🔍 PR TriageCategory: feature · Risk: low · Total score: 50/100
New eslint-factory rule ( Recommended action:
|
parseInt/parseFloat/Number()silently returnNaNfor malformedprocess.envinput. Without an explicitNumber.isNaN()/isNaN()guard, thatNaNpropagates into rate-limit thresholds, timeouts, loop bounds, and API payloads with no error surfacing. Scanningactions/setup/jsfound 12 unguarded occurrences across 9 files.New rule:
require-nan-check-after-env-numeric-parseparseInt,parseFloat,Number.parseInt,Number.parseFloat, andNumber()calls whose first argument traces back toprocess.env, when the assigned variable is never passed toisNaN()/Number.isNaN()process.env.FOO), logical fallbacks (|| / ??), optional chaining (?.trim()), ternaryisNaN(x)orNumber.isNaN(x)call with the variable as sole argument anywhere in the file scopewarnineslint.config.cjsFiles
src/rules/require-nan-check-after-env-numeric-parse.ts— rule implementationsrc/rules/require-nan-check-after-env-numeric-parse.test.ts— 22 unit testssrc/index.ts— rule registrationeslint.config.cjs— enabled aswarnREADME.md— rule documented