sindresorhus/eslint-plugin-unicorn

`no-useless-undefined` conflicts with `useRef` hook in React 19

rakleed opened this issue · 1 comments

Starting with React 19, useRef will require an argument on initialization. But the no-useless-undefined rule requires not to specify undefined. It might be worth adding it as an exception to

const shouldIgnore = node => {
let name;
if (node.type === 'Identifier') {
name = node.name;
} else if (
node.type === 'MemberExpression'
&& node.computed === false
&& node.property.type === 'Identifier'
) {
name = node.property.name;
}
return compareFunctionNames.has(name)
// `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'
// `setState(undefined)`
|| /^set[A-Z]/.test(name)
// https://vuejs.org/api/reactivity-core.html#ref
|| name === 'ref';
};
​​as in #2223.

This would be a quick fix. See the last PR to ignore some React functions: