eslint-plugin-stratified-design 0.12.7 → 0.12.8
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.
|
@@ -111,6 +111,31 @@ const deriveVarName = (nodeOrToken, levels) => {
|
|
|
111
111
|
}
|
|
112
112
|
};
|
|
113
113
|
|
|
114
|
+
const or = (...args) => {
|
|
115
|
+
for (const arg of args) {
|
|
116
|
+
try {
|
|
117
|
+
const result = arg();
|
|
118
|
+
if (result) return result;
|
|
119
|
+
else continue;
|
|
120
|
+
} catch (e) {
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return undefined;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const deriveNames = (nodeOrToken) => {
|
|
128
|
+
const declaration = deriveDeclaration(nodeOrToken);
|
|
129
|
+
const names = or(
|
|
130
|
+
() => declaration.id.name,
|
|
131
|
+
() => declaration.declarations[0].id.name,
|
|
132
|
+
() => declaration.declarations[0].id.elements.map(({ name }) => name),
|
|
133
|
+
() =>
|
|
134
|
+
declaration.declarations[0].id.properties.map(({ value }) => value.name)
|
|
135
|
+
);
|
|
136
|
+
return names === undefined ? [] : Array.isArray(names) ? names : [names];
|
|
137
|
+
};
|
|
138
|
+
|
|
114
139
|
/**
|
|
115
140
|
* @param {SourceCode} sourceCode
|
|
116
141
|
* @param {Node | Token} nodeOrToken
|
|
@@ -243,12 +268,9 @@ module.exports = {
|
|
|
243
268
|
return {
|
|
244
269
|
Program(node) {
|
|
245
270
|
node.body.forEach((token) => {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
node.body.forEach((token) => {
|
|
250
|
-
const name = deriveVarName(token, levels);
|
|
251
|
-
if (name !== null) levels[name] = deriveLevel(sourceCode, token);
|
|
271
|
+
deriveNames(token).forEach((name) => {
|
|
272
|
+
if (name) levels[name] = deriveLevel(sourceCode, token);
|
|
273
|
+
});
|
|
252
274
|
});
|
|
253
275
|
},
|
|
254
276
|
CallExpression(node) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-stratified-design",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.8",
|
|
4
4
|
"description": "ESlint rules for stratified design",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"scripts": {
|
|
21
21
|
"lint": "eslint .",
|
|
22
22
|
"test": "mocha tests --recursive",
|
|
23
|
+
"test:watch": "mocha tests --recursive --watch",
|
|
23
24
|
"versioning": "node ./scripts/versioning"
|
|
24
25
|
},
|
|
25
26
|
"dependencies": {
|
|
@@ -218,6 +218,19 @@ ruleTester.run("no-same-level-funcs", rule, {
|
|
|
218
218
|
code: "const arr2 = []; const arr1 = [...arr2];",
|
|
219
219
|
filename: "./src/foo.js",
|
|
220
220
|
},
|
|
221
|
+
|
|
222
|
+
{
|
|
223
|
+
code: "//@level 2\nconst [dat, fn2] = someFn()\nconst fn1 = () => { fn2() }\n",
|
|
224
|
+
filename: "./src/foo.js",
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
code: "//@level 2\nconst {dat, fn2} = someFn()\nconst fn1 = () => { fn2() }\n",
|
|
228
|
+
filename: "./src/foo.js",
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
code: "//@level 2\nconst {dat, fn2: func2} = someFn()\nconst fn1 = () => { func2() }\n",
|
|
232
|
+
filename: "./src/foo.js",
|
|
233
|
+
},
|
|
221
234
|
],
|
|
222
235
|
invalid: [
|
|
223
236
|
{
|
|
@@ -377,5 +390,21 @@ ruleTester.run("no-same-level-funcs", rule, {
|
|
|
377
390
|
filename: "./src/foo.js",
|
|
378
391
|
errors: [{ messageId: "no-same-level-funcs", data: { func: "arr" } }],
|
|
379
392
|
},
|
|
393
|
+
|
|
394
|
+
{
|
|
395
|
+
code: "const [dat, fn2] = someFn()\nconst fn1 = () => { fn2() }\n",
|
|
396
|
+
filename: "./src/foo.js",
|
|
397
|
+
errors: [{ messageId: "no-same-level-funcs", data: { func: "fn2" } }],
|
|
398
|
+
},
|
|
399
|
+
{
|
|
400
|
+
code: "const {dat, fn2} = someFn()\nconst fn1 = () => { fn2() }\n",
|
|
401
|
+
filename: "./src/foo.js",
|
|
402
|
+
errors: [{ messageId: "no-same-level-funcs", data: { func: "fn2" } }],
|
|
403
|
+
},
|
|
404
|
+
{
|
|
405
|
+
code: "const {dat, fn2: func2} = someFn()\nconst fn1 = () => { func2() }\n",
|
|
406
|
+
filename: "./src/foo.js",
|
|
407
|
+
errors: [{ messageId: "no-same-level-funcs", data: { func: "func2" } }],
|
|
408
|
+
},
|
|
380
409
|
],
|
|
381
410
|
});
|