Skip to content

Commit

Permalink
no-useless-undefined: Ignore Array#includes() and Set#has() (#1951
Browse files Browse the repository at this point in the history
)
  • Loading branch information
fisker committed Nov 7, 2022
1 parent 00a29c8 commit 8dfd5a7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
22 changes: 15 additions & 7 deletions rules/no-useless-undefined.js
Expand Up @@ -69,18 +69,26 @@ const shouldIgnore = node => {
}

return compareFunctionNames.has(name)
// https://vuejs.org/api/reactivity-core.html#ref
|| name === 'ref'
// `set.add(undefined)`
|| name === 'add'
// `map.set(foo, undefined)`
|| name === 'set'
// `array.push(undefined)`
|| name === 'push'
// `array.unshift(undefined)`
|| name === 'unshift'
// `array.includes(undefined)`
|| name === 'includes'

// `set.add(undefined)`
|| name === 'add'
// `set.has(undefined)`
|| name === 'has'

// `map.set(foo, undefined)`
|| name === 'set'

// `React.createContext(undefined)`
|| name === 'createContext';
|| name === 'createContext'

// https://vuejs.org/api/reactivity-core.html#ref
|| name === 'ref';
};

const getFunction = scope => {
Expand Down
2 changes: 2 additions & 0 deletions test/no-useless-undefined.mjs
Expand Up @@ -53,6 +53,8 @@ test({
'array.unshift(undefined);',
'createContext(undefined);',
'React.createContext(undefined);',
'array.includes(undefined)',
'set.has(undefined)',

// `Function#bind()`
'foo.bind(bar, undefined)',
Expand Down

0 comments on commit 8dfd5a7

Please sign in to comment.