@sister.software/oxlint-config 9.3.0 → 11.0.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.
Files changed (78) hide show
  1. package/README.md +198 -10
  2. package/out/browser-globals.d.ts +15 -0
  3. package/out/browser-globals.d.ts.map +1 -0
  4. package/out/browser-globals.js +76 -0
  5. package/out/browser-globals.js.map +1 -0
  6. package/out/console-padding-plugin.d.ts +16 -0
  7. package/out/console-padding-plugin.d.ts.map +1 -0
  8. package/out/console-padding-plugin.js +68 -0
  9. package/out/console-padding-plugin.js.map +1 -0
  10. package/out/constant-doc-plugin.d.ts +32 -0
  11. package/out/constant-doc-plugin.d.ts.map +1 -0
  12. package/out/constant-doc-plugin.js +91 -0
  13. package/out/constant-doc-plugin.js.map +1 -0
  14. package/out/headers-plugin.d.ts +6 -2
  15. package/out/headers-plugin.d.ts.map +1 -1
  16. package/out/headers-plugin.js +4 -2
  17. package/out/headers-plugin.js.map +1 -1
  18. package/out/index.d.ts +166 -13
  19. package/out/index.d.ts.map +1 -1
  20. package/out/index.js +332 -6
  21. package/out/index.js.map +1 -1
  22. package/out/jsdoc-plugin.d.ts +16 -0
  23. package/out/jsdoc-plugin.d.ts.map +1 -0
  24. package/out/jsdoc-plugin.js +68 -0
  25. package/out/jsdoc-plugin.js.map +1 -0
  26. package/out/length-truthiness-plugin.d.ts +18 -0
  27. package/out/length-truthiness-plugin.d.ts.map +1 -0
  28. package/out/length-truthiness-plugin.js +123 -0
  29. package/out/length-truthiness-plugin.js.map +1 -0
  30. package/out/multiline-statement-plugin.d.ts +18 -0
  31. package/out/multiline-statement-plugin.d.ts.map +1 -0
  32. package/out/multiline-statement-plugin.js +93 -0
  33. package/out/multiline-statement-plugin.js.map +1 -0
  34. package/out/padding-plugin.d.ts +4 -3
  35. package/out/padding-plugin.d.ts.map +1 -1
  36. package/out/padding-plugin.js +44 -27
  37. package/out/padding-plugin.js.map +1 -1
  38. package/out/padding-utils.d.ts +34 -0
  39. package/out/padding-utils.d.ts.map +1 -0
  40. package/out/padding-utils.js +50 -0
  41. package/out/padding-utils.js.map +1 -0
  42. package/out/plugin-types.d.ts +68 -3
  43. package/out/plugin-types.d.ts.map +1 -1
  44. package/out/plugin.d.ts.map +1 -1
  45. package/out/plugin.js +17 -0
  46. package/out/plugin.js.map +1 -1
  47. package/out/process-globals-plugin.d.ts.map +1 -1
  48. package/out/process-globals-plugin.js +6 -2
  49. package/out/process-globals-plugin.js.map +1 -1
  50. package/out/restrictions.d.ts +9 -3
  51. package/out/restrictions.d.ts.map +1 -1
  52. package/out/restrictions.js +4 -70
  53. package/out/restrictions.js.map +1 -1
  54. package/out/section-marker-plugin.d.ts +25 -0
  55. package/out/section-marker-plugin.d.ts.map +1 -0
  56. package/out/section-marker-plugin.js +234 -0
  57. package/out/section-marker-plugin.js.map +1 -0
  58. package/out/threshold-plugin.d.ts +27 -0
  59. package/out/threshold-plugin.d.ts.map +1 -0
  60. package/out/threshold-plugin.js +78 -0
  61. package/out/threshold-plugin.js.map +1 -0
  62. package/package.json +2 -2
  63. package/src/browser-globals.ts +77 -0
  64. package/src/console-padding-plugin.ts +76 -0
  65. package/src/constant-doc-plugin.ts +124 -0
  66. package/src/headers-plugin.ts +7 -3
  67. package/src/index.ts +490 -17
  68. package/src/jsdoc-plugin.ts +75 -0
  69. package/src/length-truthiness-plugin.ts +142 -0
  70. package/src/multiline-statement-plugin.ts +104 -0
  71. package/src/padding-plugin.ts +44 -29
  72. package/src/padding-utils.ts +70 -0
  73. package/src/plugin-types.ts +68 -3
  74. package/src/plugin.ts +22 -0
  75. package/src/process-globals-plugin.ts +6 -2
  76. package/src/restrictions.ts +16 -77
  77. package/src/section-marker-plugin.ts +306 -0
  78. package/src/threshold-plugin.ts +105 -0
