eslint-plugin-effector 0.8.2 → 0.9.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
|
@@ -89,6 +89,12 @@ This preset contains rules, which enforce _future-effector_ code-style.
|
|
|
89
89
|
- [effector/no-forward](rules/no-forward/no-forward.md)
|
|
90
90
|
- [effector/no-guard](rules/no-guard/no-guard.md)
|
|
91
91
|
|
|
92
|
+
#### plugin:effector/patronum
|
|
93
|
+
|
|
94
|
+
This preset is recommended for projects that use [Patronum](https://patronum.effector.dev/).
|
|
95
|
+
|
|
96
|
+
- [effector/no-patronum-debug](rules/no-patronum-debug/no-patronum-debug.md)
|
|
97
|
+
|
|
92
98
|
## Maintenance
|
|
93
99
|
|
|
94
100
|
### Release flow
|
package/index.js
CHANGED
|
@@ -17,11 +17,13 @@ module.exports = {
|
|
|
17
17
|
"no-guard": require("./rules/no-guard/no-guard"),
|
|
18
18
|
"mandatory-scope-binding": require("./rules/mandatory-scope-binding/mandatory-scope-binding"),
|
|
19
19
|
"prefer-useUnit": require("./rules/prefer-useUnit/prefer-useUnit"),
|
|
20
|
+
"no-patronum-debug": require("./rules/no-patronum-debug/no-patronum-debug"),
|
|
20
21
|
},
|
|
21
22
|
configs: {
|
|
22
23
|
recommended: require("./config/recommended"),
|
|
23
24
|
scope: require("./config/scope"),
|
|
24
25
|
react: require("./config/react"),
|
|
25
26
|
future: require("./config/future"),
|
|
27
|
+
patronum: require("./config/patronum"),
|
|
26
28
|
},
|
|
27
29
|
};
|
package/package.json
CHANGED
|
@@ -0,0 +1,126 @@
|
|
|
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: "suggestion",
|
|
7
|
+
docs: {
|
|
8
|
+
description: "Disallow the use of patronum `debug`",
|
|
9
|
+
category: "Quality",
|
|
10
|
+
recommended: false,
|
|
11
|
+
url: createLinkToRule("no-patronum-debug"),
|
|
12
|
+
},
|
|
13
|
+
messages: {
|
|
14
|
+
noPatronumDebug: "Unexpected patronum `debug` statement",
|
|
15
|
+
removePatronumDebug: "Remove this `debug` from patronum",
|
|
16
|
+
},
|
|
17
|
+
schema: [],
|
|
18
|
+
hasSuggestions: true,
|
|
19
|
+
},
|
|
20
|
+
create(context) {
|
|
21
|
+
const importedFromPatronum = new Map();
|
|
22
|
+
const importNodes = new Map();
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
ImportDeclaration(node) {
|
|
26
|
+
extractImportedFrom({
|
|
27
|
+
packageName: ["patronum", "patronum/debug"],
|
|
28
|
+
importMap: importedFromPatronum,
|
|
29
|
+
nodeMap: importNodes,
|
|
30
|
+
node,
|
|
31
|
+
});
|
|
32
|
+
},
|
|
33
|
+
CallExpression(node) {
|
|
34
|
+
const currentMethodName = node.callee?.name ?? node.callee?.object.name;
|
|
35
|
+
const importedDebugFromPatronum = importedFromPatronum.get("debug");
|
|
36
|
+
|
|
37
|
+
if (currentMethodName !== importedDebugFromPatronum) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
context.report({
|
|
42
|
+
messageId: "noPatronumDebug",
|
|
43
|
+
node,
|
|
44
|
+
suggest: [
|
|
45
|
+
{
|
|
46
|
+
messageId: "removePatronumDebug",
|
|
47
|
+
*fix(fixer) {
|
|
48
|
+
yield* removeDebugFromPatronum({
|
|
49
|
+
fixer,
|
|
50
|
+
node,
|
|
51
|
+
context,
|
|
52
|
+
importNodes,
|
|
53
|
+
});
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
function* removeDebugFromPatronum({
|
|
64
|
+
fixer,
|
|
65
|
+
node,
|
|
66
|
+
context,
|
|
67
|
+
importNodes,
|
|
68
|
+
targetMethod = "debug",
|
|
69
|
+
}) {
|
|
70
|
+
const sourceCode = context.getSourceCode();
|
|
71
|
+
const startToken = sourceCode.getTokenBefore(node);
|
|
72
|
+
|
|
73
|
+
// remove line with debug
|
|
74
|
+
yield fixer.removeRange([startToken.range[1], node.range[1] + 1]);
|
|
75
|
+
|
|
76
|
+
const importDebugNode = importNodes.get(targetMethod);
|
|
77
|
+
|
|
78
|
+
if (!importDebugNode) {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// remove import with debug
|
|
83
|
+
const importParentNode = importDebugNode.parent;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* import { debug } from 'patronum'
|
|
87
|
+
* import { debug } from 'patronum/debug'
|
|
88
|
+
*/
|
|
89
|
+
if (importParentNode.specifiers.length === 1) {
|
|
90
|
+
yield fixer.removeRange([
|
|
91
|
+
importParentNode.range[0],
|
|
92
|
+
importParentNode.range[1] + 1,
|
|
93
|
+
]);
|
|
94
|
+
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const amountImportFromPatronum = importParentNode.specifiers.length;
|
|
99
|
+
const importLast = importParentNode.specifiers[amountImportFromPatronum - 1];
|
|
100
|
+
|
|
101
|
+
const filterTokenComma = { filter: (token) => token.value === "," };
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* import { debug, timeout } from 'patronum'
|
|
105
|
+
* import { condition, debug, throttle } from 'patronum'
|
|
106
|
+
*/
|
|
107
|
+
if (importDebugNode !== importLast) {
|
|
108
|
+
const prevNode = sourceCode.getTokenBefore(importDebugNode);
|
|
109
|
+
const comma = sourceCode.getTokenAfter(importDebugNode, filterTokenComma);
|
|
110
|
+
|
|
111
|
+
yield fixer.removeRange([prevNode.range[1], importDebugNode.range[0]]);
|
|
112
|
+
yield fixer.remove(importDebugNode);
|
|
113
|
+
yield fixer.remove(comma);
|
|
114
|
+
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* import { condition, debug } from 'patronum'
|
|
120
|
+
*/
|
|
121
|
+
const comma = sourceCode.getTokenBefore(importDebugNode, filterTokenComma);
|
|
122
|
+
|
|
123
|
+
yield fixer.removeRange([comma.range[1], importDebugNode.range[0]]);
|
|
124
|
+
yield fixer.remove(importDebugNode);
|
|
125
|
+
yield fixer.remove(comma);
|
|
126
|
+
}
|
|
@@ -15,7 +15,7 @@ module.exports = {
|
|
|
15
15
|
},
|
|
16
16
|
messages: {
|
|
17
17
|
abusiveCall:
|
|
18
|
-
"Method `.watch` leads to imperative code. Try to replace it with
|
|
18
|
+
"Method `.watch` leads to imperative code. Try to replace it with operator (`sample`) or use the `target` parameter of the operator.",
|
|
19
19
|
},
|
|
20
20
|
schema: [],
|
|
21
21
|
},
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
function extractImportedFrom({ importMap, nodeMap, node, packageName }) {
|
|
2
|
-
|
|
2
|
+
const normalizePackageName = Array.isArray(packageName)
|
|
3
|
+
? packageName
|
|
4
|
+
: [packageName];
|
|
5
|
+
|
|
6
|
+
if (normalizePackageName.includes(node.source.value)) {
|
|
3
7
|
for (const s of node.specifiers) {
|
|
4
8
|
if (s.type === "ImportDefaultSpecifier") {
|
|
5
9
|
continue;
|