Repository navigation
Conversation
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Peli de Halleux <pelikhan@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
The rule incorrectly accepts guards in nested functions and strict undefined comparisons as null protection, suppressing valid warnings for code that can throw on null.
2 open issues
What changed in this PR
Adds a custom ESLint rule to detect object-type checks that lack null guards, helping prevent null-related failures in actions/setup/js.
Changes:
- Implements detection for
typeofobject comparisons and nearby null or truthiness checks. - Registers the rule and enables it at warning level.
- Adds rule tests and documentation with usage examples.
| File | Description |
|---|---|
eslint-factory/src/rules/require-null-check-with-typeof-object.ts |
Implements comparison detection and guard matching. |
eslint-factory/src/rules/require-null-check-with-typeof-object.test.ts |
Tests flagged comparisons and accepted guards. |
eslint-factory/src/index.ts |
Registers the rule in the plugin. |
eslint-factory/README.md |
Documents the rule and examples. |
eslint-factory/eslint.config.cjs |
Enables the rule as a warning. |
Review effort: Balanced (auto)
| if (node.type === AST_NODE_TYPES.BinaryExpression && EQUALITY_OPERATORS.has(node.operator)) { | ||
| const other = isNullish(node.right) ? node.left : isNullish(node.left) ? node.right : null; | ||
| return other !== null && subjectText(other) === text; | ||
| } |
There was a problem hiding this comment.
Fixed in 8344ab8: strict undefined comparisons no longer count as null guards; only loose ==/!= against undefined do. Added regression coverage and clarified the README.
| const stack: TSESTree.Node[] = [root]; | ||
| while (stack.length > 0) { | ||
| const node = stack.pop()!; | ||
| if (node === skip) continue; |
There was a problem hiding this comment.
Fixed in 8344ab8: earlier guards are limited to top-level early-exit checks in the nearest function, so nested-function guards cannot suppress the outer report. Added the regression case.
|
✅ Test Quality Sentinel completed test quality analysis. Test Quality SentinelOutcome: The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
|
✅ Design Decision Gate 🏗️ completed the design decision gate check. See the comment below for the result and any generated ADR draft. Design Decision Gate 🏗️Outcome: The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
|
✅ PR Code Quality Reviewer completed the code quality review. PR Code Quality ReviewerOutcome: The agent completed and reported one or more actions. The no-op output is a completion signal, not a claim that no action was taken. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
|
🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅ Matt Pocock Skills ReviewerOutcome: The agent completed and reported one or more actions. The no-op output is a completion signal, not a claim that no action was taken. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
|
✅ Ponytail Reviewer completed successfully! Ponytail ReviewerOutcome: The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
Comment MemoryPeek at saved memory (pr-code-quality-reviewer)Note This comment is managed by comment memory.Expand the saved memory block to view or edit the persistent context for this thread.
|
There was a problem hiding this comment.
Found three correctness issues in the new rule: it warns on typeof x !== "object" even though that predicate excludes null, treats arbitrary logical-expression operands as null guards, and lets unrelated earlier module-scope guards suppress findings. The inline comments describe each case and requested regression coverage.
🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~3 AIC · ⌖ ~1 AIC · ⊞ 1.6K
Comment /review to run again
|
|
||
| /** Matches `typeof <subject> <op> "object"` in either operand order. */ | ||
| function matchTypeofObject(node: TSESTree.BinaryExpression): { text: string; operator: string } | null { | ||
| if (!EQUALITY_OPERATORS.has(node.operator)) return null; |
There was a problem hiding this comment.
!==/!= are safe for this specific null concern: since typeof null === "object", typeof value !== "object" is false when value is null, so null cannot pass this condition. Requiring a null guard here creates false-positive warnings for a predicate that already excludes null. Please restrict this rule to ===/== (or otherwise handle the inequality semantics), and add a regression test for typeof value !== "object".
There was a problem hiding this comment.
Fixed in 8344ab8: the rule now reports only typeof value === "object" and ==; !==/!= comparisons are excluded and covered by tests.
|
|
||
| const guard = (candidate: TSESTree.Node) => isNullGuard(candidate, match.text); | ||
| if (someNode(outermostLogicalChain(node), node, Infinity, guard)) return; | ||
| if (someNode(enclosingFunctionOrProgram(node), node, node.range[0], guard)) return; |
There was a problem hiding this comment.
At module scope this searches the entire prefix of Program, so an unrelated earlier guard can suppress a later warning. For example, function helper(x) { if (x) return; } followed by const ok = typeof x === "object"; is treated as guarded even though the helper never establishes anything about the later x (and the same name may be a different binding). This contradicts the documented same-function scope. Please avoid using the whole Program as the earlier-guard scope, or use scope/binding-aware analysis.
There was a problem hiding this comment.
Fixed in 8344ab8: module scope is no longer searched for earlier guards. Only a nullish early-exit in the nearest function can suppress a later report; added a module-scope regression.
| if (subjectText(node) !== text) return false; | ||
| const parent = node.parent; | ||
| if (!parent) return false; | ||
| if (parent.type === AST_NODE_TYPES.LogicalExpression) return true; |
There was a problem hiding this comment.
This treats any direct child of a logical expression as a null guard, including the value operand in const result = condition && value;. That expression does not establish that value is non-null; condition may be true while value is null, and a later typeof value === "object" can still pass before property access. Restrict suppression to a condition that actually tests the subject (for example the left operand in a short-circuit guard), and add a regression case for value-position operands.
There was a problem hiding this comment.
Fixed in 8344ab8: suppression now requires a subject-specific guard in a conjunction; unrelated logical operands no longer count. Added the value-position regression, and OR expressions are not treated as null guards.
There was a problem hiding this comment.
Skills-Based Review 🧠
Applied /tdd and /grill-with-docs. Requesting changes: the rule has confirmed false negatives, and the null-guard semantics in the code and README do not yet agree.
📋 Key Themes & Highlights
Key Themes
- Guard suppression is too loose:
someNodeaccepts any truthiness or null check in the enclosing function, even when it does not dominate thetypeofsite (inline comment on line 110). Two existing threads (lines 39 and 74) cover the!== undefinedand nested-function cases. - Docs and implementation disagree: the README says "earlier in the same function", which describes the loose behaviour rather than an intended contract. Pick one and make both match.
- Test gaps: the valid cases do not include a non-dominating earlier guard, so the suppression path is untested.
Positive Highlights
- ✅ Clear separation of
matchTypeofObject,isNullGuard, andsomeNode, which keeps the traversal easy to follow. - ✅ Operand-order and optional-chaining handling are covered by tests.
- ✅ Scope is tight: a
warnseverity avoids breaking existing code.
Verification Note
The sandbox could not install eslint-factory dependencies (npm registry TLS error), so I could not run the test suite. Findings come from tracing the code paths, not from executing the tests. Please run the three new cases once they are added.
@copilot please address the review comments above.
🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · routed: haiku55 xhigh · ~6 AIC · ⌖ ~2 AIC · ⊞ 6.6K
Comment /matt to run again
|
|
||
| const guard = (candidate: TSESTree.Node) => isNullGuard(candidate, match.text); | ||
| if (someNode(outermostLogicalChain(node), node, Infinity, guard)) return; | ||
| if (someNode(enclosingFunctionOrProgram(node), node, node.range[0], guard)) return; |
There was a problem hiding this comment.
[/tdd] A truthiness check anywhere earlier in the function suppresses the report, even when it does not gate the typeof site. function f(value) { if (value) log("set"); return typeof value === "object" ? Object.keys(value) : []; } is not flagged, yet value === null still reaches Object.keys(null) and throws.
Either require the guard to dominate the site (for example an early-exit if (!value) return), or document the looser behaviour explicitly in the README. Either way, add a failing test first.
💡 Suggested test
{
code: `function f(value) { if (value) log("set"); return typeof value === "object" ? Object.keys(value) : []; }`,
errors: [{ message: messageFor("value") }],
},The README (around line 1356) currently says "earlier in the same function", which describes the loose behaviour. The docs and implementation should agree on the intended semantics.
@copilot please address this.
There was a problem hiding this comment.
Fixed in 8344ab8: non-dominating truthiness checks no longer suppress reports; earlier guards count only when a top-level if exits on nullish/falsy values. Added the suggested regression and updated the README.
|
@copilot run pr-finisher skill |
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
The finisher pass is complete. Commit |
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
|
🎉 This pull request is included in a new release. Release: |

New rule:
gh-aw-custom/require-null-check-with-typeof-objectFlags
typeof x === "object"(also!==,==,!=) whenxis not also checked for null/undefined/truthiness in the same logical expression or earlier in the same function.typeof null === "object", so a null value passes and later property access throws.Steering issue: #76732 (no
steercomments found).Research evidence
Window: 2026-10-28 to 2026-11-11 (14 days), repo
github/gh-aw.eslint,TypeError actions/setup,unhandled rejection,ENOENT,JSON.parse,setup js failure. No recurring JS/TS runtime failure inactions/setup/jsmatched; only ESLint-miner WIP issues ([WIP] ESLint Miner: work in progress #76732, [WIP] ESLint Miner: work in progress #76113, [WIP] ESLint Miner: work in progress #75588), [aw] Failed jobs: Smoke Built-in Ledgers #75548 (ENOENT, smoke ledgers) and Claim PR/discussion readback fails on fields other actors change within seconds #76460 (claim readback), none of them a lintable pattern.actions/setup/js,eslint-> [repository-quality] Repository Quality: Setup Shell Script & Shell-Out Hardening #75423 (setup shell hardening), [security-red-team] Security Analysis Findings for actions/setup #75255 (security analysis), [eslint-refiner] ESLint Refiner — factory-date 2026-10-28 run #75597, [eslint-refiner] ESLint Refiner — first review of no-path-startswith-without-separator, 0 issues (disciplined pass) #75814, [eslint-refiner] ESLint Refiner run — 2026-11-03 (factory date 2026-10-27) #74387 (eslint-refiner reports). No recurring typeof/null defect reported.actions/setup/js, not from issue evidence.Rationale
The scan found 15 unguarded
typeof ... === "object"sites in non-test.cjsfiles (e.g.pick_experiment.cjs:196/215andload_experiment_state_from_repo.cjs:36/48whereparsed.counts/entry.countsmay benullin a persisted state file;finish_work_queue_claim.cjs:530Object.values(result.claims)on null;report_markdown.cjs:200/320/473;add_reaction_and_edit_comment.cjs:185/198). Not stylistic: null input there yields aTypeErroror silently accepts a corrupt snapshot. No existing rule covers it.Low false-positive design: only identifier/non-computed member-chain subjects; any null/undefined comparison, truthiness test,
Boolean(x),!x, or logical-chain use of the same subject (before or after) suppresses the report, including an earlier guard in the enclosing function. Registered aswarn, so existing code is not made to fail.Changes
eslint-factory/src/rules/require-null-check-with-typeof-object.ts(+ test)src/index.ts, enabled ineslint.config.cjs, documented inREADME.mdValidation (from
eslint-factory)npm ci: exit 0npm run build: exit 0npm test -- src/rules/require-null-check-with-typeof-object.test.ts: 3 passednpm test(full): 78 files / 726 tests passednpm run lint:setup-js: exit 0, 1088 warnings and 0 errors in total; 15 are from the new rule. The rest are pre-existing warnings from other rules.