package/src/index.ts CHANGED
@@ -9,39 +9,209 @@ import { createRuntimeOverrides } from "./restrictions.js"
9
9
 
10
10
  export * from "./restrictions.js"
11
11
 
12
- /** An oxlint configuration object, as consumed by `oxlint.config.ts` / `.oxlintrc.json`. */
12
+ /**
13
+ * An oxlint configuration object, as consumed by `oxlint.config.ts` / `.oxlintrc.json`.
14
+ */
13
15
  export type OxlintConfig = Record<string, unknown>
14
16
 
15
- /** Options for {@link createOxlintConfig}. */
17
+ /**
18
+ * Numeric ceilings for the legibility-guardrail rules. Each is a hard ceiling, not a target.
19
+ */
20
+ export interface OxlintConfigLimits {
21
+ /**
22
+ * Maximum block nesting depth.
23
+ */
24
+ maxDepth: number
25
+ /**
26
+ * Maximum parameters on a single function.
27
+ */
28
+ maxParams: number
29
+ /**
30
+ * Maximum statements in a single function body.
31
+ */
32
+ maxStatements: number
33
+ /**
34
+ * Maximum lines in a single function body, blank lines and comments excluded.
35
+ */
36
+ maxLinesPerFunction: number
37
+ /**
38
+ * Maximum lines in a single file, blank lines and comments excluded.
39
+ */
40
+ maxLines: number
41
+ /**
42
+ * Maximum nested callback depth.
43
+ */
44
+ maxNestedCallbacks: number
45
+ /**
46
+ * Maximum nested call-expression depth, e.g. `a(b(c(d())))`.
47
+ */
48
+ maxNestedCalls: number
49
+ /**
50
+ * Maximum cyclomatic complexity of a single function.
51
+ */
52
+ complexity: number
53
+ }
54
+
55
+ /**
56
+ * Calibrated against the mailwoman corpus (1,048 non-test source files). Each value sits just past the knee in that
57
+ * repo's distribution, so considered human code stays silent and runaway generation does not. See the design spec for
58
+ * the full sweep.
59
+ *
60
+ * The four SIZE ceilings are deliberately looser than the knee. Adopting v10 surfaced 172 pre-existing violations, and
61
+ * splitting that many functions across a parser — with no accuracy gate available to verify the result — is a larger
62
+ * risk than the legibility it buys. They are set at the p90 of the measured overage instead, so the worst decile had to
63
+ * be fixed at adoption while the body was grandfathered:
64
+ *
65
+ * max-statements n=88 median= 73 p90= 115 max= 272
66
+ * complexity n=32 median= 49 p90= 84 max= 173
67
+ * max-lines-per-function n=26 median=283 p90= 829 max=1329
68
+ * max-params n=15 median= 7 p90= 8 max= 10
69
+ *
70
+ * RATCHET THESE DOWN as the grandfathered functions are split. They exist to stop new code drifting, and every step
71
+ * toward the knee makes them do more of that job.
72
+ */
73
+ export const DefaultLimits: OxlintConfigLimits = {
74
+ maxDepth: 5,
75
+ maxParams: 8,
76
+ maxStatements: 115,
77
+ maxLinesPerFunction: 830,
78
+ maxLines: 750,
79
+ maxNestedCallbacks: 4,
80
+ maxNestedCalls: 4,
81
+ complexity: 85,
82
+ }
83
+
84
+ /**
85
+ * Globs treated as test files, where the size and named-constant rules are switched off.
86
+ */
87
+ export const DefaultTestFilePatterns = [
88
+ "**/*.test.ts",
89
+ "**/*.test.tsx",
90
+ "**/test/**",
91
+ "**/fixtures/**",
92
+ "**/*.bench.ts",
93
+ // Storybook stories are fixtures in the same sense: each export is a rendered case, and its NAME is
94
+ // the label shown in the sidebar. A JSDoc block on `export const Default: Story = {}` says nothing
95
+ // the name does not.
96
+ "**/*.stories.ts",
97
+ "**/*.stories.tsx",
98
+ ]
99
+
100
+ /**
101
+ * Globs whose contents are emitted by a generator, not written by hand. The size ceilings are meaningless there — the
102
+ * file is as long as its input is wide, and no reviewer reads it top to bottom — but every correctness rule still
103
+ * applies, because generated code ships.
104
+ */
105
+ export const DefaultGeneratedFilePatterns = ["**/*.gen.ts", "**/*.gen.tsx", "**/*.generated.ts", "**/generated/**"]
106
+
107
+ /**
108
+ * Globs for files JavaScript checks at runtime rather than TypeScript checking ahead of it. A JSDoc block there often
109
+ * IS the type annotation, and a one-line `@type` cast is the idiomatic form — so the multi-line requirement, which
110
+ * exists to make prose read as documentation, does not apply.
111
+ */
112
+ export const DefaultUntypedFilePatterns = ["**/*.js", "**/*.mjs", "**/*.cjs", "**/*.jsx"]
113
+
114
+ /**
115
+ * Options for {@link createOxlintConfig}.
116
+ */
16
117
  export interface OxlintConfigOptions {
17
- /** The package namespace whose runtime boundaries are enforced, e.g. `@sister.software`. */
118
+ /**
119
+ * The package namespace whose runtime boundaries are enforced, e.g. `@sister.software`.
120
+ */
18
121
  packageNamespace?: string
19
- /** The copyright holder stamped into file headers. */
122
+ /**
123
+ * The copyright holder stamped into file headers.
124
+ */
20
125
  copyrightHolder?: string
21
- /** The SPDX license identifier stamped into file headers. */
126
+ /**
127
+ * The SPDX license identifier stamped into file headers.
128
+ */
22
129
  spdxLicenseIdentifier?: string
23
- /** The author stamped into file headers. */
130
+ /**
131
+ * The author stamped into file headers.
132
+ */
24
133
  author?: string
25
- /** Enable oxlint's React plugin (off by default). */
134
+ /**
135
+ * Enable oxlint's React plugin (off by default).
136
+ */
26
137
  react?: boolean
27
- /** Enforce file headers via the bundled JS plugin (on by default). */
138
+ /**
139
+ * Enforce file headers via the bundled JS plugin (on by default).
140
+ */
28
141
  headers?: boolean
29
- /** Require a blank line before `return`/block-like statements (on by default). */
142
+ /**
143
+ * Require a blank line before `return`/block-like statements (on by default).
144
+ */
30
145
  padding?: boolean
31
- /** Require braces around single-statement work bodies (bare `return` exempt; on by default). */
146
+ /**
147
+ * Blank line on each side of a `console.*` call, with runs of them grouped (on by default).
148
+ */
149
+ consolePadding?: boolean
150
+ /**
151
+ * Blank line on each side of a statement that spans lines (on by default).
152
+ */
153
+ multilineStatementPadding?: boolean
154
+ /**
155
+ * Require braces around single-statement work bodies (bare `return` exempt; on by default).
156
+ */
32
157
  braces?: boolean
33
158
  /**
34
159
  * Forbid direct `process.env` / `process.argv` access (off by default). Turn on once the project funnels those reads
35
160
  * through blessed helpers, which disable `sister-software/no-process-globals`.
36
161
  */
37
162
  restrictProcessGlobals?: boolean
38
- /** Override the default ignore patterns. */
163
+ /**
164
+ * Flag numeric literals used as comparison thresholds (off by default). Pass an object to change the ignore list or
165
+ * to stop exempting radix-prefixed literals.
166
+ */
167
+ unnamedThresholds?: boolean | { ignore?: number[]; allowHex?: boolean }
168
+ /**
169
+ * Require a JSDoc block on module-level constants (off by default). `scope` selects which ones: `"exported"`,
170
+ * `"screaming"`, or the default `"exported-or-screaming"`.
171
+ */
172
+ constantDocs?: boolean | { scope?: "exported" | "screaming" | "exported-or-screaming" }
173
+ /**
174
+ * Rewrite explicit length comparisons to truthiness in boolean positions (on by default).
175
+ */
176
+ lengthTruthiness?: boolean
177
+ /**
178
+ * Require JSDoc blocks to span multiple lines (on by default). Off for untyped files.
179
+ */
180
+ multilineJSDoc?: boolean
181
+ /**
182
+ * Enforce the section-marker ladder — `----` banners become `// MARK:`, long labels are flagged, and a file with many
183
+ * markers is nudged toward regions and then toward being several files (on by default).
184
+ */
185
+ sectionMarkers?: boolean | { maxBodyLength?: number; maxRegions?: number }
186
+ /**
187
+ * Override individual legibility ceilings. Unspecified keys keep their calibrated default.
188
+ */
189
+ limits?: Partial<OxlintConfigLimits>
190
+ /**
191
+ * Replace the globs treated as test files.
192
+ */
193
+ testFilePatterns?: string[]
194
+ /**
195
+ * Replace the globs treated as generated files, where only the size ceilings are switched off.
196
+ */
197
+ generatedFilePatterns?: string[]
198
+ /**
199
+ * Replace the globs treated as untyped, where the multi-line JSDoc requirement switches off.
200
+ */
201
+ untypedFilePatterns?: string[]
202
+ /**
203
+ * Override the default ignore patterns.
204
+ */
39
205
  ignorePatterns?: string[]
40
- /** Extra config deep-merged last; an escape hatch for per-repo tweaks. */
206
+ /**
207
+ * Extra config deep-merged last; an escape hatch for per-repo tweaks.
208
+ */
41
209
  overrides?: OxlintConfig
42
210
  }
43
211
 
44
- /** Default ignore patterns for generated/build output. */
212
+ /**
213
+ * Default ignore patterns for generated/build output and vendored tooling.
214
+ */
45
215
  export const DefaultIgnorePatterns = [
46
216
  "**/out",
47
217
  "**/dist",
@@ -49,6 +219,9 @@ export const DefaultIgnorePatterns = [
49
219
  "**/node_modules",
50
220
  "**/coverage",
51
221
  "**/storybook-static",
222
+ // Yarn 4 vendors its own release bundle and plugin code here. It is third-party, minified, and
223
+ // not ours to lint — Tier 2's `no-abusive-eslint-disable` fires on it otherwise.
224
+ "**/.yarn/**",
52
225
  ]
53
226
 
54
227
  /**
@@ -74,20 +247,32 @@ export function createOxlintConfig(options: OxlintConfigOptions = {}): OxlintCon
74
247
  react = false,
75
248
  headers = true,
76
249
  padding = true,
250
+ consolePadding = true,
251
+ multilineStatementPadding = true,
77
252
  braces = true,
78
253
  restrictProcessGlobals = false,
254
+ unnamedThresholds = false,
255
+ constantDocs = false,
256
+ lengthTruthiness = true,
257
+ multilineJSDoc = true,
258
+ sectionMarkers = true,
259
+ limits: limitOverrides = {},
260
+ testFilePatterns = DefaultTestFilePatterns,
261
+ generatedFilePatterns = DefaultGeneratedFilePatterns,
262
+ untypedFilePatterns = DefaultUntypedFilePatterns,
79
263
  ignorePatterns = DefaultIgnorePatterns,
80
264
  overrides = {},
81
265
  } = options
82
266
 
83
- const plugins = ["typescript", "unicorn", "oxc", ...(react ? ["react"] : [])]
267
+ const limits: OxlintConfigLimits = { ...DefaultLimits, ...limitOverrides }
268
+
269
+ const plugins = ["typescript", "unicorn", "oxc", "import", "promise", "vitest", ...(react ? ["react"] : [])]
84
270
 
85
271
  const rules: Record<string, unknown> = {
86
272
  // JavaScript
87
273
  eqeqeq: ["error", "always", { null: "ignore" }],
88
274
  "prefer-const": "warn",
89
275
  "object-shorthand": ["warn", "always"],
90
- "no-shadow": "off",
91
276
  "no-undef": "off",
92
277
  "no-unused-vars": [
93
278
  "warn",
@@ -113,6 +298,191 @@ export function createOxlintConfig(options: OxlintConfigOptions = {}): OxlintCon
113
298
  "typescript/no-non-null-assertion": "off",
114
299
  "typescript/no-var-requires": "off",
115
300
  "typescript/no-require-imports": "off",
301
+
302
+ // Tier 1 — legibility guardrails. Thresholds are ceilings past the knee of the calibration
303
+ // corpus's distribution: they stay silent on considered code and fire on runaway generation.
304
+ "max-depth": ["error", { max: limits.maxDepth }],
305
+ "max-params": ["error", { max: limits.maxParams }],
306
+ "max-statements": ["error", { max: limits.maxStatements }],
307
+ "max-lines-per-function": ["error", { max: limits.maxLinesPerFunction, skipBlankLines: true, skipComments: true }],
308
+ "max-lines": ["error", { max: limits.maxLines, skipBlankLines: true, skipComments: true }],
309
+ "max-nested-callbacks": ["error", { max: limits.maxNestedCallbacks }],
310
+ "unicorn/max-nested-calls": ["error", { max: limits.maxNestedCalls }],
311
+ complexity: ["error", limits.complexity],
312
+ "unicorn/no-array-reduce": "error",
313
+ "unicorn/no-unreadable-array-destructuring": "error",
314
+
315
+ // Tier 2 — defect classes that `correctness` does not cover. Every rule here corresponds to a
316
+ // way working-looking code is wrong at runtime.
317
+ "no-shadow": "error",
318
+ "no-promise-executor-return": "error",
319
+ "no-useless-assignment": "error",
320
+ "no-unreachable-loop": "error",
321
+ "no-unmodified-loop-condition": "error",
322
+ "no-loop-func": "error",
323
+ // `.sort()` and `.reverse()` mutate in place; on a shared or cached array that is a bug at a
324
+ // distance. The fixes are `toSorted()` / `toReversed()`.
325
+ "unicorn/no-array-sort": "error",
326
+ "unicorn/no-array-reverse": "error",
327
+ "unicorn/no-immediate-mutation": "error",
328
+ "unicorn/no-array-method-this-argument": "error",
329
+ "unicorn/no-typeof-undefined": "error",
330
+ "unicorn/no-useless-promise-resolve-reject": "error",
331
+ "unicorn/prefer-type-error": "error",
332
+ // Global `isNaN` coerces its argument; `Number.isNaN` does not.
333
+ "unicorn/prefer-number-properties": "error",
334
+ "unicorn/no-abusive-eslint-disable": "error",
335
+ // Off despite the name: it fires on `.map(x => ({ ...x, field }))`, which is O(n·k) overall and the
336
+ // ordinary way to add a field. The quadratic accumulation worth catching is `acc = { ...acc, x }`
337
+ // inside a reduce, which this does not distinguish. 14 sites, 14 false positives.
338
+ "oxc/no-map-spread": "off",
339
+ "oxc/bad-bitwise-operator": "error",
340
+ "oxc/branches-sharing-code": "error",
341
+ "typescript/no-dynamic-delete": "error",
342
+ "typescript/prefer-ts-expect-error": "error",
343
+ // A cycle here is not a style issue: it leaves bindings unevaluated at import time, which
344
+ // surfaces as a base class that is `undefined` at class-definition time.
345
+ "import/no-cycle": "error",
346
+ // `ignoreLastCallback` keeps the rule pointed at CHAINS, where a missing return silently feeds
347
+ // undefined to the next link. A terminal `.then(…)` doing side effects has nothing downstream
348
+ // to starve, and rewriting those adds a return whose value no one reads.
349
+ "promise/always-return": ["error", { ignoreLastCallback: true }],
350
+ // Off: it cannot see that a ternary settles exactly once. `cb((err) => (err ? reject(err) : resolve()))`
351
+ // is the standard way to bridge a node-style callback to a promise, and the rule flagged every
352
+ // instance of it on the calibration corpus — 6 sites, 6 false positives, no real double-settle.
353
+ "promise/no-multiple-resolved": "off",
354
+
355
+ // Tier 3 — test discipline. `expect-expect` is the one that matters most: it catches a test
356
+ // that runs, passes, and asserts nothing.
357
+ "vitest/expect-expect": "error",
358
+ // vitest's `expect(value, message)` takes an optional assertion message as a second argument —
359
+ // the rule's default of one would flag the API's own signature.
360
+ "vitest/valid-expect": ["error", { maxArgs: 2 }],
361
+ "vitest/valid-title": "error",
362
+ "vitest/valid-describe-callback": "error",
363
+ // Off: the dominant shape it flags is a parameterized assertion helper, where the conditional IS
364
+ // the contract — `expectProposal(out, { kind, body, minConfidence? })` asserts only what the
365
+ // caller specified. 33 sites on the calibration corpus, none a hidden never-running assertion.
366
+ "vitest/no-conditional-expect": "off",
367
+ "vitest/no-conditional-tests": "error",
368
+ "vitest/no-disabled-tests": "error",
369
+ "vitest/no-commented-out-tests": "error",
370
+ "vitest/no-alias-methods": "error",
371
+ "vitest/prefer-to-be": "error",
372
+ "vitest/prefer-to-have-length": "error",
373
+ "vitest/prefer-to-contain": "error",
374
+ "vitest/require-to-throw-message": "error",
375
+ // Playwright names its e2e specs `*.spec.ts`; vitest unit tests are `*.test.ts`. A repo running
376
+ // both has two legitimate conventions, so the rule is scoped to the vitest ones.
377
+ "vitest/consistent-test-filename": ["error", { allTestPattern: String.raw`.*\.test\.[tj]sx?$` }],
378
+ // Enabling a plugin also activates its `correctness`-category rules, so a rule this tier turned
379
+ // down must be switched off explicitly rather than merely left out of the list above.
380
+ "vitest/require-mock-type-parameters": "off",
381
+ "vitest/no-conditional-in-test": "off",
382
+
383
+ // Tier 4 — mechanical hygiene. All autofixable, none requiring judgment.
384
+ // Literal form.
385
+ "unicorn/numeric-separators-style": "error",
386
+ "unicorn/no-zero-fractions": "error",
387
+ "unicorn/text-encoding-identifier-case": "error",
388
+ "unicorn/escape-case": "error",
389
+ "unicorn/no-hex-escape": "error",
390
+ // Import discipline.
391
+ // `disallowTypeAnnotations: false` keeps the valuable half — a type-only import must be written
392
+ // `import type` — while allowing `typeof import("…")` in an annotation. That form is how a
393
+ // guarded dynamic import is typed: the module is optional and loaded at runtime, and the inline
394
+ // annotation is what says so. `import type` would erase to nothing and read as a hard dep.
395
+ "typescript/consistent-type-imports": ["error", { disallowTypeAnnotations: false }],
396
+ "typescript/no-import-type-side-effects": "error",
397
+ "unicorn/prefer-export-from": "error",
398
+ "import/no-duplicates": "error",
399
+ "import/first": "error",
400
+ "import/newline-after-import": "error",
401
+ // Modern API preference.
402
+ "unicorn/prefer-string-replace-all": "error",
403
+ // `caught` is permitted alongside `error`: when a catch sits inside a scope that already binds
404
+ // `error` (a React component's error state, say), no-shadow requires a different name and this
405
+ // rule would otherwise demand the shadowing one. The two rules are in direct conflict without it.
406
+ "unicorn/catch-error-name": ["error", { ignore: ["caught"] }],
407
+ "unicorn/prefer-at": "error",
408
+ "unicorn/prefer-global-this": "error",
409
+ "unicorn/consistent-existence-index-check": "error",
410
+ "unicorn/new-for-builtins": "error",
411
+ "unicorn/prefer-array-find": "error",
412
+ "unicorn/prefer-structured-clone": "error",
413
+ "unicorn/prefer-negative-index": "error",
414
+ "unicorn/prefer-math-min-max": "error",
415
+ "unicorn/no-useless-collection-argument": "error",
416
+ "unicorn/throw-new-error": "error",
417
+ // Two rules that look mechanical but are not type-safe, so they stay off:
418
+ //
419
+ // `unicorn/prefer-code-point` rewrites `charCodeAt` to `codePointAt`, which returns
420
+ // `number | undefined`. It exists for surrogate-pair correctness, but on the ASCII arithmetic
421
+ // where it usually fires it buys nothing and forces an undefined branch at every site.
422
+ //
423
+ // `unicorn/no-useless-undefined` drops an explicitly-passed `undefined` argument. oxlint has no
424
+ // type information, so it cannot tell an optional parameter from a required one and will
425
+ // silently turn `f(a, undefined)` into a call that no longer type-checks.
426
+ //
427
+ // `unicorn/prefer-string-raw` rewrites a string literal to a String.raw template. That is
428
+ // runtime-identical but not type-identical: the literal type is lost, so any template-literal
429
+ // type built from the value collapses. It widens types silently, which is worse than the
430
+ // escaped backslashes it removes.
431
+ "unicorn/prefer-code-point": "off",
432
+ "unicorn/no-useless-undefined": "off",
433
+ "unicorn/prefer-string-raw": "off",
434
+ //
435
+ // `unicorn/prefer-math-trunc` is the one that is not merely type-unsafe but semantically wrong.
436
+ // `x | 0` and `x >>> 0` are int32/uint32 coercion, and the wrapping is the point — every site on
437
+ // the calibration corpus was a hash function, a PRNG, or a seeded evaluation harness.
438
+ // `Math.trunc` does not wrap, so taking its suggestion silently changes what those produce.
439
+ "unicorn/prefer-math-trunc": "off",
440
+ //
441
+ // `unicorn/prefer-number-coercion` rewrites `Number.parseInt(x, 10)` to
442
+ // `Math.trunc(Number(x))`. parseInt parses a numeric PREFIX; Number is strict, so
443
+ // `parseInt("12px", 10)` is 12 where `Number("12px")` is NaN. On the calibration corpus the
444
+ // inputs included CLI options and an HTTP status of uncertain type — exactly where the
445
+ // difference bites. It also reintroduces Math.trunc, disabled just above.
446
+ "unicorn/prefer-number-coercion": "off",
447
+ //
448
+ // These two are not unsafe — they are unsatisfiable. oxfmt reverts both fixes on its next run:
449
+ // it lowercases hex digits, and it strips the parentheses unicorn/no-nested-ternary adds. Lint
450
+ // and format are both CI gates, so a rule the formatter undoes can never go green. Neither
451
+ // behaviour is configurable in oxfmt today.
452
+ "unicorn/number-literal-case": "off",
453
+ "unicorn/no-nested-ternary": "off",
454
+ //
455
+ // `unicorn/explicit-length-check` enforces `x.length > 0`, the opposite of the house
456
+ // convention. `sister-software/prefer-length-truthiness` enforces ours.
457
+ "unicorn/explicit-length-check": "off",
458
+ //
459
+ // Core `no-duplicate-imports` is not TypeScript-aware: it counts a value import and an
460
+ // `import type` from the same module as a duplicate, which is the split
461
+ // `typescript/consistent-type-imports` exists to create. On the calibration corpus it reported
462
+ // 71 sites where the TS-aware `import/no-duplicates` reported 1, and that 1 was real.
463
+ "no-duplicate-imports": "off",
464
+
465
+ // TS style.
466
+ "typescript/consistent-type-definitions": "error",
467
+ "typescript/consistent-indexed-object-style": "error",
468
+ "typescript/prefer-for-of": "error",
469
+ "typescript/no-inferrable-types": "error",
470
+ // Small structural.
471
+ "unicorn/prefer-ternary": "error",
472
+ "unicorn/prefer-logical-operator-over-ternary": "error",
473
+ "unicorn/no-lonely-if": "error",
474
+ "unicorn/no-console-spaces": "error",
475
+ "unicorn/no-static-only-class": "error",
476
+ "no-useless-return": "error",
477
+ }
478
+
479
+ if (react) {
480
+ rules["react-hooks/rules-of-hooks"] = "error"
481
+ rules["react/no-unstable-nested-components"] = "error"
482
+ rules["react/no-object-type-as-default-prop"] = "error"
483
+ rules["react/jsx-no-constructed-context-values"] = "error"
484
+ // The automatic JSX runtime made this obsolete; the rule predates it.
485
+ rules["react/react-in-jsx-scope"] = "off"
116
486
  }
117
487
 
118
488
  if (headers) {
@@ -136,15 +506,118 @@ export function createOxlintConfig(options: OxlintConfigOptions = {}): OxlintCon
136
506
  rules["sister-software/no-process-globals"] = "error"
137
507
  }
138
508
 
509
+ if (unnamedThresholds) {
510
+ // Error severity: an unnamed threshold is a legibility defect, not a style preference.
511
+ rules["sister-software/no-unnamed-threshold"] = [
512
+ "error",
513
+ typeof unnamedThresholds === "object" ? unnamedThresholds : {},
514
+ ]
515
+ }
516
+
517
+ if (constantDocs) {
518
+ // Error severity: an undocumented public constant or tuning knob is a legibility defect.
519
+ rules["sister-software/require-constant-doc"] = ["error", typeof constantDocs === "object" ? constantDocs : {}]
520
+ }
521
+
522
+ if (lengthTruthiness) {
523
+ rules["sister-software/prefer-length-truthiness"] = "error"
524
+ }
525
+
526
+ if (consolePadding) {
527
+ rules["sister-software/console-padding"] = "warn"
528
+ }
529
+
530
+ if (multilineStatementPadding) {
531
+ rules["sister-software/multiline-statement-padding"] = "warn"
532
+ }
533
+
534
+ if (multilineJSDoc) {
535
+ rules["sister-software/multiline-jsdoc"] = "error"
536
+ }
537
+
538
+ if (sectionMarkers) {
539
+ const markerOptions = typeof sectionMarkers === "object" ? sectionMarkers : {}
540
+ // The two mechanical rungs are errors: a banner has exactly one correct rewrite, and a label
541
+ // length is measurable. The two judgment rungs warn — where a section ends, and whether it
542
+ // should become its own file, are not decisions a linter gets to make.
543
+ rules["sister-software/prefer-mark-comment"] = "error"
544
+
545
+ rules["sister-software/concise-section-marker"] = [
546
+ "error",
547
+ markerOptions.maxBodyLength === undefined ? {} : { maxBodyLength: markerOptions.maxBodyLength },
548
+ ]
549
+
550
+ rules["sister-software/prefer-region-over-marks"] = "warn"
551
+
552
+ rules["sister-software/max-regions"] = [
553
+ "warn",
554
+ markerOptions.maxRegions === undefined ? {} : { max: markerOptions.maxRegions },
555
+ ]
556
+ }
557
+
558
+ // Rules switched off inside test files. Table-driven test bodies are legitimately long, and
559
+ // expected values are legitimately unnamed numbers. oxlint validates override entries against the
560
+ // registered rule set, so an entry may only name a rule this config actually turned on.
561
+ const testFileRules: Record<string, unknown> = {
562
+ "max-lines-per-function": "off",
563
+ "max-statements": "off",
564
+ "max-lines": "off",
565
+ }
566
+
567
+ if (react) {
568
+ // A Storybook `render` IS a component — React calls it as one — but it is not NAMED like one, so
569
+ // the hook rules read it as a plain function. Test files that render hooks go through a
570
+ // testing-library wrapper for the same reason.
571
+ testFileRules["react-hooks/rules-of-hooks"] = "off"
572
+ }
573
+
574
+ if (unnamedThresholds) {
575
+ testFileRules["sister-software/no-unnamed-threshold"] = "off"
576
+ }
577
+
578
+ if (constantDocs) {
579
+ testFileRules["sister-software/require-constant-doc"] = "off"
580
+ }
581
+
582
+ if (sectionMarkers) {
583
+ // A test file's sections track the suite's shape, which the code under test dictates — a big
584
+ // table of cases legitimately wants many markers, and splitting it would scatter the suite.
585
+ testFileRules["sister-software/prefer-region-over-marks"] = "off"
586
+ testFileRules["sister-software/max-regions"] = "off"
587
+ }
588
+
589
+ /**
590
+ * Generated files: size ceilings only. Everything else still applies — generated code ships.
591
+ */
592
+ const generatedFileRules: Record<string, unknown> = {
593
+ "max-lines": "off",
594
+ "max-lines-per-function": "off",
595
+ "max-statements": "off",
596
+ complexity: "off",
597
+ }
598
+
139
599
  return {
140
600
  plugins,
141
- ...(headers || padding || braces || restrictProcessGlobals
601
+ ...(headers ||
602
+ padding ||
603
+ braces ||
604
+ restrictProcessGlobals ||
605
+ unnamedThresholds ||
606
+ constantDocs ||
607
+ lengthTruthiness ||
608
+ multilineJSDoc ||
609
+ sectionMarkers
142
610
  ? { jsPlugins: ["@sister.software/oxlint-config/plugin"] }
143
611
  : {}),
144
612
  categories: { correctness: "error" },
145
613
  ignorePatterns,
146
614
  rules,
147
- overrides: createRuntimeOverrides(packageNamespace),
615
+ overrides: [
616
+ ...createRuntimeOverrides(packageNamespace),
617
+ { files: testFilePatterns, rules: testFileRules },
618
+ { files: generatedFilePatterns, rules: generatedFileRules },
619
+ ...(multilineJSDoc ? [{ files: untypedFilePatterns, rules: { "sister-software/multiline-jsdoc": "off" } }] : []),
620
+ ],
148
621
  ...overrides,
149
622
  }
150
623
  }
@@ -0,0 +1,75 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ * @file The `sister-software/multiline-jsdoc` rule: a JSDoc block always spans multiple lines, even
6
+ * when its content would fit on one. A one-line block reads as an aside; the multi-line form reads
7
+ * as documentation, and it leaves somewhere to put the second sentence when one is needed.
8
+ *
9
+ * Two shapes are left alone. A JSDoc that shares its line with code is a type cast or an inline
10
+ * annotation, and expanding those changes what the line means. A JSDoc on a union or intersection
11
+ * member labels one alternative in what reads as a list — three lines per entry turns a list you
12
+ * can scan into a page you have to read.
13
+ */
14
+
15
+ import type { Rule } from "./plugin-types.js"
16
+
17
+ /**
18
+ * The JSDoc opener, so the rule can tell a documentation block from a plain block comment.
19
+ */
20
+ const JSDOC_OPENER = "/**"
21
+
22
+ /**
23
+ * A `|` or `&` as the next thing after a comment, meaning the comment labels one member of a union or intersection
24
+ * rather than documenting a declaration.
25
+ */
26
+ const UNION_MEMBER = /^\s*[|&]/
27
+
28
+ export const multilineJSDocRule: Rule = {
29
+ meta: {
30
+ name: "multiline-jsdoc",
31
+ type: "layout",
32
+ fixable: "whitespace",
33
+ schema: [{ type: "object", additionalProperties: true }],
34
+ },
35
+ create(context) {
36
+ const sourceCode = context.sourceCode ?? context.getSourceCode!()
37
+ const text = sourceCode.getText()
38
+
39
+ return {
40
+ Program() {
41
+ for (const comment of sourceCode.getAllComments()) {
42
+ if (comment.type !== "Block") continue
43
+ const raw = text.slice(comment.range[0], comment.range[1])
44
+
45
+ if (!raw.startsWith(JSDOC_OPENER) || raw.includes("\n")) continue
46
+
47
+ // `value` excludes the delimiters, so a one-line block arrives as `"* x "`.
48
+ const body = comment.value.replace(/^\*/, "").trim()
49
+
50
+ if (!body) continue
51
+
52
+ // Everything from the start of the line up to the comment. All-whitespace means the
53
+ // block leads its line and owns the indentation; anything else means it is inline.
54
+ const lineStart = text.lastIndexOf("\n", comment.range[0] - 1) + 1
55
+ const indent = text.slice(lineStart, comment.range[0])
56
+
57
+ if (indent.trim()) continue
58
+
59
+ // A block documenting a union or intersection member is a label on one alternative, and
60
+ // the members read as a list. Three lines per entry turns a scannable list into a page,
61
+ // so the requirement does not reach inside one.
62
+ if (UNION_MEMBER.test(text.slice(comment.range[1]))) continue
63
+
64
+ context.report({
65
+ node: { type: "Block", range: comment.range },
66
+ message: "JSDoc should span multiple lines.",
67
+ fix(fixer) {
68
+ return fixer.replaceTextRange(comment.range, `/**\n${indent} * ${body}\n${indent} */`)
69
+ },
70
+ })
71
+ }
72
+ },
73
+ }
74
+ },
75
+ }