Skip to content

Conversation

@Kenzo-Wada
Copy link
Contributor

related: #1022

added react/no-unsafe rule to oxlinter!

Copilot AI review requested due to automatic review settings December 5, 2025 08:22
@Kenzo-Wada Kenzo-Wada requested a review from camc314 as a code owner December 5, 2025 08:22
@github-actions github-actions bot added A-linter Area - Linter C-enhancement Category - New feature or request labels Dec 5, 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 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-unsafe rule 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-hq
Copy link

codspeed-hq bot commented Dec 5, 2025

CodSpeed Performance Report

Merging #16532 will not alter performance

Comparing Kenzo-Wada:feat/react-no-unsafe (38b5110) with main (514c724)

Summary

✅ 4 untouched
⏩ 41 skipped1

Footnotes

  1. 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.

@camc314 camc314 self-assigned this Dec 5, 2025
@Kenzo-Wada Kenzo-Wada force-pushed the feat/react-no-unsafe branch from 7251266 to c2e6852 Compare December 6, 2025 04:52
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

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.

Comment on lines +48 to +50
/// 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.
Copy link

Copilot AI Dec 6, 2025

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.

Suggested change
/// 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.

Copilot uses AI. Check for mistakes.
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.

2 participants