eslint-plugin-effector 0.7.6 → 0.8.0
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
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
|
@@ -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
|
+
};
|