@zgeoff/oxlint-config 0.6.4 → 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 CHANGED
@@ -68,8 +68,8 @@ The plugin is addressable on its own at `@zgeoff/oxlint-config/plugin` for confi
68
68
  - Code style: function verbs, verb contracts, module order, abbreviated names and classes. See
69
69
  [code-style rules](../../docs/architecture/oxlint-config-code-style.md).
70
70
  - Test files: a test sits beside its module, holds only `setupTest()` and its tests, uses inline
71
- snapshots, keeps the 5 s timeout outside a lane, and waits on a condition, never a sleep. See
72
- [test-file rules](../../docs/architecture/oxlint-config-tests.md).
71
+ snapshots, keeps each timeout within its lane's limit, and waits on a condition, never a sleep.
72
+ See [test-file rules](../../docs/architecture/oxlint-config-tests.md).
73
73
  - Import boundaries: `zgeoff/import-zones` fails an import that crosses a declared zone boundary.
74
74
  See [import zones](../../docs/architecture/oxlint-config-import-zones.md).
75
75
 
@@ -0,0 +1,31 @@
1
+ // each limit is the per-test timeout in ms that the testing skill's Lanes table states
2
+ const standardLaneLimits = [
3
+ ['browser', 10_000],
4
+ ['e2e', 15_000],
5
+ ['docker', 15_000],
6
+ ['host', 15_000],
7
+ ['agent-sdk', 5000],
8
+ ['model-api', 120_000],
9
+ ];
10
+
11
+ // the array form of the option names lanes without limits, and each gets the limit of the
12
+ // standard lanes that run a real system
13
+ const listedLaneLimitMs = 15_000;
14
+
15
+ export default function buildLaneLimits(lanes) {
16
+ const limits = new Map(standardLaneLimits);
17
+
18
+ if (Array.isArray(lanes)) {
19
+ for (const lane of lanes) {
20
+ if (!limits.has(lane)) {
21
+ limits.set(lane, listedLaneLimitMs);
22
+ }
23
+ }
24
+ } else if (lanes !== undefined) {
25
+ for (const [lane, limitMs] of Object.entries(lanes)) {
26
+ limits.set(lane, limitMs);
27
+ }
28
+ }
29
+
30
+ return limits;
31
+ }
@@ -1,8 +1,7 @@
1
1
  import isStaticValue from './is-static-value.js';
2
2
 
3
- // one fix that moves every safe declaration the reports name, since oxlint
4
- // fixes a file in one pass; `moved` holds the reported entries it moves, and
5
- // `fix` is null when nothing can move
3
+ // oxlint applies one fix pass to a file, so one fix moves every safe
4
+ // declaration the reports name
6
5
  export default function buildModuleOrderFix(context, layout) {
7
6
  const names = collectNames(context);
8
7
  const reported = new Set(layout.reports.map((report) => report.entry));
@@ -38,8 +37,6 @@ export default function buildModuleOrderFix(context, layout) {
38
37
  };
39
38
  }
40
39
 
