@zgeoff/oxlint-config 0.7.3 → 0.7.5
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/max-test-timeout.js +14 -3
- package/package.json +2 -1
- package/plugin.js +19 -3
- package/read-rig-lanes.js +53 -0
- package/test-beside-module.js +55 -49
package/max-test-timeout.js
CHANGED
|
@@ -7,13 +7,15 @@ const runnerNames = new Set(['test', 'it', 'describe']);
|
|
|
7
7
|
|
|
8
8
|
const unitLimitMs = 5000;
|
|
9
9
|
|
|
10
|
-
export default function buildMaxTestTimeout(resolveRoot) {
|
|
10
|
+
export default function buildMaxTestTimeout(resolveRoot, rigLanes) {
|
|
11
11
|
return {
|
|
12
12
|
meta: {
|
|
13
13
|
type: 'problem',
|
|
14
14
|
messages: {
|
|
15
15
|
timeout:
|
|
16
16
|
'This timeout of {{timeoutMs}} ms is above the {{limitMs}} ms limit of the {{lane}} lane. Find its cause in the "Slow tests" section of the testing skill and fix it; a raised timeout only hides the cost.',
|
|
17
|
+
rigLanes:
|
|
18
|
+
'Declare lanes in rig.config.ts only: this repo has one, and the `lanes` option here would give the limits a second source.',
|
|
17
19
|
},
|
|
18
20
|
schema: [
|
|
19
21
|
{
|
|
@@ -31,7 +33,7 @@ export default function buildMaxTestTimeout(resolveRoot) {
|
|
|
31
33
|
],
|
|
32
34
|
},
|
|
33
35
|
create(context) {
|
|
34
|
-
const limits = buildLaneLimits(context.options[0]?.lanes);
|
|
36
|
+
const limits = rigLanes ?? buildLaneLimits(context.options[0]?.lanes);
|
|
35
37
|
|
|
36
38
|
const filename = context.physicalFilename;
|
|
37
39
|
const lane = resolveLane(resolveRoot(filename) ?? context.cwd, filename, limits);
|
|
@@ -41,6 +43,14 @@ export default function buildMaxTestTimeout(resolveRoot) {
|
|
|
41
43
|
};
|
|
42
44
|
|
|
43
45
|
return {
|
|
46
|
+
Program() {
|
|
47
|
+
if (rigLanes !== null && context.options[0]?.lanes !== undefined) {
|
|
48
|
+
context.report({
|
|
49
|
+
loc: { start: { line: 1, column: 0 }, end: { line: 1, column: 0 } },
|
|
50
|
+
messageId: 'rigLanes',
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
},
|
|
44
54
|
CallExpression(node) {
|
|
45
55
|
// the inner call of `test.each(rows)(…)` takes the rows, not a timeout
|
|
46
56
|
if (node.parent.type === 'CallExpression' && node.parent.callee === node) {
|
|
@@ -68,7 +78,8 @@ const laneTestPattern = /\.(?<lane>[^.]+)\.test\.tsx?$/u;
|
|
|
68
78
|
function resolveLane(root, filename, limits) {
|
|
69
79
|
const lane = laneTestPattern.exec(basename(filename))?.groups?.lane;
|
|
70
80
|
|
|
71
|
-
|
|
81
|
+
// the e2e lane is a directory, so a `.e2e` suffix outside it leaves the file in the unit run
|
|
82
|
+
if (lane !== undefined && lane !== 'e2e' && limits.has(lane)) {
|
|
72
83
|
return lane;
|
|
73
84
|
}
|
|
74
85
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zgeoff/oxlint-config",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.5",
|
|
4
4
|
"description": "Shareable oxlint config: strict categories, house-style rules, and a custom JS plugin",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
"max-test-timeout.js",
|
|
35
35
|
"test-timeout-exception-ticket.js",
|
|
36
36
|
"build-lane-limits.js",
|
|
37
|
+
"read-rig-lanes.js",
|
|
37
38
|
"resolve-suite-directory.js",
|
|
38
39
|
"no-test-sleep.js",
|
|
39
40
|
"no-require.js",
|
package/plugin.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
// oxlint-disable-next-line zgeoff/no-require -- only resolves rig's path from the repo root; an import loads it
|
|
3
|
+
import { createRequire } from 'node:module';
|
|
4
|
+
import { join } from 'node:path';
|
|
1
5
|
import functionVerb from './function-verb.js';
|
|
2
6
|
import importZones from './import-zones.js';
|
|
3
7
|
import maxConsecutiveLineComments from './max-consecutive-line-comments.js';
|
|
@@ -12,13 +16,25 @@ import noJSDoc from './no-jsdoc.js';
|
|
|
12
16
|
import noRequire from './no-require.js';
|
|
13
17
|
import noRestrictedWords from './no-restricted-words.js';
|
|
14
18
|
import noTestSleep from './no-test-sleep.js';
|
|
19
|
+
import readRigLanes from './read-rig-lanes.js';
|
|
15
20
|
import resolveRepoRoot from './resolve-repo-root.js';
|
|
16
21
|
import setupTestOnly from './setup-test-only.js';
|
|
17
|
-
import
|
|
22
|
+
import buildTestBesideModule from './test-beside-module.js';
|
|
18
23
|
import testShape from './test-shape.js';
|
|
19
24
|
import testTimeoutExceptionTicket from './test-timeout-exception-ticket.js';
|
|
20
25
|
import verbContract from './verb-contract.js';
|
|
21
26
|
|
|
27
|
+
// A repo with a rig.config.ts takes its lane limits from it, read once when oxlint loads the plugin.
|
|
28
|
+
const rigLanes = await readRigLanes(process.cwd(), {
|
|
29
|
+
resolveRepoRoot,
|
|
30
|
+
probeFile: existsSync,
|
|
31
|
+
importModule: (url) => import(url),
|
|
32
|
+
|
|
33
|
+
// The parser comes from the @zgeoff/rig that the repo's rig.config.ts imports, so both read one
|
|
34
|
+
// version of the resolved table. A bare import would resolve from this package's folder instead.
|
|
35
|
+
resolveRepoRig: (root) => createRequire(join(root, 'package.json')).resolve('@zgeoff/rig'),
|
|
36
|
+
});
|
|
37
|
+
|
|
22
38
|
const plugin = {
|
|
23
39
|
meta: { name: 'zgeoff' },
|
|
24
40
|
rules: {
|
|
@@ -106,10 +122,10 @@ const plugin = {
|
|
|
106
122
|
'module-order': moduleOrder,
|
|
107
123
|
'no-restricted-words': noRestrictedWords,
|
|
108
124
|
'no-abbreviated-names': noAbbreviatedNames,
|
|
109
|
-
'test-beside-module':
|
|
125
|
+
'test-beside-module': buildTestBesideModule(rigLanes),
|
|
110
126
|
'no-file-snapshot': noFileSnapshot,
|
|
111
127
|
'setup-test-only': setupTestOnly,
|
|
112
|
-
'max-test-timeout': buildMaxTestTimeout(resolveRepoRoot),
|
|
128
|
+
'max-test-timeout': buildMaxTestTimeout(resolveRepoRoot, rigLanes),
|
|
113
129
|
'test-timeout-exception-ticket': testTimeoutExceptionTicket,
|
|
114
130
|
'no-test-sleep': noTestSleep,
|
|
115
131
|
'no-require': noRequire,
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { pathToFileURL } from 'node:url';
|
|
3
|
+
|
|
4
|
+
// Returns the limit in ms of each lane that the repo's rig.config.ts resolves, keyed by the lane
|
|
5
|
+
// suffix without its dot, and `e2e` for the directory lane. Returns null for a repo with no
|
|
6
|
+
// rig.config.ts, which leaves the rules on their own lane table.
|
|
7
|
+
export default async function readRigLanes(cwd, dependencies) {
|
|
8
|
+
const root = dependencies.resolveRepoRoot(join(cwd, 'oxlint'));
|
|
9
|
+
|
|
10
|
+
if (root === null) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const configPath = join(root, 'rig.config.ts');
|
|
15
|
+
|
|
16
|
+
if (!dependencies.probeFile(configPath)) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const config = await importConfig(configPath, dependencies.importModule);
|
|
21
|
+
const rig = await dependencies.importModule(
|
|
22
|
+
pathToFileURL(dependencies.resolveRepoRig(root)).href,
|
|
23
|
+
);
|
|
24
|
+
const parsed = rig.parseRigConfig(config.default);
|
|
25
|
+
|
|
26
|
+
if (parsed.kind === 'refused') {
|
|
27
|
+
throw new TypeError(
|
|
28
|
+
`${configPath} must default-export the result of defineRig from @zgeoff/rig: ${parsed.reason}`,
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return new Map(
|
|
33
|
+
parsed.config.lanes
|
|
34
|
+
.filter((lane) => lane.name !== 'unit')
|
|
35
|
+
.map((lane) => [lane.suffix === null ? lane.name : lane.suffix.slice(1), lane.limitMs]),
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// oxlint runs a plugin under Node, which strips the types of a .ts file from Node 22.18, and Bun
|
|
40
|
+
// runs one as it is.
|
|
41
|
+
async function importConfig(configPath, importModule) {
|
|
42
|
+
try {
|
|
43
|
+
return await importModule(pathToFileURL(configPath).href);
|
|
44
|
+
} catch (error) {
|
|
45
|
+
// oxlint prints a plugin's load error without its cause, so the message carries the cause's.
|
|
46
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
47
|
+
|
|
48
|
+
throw new Error(
|
|
49
|
+
`cannot load ${configPath}: ${reason} (reading a TypeScript config needs Node >= 22.18 or Bun)`,
|
|
50
|
+
{ cause: error },
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
}
|
package/test-beside-module.js
CHANGED
|
@@ -6,64 +6,70 @@ import resolveSuiteDirectory from './resolve-suite-directory.js';
|
|
|
6
6
|
|
|
7
7
|
const testFilePattern = /^(?<base>.+)\.test\.tsx?$/u;
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
9
|
+
export default function buildTestBesideModule(rigLanes) {
|
|
10
|
+
return {
|
|
11
|
+
meta: {
|
|
12
|
+
type: 'problem',
|
|
13
|
+
messages: {
|
|
14
|
+
missing:
|
|
15
|
+
'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.',
|
|
16
|
+
rigLanes:
|
|
17
|
+
'Declare lanes in rig.config.ts only: this repo has one, and the `lanes` option here would give the lanes a second source.',
|
|
18
|
+
},
|
|
19
|
+
schema: [
|
|
20
|
+
{
|
|
21
|
+
type: 'object',
|
|
22
|
+
properties: {
|
|
23
|
+
lanes: {
|
|
24
|
+
anyOf: [
|
|
25
|
+
{ type: 'array', items: { type: 'string' } },
|
|
26
|
+
{ type: 'object', additionalProperties: { type: 'integer', minimum: 0 } },
|
|
27
|
+
],
|
|
28
|
+
},
|
|
25
29
|
},
|
|
30
|
+
additionalProperties: false,
|
|
26
31
|
},
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
create(context) {
|
|
32
|
-
const lanes = buildLaneLimits(context.options[0]?.lanes);
|
|
32
|
+
],
|
|
33
|
+
},
|
|
34
|
+
create(context) {
|
|
35
|
+
const lanes = rigLanes ?? buildLaneLimits(context.options[0]?.lanes);
|
|
33
36
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const match = testFilePattern.exec(basename(filename));
|
|
37
|
+
return {
|
|
38
|
+
Program() {
|
|
39
|
+
const start = context.sourceCode.ast.body[0]?.loc.start ?? { line: 1, column: 0 };
|
|
38
40
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
41
|
+
if (rigLanes !== null && context.options[0]?.lanes !== undefined) {
|
|
42
|
+
context.report({ loc: { start, end: start }, messageId: 'rigLanes' });
|
|
43
|
+
}
|
|
45
44
|
|
|
46
|
-
|
|
45
|
+
const filename = context.physicalFilename;
|
|
46
|
+
const match = testFilePattern.exec(basename(filename));
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
if (
|
|
49
|
+
match === null ||
|
|
50
|
+
resolveSuiteDirectory(resolveRepoRoot(filename) ?? context.cwd, filename) !== null
|
|
51
|
+
) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
51
54
|
|
|
52
|
-
|
|
53
|
-
// at the top of the file sits before the report and covers it
|
|
54
|
-
const start = context.sourceCode.ast.body[0]?.loc.start ?? { line: 1, column: 0 };
|
|
55
|
+
const name = toModuleName(match.groups.base, lanes);
|
|
55
56
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
data: { name },
|
|
60
|
-
});
|
|
61
|
-
},
|
|
62
|
-
};
|
|
63
|
-
},
|
|
64
|
-
};
|
|
57
|
+
if (probeModuleSibling(dirname(filename), name)) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
65
60
|
|
|
66
|
-
|
|
61
|
+
// anchor on the first statement, not offset 0, so a disable comment
|
|
62
|
+
// at the top of the file sits before the report and covers it
|
|
63
|
+
context.report({
|
|
64
|
+
loc: { start, end: start },
|
|
65
|
+
messageId: 'missing',
|
|
66
|
+
data: { name },
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
67
73
|
|
|
68
74
|
function toModuleName(base, lanes) {
|
|
69
75
|
const dot = base.lastIndexOf('.');
|