eslint-plugin-effector 0.7.3 → 0.7.6
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 +17 -6
- package/package.json +1 -1
- package/rules/keep-options-order/config.js +1 -1
- package/rules/mandatory-useEvent/mandatory-useEvent.js +3 -3
- package/rules/no-forward/no-forward.js +1 -1
- package/rules/no-guard/no-guard.js +1 -1
- package/rules/prefer-sample-over-forward-with-mapping/prefer-sample-over-forward-with-mapping.js +1 -1
- package/utils/extract-imported-from.js +4 -0
- package/utils/replace-by-sample.js +5 -1
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
|
|
@@ -72,7 +83,7 @@ This preset is recommended for projects that use [React](https://reactjs.org) wi
|
|
|
72
83
|
|
|
73
84
|
#### plugin:effector/future
|
|
74
85
|
|
|
75
|
-
This preset contains rules
|
|
86
|
+
This preset contains rules, which enforce _future-effector_ code-style.
|
|
76
87
|
|
|
77
88
|
- [effector/no-forward](rules/no-forward/no-forward.md)
|
|
78
89
|
- [effector/no-guard](rules/no-guard/no-guard.md)
|
|
@@ -86,5 +97,5 @@ This preset contains rules wich enforce _future-effector_ code-style.
|
|
|
86
97
|
3. Commit changes by `git commit -m "Release X.X.X"`
|
|
87
98
|
4. Create git tag for release by `git tag -a vX.X.X -m "vX.X.X"`
|
|
88
99
|
5. Push changes to remote by `git push --follow-tags`
|
|
89
|
-
6. Release package to registry by `
|
|
100
|
+
6. Release package to registry by `pnpm clean-publish`
|
|
90
101
|
7. Fill release page with changelog on GitHub
|
package/package.json
CHANGED
|
@@ -45,7 +45,7 @@ module.exports = {
|
|
|
45
45
|
return;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
if (
|
|
48
|
+
if (isInsideEffectorHook({ node, context })) {
|
|
49
49
|
return;
|
|
50
50
|
}
|
|
51
51
|
|
|
@@ -61,7 +61,7 @@ module.exports = {
|
|
|
61
61
|
},
|
|
62
62
|
};
|
|
63
63
|
|
|
64
|
-
function
|
|
64
|
+
function isInsideEffectorHook({ node, context }) {
|
|
65
65
|
const calleeParentNode = traverseParentByType(node.parent, "CallExpression");
|
|
66
66
|
|
|
67
67
|
if (!calleeParentNode?.callee) return false;
|
|
@@ -69,6 +69,6 @@ function isInsideUseEventCall({ node, context }) {
|
|
|
69
69
|
return nodeTypeIs.effectorReactHook({
|
|
70
70
|
node: calleeParentNode.callee,
|
|
71
71
|
context,
|
|
72
|
-
hook: ["useEvent", "useUnit"],
|
|
72
|
+
hook: ["useEvent", "useUnit", "useStore"],
|
|
73
73
|
});
|
|
74
74
|
}
|
|
@@ -16,7 +16,7 @@ module.exports = {
|
|
|
16
16
|
messages: {
|
|
17
17
|
noForward:
|
|
18
18
|
"Instead of `forward` you can use `sample`, it is more extendable.",
|
|
19
|
-
replaceWithSample: "
|
|
19
|
+
replaceWithSample: "Replace `forward` with `sample`.",
|
|
20
20
|
},
|
|
21
21
|
schema: [],
|
|
22
22
|
hasSuggestions: true,
|
|
@@ -16,7 +16,7 @@ module.exports = {
|
|
|
16
16
|
messages: {
|
|
17
17
|
noGuard:
|
|
18
18
|
"Instead of `guard` you can use `sample`, it is more extendable.",
|
|
19
|
-
replaceWithSample: "
|
|
19
|
+
replaceWithSample: "Replace `guard` with `sample`.",
|
|
20
20
|
},
|
|
21
21
|
schema: [],
|
|
22
22
|
hasSuggestions: true,
|
package/rules/prefer-sample-over-forward-with-mapping/prefer-sample-over-forward-with-mapping.js
CHANGED
|
@@ -21,7 +21,7 @@ module.exports = {
|
|
|
21
21
|
"Instead of `forward` with `{{ eventName }}.map` you can use `sample`",
|
|
22
22
|
overPrepend:
|
|
23
23
|
"Instead of `forward` with `{{ eventName }}.prepend` you can use `sample`",
|
|
24
|
-
replaceWithSample: "
|
|
24
|
+
replaceWithSample: "Replace `forward` with `sample`.",
|
|
25
25
|
},
|
|
26
26
|
schema: [],
|
|
27
27
|
hasSuggestions: true,
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
function extractImportedFrom({ importMap, nodeMap, node, packageName }) {
|
|
2
2
|
if (node.source.value === packageName) {
|
|
3
3
|
for (const s of node.specifiers) {
|
|
4
|
+
if (s.type === "ImportDefaultSpecifier") {
|
|
5
|
+
continue;
|
|
6
|
+
}
|
|
7
|
+
|
|
4
8
|
importMap.set(s.imported.name, s.local.name);
|
|
5
9
|
nodeMap?.set(s.imported.name, s);
|
|
6
10
|
}
|
|
@@ -88,7 +88,11 @@ function* replaceBySample(
|
|
|
88
88
|
})})`
|
|
89
89
|
);
|
|
90
90
|
|
|
91
|
-
|
|
91
|
+
const importNode = importNodes.get(methodName);
|
|
92
|
+
|
|
93
|
+
if (!importNodes.has("sample")) {
|
|
94
|
+
yield fixer.insertTextAfter(importNode, ", sample");
|
|
95
|
+
}
|
|
92
96
|
}
|
|
93
97
|
|
|
94
98
|
module.exports = { replaceForwardBySample, replaceGuardBySample };
|