feat(linter/react): implement react/no-did-mount-set-state#17313
feat(linter/react): implement react/no-did-mount-set-state#17313camc314 merged 4 commits intooxc-project:mainfrom
Conversation
There was a problem hiding this comment.
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 withincomponentDidMountmethods - Includes configurable
disallow_in_funcoption to control whethersetStatein 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 Performance ReportMerging #17313 will not alter performanceComparing Summary
Footnotes
|
related: #1022