@zgeoff/oxlint-config 0.6.3 → 0.7.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 +41 -310
- package/build-lane-limits.js +31 -0
- package/build-module-order-fix.js +3 -22
- package/collect-module-entries.js +2 -15
- package/collect-refusing-edges.js +0 -2
- package/collect-type-kinds.js +0 -5
- package/collect-zone-names.js +0 -1
- package/find-function-name.js +0 -3
- package/function-verb.js +0 -4
- package/get-zone-options.js +0 -1
- package/import-zones-schema.js +0 -1
- package/import-zones.js +2 -10
- package/is-edge-refusing.js +0 -4
- package/is-entry-applying.js +0 -1
- package/is-static-value.js +0 -4
- package/is-verb-match.js +2 -2
- package/load-workspace-manifests.js +0 -4
- package/make-glob-matcher.js +0 -2
- package/max-consecutive-line-comments.js +0 -5
- package/max-test-timeout.js +191 -0
- package/module-order.js +2 -21
- package/no-abbreviated-names.js +1 -22
- package/no-class.js +1 -2
- package/no-comment-rule-override.js +4 -8
- package/no-file-snapshot.js +0 -2
- package/no-hidden-cast.js +0 -2
- package/no-restricted-words.js +0 -2
- package/no-test-sleep.js +138 -0
- package/oxlintrc.json +3 -0
- package/package.json +6 -1
- package/plugin.js +7 -4
- package/resolve-import-target.js +0 -5
- package/resolve-repo-root.js +1 -2
- package/resolve-suite-directory.js +31 -0
- package/setup-test-only.js +3 -17
- package/test-beside-module.js +15 -21
- package/test-timeout-exception-ticket.js +49 -0
- package/verb-contract.js +1 -22
package/no-test-sleep.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { basename } from 'node:path';
|
|
2
|
+
import findFunctionName from './find-function-name.js';
|
|
3
|
+
|
|
4
|
+
const testFilePattern = /\.test\.tsx?$/u;
|
|
5
|
+
|
|
6
|
+
const sleepExports = new Map([
|
|
7
|
+
['node:timers/promises', new Set(['setTimeout'])],
|
|
8
|
+
['timers/promises', new Set(['setTimeout'])],
|
|
9
|
+
['bun', new Set(['sleep', 'sleepSync'])],
|
|
10
|
+
]);
|
|
11
|
+
|
|
12
|
+
const noTestSleep = {
|
|
13
|
+
meta: {
|
|
14
|
+
type: 'problem',
|
|
15
|
+
messages: {
|
|
16
|
+
sleep:
|
|
17
|
+
'Wait on a condition, never a fixed delay: poll it inside a wait helper named `waitFor…` or `waitUntil…`, or wait on the event that signals it.',
|
|
18
|
+
},
|
|
19
|
+
schema: [],
|
|
20
|
+
},
|
|
21
|
+
create(context) {
|
|
22
|
+
if (!testFilePattern.test(basename(context.physicalFilename))) {
|
|
23
|
+
return {};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
"MemberExpression[computed=false][object.name='Bun'][property.name=/^sleep(Sync)?$/]"(node) {
|
|
28
|
+
emitSleep(context, node);
|
|
29
|
+
},
|
|
30
|
+
ImportDeclaration(node) {
|
|
31
|
+
const names = sleepExports.get(node.source.value);
|
|
32
|
+
|
|
33
|
+
if (names !== undefined) {
|
|
34
|
+
for (const variable of context.sourceCode.getDeclaredVariables(node)) {
|
|
35
|
+
emitSleepReads(context, variable, names);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
CallExpression(node) {
|
|
40
|
+
if (isWrappedTimeout(node)) {
|
|
41
|
+
emitSleep(context, node);
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export default noTestSleep;
|
|
49
|
+
|
|
50
|
+
function emitSleep(context, node) {
|
|
51
|
+
if (!isInWaitHelper(node)) {
|
|
52
|
+
context.report({ node, messageId: 'sleep' });
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const waitHelperPattern = /^wait(?:For|Until)(?![a-z])/u;
|
|
57
|
+
|
|
58
|
+
const functionTypes = new Set([
|
|
59
|
+
'FunctionDeclaration',
|
|
60
|
+
'FunctionExpression',
|
|
61
|
+
'ArrowFunctionExpression',
|
|
62
|
+
]);
|
|
63
|
+
|
|
64
|
+
function isInWaitHelper(node) {
|
|
65
|
+
for (
|
|
66
|
+
let current = node.parent;
|
|
67
|
+
current !== null && current !== undefined;
|
|
68
|
+
current = current.parent
|
|
69
|
+
) {
|
|
70
|
+
if (
|
|
71
|
+
functionTypes.has(current.type) &&
|
|
72
|
+
waitHelperPattern.test(findFunctionName(current)?.name ?? '')
|
|
73
|
+
) {
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function emitSleepReads(context, variable, names) {
|
|
82
|
+
const [definition] = variable.defs;
|
|
83
|
+
|
|
84
|
+
// a default import of these modules is the same object as their namespace
|
|
85
|
+
const isNamespace = definition.node.type !== 'ImportSpecifier';
|
|
86
|
+
|
|
87
|
+
if (!isNamespace && !names.has(getImportedName(definition.node))) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
for (const reference of variable.references) {
|
|
92
|
+
const node = isNamespace ? reference.identifier.parent : reference.identifier;
|
|
93
|
+
|
|
94
|
+
if (
|
|
95
|
+
!isNamespace ||
|
|
96
|
+
(node.type === 'MemberExpression' && !node.computed && names.has(node.property.name))
|
|
97
|
+
) {
|
|
98
|
+
emitSleep(context, node);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function getImportedName(specifier) {
|
|
104
|
+
return specifier.imported.type === 'Identifier'
|
|
105
|
+
? specifier.imported.name
|
|
106
|
+
: specifier.imported.value;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function isWrappedTimeout(call) {
|
|
110
|
+
const callee = call.callee;
|
|
111
|
+
const isTimeout =
|
|
112
|
+
(callee.type === 'Identifier' && callee.name === 'setTimeout') ||
|
|
113
|
+
(callee.type === 'MemberExpression' &&
|
|
114
|
+
!callee.computed &&
|
|
115
|
+
callee.object.type === 'Identifier' &&
|
|
116
|
+
callee.object.name === 'globalThis' &&
|
|
117
|
+
callee.property.name === 'setTimeout');
|
|
118
|
+
|
|
119
|
+
if (!isTimeout) {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
let child = call;
|
|
124
|
+
|
|
125
|
+
for (let node = call.parent; node !== null && node !== undefined; node = node.parent) {
|
|
126
|
+
if (
|
|
127
|
+
node.type === 'NewExpression' &&
|
|
128
|
+
node.callee.type === 'Identifier' &&
|
|
129
|
+
node.callee.name === 'Promise'
|
|
130
|
+
) {
|
|
131
|
+
return node.arguments.includes(child);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
child = node;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return false;
|
|
138
|
+
}
|
package/oxlintrc.json
CHANGED
|
@@ -37,6 +37,9 @@
|
|
|
37
37
|
"zgeoff/test-beside-module": "error",
|
|
38
38
|
"zgeoff/no-file-snapshot": "error",
|
|
39
39
|
"zgeoff/setup-test-only": "error",
|
|
40
|
+
"zgeoff/max-test-timeout": "error",
|
|
41
|
+
"zgeoff/test-timeout-exception-ticket": "error",
|
|
42
|
+
"zgeoff/no-test-sleep": "error",
|
|
40
43
|
|
|
41
44
|
// name a value for what it holds, in full words: one letter only for a
|
|
42
45
|
// coordinate, zod's `z`, Bun's shell `$` or an unread `_` placeholder, and
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zgeoff/oxlint-config",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Shareable oxlint config: strict categories, house-style rules, and a custom JS plugin",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -30,6 +30,11 @@
|
|
|
30
30
|
"test-beside-module.js",
|
|
31
31
|
"no-file-snapshot.js",
|
|
32
32
|
"setup-test-only.js",
|
|
33
|
+
"max-test-timeout.js",
|
|
34
|
+
"test-timeout-exception-ticket.js",
|
|
35
|
+
"build-lane-limits.js",
|
|
36
|
+
"resolve-suite-directory.js",
|
|
37
|
+
"no-test-sleep.js",
|
|
33
38
|
"import-zones.js",
|
|
34
39
|
"import-zones-schema.js",
|
|
35
40
|
"import-zones-entry.js",
|
package/plugin.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import functionVerb from './function-verb.js';
|
|
2
2
|
import importZones from './import-zones.js';
|
|
3
3
|
import maxConsecutiveLineComments from './max-consecutive-line-comments.js';
|
|
4
|
+
import buildMaxTestTimeout from './max-test-timeout.js';
|
|
4
5
|
import moduleOrder from './module-order.js';
|
|
5
6
|
import noAbbreviatedNames from './no-abbreviated-names.js';
|
|
6
7
|
import noClass from './no-class.js';
|
|
@@ -9,8 +10,11 @@ import noFileSnapshot from './no-file-snapshot.js';
|
|
|
9
10
|
import noHiddenCast from './no-hidden-cast.js';
|
|
10
11
|
import noJSDoc from './no-jsdoc.js';
|
|
11
12
|
import noRestrictedWords from './no-restricted-words.js';
|
|
13
|
+
import noTestSleep from './no-test-sleep.js';
|
|
14
|
+
import resolveRepoRoot from './resolve-repo-root.js';
|
|
12
15
|
import setupTestOnly from './setup-test-only.js';
|
|
13
16
|
import testBesideModule from './test-beside-module.js';
|
|
17
|
+
import testTimeoutExceptionTicket from './test-timeout-exception-ticket.js';
|
|
14
18
|
import verbContract from './verb-contract.js';
|
|
15
19
|
|
|
16
20
|
const plugin = {
|
|
@@ -103,16 +107,15 @@ const plugin = {
|
|
|
103
107
|
'test-beside-module': testBesideModule,
|
|
104
108
|
'no-file-snapshot': noFileSnapshot,
|
|
105
109
|
'setup-test-only': setupTestOnly,
|
|
110
|
+
'max-test-timeout': buildMaxTestTimeout(resolveRepoRoot),
|
|
111
|
+
'test-timeout-exception-ticket': testTimeoutExceptionTicket,
|
|
112
|
+
'no-test-sleep': noTestSleep,
|
|
106
113
|
'import-zones': importZones,
|
|
107
114
|
},
|
|
108
115
|
};
|
|
109
116
|
|
|
110
117
|
export default plugin;
|
|
111
118
|
|
|
112
|
-
// custom rules loaded through oxlint's jsPlugins (ESLint v9 rule API): each
|
|
113
|
-
// bans a shape no native oxlint rule can express, as an esquery selector or a
|
|
114
|
-
// source-comment scan
|
|
115
|
-
|
|
116
119
|
function buildBanRule(type, message, selectors) {
|
|
117
120
|
return {
|
|
118
121
|
meta: { type, messages: { banned: message }, schema: [] },
|
package/resolve-import-target.js
CHANGED
|
@@ -2,9 +2,6 @@ import { existsSync, readFileSync, statSync } from 'node:fs';
|
|
|
2
2
|
import { isBuiltin } from 'node:module';
|
|
3
3
|
import { dirname, join, resolve } from 'node:path';
|
|
4
4
|
|
|
5
|
-
// `module` for a package or builtin, `file` with the absolute path, or
|
|
6
|
-
// `missing`. The own name, which `self` marks, resolves through `exports`, `#`
|
|
7
|
-
// names through `imports`, and a workspace name to a path in its folder.
|
|
8
5
|
export default function resolveImportTarget(filename, specifier, settings) {
|
|
9
6
|
if (isPathSpecifier(specifier)) {
|
|
10
7
|
return toTarget(resolveImportedFile(filename, toFileSpecifier(specifier), settings.extensions));
|
|
@@ -201,8 +198,6 @@ function toMappedTarget(manifest, mapped) {
|
|
|
201
198
|
: { kind: 'file', path: resolve(manifest.directory, mapped) };
|
|
202
199
|
}
|
|
203
200
|
|
|
204
|
-
// the edges judge the package folder joined with the subpath, such as
|
|
205
|
-
// `packages/store/testing`, so the exports map's keys matter and not its targets
|
|
206
201
|
function resolveWorkspaceTarget(workspaces, specifier) {
|
|
207
202
|
const workspace = workspaces.find((candidate) => isPackageSpecifier(candidate.name, specifier));
|
|
208
203
|
|
package/resolve-repo-root.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { existsSync } from 'node:fs';
|
|
2
2
|
import { dirname, join } from 'node:path';
|
|
3
3
|
|
|
4
|
-
//
|
|
5
|
-
// null outside a repository
|
|
4
|
+
// `.git` is a file, not a directory, in a git worktree
|
|
6
5
|
export default function resolveRepoRoot(filename) {
|
|
7
6
|
let directory = dirname(filename);
|
|
8
7
|
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { join, relative, sep } from 'node:path';
|
|
3
|
+
|
|
4
|
+
export default function resolveSuiteDirectory(root, filename) {
|
|
5
|
+
const directories = relative(root, filename).split(sep).slice(0, -1);
|
|
6
|
+
|
|
7
|
+
if (directories[0] === '..') {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
for (const [index, name] of directories.entries()) {
|
|
12
|
+
const parent = join(root, ...directories.slice(0, index));
|
|
13
|
+
|
|
14
|
+
if (
|
|
15
|
+
(name === 'e2e' || name === 'integration' || name === 'evals') &&
|
|
16
|
+
probeAppRoot(root, parent)
|
|
17
|
+
) {
|
|
18
|
+
return name;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (name.endsWith('-e2e') && existsSync(join(parent, name, 'package.json'))) {
|
|
22
|
+
return 'e2e';
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function probeAppRoot(root, directory) {
|
|
30
|
+
return directory === root || existsSync(join(directory, 'package.json'));
|
|
31
|
+
}
|
package/setup-test-only.js
CHANGED
|
@@ -2,8 +2,6 @@ import { basename } from 'node:path';
|
|
|
2
2
|
|
|
3
3
|
const testFilePattern = /\.test\.tsx?$/u;
|
|
4
4
|
|
|
5
|
-
// the statements a test file holds besides its tests and `setupTest()`:
|
|
6
|
-
// imports and type-only declarations, which run nothing at module level
|
|
7
5
|
const allowedStatementTypes = new Set([
|
|
8
6
|
'ImportDeclaration',
|
|
9
7
|
'TSTypeAliasDeclaration',
|
|
@@ -73,9 +71,6 @@ const setupTestOnly = {
|
|
|
73
71
|
|
|
74
72
|
const testModules = new Set(['bun:test', 'claude-code/testing']);
|
|
75
73
|
|
|
76
|
-
// the local names that `test` from a test module goes by, so an aliased import
|
|
77
|
-
// such as `import { test as check }` counts; a file that imports no `test`
|
|
78
|
-
// reads the global one, unless a module binding of its own takes the name
|
|
79
74
|
function collectTestNames(context, program) {
|
|
80
75
|
const names = program.body
|
|
81
76
|
.filter(
|
|
@@ -106,8 +101,7 @@ function getImportedName(specifier) {
|
|
|
106
101
|
: specifier.imported.value;
|
|
107
102
|
}
|
|
108
103
|
|
|
109
|
-
//
|
|
110
|
-
// the module scope, which ESM nests under the global one
|
|
104
|
+
// ESM puts module-level bindings in a module scope nested under the global one
|
|
111
105
|
function hasModuleBinding(context, program, name) {
|
|
112
106
|
const scope = context.sourceCode.getScope(program);
|
|
113
107
|
const scopes = [scope, ...scope.childScopes.filter((child) => child.type === 'module')];
|
|
@@ -123,11 +117,8 @@ function isTestCall(statement, testNames) {
|
|
|
123
117
|
);
|
|
124
118
|
}
|
|
125
119
|
|
|
126
|
-
// the members a `test` call may chain: `test.each(rows)(…)`,
|
|
127
|
-
// `test.skipIf(gate)(…)`, `test.if(gate)(…)`, and chains of them
|
|
128
120
|
const testModifiers = new Set(['each', 'skipIf', 'if']);
|
|
129
121
|
|
|
130
|
-
// `test` itself or a chain of its modifiers, such as `test.skipIf(gate).each(rows)`
|
|
131
122
|
function isTestRunner(node, testNames) {
|
|
132
123
|
let current = node;
|
|
133
124
|
|
|
@@ -171,9 +162,6 @@ function findDeclaredName(context, statement, declarators) {
|
|
|
171
162
|
return statement.id?.name;
|
|
172
163
|
}
|
|
173
164
|
|
|
174
|
-
// a gate is a declarator whose every binding is read, only in a `skipIf(...)`
|
|
175
|
-
// argument or another gate's initializer; the set grows out from the `skipIf`
|
|
176
|
-
// reads, so consts that only read each other never join it
|
|
177
165
|
function collectSkipGates(context, constants, testNames) {
|
|
178
166
|
const gates = new Set();
|
|
179
167
|
let changed = true;
|
|
@@ -195,8 +183,6 @@ function collectSkipGates(context, constants, testNames) {
|
|
|
195
183
|
function isSkipGate(context, declarator, gates, testNames) {
|
|
196
184
|
const variables = context.sourceCode.getDeclaredVariables(declarator);
|
|
197
185
|
|
|
198
|
-
// a declarator that binds nothing, such as `const {} = registerHooks()`, is
|
|
199
|
-
// a module-level call, not a gate
|
|
200
186
|
return (
|
|
201
187
|
variables.length > 0 &&
|
|
202
188
|
variables.every((variable) => {
|
|
@@ -222,8 +208,8 @@ const functionTypes = new Set([
|
|
|
222
208
|
'ArrowFunctionExpression',
|
|
223
209
|
]);
|
|
224
210
|
|
|
225
|
-
// a
|
|
226
|
-
//
|
|
211
|
+
// bun test reads a `skipIf` gate as it collects tests, so a read inside a
|
|
212
|
+
// function, which runs later, does not count
|
|
227
213
|
function isInSkipIfArgument(identifier, testNames) {
|
|
228
214
|
let child = identifier;
|
|
229
215
|
let isSkipIfArgument = false;
|
package/test-beside-module.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { readdirSync, statSync } from 'node:fs';
|
|
2
|
-
import { basename, dirname, join
|
|
2
|
+
import { basename, dirname, join } from 'node:path';
|
|
3
|
+
import buildLaneLimits from './build-lane-limits.js';
|
|
3
4
|
import resolveRepoRoot from './resolve-repo-root.js';
|
|
5
|
+
import resolveSuiteDirectory from './resolve-suite-directory.js';
|
|
4
6
|
|
|
5
7
|
const testFilePattern = /^(?<base>.+)\.test\.tsx?$/u;
|
|
6
8
|
|
|
@@ -9,27 +11,35 @@ const testBesideModule = {
|
|
|
9
11
|
type: 'problem',
|
|
10
12
|
messages: {
|
|
11
13
|
missing:
|
|
12
|
-
'Move this test beside the module it tests: no `{{name}}.<ext>` sits in this directory.
|
|
14
|
+
'Move this test beside the module it tests: no `{{name}}.<ext>` sits in this directory. A flow across several packages belongs in `integration/`, and a test that drives the built product in `e2e/`, at the repo root or an app root.',
|
|
13
15
|
},
|
|
14
16
|
schema: [
|
|
15
17
|
{
|
|
16
18
|
type: 'object',
|
|
17
19
|
properties: {
|
|
18
|
-
lanes: {
|
|
20
|
+
lanes: {
|
|
21
|
+
anyOf: [
|
|
22
|
+
{ type: 'array', items: { type: 'string' } },
|
|
23
|
+
{ type: 'object', additionalProperties: { type: 'integer', minimum: 0 } },
|
|
24
|
+
],
|
|
25
|
+
},
|
|
19
26
|
},
|
|
20
27
|
additionalProperties: false,
|
|
21
28
|
},
|
|
22
29
|
],
|
|
23
30
|
},
|
|
24
31
|
create(context) {
|
|
25
|
-
const lanes =
|
|
32
|
+
const lanes = buildLaneLimits(context.options[0]?.lanes);
|
|
26
33
|
|
|
27
34
|
return {
|
|
28
35
|
Program() {
|
|
29
36
|
const filename = context.physicalFilename;
|
|
30
37
|
const match = testFilePattern.exec(basename(filename));
|
|
31
38
|
|
|
32
|
-
if (
|
|
39
|
+
if (
|
|
40
|
+
match === null ||
|
|
41
|
+
resolveSuiteDirectory(resolveRepoRoot(filename) ?? context.cwd, filename) !== null
|
|
42
|
+
) {
|
|
33
43
|
return;
|
|
34
44
|
}
|
|
35
45
|
|
|
@@ -55,28 +65,12 @@ const testBesideModule = {
|
|
|
55
65
|
|
|
56
66
|
export default testBesideModule;
|
|
57
67
|
|
|
58
|
-
// suites that run the whole program have no single module to sit beside
|
|
59
|
-
const exemptRootDirs = new Set(['e2e', 'evals']);
|
|
60
|
-
|
|
61
|
-
// the repo root, not oxlint's working directory, so a per-package lint
|
|
62
|
-
// script neither exempts a package's own e2e/ nor flags the root one
|
|
63
|
-
function isUnderExemptRoot(cwd, filename) {
|
|
64
|
-
const [first] = relative(resolveRepoRoot(filename) ?? cwd, filename).split(sep);
|
|
65
|
-
|
|
66
|
-
return exemptRootDirs.has(first);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// a lane suite (`<name>.browser.test.ts`) tests the same module as
|
|
70
|
-
// `<name>.test.ts`, and the suffix lets a runner put it in its own lane
|
|
71
68
|
function toModuleName(base, lanes) {
|
|
72
69
|
const dot = base.lastIndexOf('.');
|
|
73
70
|
|
|
74
71
|
return dot > 0 && lanes.has(base.slice(dot + 1)) ? base.slice(0, dot) : base;
|
|
75
72
|
}
|
|
76
73
|
|
|
77
|
-
// a module is `<name>.<ext>` with a single-segment extension, so a
|
|
78
|
-
// declaration file never stands in for one, and neither does another test
|
|
79
|
-
// (`foo.test.ts` beside `foo.test.test.ts`)
|
|
80
74
|
function probeModuleSibling(directory, name) {
|
|
81
75
|
return readdirSync(directory).some((entry) => {
|
|
82
76
|
const dot = entry.lastIndexOf('.');
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const testTimeoutExceptionTicket = {
|
|
2
|
+
meta: {
|
|
3
|
+
type: 'problem',
|
|
4
|
+
messages: {
|
|
5
|
+
ticket:
|
|
6
|
+
'This comment disables zgeoff/max-test-timeout with no ticket and no `floor:` after `--`. Give the measured time and the ticket that tracks the fix, or `floor:` and the evidence that the time cannot move, as the "Slow tests" section of the testing skill shows.',
|
|
7
|
+
},
|
|
8
|
+
schema: [],
|
|
9
|
+
},
|
|
10
|
+
create(context) {
|
|
11
|
+
return {
|
|
12
|
+
Program() {
|
|
13
|
+
for (const comment of context.sourceCode.getAllComments()) {
|
|
14
|
+
if (isTicketlessDisable(comment.value)) {
|
|
15
|
+
context.report({ loc: comment.loc, messageId: 'ticket' });
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default testTimeoutExceptionTicket;
|
|
24
|
+
|
|
25
|
+
const directivePattern = /^(?:oxlint|eslint)-disable(?:-next-line|-line)?(?=\s|$)/u;
|
|
26
|
+
|
|
27
|
+
const ticketPattern = /\b[A-Z][A-Z0-9]*-\d+\b/u;
|
|
28
|
+
|
|
29
|
+
// a block comment's continuation stars are no evidence
|
|
30
|
+
const floorPattern = /\bfloor:[\s*]*[^\s*]/u;
|
|
31
|
+
|
|
32
|
+
const ruleName = 'zgeoff/max-test-timeout';
|
|
33
|
+
|
|
34
|
+
// a directive's rule names end at a `--` that whitespace precedes, and its reason follows
|
|
35
|
+
function isTicketlessDisable(comment) {
|
|
36
|
+
const body = comment.trim();
|
|
37
|
+
const name = directivePattern.exec(body);
|
|
38
|
+
|
|
39
|
+
if (name === null) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const rest = body.slice(name[0].length);
|
|
44
|
+
const separator = /\s--/u.exec(rest);
|
|
45
|
+
const rules = (separator === null ? rest : rest.slice(0, separator.index)).split(/[\s,]+/u);
|
|
46
|
+
const reason = separator === null ? '' : rest.slice(separator.index + separator[0].length);
|
|
47
|
+
|
|
48
|
+
return rules.includes(ruleName) && !ticketPattern.test(reason) && !floorPattern.test(reason);
|
|
49
|
+
}
|
package/verb-contract.js
CHANGED
|
@@ -2,9 +2,6 @@ import collectTypeKinds from './collect-type-kinds.js';
|
|
|
2
2
|
import findFunctionName from './find-function-name.js';
|
|
3
3
|
import isVerbMatch from './is-verb-match.js';
|
|
4
4
|
|
|
5
|
-
// each named function is a frame; I/O inside an unnamed callback counts
|
|
6
|
-
// against the nearest named function around it, since that name makes the
|
|
7
|
-
// promise, while a return counts only for the function it returns from
|
|
8
5
|
const verbContract = {
|
|
9
6
|
meta: {
|
|
10
7
|
type: 'problem',
|
|
@@ -35,7 +32,6 @@ const verbContract = {
|
|
|
35
32
|
}
|
|
36
33
|
};
|
|
37
34
|
|
|
38
|
-
// a bare `return` returns undefined as `return undefined` does
|
|
39
35
|
const markReturn = (argument) => {
|
|
40
36
|
const frame = frames.at(-1);
|
|
41
37
|
|
|
@@ -49,7 +45,6 @@ const verbContract = {
|
|
|
49
45
|
|
|
50
46
|
frames.push({ node, name, ioReason: null, returnsNullish: false });
|
|
51
47
|
|
|
52
|
-
// an unnamed async callback counts only through what it awaits
|
|
53
48
|
if (node.async && name !== null) {
|
|
54
49
|
markIO('is async');
|
|
55
50
|
}
|
|
@@ -116,7 +111,6 @@ function isNullishLiteral(node) {
|
|
|
116
111
|
);
|
|
117
112
|
}
|
|
118
113
|
|
|
119
|
-
// the role table's verbs that promise no I/O
|
|
120
114
|
const pureVerbs = [
|
|
121
115
|
'is',
|
|
122
116
|
'has',
|
|
@@ -135,8 +129,6 @@ const pureVerbs = [
|
|
|
135
129
|
|
|
136
130
|
const predicateVerbs = ['is', 'has', 'can', 'should', 'probe'];
|
|
137
131
|
|
|
138
|
-
// the role table's verbs that may do I/O, and common free verbs that name a
|
|
139
|
-
// change to the world; a call to a function named with one is I/O
|
|
140
132
|
const effectfulVerbs = [
|
|
141
133
|
'probe',
|
|
142
134
|
'read',
|
|
@@ -167,9 +159,6 @@ const effectfulVerbs = [
|
|
|
167
159
|
'restart',
|
|
168
160
|
];
|
|
169
161
|
|
|
170
|
-
// a function returning a success flag, such as `removeFile` or `tryLock`,
|
|
171
|
-
// rightly returns a boolean without a predicate verb, and a framework prefix
|
|
172
|
-
// such as a React hook's `use` wins over the predicate verbs
|
|
173
162
|
const flagVerbs = [...effectfulVerbs, 'try', 'use', 'on', 'handle'];
|
|
174
163
|
|
|
175
164
|
function checkFrame(context, frame) {
|
|
@@ -348,9 +337,6 @@ function findBinding(context, node, name) {
|
|
|
348
337
|
return null;
|
|
349
338
|
}
|
|
350
339
|
|
|
351
|
-
// the source a call reaches: its root binding and the member taken straight
|
|
352
|
-
// off the root, as `spawn` in `Bun.spawn(...)`, followed through each local
|
|
353
|
-
// alias such as `const read = fs.readFileSync` or `const { spawn } = Bun`
|
|
354
340
|
function resolveCallTarget(context, node, callee) {
|
|
355
341
|
const rootName = findRootName(callee);
|
|
356
342
|
let current = {
|
|
@@ -382,7 +368,6 @@ function resolveCallTarget(context, node, callee) {
|
|
|
382
368
|
return current;
|
|
383
369
|
}
|
|
384
370
|
|
|
385
|
-
// the member read straight off a chain's root: `$` in `bun.$.cwd('a')`
|
|
386
371
|
function findRootMemberName(node) {
|
|
387
372
|
let current = node;
|
|
388
373
|
let memberName = null;
|
|
@@ -409,7 +394,6 @@ function findAliasDeclarator(binding) {
|
|
|
409
394
|
: null;
|
|
410
395
|
}
|
|
411
396
|
|
|
412
|
-
// the key a destructured binding takes, as `spawn` in `const { spawn: run } = Bun`
|
|
413
397
|
function findPatternKey(pattern, name) {
|
|
414
398
|
if (pattern.type !== 'ObjectPattern') {
|
|
415
399
|
return null;
|
|
@@ -437,8 +421,6 @@ function findImportSource(variable) {
|
|
|
437
421
|
return definition.type === 'ImportBinding' ? definition.parent.source.value : null;
|
|
438
422
|
}
|
|
439
423
|
|
|
440
|
-
// Bun's shell: the `$` export of `bun` under any import form or alias, or
|
|
441
|
-
// `Bun.$`; a parameter or local named `$` is some other function
|
|
442
424
|
function isShellTarget(target) {
|
|
443
425
|
if (isBunGlobal(target)) {
|
|
444
426
|
return target.memberName === '$';
|
|
@@ -477,9 +459,7 @@ function isIOImport(source, target) {
|
|
|
477
459
|
return bunIOMembers.has(imported);
|
|
478
460
|
}
|
|
479
461
|
|
|
480
|
-
// a
|
|
481
|
-
// package keeps its own naming, and a method on a value the function makes
|
|
482
|
-
// itself, such as `date.setUTCDate`, changes only that value
|
|
462
|
+
// a package names its functions by its own conventions, not by the code-style role table's verbs
|
|
483
463
|
function isOwnCallee(callee, frameNode) {
|
|
484
464
|
if (callee.rootName === 'this') {
|
|
485
465
|
return true;
|
|
@@ -544,7 +524,6 @@ function isEnvRead(context, node) {
|
|
|
544
524
|
);
|
|
545
525
|
}
|
|
546
526
|
|
|
547
|
-
// the global itself, so a local binding of the same name passes
|
|
548
527
|
function isGlobalName(context, node, name) {
|
|
549
528
|
return (
|
|
550
529
|
node !== undefined &&
|