-
Notifications
You must be signed in to change notification settings - Fork 485
/
eslint-local-rules.js
59 lines (58 loc) · 1.54 KB
/
eslint-local-rules.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const JOTAI_USE_ATOM_HOOKS = [
"useAtom",
"useSetAtom",
"useAtomValue",
"useUpdateAtom",
"useAtomValue",
"useResetAtom",
"useReducerAtom",
"useAtomCallback",
"useHydrateAtoms",
];
module.exports = {
"no-jotai-use-atom-without-scope": {
meta: {
hasSuggestions: true,
},
create: function (context) {
return {
CallExpression: function (node) {
if (
node.callee.name &&
JOTAI_USE_ATOM_HOOKS.includes(node.callee.name)
) {
const lastArgument =
node.arguments[node.arguments.length - 1] || "";
if (!lastArgument.name.match(/scope/i)) {
context.report({
node: node,
message:
"Missing scope argument. Scope should be suffixed with -Scope",
suggest: [
{
desc: "Set the scope to `globalScope`",
fix(fixer) {
return fixer.insertTextAfter(
lastArgument,
", globalScope"
);
},
},
{
desc: "Set the scope to `tableScope`",
fix(fixer) {
return fixer.insertTextAfter(
lastArgument,
", tableScope"
);
},
},
],
});
}
}
},
};
},
},
};