@zgeoff/oxlint-config 0.6.3 → 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
@@ -1,4 +1,15 @@
1
- # @zgeoff/oxlint-config
1
+ <div align="center">
2
+ <h1>@zgeoff/oxlint-config</h1>
3
+
4
+ <p>
5
+ <a href="https://www.npmjs.com/package/@zgeoff/oxlint-config"><img src="https://img.shields.io/npm/v/@zgeoff/oxlint-config" alt="npm version"></a>
6
+ <a href="./LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue" alt="MIT license"></a>
7
+ </p>
8
+
9
+ <p>
10
+ <a href="../../docs/architecture/oxlint-config.md">Documentation</a>
11
+ </p>
12
+ </div>
2
13
 
3
14
  Shareable [oxlint](https://oxc.rs/docs/guide/usage/linter.html) config: every category at `error`,
4
15
  restriction-rule cherry-picks, comment-style enforcement via `@stylistic`, and a bundled JS plugin
@@ -8,17 +19,7 @@ await arguments, awaits hidden inside a control-flow condition or a `&&`/`||`/`?
8
19
  `switch` statement, every JSDoc block, any run of more than three line comments, a type claim with
9
20
  no `as`, and a repo config that loosens a comment rule or a type-assertion rule.
10
21
 
11
- The plugin's other rules each check one convention. `zgeoff/function-verb` bans the vague and
12
- near-synonym verbs of the shared function-naming rules, `zgeoff/verb-contract` checks the promise
13
- each role-table verb makes, `zgeoff/module-order` keeps a file in the shared module order,
14
- `zgeoff/test-beside-module` keeps each test file beside the module it tests, `zgeoff/import-zones`
15
- fails an import that crosses a module boundary the repo declares, `zgeoff/no-restricted-words` keeps
16
- the words in its `words` option out of a path's text, `zgeoff/no-abbreviated-names` reports each
17
- abbreviated value name it lists with its full word, `zgeoff/no-file-snapshot` bans file snapshots,
18
- `zgeoff/setup-test-only` keeps a test file's module level to `setupTest()` and its tests, and
19
- `zgeoff/no-class` bans every class but a custom error.
20
-
21
- ## Usage
22
+ ## Install
22
23
 
23
24
  ```sh
24
25
  bun add -d @zgeoff/oxlint-config oxlint @stylistic/eslint-plugin
@@ -45,304 +46,6 @@ import config from '@zgeoff/oxlint-config';
45
46
  The plugin is addressable on its own at `@zgeoff/oxlint-config/plugin` for configs that want the
46
47
  `zgeoff/*` rules without the rest.
47
48
 
48
- ## Type assertions
49
-
50
- `typescript/consistent-type-assertions` runs with `assertionStyle: "never"`, so every type assertion
51
- fails: `x as T`, `<T>x` and `x as unknown as T`. `as const` and `satisfies` pass, because neither
52
- claims a type the checker cannot prove. `typescript/no-unsafe-type-assertion` is off, because the
53
- ban reports every assertion that rule checks.
54
-
55
- Replace an assertion with a type guard, a type annotation, `satisfies`, or a typed helper from
56
- `@zgeoff/std`. An assertion that survives carries a disable comment on the line above it, with its
57
- approval and reason after `--`:
58
-
59
- ```ts
60
- // oxlint-disable-next-line typescript/consistent-type-assertions -- approved <issue>: <reason>
61
- ```
62
-
63
- `zgeoff/no-hidden-cast` reports a claim of a type that has no `as` for the ban to see:
64
-
65
- - a type argument on a `sql` tagged template, such as Kysely's `sql<T>`;
66
- - a call to Kysely's `$castTo()`, `$narrowType()` or `$assertType()`;
67
- - a type argument on a `query()` or `prepare()` call, such as bun:sqlite's;
68
- - a type argument on Pulumi `Config`'s `getObject()`, `requireObject()`, `getSecretObject()` or
69
- `requireSecretObject()`.
70
-
71
- The rule needs no type information, so it matches by name: a method of another library with the same
72
- name and a type argument is reported too. Read such a value as `unknown` and parse it with zod, or
73
- query through Kysely over declared table types.
74
-
75
- Every repo runs both rules as this config ships them. `zgeoff/no-comment-rule-override` reports a
76
- repo-root `.oxlintrc*.json` that sets either rule under any plugin prefix, so a disable comment on
77
- the line is the only way to keep an assertion.
78
-
79
- ## `zgeoff/function-verb`
80
-
81
- The rule reports a function, method, or function-valued variable or property whose name starts with
82
- a banned verb, and it names the role-table verb to use instead (`fetchUser` → use `read`). It also
83
- reports a bare template prefix, such as a function named `on`. A name that does not start with a
84
- lowercase letter passes. The `exemptNames` option lists names that a library contract fixes:
85
-
86
- ```jsonc
87
- {
88
- "rules": {
89
- "zgeoff/function-verb": ["error", { "exemptNames": ["execute"] }],
90
- },
91
- }
92
- ```
93
-
94
- ## `zgeoff/verb-contract`
95
-
96
- The rule reads each named function's verb and reports a body that breaks the verb's promise. It
97
- reads declared return types, since it runs without type information. It runs three checks:
98
-
99
- - **No I/O behind a no-I/O verb.** A function named with `is`, `has`, `can`, `should`, `build`,
100
- `parse`, `format`, `render`, `pick`, `find`, `get`, `collect` or `to` must not be async or await.
101
- It must not call `fs`, `child_process`, `Bun.spawn`, `Bun.file`, `Bun.write`, Bun's `$` shell
102
- under any import form, `fetch` or a Kysely `execute`, and must not read `process.env` or
103
- `Bun.env`. It must not call a function whose verb is on the rule's effectful list, such as
104
- `readConfig` or `ctx.writeText`. That check skips a callee imported from a package, a global, a
105
- bare method name such as `map.set`, and a method on a value the function declares itself. I/O
106
- inside an unnamed callback counts against the named function around it. A local alias of an I/O
107
- source, such as `const read = fs.readFileSync` or `const { spawn } = Bun`, counts as that source,
108
- and a local alias of a package's callee is skipped as the callee is.
109
- - **Predicates return a boolean.** A function named with `is`, `has`, `can`, `should` or `probe`
110
- that declares a return type declares `boolean`, a type predicate, or a promise of one. A function
111
- that declares `boolean` and does no I/O starts with one of the four no-I/O predicate verbs. That
112
- check skips an effectful verb or `try`, whose function may return a success flag, and the
113
- framework prefixes `use`, `on` and `handle`.
114
- - **`find` can miss, and `get` cannot.** A declared `find` return type holds `null`, `undefined`,
115
- `void`, `unknown` or `any`. A `get` function neither declares `null` or `undefined` nor returns
116
- either one as a literal or a bare `return`. Every check follows the file's own type aliases, and a
117
- type the rule cannot see, such as an import, a type parameter or an indexed access, never fails a
118
- check.
119
-
120
- A test in this package reads the role table in the shared code-style skill and fails when the
121
- skill's no-I/O verbs and the rule's differ in either direction.
122
-
123
- ## `zgeoff/module-order`
124
-
125
- The rule checks the module order of the shared code-style skill in each file with a primary export.
126
- The primary export is the default export, else the export whose name the file name kebab-cases, else
127
- the file's only exported function or const. A file without one, such as a test file, passes. The
128
- rule reports three breaks:
129
-
130
- - **A helper first.** A private function sits above the primary export.
131
- - **A helper out of composition order.** The helpers below the primary export follow it depth-first,
132
- each in the order its first reference appears.
133
- - **A declaration away from its first use.** A const, type alias, interface or enum sits below its
134
- first use, or a helper sits between it and that use. A declaration the primary export uses may sit
135
- just above it.
136
-
137
- The config's `import/first` rule reports an import after other code, so this rule leaves imports
138
- alone. The rule leaves a const unchecked when a helper that runs as the module loads reads it,
139
- because the const has to sit above the code that calls that helper.
140
-
141
- `--fix` moves each declaration it can move without a change in behaviour, with the comments above
142
- it, in one pass. A function declaration is hoisted and a type has no value, so both always move. A
143
- const moves only when every use sits in a function body that runs after the module loads, and its
144
- value is static. A static value runs no code and reads nothing that load-time code can change: a
145
- literal, a function, an array, object, `new Set`, `new Map` or `new RegExp` over static values, or
146
- an operator or template over primitive values, with an import only as a copied value. Any other
147
- const stays where it is, and the rule still reports it. The fix makes no change when a move would
148
- put a statement that ends without a semicolon before one that opens with a bracket or an operator.
149
-
150
- ## `zgeoff/no-jsdoc` and `zgeoff/max-consecutive-line-comments`
151
-
152
- A comment holds only what neither the code, a type, a test name, nor the subsystem doc can hold: the
153
- reason a line does the non-obvious thing. `no-jsdoc` reports every `/** … */` block (inline
154
- `@type`/`@lends` casts exempt). `max-consecutive-line-comments` reports a run of own-line `//`
155
- comments longer than `max` (default 3); tool directives (`oxlint-`, `eslint-`, `@ts-`, …) neither
156
- count nor join the prose around them. Neither rule fixes: a deleted comment is a decision, not a
157
- whitespace change.
158
-
159
- Every repo runs both rules as this config ships them. `zgeoff/no-comment-rule-override` reports a
160
- repo-root `.oxlintrc*.json` that sets either rule, once per lint run, so a repo cannot turn them off
161
- or loosen `max`.
162
-
163
- ## `zgeoff/test-beside-module`
164
-
165
- A `<name>.test.ts` or `<name>.test.tsx` file needs a non-test file `<name>.<ext>` in the same
166
- directory — `.ts`, `.tsx`, `.sh`, `.json`, or any other single extension, so `install.test.ts` may
167
- test `install.sh`. Files under an `e2e/` or `evals/` directory at the repo root (the nearest
168
- ancestor holding `.git`, else oxlint's working directory) are exempt; no other directory is. Exempt
169
- any other test with a file-level disable comment that states the reason. The rule reports at the
170
- first statement, so put the comment above it:
171
-
172
- ```ts
173
- // oxlint-disable zgeoff/test-beside-module -- tests base.json and react.json together
174
- ```
175
-
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`.
187
-
188
- ## `zgeoff/setup-test-only`
189
-
190
- A `<name>.test.ts` or `<name>.test.tsx` file declares one function, `setupTest()`, and nothing else,
191
- as the testing skill requires. At module level the rule allows imports, `type` and `interface`
192
- declarations, one `setupTest` function declaration, and statements that call `test`, `test.each`,
193
- `test.skipIf` or `test.if`, or a chain of them, with `test` under its local alias when the
194
- `bun:test` or `claude-code/testing` import renames it. It reports every other statement: a `let`, a
195
- `var`, a class, an enum, a second function, an export, and a call such as `beforeEach(...)`. The
196
- message holds the three ways out of a helper: inline it, swap it for a registered matcher, or move
197
- it to the shared test utils with tests of its own.
198
-
199
- A module-level `const` passes only as a skip gate: a declarator that binds at least one name, each
200
- binding read, and read only at collection time, inside an argument of the test runner's `skipIf` or
201
- inside the initializer of another gate. The runner is `test` as `bun:test` exports it, under its
202
- local alias if the import renames it, or a chain of its modifiers, so `matrix.skipIf(rows)` is not a
203
- gate read. A file that imports no `test` uses the global one, unless an import or a module-level
204
- declaration of its own takes the name `test`. A read inside a function never counts, so a `skipIf`
205
- in `setupTest()` or a test body leaves its `const` reported. A gate derived from an awaited probe
206
- passes beside the probe, in the same declaration or its own, but consts that only read each other
207
- never reach a `skipIf` and report. A `const` that nothing reads reports too, and so does a
208
- declarator that binds nothing, such as `const {} = registerHooks()`. The rule does not check the
209
- comment that the skill asks a gate to carry.
210
-
211
- ## `zgeoff/no-restricted-words`
212
-
213
- Off unless a repo configures it. The `words` option lists the words to keep out of the text of a
214
- file: string literals, template text and comments. A word matches whole and without case, so `imp`
215
- reports `'IMP daemon'` and `'imp-e2e'` but not `'impl'` or `'imp_name'`. Identifiers are code, not
216
- text, and the rule never reads them. Scope the rule to a path with `overrides`, and turn it off for
217
- the paths that may name the words:
218
-
219
- ```jsonc
220
- {
221
- "rules": {
222
- "zgeoff/no-restricted-words": ["error", { "words": ["imp", "impd"] }],
223
- },
224
- "overrides": [
225
- { "files": ["packages/execution/**"], "rules": { "zgeoff/no-restricted-words": "off" } },
226
- ],
227
- }
228
- ```
229
-
230
- ## `zgeoff/no-abbreviated-names`
231
-
232
- The `names` option maps each abbreviation to the text that replaces it, and the rule reports every
233
- value name that has one of those names. A value name is any name that a declaration, an import, an
234
- export alias, a key or a member write binds, so function, class and method names count beside
235
- variables and properties. A key counts in each of its spellings, so `src`, `'src'`, `['src']` and
236
- `#src` all report. A name matches whole, so `ms` reports `ms` but not `timeoutMs`.
237
-
238
- The rule leaves alone the names that hold no value of their own. A destructured key that an alias
239
- renames belongs to the object being read, so the rule reports only the alias. A computed key that
240
- reads a variable, such as `[src]`, names no property, and the rule checks the variable at its
241
- declaration. Type names, type-only imports and exports, labels and quoted module names hold no
242
- value, so the rule skips them.
243
-
244
- The shipped config lists the abbreviations that the code-style skill bans and turns on `id-length`
245
- beside the rule, so a one-letter name fails too, other than `x`, `y`, `z`, `$` and `_`.
246
-
247
- ## `zgeoff/no-file-snapshot`
248
-
249
- Snapshots are inline only, so the golden value sits in the test that pins it. The rule reports every
250
- `toMatchSnapshot` and `toThrowErrorMatchingSnapshot`, which write a `.snap` file;
251
- `toMatchInlineSnapshot` and `toThrowErrorMatchingInlineSnapshot` stay allowed. It also reports a
252
- linted file that has a `__snapshots__/<file name>.snap` beside it, at the first statement, so a
253
- file-level disable comment covers it. oxlint never visits a `.snap` file, so a snapshot file whose
254
- test file is gone is not reported.
255
-
256
- ## `zgeoff/no-class`
257
-
258
- Objects come from factory functions, as the code-style skill requires, so the rule reports every
259
- class declaration and class expression, in test files too. A custom error stays a class, because
260
- `instanceof` checks and stack traces need one. The rule counts a class as a custom error when its
261
- `extends` clause holds `Error` or another name that ends in `Error`, bare or as a member such as
262
- `errors.BrewError`. It does not check the name of the class itself, and it reports a superclass
263
- reached through a computed member, such as `errors['BrewError']`.
264
-
265
- ## `zgeoff/import-zones`
266
-
267
- Off unless a repo configures it. The options name zones (path globs, relative to the repo root) and
268
- the boundaries between them. A file belongs to every zone its path matches, so zones may overlap.
269
- Each entry has a `name`, which starts its report, an optional `reason`, which ends it, and optional
270
- `from` zones and `ignore` globs that limit which importing files it judges.
271
-
272
- - `edges` judge an import that resolves to a file: relative, with any bundler query such as `?url`
273
- dropped, or the package's own name resolved through its `exports` under `conditions` plus
274
- `default`. They also judge the name of each package whose directory a `workspaces` glob matches,
275
- such as `packages/*`, with one directory level per segment. That name maps to the package folder
276
- joined with the subpath, never to an export's target: `@demo/store/testing` is judged as
277
- `packages/store/testing`, so a zone names the folder path, such as `packages/store{,/**}`. A
278
- target in a `to` zone fails unless it is also in an `allow` zone; with `allow` alone, a target in
279
- none of the `allow` zones fails, a target in no zone included. `allowTypeOnly` exempts type-only
280
- imports (`true`, or globs the target must match), and `allowWithin: "src/*"` exempts an import
281
- inside the importer's own `src/<name>/`.
282
- - `modules` restrict a package or builtin (`node:` prefix optional, subpaths included) to the
283
- `allow` zones; `allowTypeOnly: true` exempts type-only imports. A name that ends in `*` restricts
284
- every specifier that starts with the text before it, such as `@scope/*`, and `node:*` restricts
285
- every builtin.
286
- - `globals` restrict a call to a global, bare or through `globalThis`, `self` or `window`.
287
- - `unzoned` reports a file in a `from` zone that belongs to none of `zones`.
288
- - `unresolved` reports a relative or self-referencing import that resolves to no file, a workspace
289
- import whose subpath no `exports` key lists, or one that a `null` key blocks, and a dynamic
290
- `import()`, `require()` or `import.meta.require()` whose specifier is computed. Bun's
291
- `import.meta.require` used as a value counts as computed too.
292
- - `selfImports` reports an import of the importer's own package by name, which a relative path
293
- reaches without the `exports` map.
294
-
295
- ```jsonc
296
- {
297
- "rules": {
298
- "zgeoff/import-zones": [
299
- "error",
300
- {
301
- "zones": {
302
- "core": ["src/**"],
303
- "support": ["src/{config,state}/**"],
304
- "process": ["src/process/**"],
305
- "tooling": ["scripts/**"],
306
- },
307
- "edges": [
308
- { "name": "core-no-tooling", "from": ["core"], "to": ["tooling"] },
309
- {
310
- "name": "support",
311
- "from": ["support"],
312
- "allow": ["support"],
313
- "allowTypeOnly": ["**/types.ts"],
314
- "reason": "support modules sit below the stages",
315
- },
316
- ],
317
- "modules": [
318
- {
319
- "name": "child-process",
320
- "modules": ["node:child_process"],
321
- "from": ["core"],
322
- "allow": ["process"],
323
- "allowTypeOnly": true,
324
- },
325
- ],
326
- "unresolved": [{ "name": "unresolved", "from": ["core"] }],
327
- },
328
- ],
329
- },
330
- }
331
- ```
332
-
333
- Exempt a known violation with a next-line disable comment that names the ticket that removes it. An
334
- unzoned report sits on the first statement, so its comment goes above that. Run lint with
335
- `--report-unused-disable-directives-severity error` so a comment outlives no import.
336
-
337
- The rule judges only the imports that a file holds. A repo check that judges something else, such as
338
- a dependency that a manifest declares, imports the rule's own reading from
339
- `@zgeoff/oxlint-config/import-zones`. That entry exports `importZonesSchema`, the JSON schema of the
340
- options, with an `ImportZonesOptions` type, and
341
- `collectRefusingEdges(options, { from, to, typeOnly })`. The function returns each edge in `options`
342
- that refuses an import of `to` from `from`, both paths relative to the repo root. It skips module
343
- resolution, so `to` is the path that the rule would resolve the specifier to. The rule judges each
344
- edge through the same function.
345
-
346
49
  ## Plugins and type-aware rules
347
50
 
348
51
  - The config enables the `typescript`, `unicorn`, `oxc`, `import`, and `promise` plugins and loads
@@ -353,3 +56,31 @@ edge through the same function.
353
56
  with `Cannot find module '@stylistic/eslint-plugin'` unless it's installed directly.
354
57
  - Type-aware rules activate under `oxlint --type-aware` (requires `oxlint-tsgolint`); the config
355
58
  works without it.
59
+
60
+ ## Rules
61
+
62
+ - Type assertions: every `as` other than `as const` fails, and `zgeoff/no-hidden-cast` reports a
63
+ type claim with no `as`. See
64
+ [type assertions](../../docs/architecture/oxlint-config.md#type-assertions).
65
+ - Comments: `zgeoff/no-jsdoc` and `zgeoff/max-consecutive-line-comments` keep comments to the reason
66
+ for a line. See
67
+ [the comment rules](../../docs/architecture/oxlint-config.md#zgeoffno-jsdoc-and-zgeoffmax-consecutive-line-comments).
68
+ - Code style: function verbs, verb contracts, module order, abbreviated names and classes. See
69
+ [code-style rules](../../docs/architecture/oxlint-config-code-style.md).
70
+ - Test files: a test sits beside its module, holds only `setupTest()` and its tests, uses inline
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
+ - Import boundaries: `zgeoff/import-zones` fails an import that crosses a declared zone boundary.
74
+ See [import zones](../../docs/architecture/oxlint-config-import-zones.md).
75
+
76
+ ## Configuration
77
+
78
+ Every rule runs as the config ships it, and `zgeoff/no-comment-rule-override` keeps a repo from
79
+ loosening the comment and type-assertion rules. `zgeoff/no-restricted-words` and
80
+ `zgeoff/import-zones` stay off until a repo configures them;
81
+ [the config overview](../../docs/architecture/oxlint-config.md) and
82
+ [import zones](../../docs/architecture/oxlint-config-import-zones.md) hold their options.
83
+
84
+ ## Documentation
85
+
86
+ The [oxlint-config docs](../../docs/architecture/oxlint-config.md) explain each rule.
@@ -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 = {