-
-
Notifications
You must be signed in to change notification settings - Fork 724
feat(linter): add react/no-redundant-should-component-update rule #16147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat(linter): add react/no-redundant-should-component-update rule #16147
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds the react/no-redundant-should-component-update lint rule that detects redundant shouldComponentUpdate method definitions in classes extending React.PureComponent. Since PureComponent already provides a shallow prop and state comparison via shouldComponentUpdate, defining this method explicitly is redundant and defeats the purpose of using PureComponent.
Key changes:
- Implements the rule to detect classes extending
React.PureComponentorPureComponentwithshouldComponentUpdatemethods - Handles both method definitions and arrow function property assignments
- Supports named and anonymous classes, including variable declarators
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
crates/oxc_linter/src/rules/react/no_redundant_should_component_update.rs |
New rule implementation with logic to detect redundant shouldComponentUpdate in PureComponent classes |
crates/oxc_linter/src/rules.rs |
Registers the new rule module and adds it to the rules list |
crates/oxc_linter/src/generated/rule_runner_impls.rs |
Auto-generated runner implementation for the new rule |
crates/oxc_linter/src/snapshots/react_no_redundant_should_component_update.snap |
Test snapshot showing expected diagnostic outputs |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| impl Rule for NoRedundantShouldComponentUpdate { | ||
| fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) { |
Copilot
AI
Nov 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rule is missing the should_run method that checks if the source file is JSX. All React rules in this codebase implement should_run to skip non-JSX files for performance. Add this method after the run method:\n\nrust\nfn should_run(&self, ctx: &ContextHost) -> bool {\n ctx.source_type().is_jsx()\n}\n\n\nYou'll also need to import ContextHost in the imports section.
| use oxc_macros::declare_oxc_lint; | ||
| use oxc_span::Span; | ||
|
|
||
| use crate::{AstNode, context::LintContext, rule::Rule}; |
Copilot
AI
Nov 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The import is missing ContextHost which is needed for the should_run method implementation. Update the import to:\n\nrust\nuse crate::{AstNode, context::{ContextHost, LintContext}, rule::Rule};\n
| use crate::{AstNode, context::LintContext, rule::Rule}; | |
| use crate::{AstNode, context::{ContextHost, LintContext}, rule::Rule}; |
CodSpeed Performance ReportMerging #16147 will not alter performanceComparing Summary
Footnotes
|
adds react/no-redundant-should-component-update, issue #1022
rule doc
rule source code