-
-
Notifications
You must be signed in to change notification settings - Fork 737
feat(linter/plugins): add react/no-unsafe #16532
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?
Conversation
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-unsafe linter rule to oxlinter, which identifies and restricts the use of deprecated React lifecycle methods (componentWillMount, componentWillReceiveProps, componentWillUpdate) and their UNSAFE_ prefixed variants. The rule supports version-aware checking based on React settings and includes a configurable checkAliases option.
Key changes:
- Implements the new
react/no-unsaferule with support for ES5 (createReactClass) and ES6 (class) components - Adds React version configuration to settings for version-specific rule behavior
- Includes comprehensive tests covering various scenarios and component types
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/oxc_linter/src/rules/react/no_unsafe.rs | Main rule implementation with logic to detect unsafe lifecycle methods in both class and createReactClass components |
| crates/oxc_linter/src/snapshots/react_no_unsafe.snap | Test snapshot file containing expected diagnostic output for various test cases |
| 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 implementation for the rule runner |
| crates/oxc_linter/src/config/settings/react.rs | Adds version field to React plugin settings for version-specific rule behavior |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
CodSpeed Performance ReportMerging #16532 will not alter performanceComparing Summary
Footnotes
|
7251266 to
c2e6852
Compare
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
Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| /// are considered unsafe and have been deprecated since React 16.9. They are frequently misused and cause | ||
| /// problems in async rendering. Using their `UNSAFE_` prefixed versions or the deprecated names themselves | ||
| /// should be avoided. |
Copilot
AI
Dec 6, 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 documentation states these methods were deprecated since React 16.9, but the implementation checks for React 16.3 (line 139). According to React's history, the UNSAFE_ prefix was introduced in React 16.3, and the old names were deprecated in 16.9 and removed in 17.0. The documentation should clarify that this rule flags UNSAFE_ prefixed methods starting from React 16.3+ (when they were introduced), and optionally flags the non-prefixed versions (aliases) when checkAliases is enabled.
| /// are considered unsafe and have been deprecated since React 16.9. They are frequently misused and cause | |
| /// problems in async rendering. Using their `UNSAFE_` prefixed versions or the deprecated names themselves | |
| /// should be avoided. | |
| /// are considered unsafe. The `UNSAFE_`-prefixed versions of these methods were introduced in React 16.3, | |
| /// and this rule flags their usage starting from that version. The original (non-prefixed) versions were | |
| /// deprecated in React 16.9 and removed in React 17.0. By default, only the `UNSAFE_`-prefixed methods are | |
| /// flagged; optionally, the non-prefixed versions (aliases) are also flagged when `checkAliases` is enabled. | |
| /// These methods are frequently misused and cause problems in async rendering. Their usage should be avoided. |
related: #1022
added react/no-unsafe rule to oxlinter!