Skip to content

Conversation

@baevm
Copy link
Contributor

@baevm baevm commented Nov 26, 2025

adds react/no-redundant-should-component-update, issue #1022

rule doc
rule source code

@baevm baevm requested a review from camc314 as a code owner November 26, 2025 06:07
Copilot AI review requested due to automatic review settings November 26, 2025 06:07
@graphite-app
Copy link
Contributor

graphite-app bot commented Nov 26, 2025

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

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.

@github-actions github-actions bot added A-linter Area - Linter C-enhancement Category - New feature or request labels Nov 26, 2025
Copilot finished reviewing on behalf of baevm November 26, 2025 06:10
Copy link
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

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.PureComponent or PureComponent with shouldComponentUpdate methods
  • 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.

Comment on lines +97 to +98
impl Rule for NoRedundantShouldComponentUpdate {
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
Copy link

Copilot AI Nov 26, 2025

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.

Copilot uses AI. Check for mistakes.
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;

use crate::{AstNode, context::LintContext, rule::Rule};
Copy link

Copilot AI Nov 26, 2025

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

Suggested change
use crate::{AstNode, context::LintContext, rule::Rule};
use crate::{AstNode, context::{ContextHost, LintContext}, rule::Rule};

Copilot uses AI. Check for mistakes.
@codspeed-hq
Copy link

codspeed-hq bot commented Nov 26, 2025

CodSpeed Performance Report

Merging #16147 will not alter performance

Comparing baevm:react/no-redundant-should-component-update (dba5c3a) with main (0549ae5)1

Summary

✅ 4 untouched
⏩ 41 skipped2

Footnotes

  1. No successful run was found on main (9317ebc) during the generation of this report, so 0549ae5 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

  2. 41 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-linter Area - Linter C-enhancement Category - New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant