Skip to content

Commit

Permalink
no-useless-undefined: Ignore React state setters (#2223)
Browse files Browse the repository at this point in the history
  • Loading branch information
abrahamguo authored Nov 28, 2023
1 parent 8f61f7c commit 42881ba
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions rules/no-useless-undefined.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
4 changes: 4 additions & 0 deletions test/no-useless-undefined.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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)',

Expand Down

0 comments on commit 42881ba

Please sign in to comment.