Skip to content

feat(linter/react): implement react/no-did-mount-set-state#17313

Merged
camc314 merged 4 commits intooxc-project:mainfrom
Kenzo-Wada:feat/react-no-did-mount-set-state
Dec 23, 2025
Merged

feat(linter/react): implement react/no-did-mount-set-state#17313
camc314 merged 4 commits intooxc-project:mainfrom
Kenzo-Wada:feat/react-no-did-mount-set-state

Conversation

@Kenzo-Wada
Copy link
Contributor

related: #1022

Copilot AI review requested due to automatic review settings December 23, 2025 15:07
@Kenzo-Wada Kenzo-Wada requested a review from camc314 as a code owner December 23, 2025 15:07
@github-actions github-actions bot added A-linter Area - Linter C-enhancement Category - New feature or request labels Dec 23, 2025
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 implements the react/no-did-mount-set-state linter rule, which disallows calling setState in the componentDidMount lifecycle method to prevent unnecessary re-renders and performance issues.

Key Changes

  • Adds a new React linter rule that detects this.setState() calls within componentDidMount methods
  • Includes configurable disallow_in_func option to control whether setState in nested functions/callbacks should also be flagged
  • Provides comprehensive test coverage for both ES5 and ES6 component patterns

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
crates/oxc_linter/src/rules/react/no_did_mount_set_state.rs Main rule implementation with logic to detect setState calls in componentDidMount, supporting both direct calls and nested function detection via configuration
crates/oxc_linter/src/snapshots/react_no_did_mount_set_state.snap Test snapshot for default behavior showing 7 errors for direct setState calls
crates/oxc_linter/src/snapshots/react_no_did_mount_set_state@disallow_in_func.snap Test snapshot for disallow_in_func mode showing 4 errors for nested function setState calls
crates/oxc_linter/src/rules.rs Registers the new rule module and adds it to the rule declaration list
crates/oxc_linter/src/generated/rule_runner_impls.rs Auto-generated runner implementation for the new rule

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

@codspeed-hq
Copy link

codspeed-hq bot commented Dec 23, 2025

CodSpeed Performance Report

Merging #17313 will not alter performance

Comparing Kenzo-Wada:feat/react-no-did-mount-set-state (7a80b12) with main (c813582)1

Summary

✅ 4 untouched
⏩ 41 skipped2

Footnotes

  1. No successful run was found on main (c6690d1) during the generation of this report, so c813582 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.

@github-actions github-actions bot added the A-cli Area - CLI label Dec 23, 2025
Copy link
Contributor

@camc314 camc314 left a comment

Choose a reason for hiding this comment

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

Thank you!

@camc314 camc314 merged commit 267e255 into oxc-project:main Dec 23, 2025
20 checks passed
@Kenzo-Wada Kenzo-Wada deleted the feat/react-no-did-mount-set-state branch December 23, 2025 22:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants