mirror of
https://github.com/oxc-project/oxc.git
synced 2026-11-04 10:29:58 +00:00
fix(linter/unicorn/no-useless-undefined): allow undefined in React.useRef (#25027)
## Problem React 19 requires `useRef` to receive an argument, so `useRef(undefined)` is valid while `useRef()` is a TypeScript error. [eslint-plugin-unicorn #2463](https://github.com/sindresorhus/eslint-plugin-unicorn/pull/2463) made the parallel fix, but Oxc's independent Rust port never picked up that behavior. ## Solution Add `useRef` to the existing ignored function names and cover direct, namespace, and generic TypeScript calls. ## Test plan `cargo test -p oxc_linter no_useless_undefined` `just ready` Validated against `@types/react@19.2.17`: `useRef(undefined)` passes and `useRef()` fails with TS2554. See the [React 19 upgrade guide](https://react.dev/blog/2024/04/25/react-19-upgrade-guide#useref-requires-an-argument). AI-assisted change. I reviewed the implementation and test results and take responsibility for the contribution. Co-authored-by: Cameron <cameron.clark@hey.com>
This commit is contained in:
1 parent
127fb2db44
commit
326904f133
1 file changed
+6
@@ -114,6 +114,8 @@ static FUNCTION_NAMES: &[&str] = &[
|
||||
"toEqual",
|
||||
"toHaveBeenCalledWith",
|
||||
"unshift",
|
||||
// `React.useRef(undefined)`
|
||||
"useRef",
|
||||
];
|
||||
|
||||
fn is_match_ignore_func_name(name: &str) -> bool {
|
||||
@@ -411,6 +413,8 @@ fn test() {
|
||||
("array.unshift(undefined);", None),
|
||||
("createContext(undefined);", None),
|
||||
("React.createContext(undefined);", None),
|
||||
("useRef(undefined);", None),
|
||||
("React.useRef(undefined);", None),
|
||||
("setState(undefined)", None),
|
||||
("setState?.(undefined)", None),
|
||||
("props.setState(undefined)", None),
|
||||
@@ -549,6 +553,8 @@ fn test() {
|
||||
),
|
||||
("createContext<T>(undefined);", None),
|
||||
("React.createContext<T>(undefined);", None),
|
||||
("useRef<T>(undefined);", None),
|
||||
("React.useRef<T>(undefined);", None),
|
||||
(
|
||||
"
|
||||
const y: any = {}
|
||||
|
||||
Reference in new issue
Block a user