Files
mlflow--mlflow/mlflow/server/js/eslint-plugin/rules/no-missing-react-hook-dependency-array.js
T
2026-07-13 13:22:34 +08:00

44 lines
1.2 KiB
JavaScript

const hooksWithDependencyArrays = new Set(['useCallback', 'useEffect', 'useMemo']);
module.exports = {
meta: {
type: 'problem',
messages: {
missingDependencyArray:
'Did you mean to call {{ functionName }} without a dependency array? This is an advanced way to use this hook, please check code carefully.',
},
},
create(context) {
return {
CallExpression(node) {
let functionName;
switch (node.callee.type) {
case 'Identifier': {
// This is the "useEffect" case
functionName = node.callee.name;
break;
}
case 'MemberExpression': {
// This is the "React.useEffect" case
functionName = node.callee.property.name;
break;
}
default: {
break;
}
}
// Check if the function is a hook and only has a function and no dep array
if (functionName !== undefined && hooksWithDependencyArrays.has(functionName) && node.arguments.length === 1) {
context.report({
data: { functionName },
node,
messageId: 'missingDependencyArray',
});
}
},
};
},
};