@zukhruf/eslint 0.3.43 → 0.3.44
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 +1 -1
- package/dist/test-files/config.d.ts.map +1 -1
- package/dist/test-files/config.js +4 -0
- package/dist/test-files/config.js.map +1 -1
- package/dist/test-files/no-global-test-mock.d.ts +10 -0
- package/dist/test-files/no-global-test-mock.d.ts.map +1 -0
- package/dist/test-files/no-global-test-mock.js +18 -0
- package/dist/test-files/no-global-test-mock.js.map +1 -0
- package/dist/test-files/no-sleep-poll-loop.d.ts +11 -0
- package/dist/test-files/no-sleep-poll-loop.d.ts.map +1 -0
- package/dist/test-files/no-sleep-poll-loop.js +79 -0
- package/dist/test-files/no-sleep-poll-loop.js.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -43,7 +43,7 @@ Put framework presets (for example Nx's `flat/react`) **before** the zukhruf con
|
|
|
43
43
|
| Config | Files | Rules |
|
|
44
44
|
| ----------------- | ------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
45
45
|
| `base` | all source | `@eslint/js` and `typescript-eslint` recommended; `consistent-type-assertions` (never), `no-namespace`, `zukhruf/no-enum`; `import-x/no-duplicates`, `import-x/no-unassigned-import`; `functional/no-let` (module scope); `zukhruf/no-state-managers`, `zukhruf/no-playwright-test`, `zukhruf/no-test-file-import`; typed lint: `no-floating-promises`, `no-misused-promises`, `only-throw-error`, `switch-exhaustiveness-check` (a `default` counts as exhaustive), `zukhruf/no-promise-field`, `zukhruf/no-phase-flag`; `no-require-imports` is off in `.cjs` and `.cts`, because `require()` is the only import form in a CommonJS file |
|
|
46
|
-
| `tests` | test files, `src/testing` | `no-test-lifecycle-hooks`, `no-process-env-write`, `no-direct-msw-server`, `no-catch-all-msw-handler`, `no-timer-race`
|
|
46
|
+
| `tests` | test files, `src/testing` | `no-test-lifecycle-hooks`, `no-process-env-write`, `no-direct-msw-server`, `no-catch-all-msw-handler`, `no-timer-race`, `no-sleep-poll-loop`, `no-global-test-mock` |
|
|
47
47
|
| `diagnostics` | source, not tests | `no-fabricated-fallback`, `no-hardcoded-id-shape`, `consistent-event-name` |
|
|
48
48
|
| `env` | TypeScript, not tests or tool configs | `no-undeclared-process-env`, `no-single-env-read-wrapper`, `no-default-for-path-env` |
|
|
49
49
|
| `packaged-app` | TypeScript, not tests | `no-bare-spawn` |
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/test-files/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAU,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/test-files/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAU,MAAM,eAAe,CAAC;AAoBrD,eAAO,MAAM,KAAK,EAAE,OAWnB,CAAC"}
|
|
@@ -2,7 +2,9 @@ import { enable } from "../concept.js";
|
|
|
2
2
|
import { TESTS, TEST_SUPPORT } from "../files.js";
|
|
3
3
|
import noCatchAllMswHandler from "./no-catch-all-msw-handler.js";
|
|
4
4
|
import noDirectMswServer from "./no-direct-msw-server.js";
|
|
5
|
+
import noGlobalTestMock from "./no-global-test-mock.js";
|
|
5
6
|
import noProcessEnvWrite from "./no-process-env-write.js";
|
|
7
|
+
import noSleepPollLoop from "./no-sleep-poll-loop.js";
|
|
6
8
|
import noTestLifecycleHooks from "./no-test-lifecycle-hooks.js";
|
|
7
9
|
import noTimerRace from "./no-timer-race.js";
|
|
8
10
|
const rules = {
|
|
@@ -11,6 +13,8 @@ const rules = {
|
|
|
11
13
|
'no-direct-msw-server': noDirectMswServer,
|
|
12
14
|
'no-catch-all-msw-handler': noCatchAllMswHandler,
|
|
13
15
|
'no-timer-race': noTimerRace,
|
|
16
|
+
'no-sleep-poll-loop': noSleepPollLoop,
|
|
17
|
+
'no-global-test-mock': noGlobalTestMock,
|
|
14
18
|
};
|
|
15
19
|
export const tests = {
|
|
16
20
|
name: 'tests',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/test-files/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,MAAM,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,oBAAoB,MAAM,+BAA+B,CAAC;AACjE,OAAO,iBAAiB,MAAM,2BAA2B,CAAC;AAC1D,OAAO,iBAAiB,MAAM,2BAA2B,CAAC;AAC1D,OAAO,oBAAoB,MAAM,8BAA8B,CAAC;AAChE,OAAO,WAAW,MAAM,oBAAoB,CAAC;AAE7C,MAAM,KAAK,GAAG;IACZ,yBAAyB,EAAE,oBAAoB;IAC/C,sBAAsB,EAAE,iBAAiB;IACzC,sBAAsB,EAAE,iBAAiB;IACzC,0BAA0B,EAAE,oBAAoB;IAChD,eAAe,EAAE,WAAW;
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/test-files/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,MAAM,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,oBAAoB,MAAM,+BAA+B,CAAC;AACjE,OAAO,iBAAiB,MAAM,2BAA2B,CAAC;AAC1D,OAAO,gBAAgB,MAAM,0BAA0B,CAAC;AACxD,OAAO,iBAAiB,MAAM,2BAA2B,CAAC;AAC1D,OAAO,eAAe,MAAM,yBAAyB,CAAC;AACtD,OAAO,oBAAoB,MAAM,8BAA8B,CAAC;AAChE,OAAO,WAAW,MAAM,oBAAoB,CAAC;AAE7C,MAAM,KAAK,GAAG;IACZ,yBAAyB,EAAE,oBAAoB;IAC/C,sBAAsB,EAAE,iBAAiB;IACzC,sBAAsB,EAAE,iBAAiB;IACzC,0BAA0B,EAAE,oBAAoB;IAChD,eAAe,EAAE,WAAW;IAC5B,oBAAoB,EAAE,eAAe;IACrC,qBAAqB,EAAE,gBAAgB;CACxC,CAAC;AAEF,MAAM,CAAC,MAAM,KAAK,GAAY;IAC5B,IAAI,EAAE,OAAO;IACb,KAAK;IACL,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC;QACnB;YACE,IAAI,EAAE,eAAe;YACrB,KAAK,EAAE,CAAC,GAAG,KAAK,EAAE,GAAG,YAAY,CAAC;YAClC,OAAO;YACP,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC;SACrB;KACF;CACF,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `mock` export of node:test belongs to no test: what it patches stays
|
|
3
|
+
* patched until someone calls `mock.restoreAll()`, and that call also restores
|
|
4
|
+
* the mocks of every other test that runs at the same time. `t.mock` belongs to
|
|
5
|
+
* the test, and node:test restores it when the test ends, also when an assert
|
|
6
|
+
* fails first.
|
|
7
|
+
*/
|
|
8
|
+
declare const _default: import("eslint").Rule.RuleModule;
|
|
9
|
+
export default _default;
|
|
10
|
+
//# sourceMappingURL=no-global-test-mock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-global-test-mock.d.ts","sourceRoot":"","sources":["../../src/test-files/no-global-test-mock.ts"],"names":[],"mappings":"AAIA;;;;;;GAMG;;AACH,wBAQG"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { selectorRule } from "../authoring/selector-rule.js";
|
|
2
|
+
const NODE_TEST = '/^(node:)?test$/';
|
|
3
|
+
/**
|
|
4
|
+
* The `mock` export of node:test belongs to no test: what it patches stays
|
|
5
|
+
* patched until someone calls `mock.restoreAll()`, and that call also restores
|
|
6
|
+
* the mocks of every other test that runs at the same time. `t.mock` belongs to
|
|
7
|
+
* the test, and node:test restores it when the test ends, also when an assert
|
|
8
|
+
* fails first.
|
|
9
|
+
*/
|
|
10
|
+
export default selectorRule({
|
|
11
|
+
description: 'Disallow the global mock of node:test; use t.mock',
|
|
12
|
+
selectors: [
|
|
13
|
+
`ImportDeclaration[source.value=${NODE_TEST}] > ImportSpecifier[imported.name="mock"]`,
|
|
14
|
+
`Program:has(ImportDeclaration[source.value=${NODE_TEST}]) MemberExpression[object.name=/^(test|it)$/][property.name="mock"]`,
|
|
15
|
+
],
|
|
16
|
+
message: 'Use t.mock (the TestContext of this test): node:test restores it when the test ends, also when an assert fails.',
|
|
17
|
+
});
|
|
18
|
+
//# sourceMappingURL=no-global-test-mock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-global-test-mock.js","sourceRoot":"","sources":["../../src/test-files/no-global-test-mock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAE7D,MAAM,SAAS,GAAG,kBAAkB,CAAC;AAErC;;;;;;GAMG;AACH,eAAe,YAAY,CAAC;IAC1B,WAAW,EAAE,mDAAmD;IAChE,SAAS,EAAE;QACT,kCAAkC,SAAS,2CAA2C;QACtF,8CAA8C,SAAS,sEAAsE;KAC9H;IACD,OAAO,EACL,iHAAiH;CACpH,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Rule } from 'eslint';
|
|
2
|
+
/**
|
|
3
|
+
* A loop that sleeps between checks is a hand-written `t.waitFor`: each copy
|
|
4
|
+
* picks its own interval and deadline, and most fail with "the condition never
|
|
5
|
+
* held" instead of the check's own error. `t.waitFor` of node:test retries
|
|
6
|
+
* until the check passes and fails with the last error. A `for await` loop
|
|
7
|
+
* and a timer awaited in a callback that the loop builds are not polls.
|
|
8
|
+
*/
|
|
9
|
+
declare const rule: Rule.RuleModule;
|
|
10
|
+
export default rule;
|
|
11
|
+
//# sourceMappingURL=no-sleep-poll-loop.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-sleep-poll-loop.d.ts","sourceRoot":"","sources":["../../src/test-files/no-sleep-poll-loop.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AA4DnC;;;;;;GAMG;AACH,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,UAsBhB,CAAC;AAEF,eAAe,IAAI,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { identifierName, isAstNode, isType, } from "../authoring/ast.js";
|
|
2
|
+
const TIMERS = new Set(['setTimeout', 'sleep', 'delay']);
|
|
3
|
+
const LOOPS = new Set(['WhileStatement', 'DoWhileStatement', 'ForStatement']);
|
|
4
|
+
const FUNCTIONS = new Set([
|
|
5
|
+
'FunctionDeclaration',
|
|
6
|
+
'FunctionExpression',
|
|
7
|
+
'ArrowFunctionExpression',
|
|
8
|
+
]);
|
|
9
|
+
function calleeName(call) {
|
|
10
|
+
const callee = call['callee'];
|
|
11
|
+
return isType(callee, 'MemberExpression')
|
|
12
|
+
? identifierName(callee['property'])
|
|
13
|
+
: identifierName(callee);
|
|
14
|
+
}
|
|
15
|
+
function isTimerCall(node) {
|
|
16
|
+
if (!isType(node, 'CallExpression'))
|
|
17
|
+
return false;
|
|
18
|
+
const name = calleeName(node);
|
|
19
|
+
return name !== undefined && TIMERS.has(name);
|
|
20
|
+
}
|
|
21
|
+
/** `sleep(ms)`, `setTimeout(ms)` of `node:timers/promises`, or `new Promise((r) => setTimeout(r, ms))`. */
|
|
22
|
+
function isTimer(awaited) {
|
|
23
|
+
if (isTimerCall(awaited))
|
|
24
|
+
return true;
|
|
25
|
+
if (!isType(awaited, 'NewExpression'))
|
|
26
|
+
return false;
|
|
27
|
+
const executor = Array.isArray(awaited['arguments'])
|
|
28
|
+
? awaited['arguments'][0]
|
|
29
|
+
: undefined;
|
|
30
|
+
const body = isAstNode(executor) ? executor['body'] : undefined;
|
|
31
|
+
return (isTimerCall(body) ||
|
|
32
|
+
(isType(body, 'BlockStatement') &&
|
|
33
|
+
Array.isArray(body['body']) &&
|
|
34
|
+
body['body'].some((statement) => isType(statement, 'ExpressionStatement') &&
|
|
35
|
+
isTimerCall(statement['expression']))));
|
|
36
|
+
}
|
|
37
|
+
/** The loop that runs `node` again, in the same function. */
|
|
38
|
+
function enclosingLoop(node) {
|
|
39
|
+
let parent = node['parent'];
|
|
40
|
+
while (isAstNode(parent) && !FUNCTIONS.has(parent.type)) {
|
|
41
|
+
if (LOOPS.has(parent.type))
|
|
42
|
+
return parent;
|
|
43
|
+
parent = parent['parent'];
|
|
44
|
+
}
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* A loop that sleeps between checks is a hand-written `t.waitFor`: each copy
|
|
49
|
+
* picks its own interval and deadline, and most fail with "the condition never
|
|
50
|
+
* held" instead of the check's own error. `t.waitFor` of node:test retries
|
|
51
|
+
* until the check passes and fails with the last error. A `for await` loop
|
|
52
|
+
* and a timer awaited in a callback that the loop builds are not polls.
|
|
53
|
+
*/
|
|
54
|
+
const rule = {
|
|
55
|
+
meta: {
|
|
56
|
+
type: 'problem',
|
|
57
|
+
docs: { description: 'Disallow a loop that sleeps between checks' },
|
|
58
|
+
schema: [],
|
|
59
|
+
messages: {
|
|
60
|
+
matched: 'Use t.waitFor(() => { assert… }, { interval, timeout }): it retries until the check passes and fails with the last error.',
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
create(context) {
|
|
64
|
+
const reported = new Set();
|
|
65
|
+
return {
|
|
66
|
+
AwaitExpression(node) {
|
|
67
|
+
if (!isAstNode(node) || !isTimer(node['argument']))
|
|
68
|
+
return;
|
|
69
|
+
const loop = enclosingLoop(node);
|
|
70
|
+
if (loop === undefined || reported.has(loop))
|
|
71
|
+
return;
|
|
72
|
+
reported.add(loop);
|
|
73
|
+
context.report({ node: loop, messageId: 'matched' });
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
export default rule;
|
|
79
|
+
//# sourceMappingURL=no-sleep-poll-loop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-sleep-poll-loop.js","sourceRoot":"","sources":["../../src/test-files/no-sleep-poll-loop.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,cAAc,EACd,SAAS,EACT,MAAM,GACP,MAAM,qBAAqB,CAAC;AAE7B,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,CAAC,YAAY,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;AACzD,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC,gBAAgB,EAAE,kBAAkB,EAAE,cAAc,CAAC,CAAC,CAAC;AAC9E,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC;IACxB,qBAAqB;IACrB,oBAAoB;IACpB,yBAAyB;CAC1B,CAAC,CAAC;AAEH,SAAS,UAAU,CAAC,IAAa;IAC/B,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC9B,OAAO,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC;QACvC,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QACpC,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;AAC7B,CAAC;AAED,SAAS,WAAW,CAAC,IAAa;IAChC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,gBAAgB,CAAC;QAAE,OAAO,KAAK,CAAC;IAClD,MAAM,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;IAC9B,OAAO,IAAI,KAAK,SAAS,IAAI,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAChD,CAAC;AAED,2GAA2G;AAC3G,SAAS,OAAO,CAAC,OAAgB;IAC/B,IAAI,WAAW,CAAC,OAAO,CAAC;QAAE,OA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EAAE,WAAW,EAAE,4CAA4C,EAAE;QACnE,MAAM,EAAE,EAAE;QACV,QAAQ,EAAE;YACR,OAAO,EACL,2HAA2H;SAC9H;KACF;IACD,MAAM,CAAC,OAAO;QACZ,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAW,CAAC;QACpC,OAAO;YACL,eAAe,CAAC,IAAe;gBAC7B,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;oBAAE,OAAO;gBAC3D,MAAM,IAAI,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;gBACjC,IAAI,IAAI,KAAK,SAAS,IAAI,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC;oBAAE,OAAO;gBACrD,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;gBACnB,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC,CAAC;YACvD,CAAC;SACF,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.3.
|
|
3
|
+
"version": "0.3.44",
|
|
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": {
|