mirror of
https://github.com/hanzoai/o11y.git
synced 2026-11-03 02:04:48 +00:00
* feat(oxc): move from eslint/prettier to oxlint/oxfmt * fix(scripts): formatted and linted * fix(k8s-base-list): add again the ignore rule * fix(fmt): permissions type * fix(permissions): generate correct file for format * fix(k8s): wrong update on test methods caused it to be wrong
54 lines
1.3 KiB
JavaScript
54 lines
1.3 KiB
JavaScript
/**
|
|
* Rule: no-zustand-getstate-in-hooks
|
|
*
|
|
* Prevents calling .getState() on Zustand hooks.
|
|
*
|
|
* This rule catches patterns like:
|
|
* useStore.getState()
|
|
* useAppStore.getState()
|
|
*
|
|
* Instead, export a standalone action from the store.
|
|
*
|
|
* ESLint equivalent:
|
|
* "no-restricted-syntax": [
|
|
* "error",
|
|
* {
|
|
* "selector": "CallExpression[callee.property.name='getState'][callee.object.name=/^use/]",
|
|
* "message": "Avoid calling .getState() directly. Export a standalone action from the store instead."
|
|
* }
|
|
* ]
|
|
*/
|
|
|
|
export default {
|
|
create(context) {
|
|
return {
|
|
CallExpression(node) {
|
|
const callee = node.callee;
|
|
|
|
// Check if it's a member expression (e.g., useStore.getState())
|
|
if (callee.type !== 'MemberExpression') {
|
|
return;
|
|
}
|
|
|
|
// Check if the property is 'getState'
|
|
const property = callee.property;
|
|
if (property.type !== 'Identifier' || property.name !== 'getState') {
|
|
return;
|
|
}
|
|
|
|
// Check if the object name starts with 'use'
|
|
const object = callee.object;
|
|
if (object.type !== 'Identifier' || !object.name.startsWith('use')) {
|
|
return;
|
|
}
|
|
|
|
context.report({
|
|
node,
|
|
message:
|
|
'Avoid calling .getState() directly. Export a standalone action from the store instead.',
|
|
});
|
|
},
|
|
};
|
|
},
|
|
};
|