eslint-plugin-effector 0.7.5 → 0.8.1
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 +18 -6
- package/config/react.js +2 -1
- package/index.js +2 -1
- package/package.json +1 -1
- package/rules/keep-options-order/config.js +1 -1
- 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
|
@@ -6,16 +6,27 @@ Enforcing best practices for [Effector](http://effector.dev/)
|
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Install [ESLint](http://eslint.org) and `eslint-plugin-effector`:
|
|
10
|
+
|
|
11
|
+
### pnpm
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
$ pnpm install --dev eslint
|
|
15
|
+
$ pnpm install --dev eslint-plugin-effector
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
### yarn
|
|
10
19
|
|
|
11
20
|
```
|
|
12
|
-
$ yarn add
|
|
21
|
+
$ yarn add --dev eslint
|
|
22
|
+
$ yarn add --dev eslint-plugin-effector
|
|
13
23
|
```
|
|
14
24
|
|
|
15
|
-
|
|
25
|
+
### npm
|
|
16
26
|
|
|
17
27
|
```
|
|
18
|
-
$
|
|
28
|
+
$ npm install --dev eslint
|
|
29
|
+
$ npm install --dev eslint-plugin-effector
|
|
19
30
|
```
|
|
20
31
|
|
|
21
32
|
## Usage
|
|
@@ -68,7 +79,8 @@ This preset is recommended for projects that use [Fork API](https://effector.dev
|
|
|
68
79
|
This preset is recommended for projects that use [React](https://reactjs.org) with Effector.
|
|
69
80
|
|
|
70
81
|
- [effector/enforce-gate-naming-convention](rules/enforce-gate-naming-convention/enforce-gate-naming-convention.md)
|
|
71
|
-
- [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)
|
|
72
84
|
|
|
73
85
|
#### plugin:effector/future
|
|
74
86
|
|
|
@@ -86,5 +98,5 @@ This preset contains rules, which enforce _future-effector_ code-style.
|
|
|
86
98
|
3. Commit changes by `git commit -m "Release X.X.X"`
|
|
87
99
|
4. Create git tag for release by `git tag -a vX.X.X -m "vX.X.X"`
|
|
88
100
|
5. Push changes to remote by `git push --follow-tags`
|
|
89
|
-
6. Release package to registry by `
|
|
101
|
+
6. Release package to registry by `pnpm clean-publish`
|
|
90
102
|
7. Fill release page with changelog on GitHub
|
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
|
+
};
|