Skip to content

fix(linter/react/exhaustive-deps): report setters from parenthesized or as-cast useState calls - #30016

Merged
camc314 merged 1 commit into
mainfrom
codex/exhaustive-deps-use-state-init-wrappers
Nov 22, 2026
Merged

camc314 merged 1 commit into
mainfrom
codex/exhaustive-deps-use-state-init-wrappers

Conversation

@camc314

@camc314 camc314 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

react-hooks/exhaustive-deps misses a useState setter called in an effect without a dependency array when the useState(...) initializer is parenthesized or cast with as. ExhaustiveDepsVisitor::visit_identifier_reference matched the declarator's initializer directly against CallExpression, so (useState(0)) and useState(0) as [...] were never classified as setters.

eslint-plugin-react-hooks 7.1.1 reports both: ESTree has no parenthesized-expression node, and isStableKnownHookValue unwraps as before checking the hook name (ExhaustiveDeps.ts L283). Before #29986, a useReducer dispatch in the same effect hid this miss, because the dispatch was itself reported as a setState call.

Example

Input:

import { useEffect, useState } from "react";

export function Parenthesized() {
  const [, setCount] = (useState(0));
  useEffect(() => {
    setCount(1);
  });
}

export function Cast() {
  const [, setCount] = useState(0) as [number, (value: number) => void];
  useEffect(() => {
    setCount(1);
  });
}

Before output (main, oxlint repro.tsx with .oxlintrc.json enabling react-hooks/exhaustive-deps: warn):

Found 0 warnings and 0 errors.

After output (this PR, same input and options):

  ! react-hooks(exhaustive-deps): React Hook useEffect contains a call to setState. Without a list of dependencies, this can lead to an infinite chain of updates.
   ,-[repro.tsx:5:3]
 4 |   const [, setCount] = (useState(0));
 5 |   useEffect(() => {
   :   ^^^^^^^^^
 6 |     setCount(1);
   `----
  help: Consider adding an empty list of dependencies to make it clear which values are intended to be stable.

  ! react-hooks(exhaustive-deps): React Hook useEffect contains a call to setState. Without a list of dependencies, this can lead to an infinite chain of updates.
    ,-[repro.tsx:12:3]
 11 |   const [, setCount] = useState(0) as [number, (value: number) => void];
 12 |   useEffect(() => {
    :   ^^^^^^^^^
 13 |     setCount(1);
    `----
  help: Consider adding an empty list of dependencies to make it clear which values are intended to be stable.

Found 2 warnings and 0 errors.

ESLint 10.15.0 with eslint-plugin-react-hooks 7.1.1 and @typescript-eslint/parser reports the same two effects ("React Hook useEffect contains a call to 'setCount'. Without a list of dependencies, ...").

…or `as`-cast `useState` calls

Unwrap parentheses and `as` casts around the `useState` initializer when classifying setState calls, matching eslint-plugin-react-hooks.
@camc314
camc314 added this pull request to stack #30018 November 22, 2026 22:09
@github-actions github-actions Bot added the A-linter Area - Linter (oxlint): rules, config, diagnostics, fixes. Add L-* labels for details label Nov 22, 2026
@camc314
camc314 marked this pull request as ready for review November 22, 2026 22:13
Copilot AI balanced review requested due to automatic review settings November 22, 2026 22:13
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-22T22:14:48.164738Z ebe2b91 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@codspeed

codspeed Bot commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 5 untouched benchmarks
⏩ 105 skipped benchmarks1


Comparing codex/exhaustive-deps-use-state-init-wrappers (ebe2b91) with main (1a19370)

Open in CodSpeed

Footnotes

  1. 105 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@camc314
camc314 merged commit 8726fca into main Nov 22, 2026
36 checks passed
@camc314
camc314 deleted the codex/exhaustive-deps-use-state-init-wrappers branch November 22, 2026 22:25
camc314 added a commit that referenced this pull request Nov 22, 2026
…mber expressions (#30017)

## Summary

`react-hooks/exhaustive-deps` misses a `useState` setter called through
a member expression, such as `setCount.call(null, 1)`, in an effect
without a dependency array. `ExhaustiveDepsVisitor` sets
`skip_reporting_dependency` while visiting the object of a member chain,
and `visit_identifier_reference` returned before checking whether that
identifier is a setter.

eslint-plugin-react-hooks 7.1.1 checks every reference in the effect
against `setStateCallSites` ([`ExhaustiveDeps.ts`
L694-L695](https://github.com/react/react/blob/eslint-plugin-react-hooks@7.1.1/packages/eslint-plugin-react-hooks/src/rules/ExhaustiveDeps.ts#L694-L695)),
so it reports this call. Oxlint already reported the computed form,
`setCount["call"](null, 1)`.

### Example

Input:

```jsx
import { useEffect, useState } from "react";

export function Counter() {
  const [, setCount] = useState(0);
  useEffect(() => {
    setCount.call(null, 1);
  });
}
```

Before output (#30016, `oxlint repro.jsx` with `.oxlintrc.json` enabling
`react-hooks/exhaustive-deps: warn`):

```text
Found 0 warnings and 0 errors.
```

After output (this PR, same input and options):

```text
  ! react-hooks(exhaustive-deps): React Hook useEffect contains a call to setState. Without a list of dependencies, this can lead to an infinite chain of updates.
   ,-[repro.jsx:5:3]
 4 |   const [, setCount] = useState(0);
 5 |   useEffect(() => {
   :   ^^^^^^^^^
 6 |     setCount.call(null, 1);
   `----
  help: Consider adding an empty list of dependencies to make it clear which values are intended to be stable.

Found 1 warning and 0 errors.
```

ESLint 10.15.0 with eslint-plugin-react-hooks 7.1.1 reports the same
effect ("React Hook useEffect contains a call to 'setCount'. Without a
list of dependencies, ...").
camc314 added a commit that referenced this pull request Nov 23, 2026
# Oxlint
### 💥 BREAKING CHANGES

- 8c2abc4 diagnostics: [**BREAKING**] Implement `SourceCode` for `&T`
(#29852) (overlookmotel)

### 🚀 Features

- a96e2bd linter/typescript/no-unsafe-class-instance-assignment: Add
rule (#29982) (Cameron)

### 🐛 Bug Fixes

- 11d16bd linter/eslint/prefer-object-spread: Prefix semicolon when the
fix could merge with the previous statement (#30080) (oxc-captain[bot])
- 106d301 linter/unicorn/prefer-math-trunc: Report
`parseInt(String(...), 10)` (#30067) (Lê Văn Xuân Hoàn)
- 226ba04 linter/unicorn/prefer-import-meta-properties: Stop flagging
`fileURLToPath(new URL('.', import.meta.url))` (#30041)
(oxc-captain[bot])
- 04cdaec linter/unicorn/no-useless-spread: Replace holes with
`undefined` in spread array literals (#30042) (oxc-captain[bot])
- 7141c26 linter/eslint/no-implicit-coercion: Skip autofix when coercion
constructor is shadowed (#30043) (oxc-captain[bot])
- f22709d linter/eslint/no-unused-vars: Fixes remove a whole CRLF after
an unused import (#30047) (Nicholas Rayburn)
- 6998259 linter/eslint/max-lines: Report diagnostic at the start of the
last character (#30046) (Nicholas Rayburn)
- 48ed7f7 linter: Find tsgolint in case-sensitive directories on Windows
(#26234) (Nicolas Stepien)
- f92aeab linter/vitest/valid-expect: Validate `expectTypeOf` matcher
chains (#30023) (Cameron)
- 0f774dc linter/react/exhaustive-deps: Report setters accessed through
member expressions (#30017) (Cameron)
- 8726fca linter/react/exhaustive-deps: Report setters from
parenthesized or `as`-cast `useState` calls (#30016) (Cameron)
- 1a19370 linter/eslint/no-extra-boolean-cast: Parenthesize the
replacement when needed (#30012) (Thejesh)
- 4452bb6 linter/eslint/operator-assignment: Parenthesize a conditional
right operand in the "never" fix (#30013) (Thejesh)
- ad91ec9 linter/react/exhaustive-deps: Don't report `useReducer`
dispatches as `setState` calls (#29986) (oxc-captain[bot])
- 589d281 linter/oxc/branches-sharing-code: Skip move suggestions for
branch-local references (#30006) (Cameron)
- 27440dc linter/react/jsx-curly-brace-presence: Don't report or fix
props with escape sequences and preserve raw text (#29976)
(oxc-captain[bot])
- 18d6e27 linter: Escape file and rule names in checkstyle and junit
reporters (#28962) (Zain Qureshi)
- 9882eab linter/unicorn/prefer-bigint-literals: Provide fix for hex
literals containing `e` or `E` (#29915) (overlookmotel)
- 9c39045 linter/eslint/no-unneeded-ternary: Don't drop side-effecting
tests in equal-literal fix (#29880) (oxc-captain[bot])
- 7261f5b linter/unicorn/prefer-logical-operator-over-ternary:
Parenthesize operands that bind looser than `||` in fixer (#29882)
(oxc-captain[bot])
- d4c3cbe linter/typescript/array-type: Report and fix `Readonly<T[]>`
(#29841) (camc314)
- 35694db linter/typescript/explicit-function-return-type: Check
block-bodied arrows in returned objects (#29843) (camc314)
- cf124c8 linter/typescript/prefer-as-const: Report angle-bracket
literal assertions (#29839) (camc314)
- 86cdc9d linter: Do not flag one export { a, b } from as duplicate
(#26992) (Bartok)
- 4263221 agent: Implement all_rules for --rules support (#27585)
(Bartok)
- 2f6a11f semantic: Keep catch parameters in the catch clause scope
(#29635) (Dunqing)
- f84e6b2 linter/import/extensions: Read options next to `pattern`
(#29442) (Nadir Ali)
- a527e7b linter: Preserve code in Jest and Vitest padding fixes
(#29496) (oxc-captain[bot])
- 536e240 linter/unicorn/catch-error-name: Keep the key of a shorthand
property (#28727) (YT)
- f860f1b semantic: Resolve a private name to the enclosing class that
declares it (#29714) (Nadir Ali)
- 279185a react-compiler: Ignore ESLint suppressions when hooks and memo
validations are enabled (#29655) (Boshen)
- ddedec8 linter/eslint/new-cap: Allow `UTC()` only on the global `Date`
(#29711) (Nadir Ali)
- 709d89d linter/eslint/no-async-promise-executor: Ignore shadowed
Promise (#29706) (Nadir Ali)
- 90196a5 linter/eslint/radix: Only report literal and `undefined`
radixes, skip spreads (#29708) (Nadir Ali)
- 0fb527b linter/eslint/no-invalid-regexp: Ignore a shadowed `RegExp`
(#29715) (Nadir Ali)
- 60fedf9 linter/eslint/no-loss-of-precision: Ignore a `.` with no
fraction digits (#29713) (Nadir Ali)
- 4069cb3 linter/eslint/use-isnan: Ignore a shadowed `NaN` or `Number`
(#29707) (Nadir Ali)
- dd9683c linter/eslint/prefer-promise-reject-errors: Ignore a shadowed
`Promise` (#29710) (Nadir Ali)
- d7e12de linter/eslint/no-extra-boolean-cast: Ignore a shadowed
`Boolean` (#29709) (Nadir Ali)
- 1ac8a63 linter/eslint/no-obj-calls: Respect shadowed globalThis
(#29705) (周星星同学)
- 3464a0d linter/eslint/prefer-numeric-literals: Avoid invalid fixes for
signed strings (#29703) (周星星同学)
- d3af621 linter/typescript/class-literal-property-style: Only suggest
readonly fields in TypeScript files (#29704) (Chung-il)
- 49b935a linter/eslint/no-unneeded-ternary: Preserve boolean binary
results (#29702) (周星星同学)
- 3f05c06 linter/react/require-render-return: Check non-JSX render
methods (#29701) (oxc-captain)
- 78b6494 linter/vitest/prefer-called-times: Preserve expect head in
fixes (#29699) (camc314)
- f2cd3c7 linter/jest/prefer-to-contain,linter/vitest/prefer-to-contain:
Offer rewrites as suggestions (#29698) (camc314)
- 3398425 linter/typescript/ban-tslint-comment: Preserve line breaks in
fixes (#29695) (camc314)
- a0214ae linter/eslint/no-unsafe-negation: Offer rewrite as a
suggestion (#29694) (camc314)
- 658762e linter/eslint/no-unexpected-multiline: Recognize all line
terminators (#29682) (周星星同学)
- 89ad201 linter/eslint/no-compare-neg-zero: Exclude BigInt zero
(#29683) (周星星同学)
- 5629d00 linter/eslint/no-unsafe-finally: Report labeled continues
escaping finally (#29681) (周星星同学)
- 7ab52dd
linter/jest/no-restricted-jest-methods,linter/vitest/no-restricted-vi-methods:
Report restricted methods in call chains (#29660) (oxc-captain[bot])
- 5d2129c oxlint: Write --init errors to stderr (#29654)
(oxc-captain[bot])
- a53df45 linter/eslint/no-fallthrough: Recognize all line terminators
(#29676) (周星星同学)
- 8270346 linter/typescript/consistent-type-definitions: Add a semicolon
when code follows on the same line (#29634) (Jingbo Chai)
- 132793f linter/eslint: Preserve statement boundaries in autofixes
(#29633) (Jingbo Chai)

### ⚡ Performance

- 2c4240a oxlint: Convert diagnostic offsets to positions with a line
index (#29987) (Nicholas Rayburn)
- 892f086 various: Avoid copying source text in
`OxcDiagnostic::render_with_source_code` callers (#29850)
(overlookmotel)
- 27777a9 diagnostics: Loosen lifetime bound on
`OxcDiagnostic::with_source_code` (#29849) (overlookmotel)
- f43a92f linter/plugins: Match selectors without allocating ancestor
arrays (#29652) (Shanon Jackson)
# Oxfmt
### 💥 BREAKING CHANGES

- b90b3aa ast: [**BREAKING**] Remove `base` field from `NumericLiteral`
and `BigIntLiteral` (#29919) (overlookmotel)

### 🚀 Features

- 42f62d6 formatter/sort_imports: Break ties for the same source by
subgroup (#29817) (leaysgur)
- d3af78a formatter_htmlish/angular: Support Tailwind class sorting
(#29737) (leaysgur)
- 0fe3d0c formatter_htmlish/angular: Format template JS expressions
(#29726) (leaysgur)
- ae32aed formatter_htmlish/angular: Implement printer w/o JS
expressions (#29657) (leaysgur)

### 🐛 Bug Fixes

- b373412 formatter_css: Preserve glued numbers (#29941) (leaysgur)
- f1816d8 formatter_htmlish: Count a blank line after unclosed element
(#29881) (leaysgur)
- 5952610 formatter_htmlish/angular: Do not break a parent for ICU
(#29874) (leaysgur)
- 596c70d formatter_htmlish/angular: Break as-written block parameters
(#29873) (leaysgur)
- 1fb897f formatter_htmlish: Keep blank lines before borrowed `}}` when
preserved (#29872) (leaysgur)
- 488a9fa formatter: Break an assigned class's heritage as a class
anywhere else (#29869) (leaysgur)
- 7053128 formatter_markdown: Handle empty footnote (#29735) (leaysgur)
- 7caf3be oxfmt: Run `WalkRunner` in `block_in_place()` to avoid hang
with 1 Tokio worker (#29728) (Yuji Sugiura)

### ⚡ Performance

- 892f086 various: Avoid copying source text in
`OxcDiagnostic::render_with_source_code` callers (#29850)
(overlookmotel)

### 📚 Documentation

- c5790e2 formatter_css: Record multi-line value comment expanding its
group as a divergence (#29950) (leaysgur)
- a5b1405 formatter: Move open debts out of comments and add heritage
items (#29870) (leaysgur)

---------

Co-authored-by: Cameron <cameron.clark@hey.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-linter Area - Linter (oxlint): rules, config, diagnostics, fixes. Add L-* labels for details

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants