@zgeoff/oxlint-config 0.8.0 → 0.8.3

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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/setup-test-only.js +61 -12
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zgeoff/oxlint-config",
3
- "version": "0.8.0",
3
+ "version": "0.8.3",
4
4
  "description": "Shareable oxlint config: strict categories, house-style rules, and a custom JS plugin",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -83,7 +83,7 @@
83
83
  },
84
84
  "devDependencies": {
85
85
  "@types/bun": "1.4.4",
86
- "@zgeoff/rig": "0.1.0",
86
+ "@zgeoff/rig": "0.1.3",
87
87
  "@zgeoff/testing": "0.2.0",
88
88
  "tsrs": "0.18.0-ts7.1.0-dev.20260929",
89
89
  "typescript": "7.0.2"
@@ -24,16 +24,33 @@ const setupTestOnly = {
24
24
  modifier:
25
25
  '`test.{{modifier}}` is banned: use `test.skipIf(<condition>)` for a skip. Committed `skip`, `todo`, `only` and `failing` tests are not allowed.',
26
26
  concurrent: '`test.concurrent` is banned: tests that use `onTestFinished` run in order.',
27
+ branch:
28
+ 'Move the case this {{branch}} picks into the test that needs it: the testing skill gives `setupTest()` no `if` and no ternary, because a branch there picks a scenario, and the scenario belongs in the test. Keep `setupTest()` to the wiring that every test shares.',
27
29
  },
28
30
  schema: [],
29
31
  },
30
32
  create(context) {
33
+ if (!testFilePattern.test(basename(context.physicalFilename))) {
34
+ return {};
35
+ }
36
+
31
37
  return {
32
- Program(program) {
33
- if (!testFilePattern.test(basename(context.physicalFilename))) {
38
+ IfStatement(node) {
39
+ // an `else if` belongs to the chain that its first `if` reports
40
+ if (node.parent.type === 'IfStatement' && node.parent.alternate === node) {
34
41
  return;
35
42
  }
36
43
 
44
+ reportSetupTestBranch(context, node, '`if`');
45
+ },
46
+ ConditionalExpression(node) {
47
+ if (isOptionalSpread(node)) {
48
+ return;
49
+ }
50
+
51
+ reportSetupTestBranch(context, node, 'ternary');
52
+ },
53
+ Program(program) {
37
54
  const testNames = collectTestNames(context, program);
38
55
  const isBunTest = isBunTestFile(program);
39
56
  const constants = [];
@@ -90,6 +107,48 @@ const setupTestOnly = {
90
107
  },
91
108
  };
92
109
 
110
+ // a branch in a function nested in setupTest, such as a stub callback, runs only when the
111
+ // unit calls it, so only setupTest's own body counts
112
+ function reportSetupTestBranch(context, node, branch) {
113
+ let current = node.parent;
114
+
115
+ while (isOutsideFunction(current)) {
116
+ current = current.parent;
117
+ }
118
+
119
+ if (
120
+ current?.type === 'FunctionDeclaration' &&
121
+ current.id?.name === 'setupTest' &&
122
+ current.parent.type === 'Program'
123
+ ) {
124
+ context.report({ node, messageId: 'branch', data: { branch } });
125
+ }
126
+ }
127
+
128
+ const functionTypes = new Set([
129
+ 'FunctionDeclaration',
130
+ 'FunctionExpression',
131
+ 'ArrowFunctionExpression',
132
+ ]);
133
+
134
+ function isOutsideFunction(node) {
135
+ return node !== null && node !== undefined && !functionTypes.has(node.type);
136
+ }
137
+
138
+ // `...(cond ? {} : { lid })` adds an optional property under exactOptionalPropertyTypes, which
139
+ // is wiring like `??`
140
+ function isOptionalSpread(node) {
141
+ return (
142
+ node.parent.type === 'SpreadElement' &&
143
+ node.parent.parent.type === 'ObjectExpression' &&
144
+ (isEmptyObject(node.consequent) || isEmptyObject(node.alternate))
145
+ );
146
+ }
147
+
148
+ function isEmptyObject(node) {
149
+ return node.type === 'ObjectExpression' && node.properties.length === 0;
150
+ }
151
+
93
152
  const testModules = new Set(['bun:test', 'claude-code/testing']);
94
153
 
95
154
  function collectTestNames(context, program) {
@@ -259,12 +318,6 @@ function isSkipGate(context, declarator, gates, testNames) {
259
318
  );
260
319
  }
261
320
 
262
- const functionTypes = new Set([
263
- 'FunctionDeclaration',
264
- 'FunctionExpression',
265
- 'ArrowFunctionExpression',
266
- ]);
267
-
268
321
  // bun test reads a `skipIf` gate as it collects tests, so a read inside a
269
322
  // function, which runs later, does not count
270
323
  function isInSkipIfArgument(identifier, testNames) {
@@ -307,8 +360,4 @@ function isInGateInit(identifier, gates) {
307
360
  return false;
308
361
  }
309
362
 
310
- function isOutsideFunction(node) {
311
- return node !== null && node !== undefined && !functionTypes.has(node.type);
312
- }
313
-
314
363
  export default setupTestOnly;