Files
gridpilot.gg/apps/website/eslint-rules/no-use-mutation-in-client.js
2026-01-16 01:32:55 +01:00

51 lines
1.4 KiB
JavaScript

/**
* ESLint Rule: No useMutation in Client Components
*
* Forbids the use of useMutation from @tanstack/react-query in client components.
* All write operations must go through Next.js Server Actions.
*/
module.exports = {
meta: {
type: 'problem',
docs: {
description: 'Forbid useMutation usage in client components',
category: 'Architecture',
recommended: true,
},
messages: {
noUseMutation: 'useMutation from @tanstack/react-query is forbidden. Use Next.js Server Actions for all write operations. See docs/architecture/website/FORM_SUBMISSION.md',
},
schema: [],
},
create(context) {
return {
ImportDeclaration(node) {
if (node.source.value === '@tanstack/react-query') {
const useMutationSpecifier = node.specifiers.find(
(specifier) =>
specifier.type === 'ImportSpecifier' &&
specifier.imported.name === 'useMutation'
);
if (useMutationSpecifier) {
context.report({
node: useMutationSpecifier,
messageId: 'noUseMutation',
});
}
}
},
CallExpression(node) {
if (node.callee.type === 'Identifier' && node.callee.name === 'useMutation') {
context.report({
node,
messageId: 'noUseMutation',
});
}
},
};
},
};