@zgeoff/oxlint-config 0.6.0 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -173,8 +173,17 @@ first statement, so put the comment above it:
173
173
  // oxlint-disable zgeoff/test-beside-module -- tests base.json and react.json together
174
174
  ```
175
175
 
176
- A second test file for a module (`<name>.host.test.ts`) needs its own `<name>.host.<ext>`, so the
177
- rule reports it beside only `<name>.ts`.
176
+ A lane suite, such as `<name>.browser.test.ts`, tests the same module as `<name>.test.ts` and needs
177
+ only `<name>.<ext>`; the suffix lets the repo's test script run the suite in its own lane. The rule
178
+ treats `browser` as a lane with no configuration. A repo adds its own lanes with the `lanes` option,
179
+ and `browser` stays a lane beside them:
180
+
181
+ ```json
182
+ { "rules": { "zgeoff/test-beside-module": ["error", { "lanes": ["sdk"] }] } }
183
+ ```
184
+
185
+ Any other suffix is part of the name. A second test file for a module (`<name>.host.test.ts`) needs
186
+ its own `<name>.host.<ext>`, so the rule reports it beside only `<name>.ts`.
178
187
 
179
188
  ## `zgeoff/setup-test-only`
180
189
 
@@ -334,7 +343,7 @@ that refuses an import of `to` from `from`, both paths relative to the repo root
334
343
  resolution, so `to` is the path that the rule would resolve the specifier to. The rule judges each
335
344
  edge through the same function.
336
345
 
337
- ## Notes
346
+ ## Plugins and type-aware rules
338
347
 
339
348
  - The config enables the `typescript`, `unicorn`, `oxc`, `import`, and `promise` plugins and loads
340
349
  `@stylistic/eslint-plugin` through `jsPlugins`. oxlint resolves `jsPlugins` specifiers from the
@@ -0,0 +1,89 @@
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
+ export default function collectTypeKinds(
5
+ type,
6
+ localTypes,
7
+ resolvePromise = false,
8
+ seen = new Set(),
9
+ ) {
10
+ if (type.type === 'TSUnionType') {
11
+ return type.types.flatMap((member) =>
12
+ collectTypeKinds(member, localTypes, resolvePromise, seen),
13
+ );
14
+ }
15
+
16
+ if (type.type === 'TSParenthesizedType' || isReadonlyOperator(type)) {
17
+ return collectTypeKinds(type.typeAnnotation, localTypes, resolvePromise, seen);
18
+ }
19
+
20
+ if (type.type !== 'TSTypeReference') {
21
+ return [pickTypeKind(type)];
22
+ }
23
+
24
+ const name = type.typeName.type === 'Identifier' ? type.typeName.name : null;
25
+ const alias = name === null ? undefined : localTypes.aliases.get(name);
26
+
27
+ if (alias !== undefined && !seen.has(name)) {
28
+ return collectTypeKinds(alias, localTypes, resolvePromise, new Set([...seen, name]));
29
+ }
30
+
31
+ const typeArguments = type.typeArguments ?? type.typeParameters;
32
+
33
+ if (resolvePromise && name === 'Promise' && typeArguments?.params.length === 1) {
34
+ const [value] = typeArguments.params;
35
+
36
+ return collectTypeKinds(value, localTypes, resolvePromise, seen);
37
+ }
38
+
39
+ // an interface never holds null; any other reference, such as an import or
40
+ // a type parameter, is a type the rule cannot read
41
+ return [localTypes.interfaces.has(name) ? 'value' : 'open'];
42
+ }
43
+
44
+ function isReadonlyOperator(type) {
45
+ return type.type === 'TSTypeOperator' && type.operator === 'readonly';
46
+ }
47
+
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
+ const valueTypes = new Set([
51
+ 'TSStringKeyword',
52
+ 'TSNumberKeyword',
53
+ 'TSBigIntKeyword',
54
+ 'TSSymbolKeyword',
55
+ 'TSObjectKeyword',
56
+ 'TSNeverKeyword',
57
+ 'TSLiteralType',
58
+ 'TSTemplateLiteralType',
59
+ 'TSArrayType',
60
+ 'TSTupleType',
61
+ 'TSTypeLiteral',
62
+ 'TSFunctionType',
63
+ 'TSConstructorType',
64
+ ]);
65
+
66
+ function pickTypeKind(type) {
67
+ if (
68
+ type.type === 'TSBooleanKeyword' ||
69
+ (type.type === 'TSTypePredicate' && !type.asserts) ||
70
+ (type.type === 'TSLiteralType' && typeof type.literal.value === 'boolean')
71
+ ) {
72
+ return 'boolean';
73
+ }
74
+
75
+ if (type.type === 'TSNullKeyword' || type.type === 'TSUndefinedKeyword') {
76
+ return 'nullish';
77
+ }
78
+
79
+ if (type.type === 'TSVoidKeyword') {
80
+ return 'void';
81
+ }
82
+
83
+ // `asserts value is T` throws instead of returning a boolean
84
+ if (type.type === 'TSTypePredicate' || valueTypes.has(type.type)) {
85
+ return 'value';
86
+ }
87
+
88
+ return 'open';
89
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zgeoff/oxlint-config",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "description": "Shareable oxlint config: strict categories, house-style rules, and a custom JS plugin",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -13,6 +13,7 @@
13
13
  "plugin.js",
14
14
  "function-verb.js",
15
15
  "verb-contract.js",
16
+ "collect-type-kinds.js",
16
17
  "module-order.js",
17
18
  "collect-module-entries.js",
18
19
  "build-module-order-fix.js",
@@ -59,13 +60,14 @@
59
60
  "access": "public"
60
61
  },
61
62
  "scripts": {
62
- "typecheck": "tsc"
63
+ "typecheck": "tsrs"
63
64
  },
64
65
  "dependencies": {
65
66
  "@stylistic/eslint-plugin": "5.10.0"
66
67
  },
67
68
  "devDependencies": {
68
69
  "@types/bun": "1.4.2",
70
+ "tsrs": "0.18.0-ts7.1.0-dev.20260929",
69
71
  "typescript": "7.0.2"
70
72
  },
71
73
  "peerDependencies": {
@@ -2,9 +2,7 @@ import { readdirSync, statSync } from 'node:fs';
2
2
  import { basename, dirname, join, relative, sep } from 'node:path';
3
3
  import resolveRepoRoot from './resolve-repo-root.js';
4
4
 
5
- // a browser suite (`<name>.browser.test.ts`) tests the same module as
6
- // `<name>.test.ts`, and the suffix lets a runner put it in its own lane
7
- const testFilePattern = /^(?<base>.+?)(?:\.browser)?\.test\.tsx?$/u;
5
+ const testFilePattern = /^(?<base>.+)\.test\.tsx?$/u;
8
6
 
9
7
  const testBesideModule = {
10
8
  meta: {
@@ -13,9 +11,19 @@ const testBesideModule = {
13
11
  missing:
14
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.',
15
13
  },
16
- schema: [],
14
+ schema: [
15
+ {
16
+ type: 'object',
17
+ properties: {
18
+ lanes: { type: 'array', items: { type: 'string' } },
19
+ },
20
+ additionalProperties: false,
21
+ },
22
+ ],
17
23
  },
18
24
  create(context) {
25
+ const lanes = new Set(['browser', ...(context.options[0]?.lanes ?? [])]);
26
+
19
27
  return {
20
28
  Program() {
21
29
  const filename = context.physicalFilename;
@@ -25,7 +33,7 @@ const testBesideModule = {
25
33
  return;
26
34
  }
27
35
 
28
- const name = match.groups.base;
36
+ const name = toModuleName(match.groups.base, lanes);
29
37
 
30
38
  if (probeModuleSibling(dirname(filename), name)) {
31
39
  return;
@@ -58,6 +66,14 @@ function isUnderExemptRoot(cwd, filename) {
58
66
  return exemptRootDirs.has(first);
59
67
  }
60
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
+ function toModuleName(base, lanes) {
72
+ const dot = base.lastIndexOf('.');
73
+
74
+ return dot > 0 && lanes.has(base.slice(dot + 1)) ? base.slice(0, dot) : base;
75
+ }
76
+
61
77
  // a module is `<name>.<ext>` with a single-segment extension, so a
62
78
  // declaration file never stands in for one, and neither does another test
63
79
  // (`foo.test.ts` beside `foo.test.test.ts`)
package/verb-contract.js CHANGED
@@ -1,3 +1,4 @@
1
+ import collectTypeKinds from './collect-type-kinds.js';
1
2
  import findFunctionName from './find-function-name.js';
2
3
  import isVerbMatch from './is-verb-match.js';
3
4
 
@@ -251,91 +252,6 @@ function collectLocalTypes(program) {
251
252
  return localTypes;
252
253
  }
253
254
 
254
- // the kind of each member of a declared type, read without type information:
255
- // a union splits into its members, a reference follows the file's own type
256
- // aliases, and `resolvePromise` reads a promise as the value it resolves to
257
- function collectTypeKinds(type, localTypes, resolvePromise = false, seen = new Set()) {
258
- if (type.type === 'TSUnionType') {
259
- return type.types.flatMap((member) =>
260
- collectTypeKinds(member, localTypes, resolvePromise, seen),
261
- );
262
- }
263
-
264
- if (type.type === 'TSParenthesizedType' || isReadonlyOperator(type)) {
265
- return collectTypeKinds(type.typeAnnotation, localTypes, resolvePromise, seen);
266
- }
267
-
268
- if (type.type !== 'TSTypeReference') {
269
- return [pickTypeKind(type)];
270
- }
271
-
272
- const name = type.typeName.type === 'Identifier' ? type.typeName.name : null;
273
- const alias = name === null ? undefined : localTypes.aliases.get(name);
274
-
275
- if (alias !== undefined && !seen.has(name)) {
276
- return collectTypeKinds(alias, localTypes, resolvePromise, new Set([...seen, name]));
277
- }
278
-
279
- const typeArguments = type.typeArguments ?? type.typeParameters;
280
-
281
- if (resolvePromise && name === 'Promise' && typeArguments?.params.length === 1) {
282
- const [value] = typeArguments.params;
283
-
284
- return collectTypeKinds(value, localTypes, resolvePromise, seen);
285
- }
286
-
287
- // an interface never holds null; any other reference, such as an import or
288
- // a type parameter, is a type the rule cannot read
289
- return [localTypes.interfaces.has(name) ? 'value' : 'open'];
290
- }
291
-
292
- function isReadonlyOperator(type) {
293
- return type.type === 'TSTypeOperator' && type.operator === 'readonly';
294
- }
295
-
296
- // a type whose members the rule can see and that never holds null; any other
297
- // shape, such as an indexed access or a conditional type, is open
298
- const valueTypes = new Set([
299
- 'TSStringKeyword',
300
- 'TSNumberKeyword',
301
- 'TSBigIntKeyword',
302
- 'TSSymbolKeyword',
303
- 'TSObjectKeyword',
304
- 'TSNeverKeyword',
305
- 'TSLiteralType',
306
- 'TSTemplateLiteralType',
307
- 'TSArrayType',
308
- 'TSTupleType',
309
- 'TSTypeLiteral',
310
- 'TSFunctionType',
311
- 'TSConstructorType',
312
- ]);
313
-
314
- function pickTypeKind(type) {
315
- if (
316
- type.type === 'TSBooleanKeyword' ||
317
- (type.type === 'TSTypePredicate' && !type.asserts) ||
318
- (type.type === 'TSLiteralType' && typeof type.literal.value === 'boolean')
319
- ) {
320
- return 'boolean';
321
- }
322
-
323
- if (type.type === 'TSNullKeyword' || type.type === 'TSUndefinedKeyword') {
324
- return 'nullish';
325
- }
326
-
327
- if (type.type === 'TSVoidKeyword') {
328
- return 'void';
329
- }
330
-
331
- // `asserts value is T` throws instead of returning a boolean
332
- if (type.type === 'TSTypePredicate' || valueTypes.has(type.type)) {
333
- return 'value';
334
- }
335
-
336
- return 'open';
337
- }
338
-
339
255
  function isBooleanOrOpen(kinds) {
340
256
  return kinds.every((kind) => kind === 'boolean' || kind === 'open');
341
257
  }
@@ -386,7 +302,7 @@ function findCallIO(context, node, frameNode) {
386
302
  name: callee.type === 'Identifier' ? callee.name : memberName,
387
303
  isMethod: memberName !== null,
388
304
  },
389
- { name: target.memberName ?? target.rootName, isMethod: target.memberName !== null },
305
+ buildCalledName(context, node, callee),
390
306
  ];
391
307
 
392
308
  const effectful = names.find((entry) => {
@@ -591,6 +507,36 @@ function isLocalVariable(binding, frameNode) {
591
507
  );
592
508
  }
593
509
 
510
+ function buildCalledName(context, node, callee) {
511
+ let current = callee;
512
+ let scopeNode = node;
513
+
514
+ for (let depth = 0; depth < 8; depth++) {
515
+ if (current.type === 'MemberExpression') {
516
+ return { name: findMemberName(current), isMethod: true };
517
+ }
518
+
519
+ if (current.type !== 'Identifier') {
520
+ break;
521
+ }
522
+
523
+ const declarator = findAliasDeclarator(findBinding(context, scopeNode, current.name));
524
+
525
+ if (declarator === null) {
526
+ return { name: current.name, isMethod: false };
527
+ }
528
+
529
+ if (declarator.id.type !== 'Identifier') {
530
+ return { name: findPatternKey(declarator.id, current.name), isMethod: true };
531
+ }
532
+
533
+ current = declarator.init;
534
+ scopeNode = declarator.init;
535
+ }
536
+
537
+ return { name: null, isMethod: false };
538
+ }
539
+
594
540
  function isEnvRead(context, node) {
595
541
  return (
596
542
  findMemberName(node) === 'env' &&