41
- // every name the file binds at its top level, so that a value can tell an
42
- // import or a global from a local
43
40
  function collectNames(context) {
44
41
  const programScope = context.sourceCode.getScope(context.sourceCode.ast);
45
42
  const scope = programScope.childScopes.find((child) => child.type === 'module') ?? programScope;
@@ -55,8 +52,6 @@ function collectNames(context) {
55
52
  return { imports, locals };
56
53
  }
57
54
 
58
- // a type always moves safely; a const moves only when every use sits in a
59
- // function body that runs after the module loads, and its value is static
60
55
  function isSafeToMove(entry, names) {
61
56
  const type = entry.declaration.type;
62
57
 
@@ -77,9 +72,7 @@ function isSafeToMove(entry, names) {
77
72
  return isUsedAfterLoad && isStaticValue(entry.declaration.declarations[0].init, names);
78
73
  }
79
74
 
80
- // the unreported consts and types whose home is the helper, which sit above
81
- // it and move with it when they move safely; a function declaration is
82
- // hoisted, so the helper itself always moves
75
+ // a function declaration is hoisted, so the helper itself always moves
83
76
  function collectStack(helper, layout, context) {
84
77
  return layout.entries.filter(
85
78
  (entry) =>
@@ -90,9 +83,6 @@ function collectStack(helper, layout, context) {
90
83
  );
91
84
  }
92
85
 
93
- // each moving helper, with its stack, goes directly after the entry before it
94
- // in the main order; then each moving const or type goes directly above the
95
- // first entry in its home's block that uses it
96
86
  function buildOrder(layout, moves) {
97
87
  const moving = new Set([
98
88
  ...moves.helpers.flatMap((helper) => [...moves.stacks.get(helper), helper]),
@@ -138,8 +128,6 @@ function buildOrder(layout, moves) {
138
128
  return order;
139
129
  }
140
130
 
141
- // the position directly after `previous`, past an `export default` that
142
- // names it
143
131
  function findInsertAfter(order, previous) {
144
132
  const at = order.indexOf(previous) + 1;
145
133
  const next = order[at];
@@ -178,8 +166,6 @@ function isTerminated(text, entry) {
178
166
  );
179
167
  }
180
168
 
181
- // the range from the first entry that moves to the last, and its new text;
182
- // an entry keeps the blank lines before it while the entry before it stays
183
169
  function renderOrder(context, entries, order) {
184
170
  const text = context.sourceCode.text;
185
171
  const chunks = collectChunks(context, entries);
@@ -205,9 +191,6 @@ function renderOrder(context, entries, order) {
205
191
  return [[chunks[first].start, chunks[last].end], parts.join('')];
206
192
  }
207
193
 
208
- // each statement's text, with the comments on the lines above it and a
209
- // comment that ends its last line; the first statement leaves a file header
210
- // that a blank line parts from it, such as a disable directive, in place
211
194
  function collectChunks(context, entries) {
212
195
  const text = context.sourceCode.text;
213
196
  const comments = context.sourceCode.getAllComments();
@@ -239,8 +222,6 @@ function collectChunks(context, entries) {
239
222
  });
240
223
  }
241
224
 
242
- // the start of the run of comments directly above `start`, with no blank
243
- // line inside it
244
225
  function findAdjacentCommentsStart(text, comments, start) {
245
226
  let current = start;
246
227
 
@@ -1,6 +1,3 @@
1
- // one entry per top-level statement, linked to the entries it references;
2
- // `kind` is 'import', 'function' for a function declaration, 'supporting'
3
- // for a const, type alias, interface or enum, and 'other' for the rest
4
1
  export default function collectModuleEntries(context, program) {
5
2
  const overloaded = new Set();
6
3
  const entries = program.body.map((statement, index) => {
@@ -55,7 +52,6 @@ function pickKind(statement, declaration) {
55
52
  return { kind: 'function', name: 'default', nameNode: statement, ...links };
56
53
  }
57
54
 
58
- // a default export of an expression, such as an object, binds no name
59
55
  if (statement.type === 'ExportDefaultDeclaration' && declaration.type !== 'FunctionDeclaration') {
60
56
  return { kind: 'other', name: 'default', nameNode: statement, ...links };
61
57
  }
@@ -71,8 +67,6 @@ function pickKind(statement, declaration) {
71
67
  return { kind, name: name.name, nameNode: name, ...links };
72
68
  }
73
69
 
74
- // the name a declaration binds: a function, a const with one plain binding,
75
- // a type alias, an interface or an enum
76
70
  function findDeclarationName(declaration) {
77
71
  if (
78
72
  declaration.type === 'FunctionDeclaration' ||
@@ -104,9 +98,6 @@ function isExportOnly(statement) {
104
98
  );
105
99
  }
106
100
 
107
- // fills each entry's `uses` and `users` from the file's top-level scope, and
108
- // its `references`: each identifier that names it, the entry that holds it,
109
- // and whether it runs as the module loads
110
101
  function linkReferences(context, program, entries) {
111
102
  const programScope = context.sourceCode.getScope(program);
112
103
  const scope = programScope.childScopes.find((child) => child.type === 'module') ?? programScope;
@@ -141,9 +132,8 @@ function linkReferences(context, program, entries) {
141
132
  }
142
133
  }
143
134
 
144
- // a reference runs as the module loads unless a function body wraps it; a
145
- // function with a call above it, such as a `.map` callback or the function in
146
- // `(() => value).call()`, may run at once, so it wraps nothing
135
+ // a function under a call, such as a `.map` callback or the function in
136
+ // `(() => value).call()`, may run at once, so it defers nothing
147
137
  function isLoadTime(identifier) {
148
138
  const ancestors = [];
149
139
 
@@ -174,9 +164,6 @@ function isInvocation(node) {
174
164
  );
175
165
  }
176
166
 
177
- // an entry is live when code that runs as the module loads may call into it;
178
- // a load-time reference outside an export list makes its target live, and a
179
- // live entry makes everything it references live
180
167
  function markLiveEntries(entries) {
181
168
  const live = new Set();
182
169
  const pending = [];
@@ -2,8 +2,6 @@ import collectZoneNames from './collect-zone-names.js';
2
2
  import getZoneOptions from './get-zone-options.js';
3
3
  import isEdgeRefusing from './is-edge-refusing.js';
4
4
 
5
- // the edges in `options` that refuse an import from `edgeImport.from` of
6
- // `edgeImport.to`, as the options list them
7
5
  export default function collectRefusingEdges(options, edgeImport) {
8
6
  const compiled = getZoneOptions(options);
9
7
 
@@ -1,6 +1,3 @@
1
- // the kind of each member of a declared type, read without type information:
2
- // a union splits into its members, a reference follows the file's own type
3
- // aliases, and `resolvePromise` reads a promise as the value it resolves to
4
1
  export default function collectTypeKinds(
5
2
  type,
6
3
  localTypes,
@@ -45,8 +42,6 @@ function isReadonlyOperator(type) {
45
42
  return type.type === 'TSTypeOperator' && type.operator === 'readonly';
46
43
  }
47
44
 
48
- // a type whose members the rule can see and that never holds null; any other
49
- // shape, such as an indexed access or a conditional type, is open
50
45
  const valueTypes = new Set([
51
46
  'TSStringKeyword',
52
47
  'TSNumberKeyword',
@@ -1,4 +1,3 @@
1
- // `zones` holds the compiled zones, each a name and a path matcher
2
1
  export default function collectZoneNames(zones, path) {
3
2
  return zones.filter((zone) => zone.match(path)).map((zone) => zone.name);
4
3
  }
@@ -1,6 +1,3 @@
1
- // a declaration's own name, the variable or key a function is assigned to,
2
- // or else a function expression's own name; getters, setters, computed and
3
- // quoted keys name nothing
4
1
  export default function findFunctionName(node) {
5
2
  if (node.type === 'FunctionDeclaration') {
6
3
  return node.id;
package/function-verb.js CHANGED
@@ -41,8 +41,6 @@ const functionVerb = {
41
41
 
42
42
  export default functionVerb;
43
43
 
44
- // the role table's template prefixes (`with<X>`, `handle<Event>`, …): each is
45
- // only valid with a suffix, and a bare `handle` is the vague banned verb
46
44
  const suffixRequiredVerbs = new Set(['to', 'with', 'make', 'use', 'on']);
47
45
 
48
46
  function planReport(name, exemptNames) {
@@ -70,8 +68,6 @@ function planReport(name, exemptNames) {
70
68
  };
71
69
  }
72
70
 
73
- // banned verb → the role-table verb to use instead; null means the verb is
74
- // too vague to map and the name should say what the function does
75
71
  const bannedVerbs = new Map([
76
72
  ['process', null],
77
73
  ['manage', null],
@@ -55,7 +55,6 @@ function buildEntry(entry) {
55
55
  };
56
56
  }
57
57
 
58
- // `src/*` keeps an import inside the importer's own `src/<name>/` directory
59
58
  function makeWithinMatcher(glob) {
60
59
  const depth = glob.split('/').length;
61
60
  const match = makeGlobMatcher([glob]);
@@ -1,4 +1,3 @@
1
- // the options of zgeoff/import-zones; oxlint rejects a config that breaks it
2
1
  const stringList = { type: 'array', items: { type: 'string' } };
3
2
 
4
3
  const importZonesSchema = {
package/import-zones.js CHANGED
@@ -81,9 +81,6 @@ const importZones = {
81
81
 
82
82
  export default importZones;
83
83
 
84
- // Judges each import against named zones: path globs relative to the repo
85
- // root, which may overlap. A file belongs to every zone its path matches.
86
-
87
84
  function loadFileState(context) {
88
85
  const options = getZoneOptions(context.options[0] ?? {});
89
86
  const filename = context.physicalFilename;
@@ -108,8 +105,8 @@ function toRootPath(root, path) {
108
105
  }
109
106
 
110
107
  function checkUnzoned(file, program) {
111
- // anchor on the first statement, as test-beside-module does, so a disable
112
- // comment at the top of the file covers the report
108
+ // anchor on the first statement, not offset 0, so a disable comment at the
109
+ // top of the file covers the report
113
110
  const start = program.body[0]?.loc.start ?? { line: 1, column: 0 };
114
111
 
115
112
  for (const entry of collectEntries(file, file.options.unzoned)) {
@@ -127,7 +124,6 @@ function collectEntries(file, entries) {
127
124
  return entries.filter((entry) => isEntryApplying(entry, file.path, file.zones));
128
125
  }
129
126
 
130
- // `at` is `{ node }` or `{ loc }`
131
127
  function emitReport(file, entry, report) {
132
128
  const reason = entry.reason === undefined ? '' : ` — ${entry.reason}`;
133
129
 
@@ -142,7 +138,6 @@ function formatZones(names) {
142
138
  return names.length === 0 ? 'no zone' : names.join(', ');
143
139
  }
144
140
 
145
- // `imported` is `{ node, source, typeOnly }`, one per import of any form
146
141
  function checkImport(file, imported) {
147
142
  const specifier = findStaticSpecifier(imported.source);
148
143
 
@@ -172,7 +167,6 @@ function checkImport(file, imported) {
172
167
  }
173
168
  }
174
169
 
175
- // a string literal, or a template literal with nothing interpolated
176
170
  function findStaticSpecifier(node) {
177
171
  if (node?.type === 'Literal' && typeof node.value === 'string') {
178
172
  return node.value;
@@ -239,7 +233,6 @@ function isPrefixMatch(prefix, specifier) {
239
233
  return prefix === 'node:' && isBuiltin(specifier);
240
234
  }
241
235
 
242
- // collectRefusingEdges judges an edge the same way, through isEdgeRefusing
243
236
  function checkEdge(file, imported, target) {
244
237
  const edgeImport = {
245
238
  from: file.path,
@@ -294,7 +287,6 @@ function checkGlobalCall(file, node) {
294
287
 
295
288
  const globalObjects = new Set(['globalThis', 'self', 'window']);
296
289
 
297
- // a call of the global itself, so a local binding of the same name passes
298
290
  function findGlobalCallName(file, node, names) {
299
291
  const callee = node.callee;
300
292
  let name = null;
@@ -1,11 +1,7 @@
1
1
  import isEntryApplying from './is-entry-applying.js';
2
2
  import isInAnyZone from './is-in-any-zone.js';
3
3
 
4
- // `entry` is a compiled edge; `edgeImport` is `{ from, to, fromZones,
5
- // toZones, typeOnly }`, both paths relative to the repo root
6
4
  export default function isEdgeRefusing(entry, edgeImport) {
7
- // `to` picks the targets judged, every target when absent; `allow` exempts
8
- // some of them. The schema needs one of the two.
9
5
  const isForbidden =
10
6
  (entry.to === undefined || isInAnyZone(edgeImport.toZones, entry.to)) &&
11
7
  (entry.allow === undefined || !isInAnyZone(edgeImport.toZones, entry.allow));
@@ -1,6 +1,5 @@
1
1
  import isInAnyZone from './is-in-any-zone.js';
2
2
 
3
- // an entry without `from` applies to every file
4
3
  export default function isEntryApplying(entry, path, zones) {
5
4
  return (entry.from === undefined || isInAnyZone(zones, entry.from)) && !entry.ignore(path);
6
5
  }
@@ -34,9 +34,6 @@ const checks = {
34
34
  value.arguments.every((argument) => isStaticArgument(argument, names)),
35
35
  };
36
36
 
37
- // a value that runs no code and reads nothing that load-time code can change,
38
- // so it is the same wherever it sits; an import stands only where its value
39
- // is copied, such as an array element, and never where it is read through
40
37
  export default function isStaticValue(node, names, canCopyImport = true) {
41
38
  const value = unwrapExpression(node);
42
39
  const check = checks[value.type];
@@ -52,7 +49,6 @@ const wrapperTypes = new Set([
52
49
  'ParenthesizedExpression',
53
50
  ]);
54
51
 
55
- // a type assertion or parentheses leave the value as it is
56
52
  function unwrapExpression(node) {
57
53
  let current = node;
58
54
 
package/is-verb-match.js CHANGED
@@ -1,5 +1,5 @@
1
- // a name starts with a verb when the verb ends at a camelCase boundary; a
2
- // digit also ends it, since acronyms like 2FA start camelCase segments
1
+ // a digit ends a verb too, since an acronym such as 2FA starts a camelCase
2
+ // segment
3
3
  export default function isVerbMatch(name, verb) {
4
4
  return name === verb || (name.startsWith(verb) && /[A-Z0-9]/u.test(name.charAt(verb.length)));
5
5
  }
@@ -2,9 +2,6 @@ import { existsSync, readFileSync, readdirSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
3
  import makeGlobMatcher from './make-glob-matcher.js';
4
4
 
5
- // The manifest of every package directory the globs match, relative to the
6
- // root. Each glob segment matches one directory level, as a workspaces
7
- // field's globs do.
8
5
  export default function loadWorkspaceManifests(root, globs) {
9
6
  return withManifestCache(JSON.stringify([root, globs]), () =>
10
7
  globs
@@ -48,7 +45,6 @@ function splitGlob(glob) {
48
45
  return glob.split('/').filter((segment) => segment !== '' && segment !== '.');
49
46
  }
50
47
 
51
- // `directory` is the field the resolver reads from every manifest it loads
52
48
  function loadManifest(directory) {
53
49
  const path = join(directory, 'package.json');
54
50
 
@@ -1,5 +1,3 @@
1
- // supports `**`, `*`, `?` and one level of `{a,b}`; every other character is
2
- // literal. Paths and globs use `/`.
3
1
  export default function makeGlobMatcher(globs) {
4
2
  const patterns = globs.map((glob) => toGlobRegExp(glob));
5
3
 
@@ -39,9 +39,6 @@ const maxConsecutiveLineComments = {
39
39
 
40
40
  export default maxConsecutiveLineComments;
41
41
 
42
- // a run is prose line comments on consecutive lines; whatever else occupies
43
- // a line between two of them (code, a blank, a directive, a block comment)
44
- // breaks adjacency and so ends the run
45
42
  function collectRuns(text, comments) {
46
43
  const runs = [];
47
44
 
@@ -58,8 +55,6 @@ function collectRuns(text, comments) {
58
55
  return runs;
59
56
  }
60
57
 
61
- // tool directives are not prose: they neither count toward a run nor join
62
- // the prose on either side of them into one
63
58
  const directivePattern =
64
59
  /^\s*(?:oxlint-|eslint-|@ts-|prettier-|oxfmt-|biome-ignore|#region|#endregion|\/\s*<)/u;
65
60
 
@@ -1,34 +1,43 @@
1
- import { basename, relative, sep } from 'node:path';
1
+ import { basename } from 'node:path';
2
+ import buildLaneLimits from './build-lane-limits.js';
3
+ import resolveSuiteDirectory from './resolve-suite-directory.js';
2
4
 
3
5
  const runnerNames = new Set(['test', 'it', 'describe']);
4
6
 
7
+ const unitLimitMs = 5000;
8
+
5
9
  export default function buildMaxTestTimeout(resolveRoot) {
6
10
  return {
7
11
  meta: {
8
12
  type: 'problem',
9
13
  messages: {
10
14
  timeout:
11
- 'Keep this timeout of {{timeoutMs}} ms within the 5 s limit, or move the test into a lane: a root `e2e/` suite, or a `*.browser.test.ts`, `*.docker.test.ts` or `*.host.test.ts` file.',
15
+ '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.',
12
16
  },
13
17
  schema: [
14
18
  {
15
19
  type: 'object',
16
20
  properties: {
17
- lanes: { type: 'array', items: { type: 'string' } },
21
+ lanes: {
22
+ anyOf: [
23
+ { type: 'array', items: { type: 'string' } },
24
+ { type: 'object', additionalProperties: { type: 'integer', minimum: 0 } },
25
+ ],
26
+ },
18
27
  },
19
28
  additionalProperties: false,
20
29
  },
21
30
  ],
22
31
  },
23
32
  create(context) {
24
- const lanes = new Set(['browser', 'docker', 'host', ...(context.options[0]?.lanes ?? [])]);
33
+ const limits = buildLaneLimits(context.options[0]?.lanes);
25
34
 
26
35
  const filename = context.physicalFilename;
27
- const root = resolveRoot(filename) ?? context.cwd;
28
-
29
- if (isLaneFile(relative(root, filename), lanes)) {
30
- return {};
31
- }
36
+ const lane = resolveLane(resolveRoot(filename) ?? context.cwd, filename, limits);
37
+ const limit = {
38
+ lane: lane ?? 'unit',
39
+ limitMs: lane === null ? unitLimitMs : limits.get(lane),
40
+ };
32
41
 
33
42
  return {
34
43
  CallExpression(node) {
@@ -40,9 +49,9 @@ export default function buildMaxTestTimeout(resolveRoot) {
40
49
  const name = findRunnerName(context, node.callee);
41
50
 
42
51
  if (name === 'setDefaultTimeout') {
43
- emitTimeouts(context, node.arguments.slice(0, 1));
52
+ emitTimeouts(context, node.arguments.slice(0, 1), limit);
44
53
  } else if (name !== null && runnerNames.has(name)) {
45
- emitTimeouts(context, node.arguments.slice(1));
54
+ emitTimeouts(context, node.arguments.slice(1), limit);
46
55
  }
47
56
  },
48
57
  };
@@ -52,13 +61,17 @@ export default function buildMaxTestTimeout(resolveRoot) {
52
61
 
53
62
  const laneTestPattern = /\.(?<lane>[^.]+)\.test\.tsx?$/u;
54
63
 
55
- // relative to the repo root, not oxlint's working directory, so a per-package
56
- // lint script reads the same root `e2e/` as a run from the root
57
- function isLaneFile(path, lanes) {
58
- const lane = laneTestPattern.exec(basename(path))?.groups?.lane;
59
- const [first] = path.split(sep);
64
+ // a lane suffix wins over the directory, because the default run leaves a suffixed file out and its
65
+ // lane's script runs it; the directory is relative to the repo root, not oxlint's working
66
+ // directory, so a per-package lint script reads the same root `e2e/` as a run from the root
67
+ function resolveLane(root, filename, limits) {
68
+ const lane = laneTestPattern.exec(basename(filename))?.groups?.lane;
60
69
 
61
- return first === 'e2e' || (lane !== undefined && lanes.has(lane));
70
+ if (lane !== undefined && limits.has(lane)) {
71
+ return lane;
72
+ }
73
+
74
+ return resolveSuiteDirectory(root, filename) === 'e2e' ? 'e2e' : null;
62
75
  }
63
76
 
64
77
  function findRunnerName(context, callee) {
@@ -118,15 +131,13 @@ function getImportedName(specifier) {
118
131
  : specifier.imported.value;
119
132
  }
120
133
 
121
- const limitMs = 5000;
122
-
123
- function emitTimeouts(context, args) {
134
+ function emitTimeouts(context, args, limit) {
124
135
  for (const argument of args) {
125
136
  const value = argument.type === 'ObjectExpression' ? findTimeoutValue(argument) : argument;
126
137
  const timeoutMs = value === undefined ? null : findNumber(context, value, new Set());
127
138
 
128
- if (timeoutMs !== null && timeoutMs > limitMs) {
129
- context.report({ node: value, messageId: 'timeout', data: { timeoutMs } });
139
+ if (timeoutMs !== null && timeoutMs > limit.limitMs) {
140
+ context.report({ node: value, messageId: 'timeout', data: { timeoutMs, ...limit } });
130
141
  }
131
142
  }
132
143
  }
package/module-order.js CHANGED
@@ -2,8 +2,6 @@ import { basename } from 'node:path';
2
2
  import buildModuleOrderFix from './build-module-order-fix.js';
3
3
  import collectModuleEntries from './collect-module-entries.js';
4
4
 
5
- // the code-style module order: the primary export, then its private helpers
6
- // depth-first, with each const, type or enum directly above its first use
7
5
  const moduleOrder = {
8
6
  meta: {
9
7
  type: 'suggestion',
@@ -73,9 +71,6 @@ function checkModule(context, program) {
73
71
  }
74
72
  }
75
73
 
76
- // the default export, else the export the file is named for, else the only
77
- // value the file exports; `export default name` names the declaration of
78
- // `name`, and a default export of any other expression is the statement
79
74
  function findPrimaryExport(entries, filename) {
80
75
  const defaultEntry = entries.find((entry) => entry.exportKind === 'default') ?? null;
81
76
  const defaultName =
@@ -98,7 +93,6 @@ function findPrimaryExport(entries, filename) {
98
93
  return named ?? only;
99
94
  }
100
95
 
101
- // `parseCLIArgs` becomes `parse-cli-args`, as the code-style file names read
102
96
  function toKebabCase(name) {
103
97
  return name
104
98
  .replaceAll(/(?<before>[a-z\d])(?<after>[A-Z])/gu, '$<before>-$<after>')
@@ -106,9 +100,6 @@ function toKebabCase(name) {
106
100
  .toLowerCase();
107
101
  }
108
102
 
109
- // the primary export, then each private helper it reaches, depth-first in the
110
- // order each one is first referenced; a const or type passes its references
111
- // through, so a helper that only a const names still has a place
112
103
  function collectMainOrder(primary) {
113
104
  const order = [primary];
114
105
  const seen = new Set([primary]);
@@ -139,8 +130,6 @@ function isHelper(entry) {
139
130
  return entry.kind === 'function' && entry.exportKind === null;
140
131
  }
141
132
 
142
- // the main-order entry each const or type belongs above: the earliest one
143
- // that uses it, directly or through another const or type
144
133
  function buildHomes(entries, ranks) {
145
134
  const homes = new Map();
146
135
  const visiting = new Set();
@@ -179,17 +168,12 @@ function buildHomes(entries, ranks) {
179
168
  return homes;
180
169
  }
181
170
 
182
- // the users of `entry` in its home's block: the home itself and each const
183
- // or type with the same home
184
171
  function collectBlockUsers(entry, homes) {
185
172
  const home = homes.get(entry);
186
173
 
187
174
  return [...entry.users].filter((user) => user === home || homes.get(user) === home);
188
175
  }
189
176
 
190
- // a helper above the primary export, and a helper below it that breaks the
191
- // depth-first order; the longest run already in order stays, so each report
192
- // names one helper to move
193
177
  function collectHelperReports(layout) {
194
178
  const primary = layout.primary;
195
179
  const reports = [];
@@ -218,7 +202,6 @@ function collectHelperReports(layout) {
218
202
  return reports;
219
203
  }
220
204
 
221
- // the positions of one longest increasing run in `values`
222
205
  function collectLongestRun(values) {
223
206
  const lengths = values.map(() => 1);
224
207
  const previous = values.map(() => -1);
@@ -243,9 +226,6 @@ function collectLongestRun(values) {
243
226
  return kept;
244
227
  }
245
228
 
246
- // a const or type sits above every use in its home's block, with no helper
247
- // that stays between it and its home; a const that a live function reads
248
- // stays unchecked, since below the primary export it could be read unset
249
229
  function collectDeclarationReports(layout, helperReports) {
250
230
  const homes = layout.homes;
251
231
  const moving = new Set(helperReports.map((report) => report.entry));
@@ -255,6 +235,8 @@ function collectDeclarationReports(layout, helperReports) {
255
235
  for (const entry of layout.entries) {
256
236
  const home = homes.get(entry) ?? null;
257
237
 
238
+ // load-time code can call a live function before a const below the primary
239
+ // export is set, so a const that a live function reads stays unchecked
258
240
  if (home === null || (hasValue(entry) && isReadByLiveFunction(entry))) {
259
241
  continue;
260
242
  }
@@ -278,7 +260,6 @@ function collectDeclarationReports(layout, helperReports) {
278
260
  return reports;
279
261
  }
280
262
 
281
- // a type has no value to read unset, so it is always checked
282
263
  function hasValue(entry) {
283
264
  const type = entry.declaration.type;
284
265
 
@@ -1,5 +1,3 @@
1
- // each `names` key is a short name and its value the text that replaces it;
2
- // the rule matches a whole name, so `timeoutMs` passes when `ms` is listed
3
1
  const noAbbreviatedNames = {
4
2
  meta: {
5
3
  type: 'suggestion',
@@ -46,9 +44,6 @@ const noAbbreviatedNames = {
46
44
  }
47
45
  };
48
46
 
49
- // a computed key names its property as a plain key does when it is a
50
- // string written in place, as in `{ ['src']: 1 }`; a computed identifier
51
- // reads a variable, whose declaration is checked where it is made
52
47
  const checkMemberName = (node, name) => {
53
48
  if (!node.computed || name.type !== 'Identifier') {
54
49
  checkName(name);
@@ -65,8 +60,6 @@ const noAbbreviatedNames = {
65
60
  }
66
61
  };
67
62
 
68
- // a write to a member names that property, whether the member stands
69
- // alone or sits inside a destructuring target
70
63
  const checkAssignmentTarget = (node) => {
71
64
  for (const member of collectTargetMembers(node)) {
72
65
  checkMemberName(member, member.property);
@@ -79,8 +72,6 @@ const noAbbreviatedNames = {
79
72
  }
80
73
  };
81
74
 
82
- // function-verb checks only a plain function or method name, so a quoted
83
- // method, a signature or a declared function would pass both rules
84
75
  const checkFunction = (node) => {
85
76
  checkName(node.id);
86
77
  checkParams(node);
@@ -94,7 +85,6 @@ const noAbbreviatedNames = {
94
85
  FunctionExpression: checkFunction,
95
86
  ArrowFunctionExpression: checkParams,
96
87
 
97
- // a signature without a body names its parameters as an implementation does
98
88
  TSDeclareFunction: checkFunction,
99
89
  TSEmptyBodyFunctionExpression: checkParams,
100
90
  TSFunctionType: checkParams,
@@ -117,19 +107,16 @@ const noAbbreviatedNames = {
117
107
  MethodDefinition: checkKey,
118
108
  TSAbstractMethodDefinition: checkKey,
119
109
 
120
- // a class, an enum and a namespace are values at run time; a quoted
121
- // module name is a path, not a value name
122
110
  'ClassDeclaration, ClassExpression, TSEnumDeclaration'(node) {
123
111
  checkName(node.id);
124
112
  },
125
113
  TSModuleDeclaration(node) {
114
+ // `declare module 'name'` quotes a module path, not a value name
126
115
  if (node.id.type === 'Identifier') {
127
116
  checkName(node.id);
128
117
  }
129
118
  },
130
119
 
131
- // an import's local binding is a value name in this module, whatever the
132
- // exporting module calls it; a type-only import names a type, not a value
133
120
  'ImportSpecifier, ImportDefaultSpecifier, ImportNamespaceSpecifier'(node) {
134
121
  if (!isTypeOnlyImport(node)) {
135
122
  checkName(node.local);
@@ -149,7 +136,6 @@ const noAbbreviatedNames = {
149
136
  checkName(node.id);
150
137
  },
151
138
 
152
- // an export alias is the name every importing module reads the value by
153
139
  ExportSpecifier(node) {
154
140
  if (!isTypeOnlyExport(node)) {
155
141
  checkName(node.exported);
@@ -169,9 +155,6 @@ const noAbbreviatedNames = {
169
155
  },
170
156
  };
171
157
 
172
- // the name a key or binding spells out in the source: an identifier, a
173
- // string, or a template with no substitutions; a key built at run time has
174
- // no static name, so the result is null
175
158
  function findStaticName(node) {
176
159
  if (node?.type === 'Identifier' || node?.type === 'PrivateIdentifier') {
177
160
  return node.name;
@@ -188,8 +171,6 @@ function findStaticName(node) {
188
171
  return null;
189
172
  }
190
173
 
191
- // the names a binding pattern declares: a destructured key's alias, not the
192
- // key, since the key belongs to the object being read
193
174
  function collectPatternIdentifiers(node) {
194
175
  if (node === null || node === undefined) {
195
176
  return [];
@@ -226,8 +207,6 @@ function collectPatternIdentifiers(node) {
226
207
  return [];
227
208
  }
228
209
 
229
- // the members an assignment target writes; a bare identifier in the target
230
- // writes a variable declared elsewhere, and its declaration is checked there
231
210
  function collectTargetMembers(node) {
232
211
  if (node === null || node === undefined) {
233
212
  return [];
package/no-class.js CHANGED
@@ -1,6 +1,5 @@
1
1
  // a custom error stays a class, since `instanceof` checks and stack traces
2
- // need one: its superclass is `Error` or another name that ends in `Error`,
3
- // bare or as a member such as `errors.BrewError`
2
+ // need one
4
3
  const noClass = {
5
4
  meta: {
6
5
  type: 'problem',
@@ -2,9 +2,8 @@ import { readFileSync, readdirSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
3
  import resolveRepoRoot from './resolve-repo-root.js';
4
4
 
5
- // the one file per repo that carries the report, so a repo with an override
6
- // sees it once per run rather than on every file, and an editor's language
7
- // server keeps it on that file across edits
5
+ // a report on one file per repo shows once per run, and an editor's
6
+ // language server keeps it on that file across edits
8
7
  const anchorFiles = new Map();
9
8
 
10
9
  const noCommentRuleOverride = {
@@ -45,8 +44,6 @@ export default noCommentRuleOverride;
45
44
 
46
45
  const configPattern = /^\.oxlintrc(?:\.[\w-]+)?\.jsonc?$/u;
47
46
 
48
- // every repo runs the comment rules and the type-assertion rules exactly as
49
- // this config ships them, each named here without its plugin prefix
50
47
  const lockedRules = [
51
48
  'no-jsdoc',
52
49
  'max-consecutive-line-comments',
@@ -54,9 +51,8 @@ const lockedRules = [
54
51
  'no-hidden-cast',
55
52
  ];
56
53
 
57
- // a rule key under any plugin prefix or none, since oxlint also reads
58
- // `@typescript-eslint/consistent-type-assertions` and the bare name, as
59
- // opposed to the same text inside a comment or a string value
54
+ // oxlint reads a rule under any plugin prefix, such as
55
+ // `@typescript-eslint/consistent-type-assertions`, or under its bare name
60
56
  const keyPatterns = lockedRules.map(
61
57
  (rule) => new RegExp(`"(?<key>(?:[^"/\\s]+/)?${rule})"\\s*:`, 'gu'),
62
58
  );
@@ -1,8 +1,6 @@
1
1
  import { statSync } from 'node:fs';
2
2
  import { basename, dirname, join } from 'node:path';
3
3
 
4
- // the matchers that write `__snapshots__/<test file>.snap`; their inline
5
- // counterparts keep the golden value in the test itself
6
4
  const fileMatchers = ['toMatchSnapshot', 'toThrowErrorMatchingSnapshot'];
7
5
 
8
6
  const noFileSnapshot = {
package/no-hidden-cast.js CHANGED
@@ -50,8 +50,6 @@ const noHiddenCast = {
50
50
  },
51
51
  };
52
52
 
53
- // the name an identifier or a member access ends in, `sql` for both `sql` and
54
- // `db.sql`, or null for a computed member that is not a string literal
55
53
  function findName(node) {
56
54
  if (node.type === 'Identifier') {
57
55
  return node.name;
@@ -48,8 +48,6 @@ const noRestrictedWords = {
48
48
  },
49
49
  };
50
50
 
51
- // a letter, digit or underscore on either side makes the match part of a
52
- // longer word (`impl`, `simple`), so only those characters bound it
53
51
  function buildWordPattern(words) {
54
52
  const alternatives = words.map((word) =>
55
53
  word.replaceAll(/[$()*+.?[\\\]^{|}]/gu, String.raw`\$&`),
package/oxlintrc.json CHANGED
@@ -38,6 +38,7 @@
38
38
  "zgeoff/no-file-snapshot": "error",
39
39
  "zgeoff/setup-test-only": "error",
40
40
  "zgeoff/max-test-timeout": "error",
41
+ "zgeoff/test-timeout-exception-ticket": "error",
41
42
  "zgeoff/no-test-sleep": "error",
42
43
 
43
44
  // name a value for what it holds, in full words: one letter only for a
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zgeoff/oxlint-config",
3
- "version": "0.6.4",
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": {
@@ -31,6 +31,9 @@
31
31
  "no-file-snapshot.js",
32
32
  "setup-test-only.js",
33
33
  "max-test-timeout.js",
34
+ "test-timeout-exception-ticket.js",
35
+ "build-lane-limits.js",
36
+ "resolve-suite-directory.js",
34
37
  "no-test-sleep.js",
35
38
  "import-zones.js",
36
39
  "import-zones-schema.js",
package/plugin.js CHANGED
@@ -14,6 +14,7 @@ import noTestSleep from './no-test-sleep.js';
14
14
  import resolveRepoRoot from './resolve-repo-root.js';
15
15
  import setupTestOnly from './setup-test-only.js';
16
16
  import testBesideModule from './test-beside-module.js';
17
+ import testTimeoutExceptionTicket from './test-timeout-exception-ticket.js';
17
18
  import verbContract from './verb-contract.js';
18
19
 
19
20
  const plugin = {
@@ -107,6 +108,7 @@ const plugin = {
107
108
  'no-file-snapshot': noFileSnapshot,
108
109
  'setup-test-only': setupTestOnly,
109
110
  'max-test-timeout': buildMaxTestTimeout(resolveRepoRoot),
111
+ 'test-timeout-exception-ticket': testTimeoutExceptionTicket,
110
112
  'no-test-sleep': noTestSleep,
111
113
  'import-zones': importZones,
112
114
  },
@@ -114,10 +116,6 @@ const plugin = {
114
116
 
115
117
  export default plugin;
116
118
 
117
- // custom rules loaded through oxlint's jsPlugins (ESLint v9 rule API): each
118
- // bans a shape no native oxlint rule can express, as an esquery selector or a
119
- // source-comment scan
120
-
121
119
  function buildBanRule(type, message, selectors) {
122
120
  return {
123
121
  meta: { type, messages: { banned: message }, schema: [] },
@@ -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
 
@@ -1,8 +1,7 @@
1
1
  import { existsSync } from 'node:fs';
2
2
  import { dirname, join } from 'node:path';
3
3
 
4
- // the nearest ancestor holding `.git` (a directory, or a worktree's file), or
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
+ }
@@ -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
- // every import form and every module-level declaration defines a binding in
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 read counts only at collection time, so no function may enclose it: a
226
- // `skipIf` inside `setupTest()` or a test runs later
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;
@@ -1,6 +1,8 @@
1
1
  import { readdirSync, statSync } from 'node:fs';
2
- import { basename, dirname, join, relative, sep } from 'node:path';
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. Whole-program suites belong in a root `e2e/` or `evals/` 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: { type: 'array', items: { type: 'string' } },
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 = new Set(['browser', ...(context.options[0]?.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 (match === null || probeUnderExemptRoot(context.cwd, filename)) {
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 probeUnderExemptRoot(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 callee declared in the file or imported by a relative or aliased path; 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 &&