feat(react-x): add additionalMutableHooks setting, closes #1924 - #1931
Open
christopher-buss wants to merge 3 commits into
Open
feat(react-x): add additionalMutableHooks setting, closes #1924#1931christopher-buss wants to merge 3 commits into
additionalMutableHooks setting, closes #1924#1931christopher-buss wants to merge 3 commits into
Conversation
|
@christopher-buss is attempting to deploy a commit to the Rel1cx's projects Team on Vercel. A member of the Team first needs to authorize it. |
Rel1cx
force-pushed
the
main
branch
4 times, most recently
from
August 7, 2026 19:54
3f9ccf0 to
716d39b
Compare
Registers custom hooks that return external mutable stores. Writes through values from such hooks are exempt, like navigation hook values. Also widens the navigation-hook exemption from mutating method calls to all writes through the value; binding reassignment is still reported. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Drops the per-call `core.isAPICall` closures for `NAVIGATION_HOOKS` and reuses the callee name already computed for the regex test. Also runs the cheaper ref check before the store check. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…case The report still described the exemption as method-call-only and listed three navigation hooks; `useHistory` landed in 5.16.1. Adds a valid test for sibling bindings of a destructured store hook call. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
christopher-buss
force-pushed
the
feat/additional-mutable-hooks
branch
from
August 8, 2026 10:04
cba6d24 to
210037d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce?
Adds an
additionalMutableHooksshared setting, as proposed in #1924: a regex matching custom hooks that return external mutable stores. Writes through values initialized by such a hook are exempted byreact-x/immutability, the same way values returned by the built-in navigation hooks already are.{ "settings": { "react-x": { "additionalMutableHooks": "/^(useWorld|useMyStore)$/u" } } }Registering such a hook under
additionalRefHooksworks today, but it declares the value a ref, soreact-naming-convention/ref-namethen asks for it to be renamed — the misdeclaration leaks into other rules.Implementation notes
packages/shared/src/settings.ts:additionalMutableHooksfollows the existingadditional*Hooksshape (schema, normalized interface,toRegExp).immutability/lib.ts:isKnownNonMutatingMethodCallbecomesisInitializedFromMutableHook. Both the built-inNAVIGATION_HOOKSand the configured pattern are matched on the callee name fromExtract.getCalleeName, which is howisUseRefLikeCalland the otherisUse*LikeCallpredicates match.isAPIis name-shaped too, so this is not a behaviour change; it removes the second matching mechanism from one function.immutability/effects.ts: the exemption applies to every write through the value (store.count = 1,delete store.stale), not only to mutating method calls. This widens the existing navigation-hook exemption. The reason for the exemption is a property of the value — it is not a captured local — so it does not depend on the write syntax, and theuseRefexemption is already syntax-uniform (ref.current = 1andbox.current.push(1)are both exempt). Reassignment of the binding itself (world = null) stays a mutation.immutability.spec.diff.md: the mutation table and the exception paragraph still described the exemption as method-call-only and listed three navigation hooks;useHistorylanded in 5.16.1. Updated, with the destructuring boundary recorded. TheLast verifiedstamp is left for you.Provenance is per declaration, not per destructured element:
const { store, actions } = useMyStore()exempts writes throughactionsas well. That looks right for a store hook, and there is now a valid test pinning it.Open question
additionalRefHooksshipped with acore.isUseRefLikeCallpredicate plus aRuleToolkit.isentry. I did not add a core predicate here, because it would move third-party hook names (useRouter,useNavigate, …) intopackages/core, which today holds React built-ins only. Happy to addcore.isUseMutableStoreLikeCall+ the kit entry if you would rather keep the symmetry.Does this PR introduce a breaking change?
Checklist
Other information
Docs updated: rule
immutability.mdx,configure-analyzer.mdx/.tsx,kit.mdxsettings table,faq.mdx, ruleCHANGELOG.md, plus regenerated typedoc output for@eslint-react/shared. Full test suite passes, including 4 new valid and 2 new invalid cases for the setting.