Skip to content

fix(immutability): exclude event handler params from props mutation check#1647

Merged
Rel1cx merged 3 commits intoRel1cx:mainfrom
zerone0x:fix/immutability-false-positive-event-handler
Mar 28, 2026
Merged

fix(immutability): exclude event handler params from props mutation check#1647
Rel1cx merged 3 commits intoRel1cx:mainfrom
zerone0x:fix/immutability-false-positive-event-handler

Conversation

@zerone0x
Copy link
Copy Markdown
Contributor

Summary

  • Fixes false positive where react/immutability flagged mutations of DOM element properties via event handler parameters (e.g. e.currentTarget.value = "") as props mutations
  • Changed isPropsObject to return the defining function node, which is then verified at Program:exit to be an actual component or hook — event handler parameters are no longer misidentified as React props
  • Added test cases for DOM event target mutations in both named and inline event handlers

Closes #1626

Test plan

  • All 65 existing tests pass (vitest run on immutability spec)
  • New test cases cover e.currentTarget.value = "" in named handler functions
  • New test cases cover e.currentTarget.disabled = true in inline arrow handlers
  • Existing props mutation detection still works (invalid test cases unchanged)

🤖 Generated with Claude Code

…heck

The `isPropsObject` check incorrectly treated the first parameter of
any function as a React props object. This caused false positives when
mutating DOM properties via event handler parameters like
`e.currentTarget.value = ""`.

The fix defers verification of the props-defining function to
Program:exit, where the component/hook collector results are available,
ensuring only parameters of actual components or hooks are flagged.

Closes Rel1cx#1626

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 27, 2026

@zerone0x is attempting to deploy a commit to the Rel1cx's projects Team on Vercel.

A member of the Team first needs to authorize it.

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 27, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
eslint-react Ready Ready Preview, Comment Mar 28, 2026 6:28am

Request Review

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the react/immutability ESLint rule logic to avoid false positives when mutating DOM element properties via event handler parameters (e.g. e.currentTarget.value = "") while preserving existing props/state mutation detection.

Changes:

  • Replaces boolean isPropsObject logic with getPropsDefiningFunction, returning the parameter-defining function node (or null).
  • Adds a Program:exit verification step to ensure props-based violations originate from an actual component or hook function, preventing event-handler-parameter misclassification.
  • Adds valid test cases covering DOM currentTarget mutations in both named and inline event handlers.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
packages/plugins/eslint-plugin-react-x/src/rules/immutability/immutability.ts Refines props-parameter detection by tracking the defining function and validating it against collected components/hooks at Program:exit.
packages/plugins/eslint-plugin-react-x/src/rules/immutability/immutability.spec.ts Adds regression tests ensuring DOM event target mutations in handlers are not flagged as props/state mutations.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Rel1cx Rel1cx merged commit ffbb804 into Rel1cx:main Mar 28, 2026
10 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] immutability: false positive on DOM event target mutation

3 participants