@zukhruf/eslint 0.4.1 → 0.4.2
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/dist/async-values/no-collect-loop.d.ts +2 -1
- package/dist/async-values/no-collect-loop.d.ts.map +1 -1
- package/dist/async-values/no-collect-loop.js +62 -6
- package/dist/async-values/no-collect-loop.js.map +1 -1
- package/dist/test-files/no-global-test-mock.d.ts +5 -3
- package/dist/test-files/no-global-test-mock.d.ts.map +1 -1
- package/dist/test-files/no-global-test-mock.js +51 -10
- package/dist/test-files/no-global-test-mock.js.map +1 -1
- package/package.json +2 -2
|
@@ -2,7 +2,8 @@ import type { Rule } from 'eslint';
|
|
|
2
2
|
/**
|
|
3
3
|
* A `for await` loop whose only statement pushes each value into an array is
|
|
4
4
|
* `Array.fromAsync`, with the push's expression as its map function. A loop
|
|
5
|
-
* that pushes on a condition, adds to a Set, or does more stays a loop
|
|
5
|
+
* that pushes on a condition, adds to a Set, or does more stays a loop, and so
|
|
6
|
+
* does a loop whose array other code reads before the loop ends.
|
|
6
7
|
*/
|
|
7
8
|
declare const rule: Rule.RuleModule;
|
|
8
9
|
export default rule;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-collect-loop.d.ts","sourceRoot":"","sources":["../../src/async-values/no-collect-loop.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"no-collect-loop.d.ts","sourceRoot":"","sources":["../../src/async-values/no-collect-loop.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AA+GnC;;;;;GAKG;AACH,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,UAmDhB,CAAC;AAEF,eAAe,IAAI,CAAC"}
|
|
@@ -6,8 +6,8 @@ function onlyStatement(body) {
|
|
|
6
6
|
const statements = Array.isArray(body['body']) ? body['body'] : [];
|
|
7
7
|
return statements.length === 1 ? statements[0] : undefined;
|
|
8
8
|
}
|
|
9
|
-
/** The
|
|
10
|
-
function
|
|
9
|
+
/** The `<array>.push(<argument>)` call that is the whole statement. */
|
|
10
|
+
function pushCall(statement) {
|
|
11
11
|
if (!isType(statement, 'ExpressionStatement'))
|
|
12
12
|
return undefined;
|
|
13
13
|
const call = statement['expression'];
|
|
@@ -22,7 +22,55 @@ function pushedValue(statement) {
|
|
|
22
22
|
isType(args[0], 'SpreadElement')) {
|
|
23
23
|
return undefined;
|
|
24
24
|
}
|
|
25
|
-
return
|
|
25
|
+
return call;
|
|
26
|
+
}
|
|
27
|
+
/** The function whose body holds `node`, nearest first. */
|
|
28
|
+
function enclosingFunction(node) {
|
|
29
|
+
for (let current = node['parent']; isAstNode(current);) {
|
|
30
|
+
if (isType(current, 'FunctionExpression') ||
|
|
31
|
+
isType(current, 'ArrowFunctionExpression') ||
|
|
32
|
+
isType(current, 'FunctionDeclaration')) {
|
|
33
|
+
return current;
|
|
34
|
+
}
|
|
35
|
+
current = current['parent'];
|
|
36
|
+
}
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
function contains(outer, node) {
|
|
40
|
+
for (let current = node; isAstNode(current); current = current['parent']) {
|
|
41
|
+
if (current === outer)
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Other code can read the array while the loop runs when the loop sits in a
|
|
48
|
+
* function called in place whose promise is stored or returned, and the array
|
|
49
|
+
* is declared outside that function. `Array.fromAsync` gives the array only
|
|
50
|
+
* when the iterable ends. A promise awaited in place, or handed to a call,
|
|
51
|
+
* ends before the next statement reads the array, as far as the AST shows.
|
|
52
|
+
*/
|
|
53
|
+
function readWhileFilling(context, loop, push) {
|
|
54
|
+
const fn = enclosingFunction(loop);
|
|
55
|
+
const call = fn?.['parent'];
|
|
56
|
+
if (fn === undefined ||
|
|
57
|
+
!isType(call, 'CallExpression') ||
|
|
58
|
+
call['callee'] !== fn ||
|
|
59
|
+
!(isType(call['parent'], 'VariableDeclarator') ||
|
|
60
|
+
isType(call['parent'], 'AssignmentExpression') ||
|
|
61
|
+
isType(call['parent'], 'ReturnStatement'))) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
const callee = push['callee'];
|
|
65
|
+
const array = isType(callee, 'MemberExpression')
|
|
66
|
+
? callee['object']
|
|
67
|
+
: undefined;
|
|
68
|
+
if (!isType(array, 'Identifier'))
|
|
69
|
+
return false;
|
|
70
|
+
const variable = context.sourceCode
|
|
71
|
+
.getScope(array)
|
|
72
|
+
.references.find(({ identifier }) => identifier === array)?.resolved;
|
|
73
|
+
return !contains(fn, variable?.scope.block);
|
|
26
74
|
}
|
|
27
75
|
/** The identifiers in `node`, a binding pattern or an expression. */
|
|
28
76
|
function identifiers(node) {
|
|
@@ -43,7 +91,8 @@ function identifiers(node) {
|
|
|
43
91
|
/**
|
|
44
92
|
* A `for await` loop whose only statement pushes each value into an array is
|
|
45
93
|
* `Array.fromAsync`, with the push's expression as its map function. A loop
|
|
46
|
-
* that pushes on a condition, adds to a Set, or does more stays a loop
|
|
94
|
+
* that pushes on a condition, adds to a Set, or does more stays a loop, and so
|
|
95
|
+
* does a loop whose array other code reads before the loop ends.
|
|
47
96
|
*/
|
|
48
97
|
const rule = {
|
|
49
98
|
meta: {
|
|
@@ -70,9 +119,16 @@ const rule = {
|
|
|
70
119
|
const pattern = declarations.length === 1 && isAstNode(declarations[0])
|
|
71
120
|
? declarations[0]['id']
|
|
72
121
|
: undefined;
|
|
73
|
-
const
|
|
74
|
-
|
|
122
|
+
const push = pushCall(onlyStatement(loop['body']));
|
|
123
|
+
const args = Array.isArray(push?.['arguments'])
|
|
124
|
+
? push['arguments']
|
|
125
|
+
: [];
|
|
126
|
+
const value = args[0];
|
|
127
|
+
if (pattern === undefined ||
|
|
128
|
+
push === undefined ||
|
|
129
|
+
readWhileFilling(context, loop, push)) {
|
|
75
130
|
return;
|
|
131
|
+
}
|
|
76
132
|
const bound = identifiers(pattern);
|
|
77
133
|
if (isType(pattern, 'Identifier') &&
|
|
78
134
|
identifierName(value) === bound[0]) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-collect-loop.js","sourceRoot":"","sources":["../../src/async-values/no-collect-loop.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,cAAc,EACd,SAAS,EACT,MAAM,GACP,MAAM,qBAAqB,CAAC;AAE7B,gEAAgE;AAChE,SAAS,aAAa,CAAC,IAAa;IAClC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,gBAAgB,CAAC;QAAE,OAAO,IAAI,CAAC;IACjD,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACnE,OAAO,UAAU,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAC7D,CAAC;AAED,uEAAuE;AACvE,SAAS,
|
|
1
|
+
{"version":3,"file":"no-collect-loop.js","sourceRoot":"","sources":["../../src/async-values/no-collect-loop.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,cAAc,EACd,SAAS,EACT,MAAM,GACP,MAAM,qBAAqB,CAAC;AAE7B,gEAAgE;AAChE,SAAS,aAAa,CAAC,IAAa;IAClC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,gBAAgB,CAAC;QAAE,OAAO,IAAI,CAAC;IACjD,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACnE,OAAO,UAAU,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,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AE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC;gBACrD,CAAC;qBAAM,IAAI,WAAW,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;oBACnE,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,CAAC;gBACtD,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC;AAEF,eAAe,IAAI,CAAC"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import type { Rule } from 'eslint';
|
|
1
2
|
/**
|
|
2
3
|
* The `mock` export of node:test belongs to no test: what it patches stays
|
|
3
4
|
* patched until someone calls `mock.restoreAll()`, and that call also restores
|
|
4
5
|
* the mocks of every other test that runs at the same time. `t.mock` belongs to
|
|
5
6
|
* the test, and node:test restores it when the test ends, also when an assert
|
|
6
|
-
* fails first.
|
|
7
|
+
* fails first. The import is allowed only when every use of it is a
|
|
8
|
+
* `mock.module(...)` statement of the program (see `isFileModuleMock`).
|
|
7
9
|
*/
|
|
8
|
-
declare const
|
|
9
|
-
export default
|
|
10
|
+
declare const rule: Rule.RuleModule;
|
|
11
|
+
export default rule;
|
|
10
12
|
//# sourceMappingURL=no-global-test-mock.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-global-test-mock.d.ts","sourceRoot":"","sources":["../../src/test-files/no-global-test-mock.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"no-global-test-mock.d.ts","sourceRoot":"","sources":["../../src/test-files/no-global-test-mock.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AA6BnC;;;;;;;GAOG;AACH,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,UAiChB,CAAC;AAEF,eAAe,IAAI,CAAC"}
|
|
@@ -1,18 +1,59 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { identifierName, isAstNode, isType } from "../authoring/ast.js";
|
|
2
2
|
const NODE_TEST = '/^(node:)?test$/';
|
|
3
|
+
/**
|
|
4
|
+
* `mock.module(...)` as a statement of the program itself, outside every
|
|
5
|
+
* function, test and describe. node:test runs each test file in its own
|
|
6
|
+
* process, so that mock lives as long as the file and reaches no other file.
|
|
7
|
+
* A subject that binds a module when it loads needs it: a `t.mock.module`
|
|
8
|
+
* made inside one test cannot reach later tests, because the ESM cache keeps
|
|
9
|
+
* the first link.
|
|
10
|
+
*/
|
|
11
|
+
function isFileModuleMock(reference) {
|
|
12
|
+
const access = isAstNode(reference) ? reference['parent'] : undefined;
|
|
13
|
+
const call = isAstNode(access) ? access['parent'] : undefined;
|
|
14
|
+
return (isType(access, 'MemberExpression') &&
|
|
15
|
+
access['object'] === reference &&
|
|
16
|
+
access['computed'] === false &&
|
|
17
|
+
identifierName(access['property']) === 'module' &&
|
|
18
|
+
isType(call, 'CallExpression') &&
|
|
19
|
+
call['callee'] === access &&
|
|
20
|
+
isType(call['parent'], 'ExpressionStatement') &&
|
|
21
|
+
isType(call['parent']['parent'], 'Program'));
|
|
22
|
+
}
|
|
3
23
|
/**
|
|
4
24
|
* The `mock` export of node:test belongs to no test: what it patches stays
|
|
5
25
|
* patched until someone calls `mock.restoreAll()`, and that call also restores
|
|
6
26
|
* the mocks of every other test that runs at the same time. `t.mock` belongs to
|
|
7
27
|
* the test, and node:test restores it when the test ends, also when an assert
|
|
8
|
-
* fails first.
|
|
28
|
+
* fails first. The import is allowed only when every use of it is a
|
|
29
|
+
* `mock.module(...)` statement of the program (see `isFileModuleMock`).
|
|
9
30
|
*/
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
31
|
+
const rule = {
|
|
32
|
+
meta: {
|
|
33
|
+
type: 'problem',
|
|
34
|
+
docs: {
|
|
35
|
+
description: 'Disallow the global mock of node:test; use t.mock',
|
|
36
|
+
},
|
|
37
|
+
schema: [],
|
|
38
|
+
messages: {
|
|
39
|
+
matched: 'Use t.mock (the TestContext of this test): node:test restores it when the test ends, also when an assert fails.',
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
create(context) {
|
|
43
|
+
const report = (node) => context.report({ node, messageId: 'matched' });
|
|
44
|
+
return {
|
|
45
|
+
[`ImportDeclaration[source.value=${NODE_TEST}] > ImportSpecifier[imported.name="mock"]`](specifier) {
|
|
46
|
+
const references = context.sourceCode
|
|
47
|
+
.getDeclaredVariables(specifier)
|
|
48
|
+
.flatMap((variable) => variable.references);
|
|
49
|
+
if (references.length === 0 ||
|
|
50
|
+
!references.every(({ identifier }) => isFileModuleMock(identifier))) {
|
|
51
|
+
report(specifier);
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
[`Program:has(ImportDeclaration[source.value=${NODE_TEST}]) MemberExpression[object.name=/^(test|it)$/][property.name="mock"]`]: report,
|
|
55
|
+
};
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
export default rule;
|
|
18
59
|
//# sourceMappingURL=no-global-test-mock.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-global-test-mock.js","sourceRoot":"","sources":["../../src/test-files/no-global-test-mock.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"no-global-test-mock.js","sourceRoot":"","sources":["../../src/test-files/no-global-test-mock.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAExE,MAAM,SAAS,GAAG,kBAAkB,CAAC;AAErC;;;;;;;GAOG;AACH,SAAS,gBAAgB,CAAC,SAAkB;IAC1C,MAAM,MAAM,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAA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C,IACE,UAAU,CAAC,MAAM,KAAK,CAAC;oBACvB,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC,EACnE,CAAC;oBACD,MAAM,CAAC,SAAS,CAAC,CAAC;gBACpB,CAAC;YACH,CAAC;YACD,CAAC,8CAA8C,SAAS,sEAAsE,CAAC,EAC7H,MAAM;SACT,CAAC;IACJ,CAAC;CACF,CAAC;AAEF,eAAe,IAAI,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zukhruf/eslint",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "ESLint rules and configs shared across workspaces. Every check is its own named rule, so a repo's own config cannot silently erase it.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"ts-api-utils": "^2.5.0"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@zukhruf/testing": "^0.4.
|
|
65
|
+
"@zukhruf/testing": "^0.4.2"
|
|
66
66
|
},
|
|
67
67
|
"peerDependencies": {
|
|
68
68
|
"@eslint/js": "^9.30.0 || ^10.0.0",
|