eslint-plugin-effector 0.7.6 → 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/config/react.js +2 -1
- package/index.js +2 -1
- package/package.json +1 -1
- package/rules/enforce-store-naming-convention/enforce-store-naming-convention.js +16 -13
- package/rules/{mandatory-useEvent/mandatory-useEvent.js → mandatory-scope-binding/mandatory-scope-binding.js} +3 -3
- package/rules/prefer-useUnit/prefer-useUnit.js +56 -0
package/README.md
CHANGED
|
@@ -79,7 +79,8 @@ This preset is recommended for projects that use [Fork API](https://effector.dev
|
|
|
79
79
|
This preset is recommended for projects that use [React](https://reactjs.org) with Effector.
|
|
80
80
|
|
|
81
81
|
- [effector/enforce-gate-naming-convention](rules/enforce-gate-naming-convention/enforce-gate-naming-convention.md)
|
|
82
|
-
- [effector/mandatory-
|
|
82
|
+
- [effector/mandatory-scope-binding](rules/mandatory-scope-binding/mandatory-scope-binding.md)
|
|
83
|
+
- [effector/prefer-useUnit](rules/prefer-useUnit/prefer-useUnit.md)
|
|
83
84
|
|
|
84
85
|
#### plugin:effector/future
|
|
85
86
|
|
package/config/react.js
CHANGED
package/index.js
CHANGED
|
@@ -15,7 +15,8 @@ module.exports = {
|
|
|
15
15
|
"keep-options-order": require("./rules/keep-options-order/keep-options-order"),
|
|
16
16
|
"no-forward": require("./rules/no-forward/no-forward"),
|
|
17
17
|
"no-guard": require("./rules/no-guard/no-guard"),
|
|
18
|
-
"mandatory-
|
|
18
|
+
"mandatory-scope-binding": require("./rules/mandatory-scope-binding/mandatory-scope-binding"),
|
|
19
|
+
"prefer-useUnit": require("./rules/prefer-useUnit/prefer-useUnit"),
|
|
19
20
|
},
|
|
20
21
|
configs: {
|
|
21
22
|
recommended: require("./config/recommended"),
|
package/package.json
CHANGED
|
@@ -11,6 +11,7 @@ const {
|
|
|
11
11
|
} = require("../../utils/get-corrected-store-name");
|
|
12
12
|
const { createLinkToRule } = require("../../utils/create-link-to-rule");
|
|
13
13
|
const { nodeTypeIs } = require("../../utils/node-type-is");
|
|
14
|
+
const { traverseParentByType } = require("../../utils/traverse-parent-by-type");
|
|
14
15
|
|
|
15
16
|
module.exports = {
|
|
16
17
|
meta: {
|
|
@@ -75,31 +76,31 @@ module.exports = {
|
|
|
75
76
|
// Store creation with method
|
|
76
77
|
const STORE_CREATION_METHODS = ["createStore", "restore", "combine"];
|
|
77
78
|
for (const method of STORE_CREATION_METHODS) {
|
|
78
|
-
const localMethod = importedFromEffector.get(method);
|
|
79
|
+
const localMethod = importedFromEffector.get(method);
|
|
79
80
|
if (!localMethod) {
|
|
80
81
|
continue;
|
|
81
82
|
}
|
|
82
|
-
|
|
83
|
+
|
|
83
84
|
const isEffectorStoreCreation = node.callee.name === localMethod;
|
|
84
85
|
if (!isEffectorStoreCreation) {
|
|
85
86
|
continue;
|
|
86
87
|
}
|
|
87
88
|
|
|
88
|
-
const
|
|
89
|
-
|
|
89
|
+
const parentNode = traverseParentByType(node, "VariableDeclarator", ["Program"]);
|
|
90
|
+
|
|
91
|
+
const resultSavedInVariable = parentNode.type === "VariableDeclarator";
|
|
90
92
|
if (!resultSavedInVariable) {
|
|
91
93
|
continue;
|
|
92
94
|
}
|
|
93
95
|
|
|
94
|
-
const storeName =
|
|
95
|
-
|
|
96
|
+
const storeName = parentNode.id.name;
|
|
96
97
|
if (namingOf.store.isValid({ name: storeName, context })) {
|
|
97
98
|
continue;
|
|
98
99
|
}
|
|
99
100
|
|
|
100
101
|
reportStoreNameConventionViolation({
|
|
101
102
|
context,
|
|
102
|
-
node:
|
|
103
|
+
node: parentNode,
|
|
103
104
|
storeName,
|
|
104
105
|
});
|
|
105
106
|
return;
|
|
@@ -115,8 +116,8 @@ module.exports = {
|
|
|
115
116
|
return;
|
|
116
117
|
}
|
|
117
118
|
|
|
118
|
-
const resultSavedInVariable =
|
|
119
|
-
|
|
119
|
+
const resultSavedInVariable = node.parent.type === "VariableDeclarator";
|
|
120
|
+
|
|
120
121
|
if (!resultSavedInVariable) {
|
|
121
122
|
return;
|
|
122
123
|
}
|
|
@@ -140,13 +141,15 @@ module.exports = {
|
|
|
140
141
|
if (
|
|
141
142
|
STORE_IN_DOMAIN_CREATION_METHODS.includes(node.callee?.property?.name)
|
|
142
143
|
) {
|
|
143
|
-
|
|
144
|
-
|
|
144
|
+
|
|
145
|
+
const parentNode = traverseParentByType(node, "VariableDeclarator", ["Program"]);
|
|
146
|
+
|
|
147
|
+
const resultSavedInVariable = parentNode.type === "VariableDeclarator";
|
|
145
148
|
if (!resultSavedInVariable) {
|
|
146
149
|
return;
|
|
147
150
|
}
|
|
148
151
|
|
|
149
|
-
const storeName =
|
|
152
|
+
const storeName = parentNode.id.name;
|
|
150
153
|
|
|
151
154
|
if (namingOf.store.isValid({ name: storeName, context })) {
|
|
152
155
|
return;
|
|
@@ -154,7 +157,7 @@ module.exports = {
|
|
|
154
157
|
|
|
155
158
|
reportStoreNameConventionViolation({
|
|
156
159
|
context,
|
|
157
|
-
node:
|
|
160
|
+
node: parentNode,
|
|
158
161
|
storeName,
|
|
159
162
|
});
|
|
160
163
|
return;
|
|
@@ -9,14 +9,14 @@ module.exports = {
|
|
|
9
9
|
type: "problem",
|
|
10
10
|
docs: {
|
|
11
11
|
description:
|
|
12
|
-
"Forbids `Event` and `Effect` usage without `
|
|
12
|
+
"Forbids `Event` and `Effect` usage without `useUnit` in React components.",
|
|
13
13
|
category: "Quality",
|
|
14
14
|
recommended: true,
|
|
15
|
-
url: createLinkToRule("mandatory-
|
|
15
|
+
url: createLinkToRule("mandatory-scope-binding"),
|
|
16
16
|
},
|
|
17
17
|
messages: {
|
|
18
18
|
useEventNeeded:
|
|
19
|
-
"{{ unitName }} must be wrapped with `
|
|
19
|
+
"{{ unitName }} must be wrapped with `useUnit` from `effector-react` before usage inside React components",
|
|
20
20
|
},
|
|
21
21
|
schema: [],
|
|
22
22
|
},
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
const { createLinkToRule } = require("../../utils/create-link-to-rule");
|
|
2
|
+
const { extractImportedFrom } = require("../../utils/extract-imported-from");
|
|
3
|
+
|
|
4
|
+
module.exports = {
|
|
5
|
+
meta: {
|
|
6
|
+
type: "problem",
|
|
7
|
+
docs: {
|
|
8
|
+
description:
|
|
9
|
+
"Suggests to replace old hooks `useStore`/`useEvent` by the new one `useUnit`",
|
|
10
|
+
category: "Quality",
|
|
11
|
+
recommended: true,
|
|
12
|
+
url: createLinkToRule("prefer-useUnit"),
|
|
13
|
+
},
|
|
14
|
+
messages: {
|
|
15
|
+
useUnitNeeded: "`{{ hookName }}` could be replaced by `useUnit`",
|
|
16
|
+
},
|
|
17
|
+
schema: [],
|
|
18
|
+
},
|
|
19
|
+
create(context) {
|
|
20
|
+
const importedFromEffectorReact = new Map();
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
ImportDeclaration(node) {
|
|
24
|
+
extractImportedFrom({
|
|
25
|
+
importMap: importedFromEffectorReact,
|
|
26
|
+
packageName: "effector-react",
|
|
27
|
+
node,
|
|
28
|
+
});
|
|
29
|
+
},
|
|
30
|
+
CallExpression(node) {
|
|
31
|
+
const OLD_HOOKS = ["useStore", "useEvent"];
|
|
32
|
+
const NEW_HOOK = ["useUnit"];
|
|
33
|
+
|
|
34
|
+
for (const oldHookName of OLD_HOOKS) {
|
|
35
|
+
const localOldHookName = importedFromEffectorReact.get(oldHookName);
|
|
36
|
+
if (!localOldHookName) {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const isOldHook = node.callee.name === localOldHookName;
|
|
41
|
+
if (!isOldHook) {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
context.report({
|
|
46
|
+
node,
|
|
47
|
+
messageId: "useUnitNeeded",
|
|
48
|
+
data: {
|
|
49
|
+
hookName: oldHookName,
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
};
|