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-useEvent](rules/mandatory-useEvent/mandatory-useEvent.md)
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
@@ -1,6 +1,7 @@
1
1
  module.exports = {
2
2
  rules: {
3
3
  "effector/enforce-gate-naming-convention": "error",
4
- "effector/mandatory-useEvent": "error",
4
+ "effector/mandatory-scope-binding": "error",
5
+ "effector/prefer-useUnit": "warning",
5
6
  },
6
7
  };
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-useEvent": require("./rules/mandatory-useEvent/mandatory-useEvent"),
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-effector",
3
- "version": "0.7.6",
3
+ "version": "0.8.0",
4
4
  "description": "Enforcing best practices for Effector",
5
5
  "keywords": [
6
6
  "eslint",
@@ -9,14 +9,14 @@ module.exports = {
9
9
  type: "problem",
10
10
  docs: {
11
11
  description:
12
- "Forbids `Event` and `Effect` usage without `useEvent` in React components.",
12
+ "Forbids `Event` and `Effect` usage without `useUnit` in React components.",
13
13
  category: "Quality",
14
14
  recommended: true,
15
- url: createLinkToRule("mandatory-useEvent"),
15
+ url: createLinkToRule("mandatory-scope-binding"),
16
16
  },
17
17
  messages: {
18
18
  useEventNeeded:
19
- "{{ unitName }} must be wrapped with `useEvent` from `effector-react` before usage inside React components",
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
+ };