@zgeoff/oxlint-config 0.10.4 → 0.10.6

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/bench-shape.js ADDED
@@ -0,0 +1,62 @@
1
+ import { basename } from 'node:path';
2
+ import findVariable from './find-variable.js';
3
+ import getImportedName from './get-imported-name.js';
4
+
5
+ const benchFilePattern = /\.bench\.tsx?$/u;
6
+
7
+ const benchShape = {
8
+ meta: {
9
+ type: 'problem',
10
+ messages: {
11
+ shape:
12
+ "A benchmark file holds one benchmark that `rig bench` runs: write `export default defineBench({ name, budget, run })`, with `defineBench` imported from '@zgeoff/rig/bench'.",
13
+ },
14
+ schema: [],
15
+ },
16
+ create(context) {
17
+ if (!benchFilePattern.test(basename(context.physicalFilename))) {
18
+ return {};
19
+ }
20
+
21
+ return {
22
+ Program(program) {
23
+ const defaultExport = program.body.find(
24
+ (statement) => statement.type === 'ExportDefaultDeclaration',
25
+ );
26
+
27
+ if (defaultExport !== undefined && isDefineBenchCall(context, defaultExport.declaration)) {
28
+ return;
29
+ }
30
+
31
+ if (defaultExport !== undefined) {
32
+ context.report({ node: defaultExport, messageId: 'shape' });
33
+
34
+ return;
35
+ }
36
+
37
+ const start = program.body[0]?.loc.start ?? { line: 1, column: 0 };
38
+
39
+ context.report({ loc: { start, end: start }, messageId: 'shape' });
40
+ },
41
+ };
42
+ },
43
+ };
44
+
45
+ export default benchShape;
46
+
47
+ const benchModule = '@zgeoff/rig/bench';
48
+
49
+ function isDefineBenchCall(context, node) {
50
+ if (node.type !== 'CallExpression' || node.callee.type !== 'Identifier') {
51
+ return false;
52
+ }
53
+
54
+ const definition = findVariable(context, node.callee)?.defs[0];
55
+
56
+ return (
57
+ definition?.type === 'ImportBinding' &&
58
+ definition.node.type === 'ImportSpecifier' &&
59
+ definition.parent.source.value === benchModule &&
60
+ getImportedName(definition.node) === 'defineBench'
61
+ );
62
+ }
package/oxlintrc.json CHANGED
@@ -46,6 +46,7 @@
46
46
  "zgeoff/seed-only": "error",
47
47
  "zgeoff/test-beside-seed": "error",
48
48
  "zgeoff/file-named-for-export": "error",
49
+ "zgeoff/bench-shape": "error",
49
50
 
50
51
  // name a value for what it holds, in full words: one letter only for a
51
52
  // 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.10.4",
3
+ "version": "0.10.6",
4
4
  "description": "Shareable oxlint config: strict categories, house-style rules, and a custom JS plugin",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -41,6 +41,7 @@
41
41
  "get-imported-name.js",
42
42
  "test-shape.js",
43
43
  "banned-test-calls.js",
44
+ "bench-shape.js",
44
45
  "is-bun-test-file.js",
45
46
  "find-bun-test-name.js",
46
47
  "find-chain-root.js",
@@ -109,7 +110,7 @@
109
110
  },
110
111
  "devDependencies": {
111
112
  "@types/bun": "1.4.4",
112
- "@zgeoff/rig": "0.2.2",
113
+ "@zgeoff/rig": "0.2.3",
113
114
  "@zgeoff/std": "0.4.3",
114
115
  "@zgeoff/testing": "0.3.0",
115
116
  "tsrs": "0.18.0-ts7.1.0-dev.20260929",
package/plugin.js CHANGED
@@ -2,6 +2,7 @@ import { existsSync } from 'node:fs';
2
2
  // oxlint-disable-next-line zgeoff/no-require -- only resolves rig's path from the repo root; an import loads it
3
3
  import { createRequire } from 'node:module';
4
4
  import { join } from 'node:path';
5
+ import benchShape from './bench-shape.js';
5
6
  import buildMaxTestTimeout from './build-max-test-timeout.js';
6
7
  import buildSeedOnly from './build-seed-only.js';
7
8
  import buildTestBesideModule from './build-test-beside-module.js';
@@ -140,6 +141,7 @@ const plugin = {
140
141
  'seed-only': buildSeedOnly(readFolderSources),
141
142
  'test-beside-seed': testBesideSeed,
142
143
  'file-named-for-export': fileNamedForExport,
144
+ 'bench-shape': benchShape,
143
145
  },
144
146
  };
145
147