From 42881ba35d8e70511302d00a7ce1a1b30b951f91 Mon Sep 17 00:00:00 2001 From: Abraham Guo Date: Tue, 28 Nov 2023 11:52:34 -0600 Subject: [PATCH] `no-useless-undefined`: Ignore React state setters (#2223) --- rules/no-useless-undefined.js | 2 ++ test/no-useless-undefined.mjs | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/rules/no-useless-undefined.js b/rules/no-useless-undefined.js index c5aae75ede..2a4b4f13f8 100644 --- a/rules/no-useless-undefined.js +++ b/rules/no-useless-undefined.js @@ -60,6 +60,8 @@ const shouldIgnore = node => { // `React.createContext(undefined)` || name === 'createContext' + // `setState(undefined)` + || /^set[A-Z]/.test(name) // https://vuejs.org/api/reactivity-core.html#ref || name === 'ref'; diff --git a/test/no-useless-undefined.mjs b/test/no-useless-undefined.mjs index 9964a7a14c..b55756aa47 100644 --- a/test/no-useless-undefined.mjs +++ b/test/no-useless-undefined.mjs @@ -53,6 +53,10 @@ test({ 'array.unshift(undefined);', 'createContext(undefined);', 'React.createContext(undefined);', + 'setState(undefined)', + 'setState?.(undefined)', + 'props.setState(undefined)', + 'props.setState?.(undefined)', 'array.includes(undefined)', 'set.has(undefined)',