@stateward/core 1.2.1 → 1.3.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 (75) hide show
  1. package/dist/analyses.d.ts +37 -0
  2. package/dist/analyses.js +57 -0
  3. package/dist/backend/program-record.d.ts +7 -0
  4. package/dist/backend/typescript6.d.ts +35 -32
  5. package/dist/backend/typescript6.js +3804 -163
  6. package/dist/baseline.d.ts +1 -1
  7. package/dist/baseline.js +14 -10
  8. package/dist/cache.d.ts +89 -5
  9. package/dist/cache.js +271 -40
  10. package/dist/checker.d.ts +11 -1
  11. package/dist/checker.js +32 -2
  12. package/dist/class-id.d.ts +34 -0
  13. package/dist/class-id.js +93 -0
  14. package/dist/code-text.d.ts +8 -0
  15. package/dist/code-text.js +66 -0
  16. package/dist/config-file.js +7 -5
  17. package/dist/config.d.ts +10 -2
  18. package/dist/config.js +541 -49
  19. package/dist/define.d.ts +8 -2
  20. package/dist/disk-cache.d.ts +2 -0
  21. package/dist/disk-cache.js +77 -11
  22. package/dist/engine.d.ts +51 -1
  23. package/dist/engine.js +517 -42
  24. package/dist/fact-lines.d.ts +31 -0
  25. package/dist/fact-lines.js +197 -0
  26. package/dist/facts-versions.d.ts +27 -0
  27. package/dist/facts-versions.js +99 -0
  28. package/dist/fixes.js +9 -4
  29. package/dist/guarantees.d.ts +63 -11
  30. package/dist/guarantees.js +151 -21
  31. package/dist/ignores.d.ts +11 -0
  32. package/dist/ignores.js +74 -27
  33. package/dist/implementation.d.ts +0 -6
  34. package/dist/implementation.js +0 -17
  35. package/dist/index.d.ts +10 -9
  36. package/dist/index.js +14 -7
  37. package/dist/internal.d.ts +9 -5
  38. package/dist/internal.js +6 -3
  39. package/dist/lazy.d.ts +8 -1
  40. package/dist/lazy.js +27 -2
  41. package/dist/ledger.d.ts +77 -0
  42. package/dist/ledger.js +423 -0
  43. package/dist/off-by-default.d.ts +13 -0
  44. package/dist/off-by-default.js +15 -0
  45. package/dist/options.d.ts +21 -5
  46. package/dist/options.js +22 -7
  47. package/dist/package-facts.d.ts +211 -17
  48. package/dist/package-facts.js +520 -38
  49. package/dist/plan.d.ts +1 -1
  50. package/dist/plan.js +7 -2
  51. package/dist/release.d.ts +12 -21
  52. package/dist/release.js +28 -38
  53. package/dist/renamed.d.ts +22 -3
  54. package/dist/renamed.js +50 -16
  55. package/dist/rollout.js +7 -4
  56. package/dist/safe-calls.d.ts +26 -0
  57. package/dist/safe-calls.js +345 -0
  58. package/dist/severity.d.ts +1 -1
  59. package/dist/severity.js +17 -3
  60. package/dist/stated.d.ts +37 -0
  61. package/dist/stated.js +123 -0
  62. package/dist/test-runner.d.ts +18 -0
  63. package/dist/test-runner.js +483 -0
  64. package/dist/testing-tsc.d.ts +16 -0
  65. package/dist/testing-tsc.js +86 -0
  66. package/dist/testing.d.ts +5 -4
  67. package/dist/testing.js +6 -6
  68. package/dist/timing.d.ts +15 -0
  69. package/dist/timing.js +41 -2
  70. package/dist/types.d.ts +1068 -16
  71. package/dist/unread.d.ts +90 -0
  72. package/dist/unread.js +405 -0
  73. package/dist/vocabulary.d.ts +1 -1
  74. package/dist/vocabulary.js +1 -1
  75. package/package.json +4 -2
package/dist/types.d.ts CHANGED
@@ -89,7 +89,7 @@ export type FixReview = {
89
89
  /**
90
90
  * The finding with only the fixes that compile, each as its first form that does (without
91
91
  * `alternatives`). When it had fixes and none compiles, its hint ends with the line
92
- * "no automatic fix: <TypeScript's message>".
92
+ * "no automatic fix: <TypeScript's message>", from the last form tried of the first fix.
93
93
  */
94
94
  finding: Finding;
95
95
  /** Fixes that could not be tried: never offered, listed by `check --format json` as not verified. */
@@ -118,6 +118,19 @@ export type Finding = {
118
118
  * (`ReportProblem.about`); read by `RuleMeta.yieldsTo`, then dropped from the result.
119
119
  */
120
120
  about?: Location;
121
+ /**
122
+ * The finding stands against a guarantee the code states (`ReportProblem.against`): a proof
123
+ * counts it whatever its severity, and a config that turns its kind off leaves it as an info.
124
+ */
125
+ against?: true;
126
+ /**
127
+ * The guarantees this finding is against, by the id of each stated declaration
128
+ * (`StatedGuarantee.declaration`): a proof reads a guarantee as not proven while a finding
129
+ * names it, whatever the finding's severity or the settings. Set by a rule that says what it
130
+ * is against (`ReportProblem.against`), else from where the finding lies (`linkFindings`);
131
+ * absent when no guarantee is known for it.
132
+ */
133
+ guarantees?: readonly string[];
121
134
  }
122
135
  /**
123
136
  * Analysis could not decide: always reported, never silent. `hint` says what would make it
@@ -133,6 +146,15 @@ export type Finding = {
133
146
  shown?: "warning" | "off";
134
147
  /** The rule asks for its places not checked to be listed (`RuleMeta.listUnknowns`). */
135
148
  listed?: true;
149
+ /**
150
+ * The guarantees whose proof stops here (as `guarantees` of a problem): each reads "not
151
+ * checked" at this place, whatever `shown` says.
152
+ */
153
+ guarantees?: readonly string[];
154
+ /** The `facts` lines that would decide it, each a package call no line states. */
155
+ needs?: readonly FactNeed[];
156
+ /** The package calls that decide it and that no `facts` key can name, with why. */
157
+ unnamed?: readonly UnnamedFact[];
136
158
  }
137
159
  /** A rule threw: the check is incomplete, so it fails CI. */
138
160
  | {
@@ -147,13 +169,26 @@ export type Json = null | boolean | number | string | readonly Json[] | {
147
169
  };
148
170
  /**
149
171
  * Where a rule sits in its pack: `core` carries the guarantee, `coverage` finds
150
- * code outside the pack's standard, `addon` is opt-in by name.
172
+ * code outside the pack's standard, `convention` checks a team convention rather than a fact
173
+ * about the code (off in every preset; on with the config's `conventions: true` or by its id),
174
+ * `addon` is opt-in by name.
151
175
  */
152
176
  export type RuleTier = (typeof RULE_TIERS)[number];
153
177
  export type BooleanOption = {
154
178
  kind: "boolean";
155
179
  default: boolean;
156
180
  description: string;
181
+ /**
182
+ * The option turns on a check of a team convention rather than a fact about the code: it is
183
+ * true when the config sets `conventions: true` and does not set the option itself. Only on an
184
+ * option whose `default` is false.
185
+ */
186
+ convention?: true;
187
+ /**
188
+ * Set by stateward from the config, never by it (`asked`: the config names the rule): it is
189
+ * not documented, and a config that sets it gets an error.
190
+ */
191
+ internal?: true;
157
192
  };
158
193
  export type NumberOption = {
159
194
  kind: "number";
@@ -233,6 +268,13 @@ export type RuleInfo<S extends OptionSpecs = OptionSpecs, G extends string = str
233
268
  group: G;
234
269
  /** The add-on this rule belongs to (kebab-case); present exactly when `tier` is "addon". */
235
270
  addon?: string;
271
+ /**
272
+ * Only for tier `addon`: the rule was on by default until release `since`, and was made an
273
+ * add-on because too few of its findings were right on real projects. Its page says so
274
+ * (`offByDefaultText`), and a config that turns it on in `rules` gets a note with the same
275
+ * figure.
276
+ */
277
+ offByDefault?: OffByDefault;
236
278
  /**
237
279
  * Add-ons (kebab-case) that widen what this core or coverage rule checks. The rule reads which
238
280
  * are on from `FileContext.addons`; they count as add-ons of the plugin, so a config may list them.
@@ -240,6 +282,12 @@ export type RuleInfo<S extends OptionSpecs = OptionSpecs, G extends string = str
240
282
  widenedBy?: readonly string[];
241
283
  /** A guess, never an error: its severity is capped at "warning" unless the config sets it. */
242
284
  heuristic?: true;
285
+ /**
286
+ * Only for tier `convention`: the convention is the project's to state, and the rule reads only
287
+ * what the project states, so it reports nothing until the project states something. It is on
288
+ * like a core rule, without `conventions: true`; the config can still turn it off by its id.
289
+ */
290
+ whenStated?: true;
243
291
  /**
244
292
  * The rule reads JSDoc in TypeScript files (`@throws`). Files are parsed as tsc parses them,
245
293
  * without the JSDoc of TypeScript files, unless a rule that is on asks for it: parsing it costs
@@ -282,6 +330,20 @@ export type RuleInfo<S extends OptionSpecs = OptionSpecs, G extends string = str
282
330
  * TypeScript then checks): in a project without it, each finding's fix line says so.
283
331
  */
284
332
  fixNeedsStrictNulls?: true;
333
+ /**
334
+ * The traits this rule proves. The engine lists every reference to each declaration that states
335
+ * one (the reference ledger, `FileContext.ledger`); the rule marks each reference it reads with
336
+ * `FileContext.read`, and a reference it leaves unmarked reads "not checked" in the guarantee's
337
+ * proof.
338
+ */
339
+ proves?: RuleProves;
340
+ };
341
+ /** Why a rule is off by default: the release that made it so, and its findings checked on real projects. */
342
+ export type OffByDefault = {
343
+ /** The release that made it off by default: `"1.3"`. */
344
+ readonly since: string;
345
+ readonly right: number;
346
+ readonly checked: number;
285
347
  };
286
348
  /** A library a rule reads by its types: its name as people say it, and the modules that give them. */
287
349
  export type LibraryTypes = {
@@ -299,6 +361,8 @@ export type Literal = {
299
361
  value: string | number | boolean | null | undefined;
300
362
  label: string;
301
363
  };
364
+ /** A type that is one of TypeScript's own, read from the type's flags (`TypeQueries.builtinTypeOf`). */
365
+ export type BuiltinType = "any" | "unknown" | "never" | "void" | "undefined" | "null";
302
366
  /**
303
367
  * A test that narrows a reference by the kind of value it holds rather than by a literal:
304
368
  * `typeof x === "string"`, `"p" in x`, `x instanceof C` and a call to a user type guard.
@@ -342,6 +406,175 @@ export type SymbolRef = {
342
406
  readonly id: string;
343
407
  readonly name: string;
344
408
  };
409
+ /**
410
+ * A declaration whose written type states guarantees (`TypeQueries.statedDeclarationsIn`):
411
+ * `start` is where its node starts, the place a plugin lists it at (`StatedGuarantee.location`).
412
+ */
413
+ export type StatedDeclaration = {
414
+ readonly file: string;
415
+ readonly start: number;
416
+ /** The end of the declaration's head: its name and written type, not an initializer or a body. */
417
+ readonly headEnd: number;
418
+ readonly end: number;
419
+ readonly name: string;
420
+ /** The marker type as written: `Pending`. */
421
+ readonly marker: string;
422
+ /** The guarantee names the type states, sorted: `["pending"]`. */
423
+ readonly guarantees: readonly string[];
424
+ };
425
+ /**
426
+ * How a reference uses a stated declaration, as the reference ledger lists it (closed: a form not
427
+ * listed here is `other`). `call`: the callee of a call or `new`; `read`: read in place (a member
428
+ * read, an operand, a condition); `write`: assigned, changed with `++`, deleted, or a property given
429
+ * its value in an object literal; `alias`: copied to another name (a variable, a field, a default,
430
+ * a destructured name); `import` and `export`: named in an import or export; `argument`: passed to a
431
+ * call or to JSX; `stored`: put in an array or object literal; `returned`: returned or yielded;
432
+ * `jsx-tag` and `jsx-attribute`: a JSX element's tag or attribute name; `type`: named in a type;
433
+ * `computed`: used as a computed key; `other`: anything else (a branch of `?:`, `??`, a `for…of`);
434
+ * `tag`: the JSDoc tag that states the trait (`RuleProves.tags`), standing for the declaration's own
435
+ * body or definition, which its rule reads. The typed flows (`TypeQueries.typedFlowsIn`) are listed by their kind (`FlowKind`).
436
+ */
437
+ export type ReferenceForm = "call" | "read" | "write" | "alias" | "import" | "export" | "argument" | "stored" | "returned" | "jsx-tag" | "jsx-attribute" | "type" | "computed" | "other" | "tag" | FlowKind;
438
+ /**
439
+ * How a value of a stated type flows (`TypeQueries.typedFlowsIn`): `produced`, a place typed with
440
+ * it gets a value whose own type does not hold it (a cast, an `any`, a plain value, a generic call
441
+ * that returns it); `decided`, the code decides by it (a `switch` subject, a comparison, a key, an
442
+ * `in` test); `escaped`, an object holding a stated member is written in a way no reference names
443
+ * (`Object.assign(this, …)`, a literal for a state whose setter also takes a function).
444
+ */
445
+ export type FlowKind = "produced" | "decided" | "escaped";
446
+ /**
447
+ * What a typed flow goes through (`StatedReference.via`): `value`, a value given to a typed place;
448
+ * `cast`, `as`, `<T>` or `satisfies`; `any`, an `any` value; `overload`, a return of an overload's
449
+ * implementation; `override`, a value a class member gives where the member it overrides or
450
+ * implements is typed (`override id() { return "x" }` over `id(): OrderId`); `function-type`, a function given where one returning the type is expected;
451
+ * `generic-call`, a call whose type arguments give the type its arguments do not hold;
452
+ * `indirect-call`, `.call`, `.apply`, `.bind`, `Reflect.apply` or `Reflect.construct`; `spread`, a
453
+ * spread argument, attribute or property; `reflect`, `Object.assign`, `Object.defineProperty`,
454
+ * `Reflect.set` or a computed key; `literal`, an object literal; `for-of`, the target of a
455
+ * `for…of`; `derived`, a value made from one by a method (`switch (s.toLowerCase())`);
456
+ * `call`, a value given to a call that decides by it (`list.includes(s)`, `map.get(s)`,
457
+ * `Object.is(s, …)`); `stopped`, the flow scan of the file stopped at its budget here, so the flows after it
458
+ * are not listed.
459
+ */
460
+ export type FlowVia = "value" | "cast" | "any" | "overload" | "override" | "function-type" | "generic-call" | "indirect-call" | "spread" | "reflect" | "literal" | "for-of" | "derived" | "call" | "stopped";
461
+ /**
462
+ * What a rule proves (`RuleInfo.proves`): the reference ledger lists every reference to each
463
+ * declaration that states one of these, and the rule marks the ones it reads (`FileContext.read`).
464
+ */
465
+ export type RuleProves = {
466
+ /** Traits a value, property or parameter states by its written type (`Owned<T>`). */
467
+ readonly traits?: readonly string[];
468
+ /**
469
+ * Traits a function states by its written return type (`(): Marker<…>`, or a promise of one): the
470
+ * function is the stated declaration, and each call a reference to it.
471
+ */
472
+ readonly returns?: readonly string[];
473
+ /**
474
+ * Traits a module variable with no written type states by the type of the call that makes it
475
+ * (`const ThemeContext = requiredContext<Theme>()`): the variable is the stated declaration.
476
+ */
477
+ readonly made?: readonly string[];
478
+ /**
479
+ * Traits a variable declared by an array destructuring states by a type written on it or on the
480
+ * call that makes it (`const [saving, setSaving] = useState<Pending<boolean>>(false)`): every
481
+ * element whose type holds the trait (as itself, or in a union member, a parameter or a return of
482
+ * a function, up to three levels) refers to one stated declaration, the variable declaration.
483
+ */
484
+ readonly holders?: readonly string[];
485
+ /**
486
+ * Traits whose typed flows enter the ledger, by kind (`TypeQueries.typedFlowsIn`): a type alias
487
+ * stating a trait of `produced` or `decided` is a stated declaration (each name of it in a type
488
+ * a reference), with its flows of that kind; a member stating a trait of `escaped` has its holder's
489
+ * escapes. Listed only when a file of the project declares the trait.
490
+ */
491
+ readonly flows?: {
492
+ readonly produced?: readonly string[];
493
+ readonly decided?: readonly string[];
494
+ readonly escaped?: readonly string[];
495
+ };
496
+ /**
497
+ * JSDoc tags (without `@`) whose declarations enter the ledger under the trait `@<tag>`: a
498
+ * function, a method, a variable holding a function, a property or method of a type, or a type
499
+ * alias the tag is written on. Each reference to it is listed, and the tag itself as a reference
500
+ * of form `tag`, which stands for the declaration's body: the rule reads it there.
501
+ */
502
+ readonly tags?: readonly string[];
503
+ };
504
+ /** A reference to a stated declaration (`TypeQueries.statedReferencesIn`, `typedFlowsIn`). */
505
+ export type StatedReference = {
506
+ /** The id of the declaration (`declarationId`). */
507
+ readonly declaration: string;
508
+ /** The declaration as a symbol: `declarationOf` finds it. */
509
+ readonly symbol: SymbolRef;
510
+ /** The declaration's name, and its marker type as written (`Owned`). */
511
+ readonly name: string;
512
+ readonly marker: string;
513
+ /** The trait the reference is listed for: one entry per trait the declaration states. */
514
+ readonly trait: string;
515
+ /** The identifier, private name or string key that refers to it; for a flow, the expression. */
516
+ readonly node: ts.Node;
517
+ readonly form: ReferenceForm;
518
+ /** For a typed flow (a `FlowKind` form): what it goes through. */
519
+ readonly via?: FlowVia;
520
+ /** The code around it, short and on one line: `w = watchPrices`. */
521
+ readonly text: string;
522
+ };
523
+ /** A reference in the ledger: a `StatedReference` without its node, as the cache keeps it. */
524
+ export type LedgerRef = {
525
+ /** `<file>#<start>` of the reference; `<file>#<start>-<end>` of a typed flow. */
526
+ readonly id: string;
527
+ readonly declaration: string;
528
+ readonly name: string;
529
+ readonly marker: string;
530
+ readonly trait: string;
531
+ readonly form: ReferenceForm;
532
+ readonly via?: FlowVia;
533
+ readonly location: Location;
534
+ readonly text: string;
535
+ };
536
+ /**
537
+ * What a rule says of a reference it read (`FileContext.read`): `decided`, the rule read it
538
+ * completely (a finding says when it is wrong); `irrelevant`, nothing the guarantee promises
539
+ * depends on it (an import, a read of a part that cannot change it); `handed-on`, the value goes
540
+ * to `to`, which the rule's project side settles (`ProjectContext.read`); `unchecked`, the rule
541
+ * cannot follow it, and `reason` says what it is (after "not checked: ").
542
+ */
543
+ export type ReadOutcome = {
544
+ readonly kind: "decided";
545
+ } | {
546
+ readonly kind: "irrelevant";
547
+ } | {
548
+ readonly kind: "handed-on";
549
+ readonly to: string;
550
+ } | {
551
+ readonly kind: "unchecked";
552
+ readonly reason: string;
553
+ };
554
+ /** One rule's mark on a reference of the ledger. */
555
+ export type LedgerMark = {
556
+ readonly ruleId: string;
557
+ /** `LedgerRef.id`. */
558
+ readonly ref: string;
559
+ readonly trait: string;
560
+ readonly outcome: ReadOutcome;
561
+ };
562
+ /**
563
+ * Every reference to each stated declaration of a check, and what the rules said of them: a
564
+ * proof reads a reference its rule did not mark as not checked (`proveGuarantees`).
565
+ */
566
+ export type Ledger = {
567
+ /** The traits the ledger lists references for (the active rules' `proves`), sorted. */
568
+ readonly traits: readonly string[];
569
+ /** In file and offset order. */
570
+ readonly refs: readonly LedgerRef[];
571
+ readonly marks: readonly LedgerMark[];
572
+ /**
573
+ * The rule that proves each tag trait (`@neverRejects`, from `RuleProves.tags`): the first active
574
+ * rule, by id, that lists the tag. Absent when no active rule proves a tag.
575
+ */
576
+ readonly tagRules?: Readonly<Record<string, string>>;
577
+ };
345
578
  /** A type alias by its name and the file that declares it. */
346
579
  export type AliasRef = {
347
580
  readonly name: string;
@@ -368,6 +601,45 @@ export type TypeQueries = {
368
601
  * through the program, so a renamed package changes the dependency fingerprints.
369
602
  */
370
603
  packageOf(file: string): string | undefined;
604
+ /**
605
+ * What a `facts` key names (0041): `module` resolved as an import of it from the project would
606
+ * (`node:path`, `typeorm`, `@acme/kit/lib/x`), then the dotted `name` through its exports and
607
+ * their members (`Repository.find`), to the declarations of the symbol it reaches. Two keys
608
+ * that resolve to one symbol name the same declarations, however the module's types are
609
+ * written.
610
+ */
611
+ factTarget(module: string, name: string): FactTarget;
612
+ /**
613
+ * The names `factTarget` resolves in `module` up to two levels deep (`join`, `Repository.find`),
614
+ * shortest first: what a "did you mean" chooses from.
615
+ */
616
+ factNames(module: string): readonly string[];
617
+ /**
618
+ * `factTarget` in reverse: the shortest name in `module` that resolves to `declaration`, so a
619
+ * hint's `facts` line names what the call calls. The names tried are the last parts of the
620
+ * declaration's own path in its types (`join`, then `PlatformPath.join`), then `default`, each
621
+ * resolved forward; undefined when none resolves to it.
622
+ */
623
+ factNameOf(module: string, declaration: ts.Node): string | undefined;
624
+ /**
625
+ * The module a `facts` key for `declaration`, a declaration outside the project, is written
626
+ * from, and its name there (`factNameOf`), as `reference` reaches it: the module the project
627
+ * imports it from, as written (a deep path stays deep), followed through the project's own
628
+ * re-exports and aliases to the first module outside the project; else a module the project's
629
+ * files import, the module or package that declares it, or a module of its package the program
630
+ * loads (a global such as `Buffer`, named from a module that exports it). `platform`: the
631
+ * module's types are the platform's. `unnamed` when no such module names it.
632
+ */
633
+ factModuleOf(declaration: ts.Node, reference: ts.Node): FactModule;
634
+ /**
635
+ * The class a module of a package exports under `name` (`QueryFailedError` of `typeorm`), as
636
+ * the project would import it: its declaration, from the package's types. Undefined when the
637
+ * module's types are not in the program or export no class by that name.
638
+ */
639
+ exportedClassOf(module: string, name: string): {
640
+ file: string;
641
+ node: ts.Node;
642
+ } | undefined;
371
643
  /**
372
644
  * The finite literal union of the node's type (a type parameter is widened to its constraint),
373
645
  * sorted by label so the order does not depend on what TypeScript checked earlier.
@@ -392,6 +664,8 @@ export type TypeQueries = {
392
664
  canBeUndefined(node: ts.Node): boolean;
393
665
  /** Whether the type of an expression includes `null`; `any` and `unknown` count as yes. */
394
666
  canBeNull(node: ts.Node): boolean;
667
+ /** Whether the type of an expression includes `false` (`boolean` does); `any` and `unknown` count as yes. */
668
+ canBeFalse(node: ts.Node): boolean;
395
669
  /**
396
670
  * Whether `propertyName` discriminates the type of the object expression (a type parameter
397
671
  * widened to its constraint): the type is a union, every member is an object type (an
@@ -432,6 +706,13 @@ export type TypeQueries = {
432
706
  * nothing gives one.
433
707
  */
434
708
  expectsPromiseReturn(node: ts.Expression): boolean;
709
+ /**
710
+ * Whether the type the surrounding code expects for an expression is a function that may return
711
+ * a function: some call signature's return type has a callable member (`() => void | Destructor`,
712
+ * as an effect callback is typed). What such a function returns may be called later, as a
713
+ * cleanup, by code stateward does not read. False when nothing gives one.
714
+ */
715
+ expectsCallableReturn(node: ts.Expression): boolean;
435
716
  /**
436
717
  * Whether argument `argumentIndex` of the call goes to a parameter that the called function's
437
718
  * declaration types as the `never` keyword. A rest parameter or a missing declaration is false.
@@ -470,6 +751,13 @@ export type TypeQueries = {
470
751
  * with `contextual`, of the type the surrounding code expects for the expression. Undefined when
471
752
  * the type does not state the trait; `"not-finite"` when the property's type is not literals.
472
753
  */
754
+ /**
755
+ * The literal values of an optional marker property on the type of a node, sorted: `"startsAt"`
756
+ * and `"endsAt"` for `LocalTimestamp<"startsAt" | "endsAt">` declaring
757
+ * `readonly __localTimestamp?: K`. Undefined when no member of the type has the property as an
758
+ * optional property; `"not-finite"` when its type is not literals.
759
+ */
760
+ markerValuesOf(node: ts.Node, property: string): readonly Literal[] | "not-finite" | undefined;
473
761
  guaranteeValuesOf(target: ts.Node | SymbolRef, name: string, contextual?: boolean): readonly Literal[] | "not-finite" | undefined;
474
762
  /**
475
763
  * How a value is disposed when its type is a standard `Disposable` or `AsyncDisposable`: it has
@@ -487,6 +775,15 @@ export type TypeQueries = {
487
775
  * alias is generic.
488
776
  */
489
777
  contextualAliasOf(node: ts.Expression): SymbolRef | undefined;
778
+ /**
779
+ * The type aliases (not generic ones) that the type of an expression, or with `contextual` the
780
+ * type the surrounding code expects for it, holds inside: the elements and type arguments of an
781
+ * array, tuple, `Map`, `Set` or `Promise`, and the properties of an object type, up to three
782
+ * levels down (`OrderId` in `OrderId[]`, `Map<string, OrderId>`, `{ id: OrderId }`). The type
783
+ * itself is not listed (`contextualAliasOf` gives it), and an alias is not entered. Sorted by
784
+ * name; each once.
785
+ */
786
+ heldAliasesOf(node: ts.Expression, contextual?: boolean): readonly SymbolRef[];
490
787
  /**
491
788
  * The property a name destructured from an object reads: `cacheEntryRemoved` of the
492
789
  * parameter's type for `{ cacheEntryRemoved }`, as a symbol whose declaration `declarationOf`
@@ -499,6 +796,51 @@ export type TypeQueries = {
499
796
  * a trait, `"__guarantee:<name>"`: a rule skips work for a trait nobody states.
500
797
  */
501
798
  declaresTrait(name: string): boolean;
799
+ /**
800
+ * The declarations of `sourceFile` that state a guarantee in their written type: a variable, a
801
+ * property (a `#private` field, a member of an object type), a parameter of a function with a
802
+ * body, or a type alias (not a generic one, which is how a marker is defined), whose annotation
803
+ * names a type that states one or more guarantees. Empty when no file of the program writes a
804
+ * marker. In source order.
805
+ */
806
+ statedDeclarationsIn(sourceFile: ts.SourceFile): readonly StatedDeclaration[];
807
+ /**
808
+ * Every reference in `sourceFile` to a declaration of the project that states a trait of
809
+ * `proves` (the reference ledger): an identifier, private name, string key, JSX name, import or
810
+ * export name, shorthand property, destructured name or contextually typed property name whose
811
+ * symbol, after aliases and to its root, is such a declaration. A value, property or parameter
812
+ * states a trait by its written type (a rest parameter by its elements), a function by its
813
+ * written return type or a promise of it (`proves.returns`), a declaration with a JSDoc tag of
814
+ * `proves.tags` by the tag (and the tag itself, form `tag`). Each with its form. Sorted by
815
+ * offset, then declaration and trait. Empty when no file of the program writes a marker or a tag.
816
+ */
817
+ statedReferencesIn(sourceFile: ts.SourceFile, proves: RuleProves): readonly StatedReference[];
818
+ /**
819
+ * The typed flows in `sourceFile` of the traits `proves.flows` lists (the reference ledger's
820
+ * flows): at a return, an argument (a spread one too), an initializer, an assignment, a property
821
+ * or element of a literal, a JSX attribute or spread, a `yield`, a cast and a `for…of` target, each
822
+ * value given to a place whose type holds a stated type alias its own type does not (`produced`);
823
+ * each value of a stated alias the code decides by (`decided`: a `switch` subject, a comparison, a
824
+ * key, an `in` test); each holder of a stated member written by reflection or in an object literal
825
+ * whose members no reference names (`escaped`). Only in a file whose imports reach a declaring
826
+ * file. Past `budget` type questions (default `FLOW_BUDGET`), the scan stops: one flow of `via`
827
+ * `stopped` for each stated declaration, at the node where it stopped. Sorted by offset, then end,
828
+ * declaration and trait. Empty when no file of the program declares a flow trait.
829
+ */
830
+ typedFlowsIn(sourceFile: ts.SourceFile, proves: RuleProves, budget?: number): readonly StatedReference[];
831
+ /**
832
+ * Whether every value the node's type can hold is a primitive, or an array or tuple of them (up to
833
+ * three levels): a copy of it shares nothing that can be changed.
834
+ */
835
+ holdsOnlyPrimitives(node: ts.Node): boolean;
836
+ /**
837
+ * The declaration a value is, as far as its type says: the function, class or method whose type
838
+ * `node` has (`w` in `const w = watchPrices` and `watchPrices` in `const { watchPrices } = await
839
+ * import(…)` both give `watchPrices`). Undefined when the type belongs to no declaration (a
840
+ * union, a primitive, an object literal type). It follows no assignment: a wrapper function is
841
+ * its own declaration.
842
+ */
843
+ valueOriginOf(node: ts.Node): SymbolRef | undefined;
502
844
  /**
503
845
  * Whether a file of the project declares a member named `[Symbol.dispose]` or
504
846
  * `[Symbol.asyncDispose]` (a class, an interface, a type or an object literal), read from the
@@ -552,6 +894,15 @@ export type TypeQueries = {
552
894
  * are assignable to everything and so prove nothing.
553
895
  */
554
896
  isAssignableWithoutNullish(from: ts.Node, to: ts.Node): boolean;
897
+ /**
898
+ * Whether a value of `output`, and `undefined` too when `orUndefined`, is assignable to the
899
+ * declared type of `target` (a declaration's name). `output` is a type node, read awaited (a
900
+ * `Promise<T>` gives `T`), or one of TypeScript's own types by name; `"array"` is an array of any
901
+ * items. A brand on the target (`string & { __brand: "Uuid" }`) counts as the type it brands:
902
+ * it adds no runtime value. Undefined when the type node is `any` or `unknown`, which states
903
+ * nothing.
904
+ */
905
+ valueAssignableTo(output: ts.TypeNode | "string" | "number" | "boolean" | "array", orUndefined: boolean, target: ts.Node): boolean | undefined;
555
906
  /**
556
907
  * Whether argument `argumentIndex` of the call goes to a parameter through which the callee
557
908
  * cannot add, change or remove a key: `Readonly<Record<string, V>>`, a type with a `readonly`
@@ -582,6 +933,24 @@ export type TypeQueries = {
582
933
  * says the type is unknown here, so a rule must not read it as `string` or as anything else.
583
934
  */
584
935
  isErrorType(node: ts.Node): boolean;
936
+ /**
937
+ * Whether the type of an expression is `any`: written so, the value of an untyped `require`, or
938
+ * the error type. No type states what such a value is or what calling it does.
939
+ */
940
+ hasNoType(node: ts.Node): boolean;
941
+ /**
942
+ * Whether the type of an expression, or the type a type node names, is `any` or `unknown`
943
+ * (read from the type's flags, not its text): it states nothing about the value. Unlike
944
+ * `hasNoType`, `unknown` counts, and so does the error type.
945
+ */
946
+ isOpenType(node: ts.Node): boolean;
947
+ /**
948
+ * Which of TypeScript's own types the type of an expression, or the type a type node names, is,
949
+ * read from the type's flags, not its text (`type Nothing = void` is `void`); undefined for any
950
+ * other type, a union included. `"awaited"` reads what awaiting it gives (`Promise<void>` is
951
+ * `void`).
952
+ */
953
+ builtinTypeOf(node: ts.Node, read: "as-is" | "awaited"): BuiltinType | undefined;
585
954
  /**
586
955
  * Whether the type of an expression is promise-like: awaiting it gives another type
587
956
  * (`Promise<T>`, a thenable, `Promise<T> | undefined`). `any` and `unknown` are false.
@@ -589,6 +958,19 @@ export type TypeQueries = {
589
958
  isPromiseLike(node: ts.Node): boolean;
590
959
  /** As `isPromiseLike`, for what a function declaration, function expression, arrow or method returns (declared or inferred). */
591
960
  returnsPromiseLike(fn: ts.SignatureDeclaration): boolean;
961
+ /**
962
+ * Whether what a function declaration returns can be a promise: a promise-like type, `any`,
963
+ * `unknown`, a type parameter (`<T>(): T`), a type `Promise` is assignable to (`object`), or a
964
+ * union with such a member. False only for a type that cannot be one (`string`, `void`, a class
965
+ * without `then`).
966
+ */
967
+ mayReturnPromise(fn: ts.SignatureDeclaration): boolean;
968
+ /**
969
+ * Whether the type of an expression has a method `name` whose every call signature returns a
970
+ * promise-like type, as `isPromiseLike` reads it (`release(): Promise<void>`, and
971
+ * `Promise<void> | void`). False when it has no such method.
972
+ */
973
+ methodReturnsPromiseLike(node: ts.Node, name: string): boolean;
592
974
  /**
593
975
  * Whether the type of an expression surely has property `name` with a value: every member of
594
976
  * its type (a type parameter widened to its constraint) declares it, not optional, and its type
@@ -643,6 +1025,13 @@ export type TypeQueries = {
643
1025
  * type (`Readonly<T>`). False for anything that is not a property access chain.
644
1026
  */
645
1027
  isReadonlyPath(node: ts.Expression): boolean;
1028
+ /**
1029
+ * Whether the prop a JSX attribute gives its value to is declared in the project with a type no
1030
+ * code can change through: every property `readonly` (declared so, or by `Readonly<T>`), with a
1031
+ * primitive or such a type in turn; a `ReadonlyArray` of such values; no method, no function, no
1032
+ * mutable array, `Map` or `Set`. False for a prop declared in a package, or with no declaration.
1033
+ */
1034
+ propIsDeeplyReadonly(attribute: ts.JsxAttribute): boolean;
646
1035
  /**
647
1036
  * Whether the call may change what it is given: `argument` is the index of an argument, or
648
1037
  * `"receiver"` for the object a method is called on. True only when the callee's declaration is
@@ -675,6 +1064,70 @@ export type TypeQueries = {
675
1064
  * time is still the same value. False for objects, functions, symbols, `any` and `unknown`.
676
1065
  */
677
1066
  isPrimitive(node: ts.Node): boolean;
1067
+ /**
1068
+ * Whether every value of an expression's type is a number: `number`, a number literal or a
1069
+ * numeric enum (a type parameter widened to its constraint; a branded `number & {…}` counts).
1070
+ * False for `bigint`, `any` and `unknown`: dividing a `bigint` by zero throws.
1071
+ */
1072
+ isNumber(node: ts.Node): boolean;
1073
+ /**
1074
+ * The platform's own type of an expression's value, by its name in TypeScript's lib or Node's
1075
+ * types (`Array`, `Map`, `String` for a string or a branded string, `Math`, `MapConstructor` for
1076
+ * `Map` itself), when
1077
+ * every member of its type (`null` and `undefined` aside) is that one type and no class or
1078
+ * interface of the project extends or implements it (a value typed `Map` may then be the
1079
+ * project's subclass). A tuple is `Array`. Undefined for anything else: a type of the project or
1080
+ * a package, a union of two types, `any`, `unknown`.
1081
+ */
1082
+ platformTypeOf(node: ts.Node): string | undefined;
1083
+ /**
1084
+ * For an expression whose type is the platform's array or a tuple (every member of a union), and
1085
+ * so iterates without running code of the project: `"primitives"` when every element type is one
1086
+ * `isPrimitive` accepts, `"values"` otherwise. Undefined when the type is anything else
1087
+ * (`Iterable<T>`, a `Set`, a union with one).
1088
+ */
1089
+ arrayElementsOf(node: ts.Node): "primitives" | "values" | undefined;
1090
+ /**
1091
+ * For an expression whose type is the platform's array or a tuple (every member of a union):
1092
+ * whether a value of it can have no element. True for `T[]`, `readonly T[]` and a tuple whose
1093
+ * elements are all optional or rest (`[T?]`, `[...T[]]`); false when every member is a tuple
1094
+ * with a required element (`[T, ...T[]]`). Undefined when the type is anything else.
1095
+ */
1096
+ arrayCanBeEmpty(node: ts.Node): boolean | undefined;
1097
+ /**
1098
+ * Whether a property read, an element read or a destructured property runs no code and cannot
1099
+ * throw, as far as the declared types say: the member is declared a property (never an accessor)
1100
+ * of a class, an interface, an object type, a mapped type such as `Record`, an enum or a module
1101
+ * (a class that gives an interface's property as a getter is not seen); or a property of the
1102
+ * platform's types on its closed list (`length` of an array or string, `size` of a `Map`).
1103
+ * An element read is plain with a literal index inside a tuple, a literal key of such a member, or
1104
+ * a key of an index signature whose value is a primitive and is not read further (`xs[0].length`
1105
+ * throws on an empty array). An array pattern is plain on an array.
1106
+ */
1107
+ readIsPlain(node: ts.PropertyAccessExpression | ts.ElementAccessExpression | ts.BindingElement): boolean;
1108
+ /**
1109
+ * Whether reading or writing a property may run a getter or setter of the project: the member is
1110
+ * declared as one, with a body. A member declared as a property is read as one, as far as the
1111
+ * declared types say (a class that gives an interface's property as a getter is not seen).
1112
+ */
1113
+ readMayRunAccessor(node: ts.PropertyAccessExpression): boolean;
1114
+ /**
1115
+ * Whether a name is declared by the platform only: TypeScript's lib, Node's types or a package
1116
+ * the config's `platform` names, not the project or another package (`String`, `setTimeout`).
1117
+ */
1118
+ isPlatformName(node: ts.Node): boolean;
1119
+ /**
1120
+ * The packages outside the platform that declare a global name (`setInterval` in a
1121
+ * `declare global` of a package's types), sorted; empty for a name the platform alone declares,
1122
+ * an imported name, or one no package declares. A name some package declares is not the
1123
+ * platform's (`isPlatformName`) until the config's `platform` lists that package.
1124
+ */
1125
+ globalPackagesOf(node: ts.Node): readonly string[];
1126
+ /**
1127
+ * Whether the type of the right side of `instanceof` is a class the test cannot run code of: a
1128
+ * constructor of the platform, or a class of the project with no static `Symbol.hasInstance`.
1129
+ */
1130
+ isPlainClass(node: ts.Expression): boolean;
678
1131
  /**
679
1132
  * Whether the type of an expression is declared outside the project: in a package (a file found
680
1133
  * through node_modules) or in TypeScript's own lib. What is asked is where the type is named: its
@@ -719,7 +1172,7 @@ export type TypeQueries = {
719
1172
  * an optional parameter the call leaves out counts (`fetch(url)`). Undefined when no parameter
720
1173
  * takes one, the call does not resolve, or the parameter is a rest parameter.
721
1174
  */
722
- signalParameterOf(call: ts.CallExpression): SignalParameter | undefined;
1175
+ signalParameterOf(call: ts.CallExpression | ts.NewExpression): SignalParameter | undefined;
723
1176
  /**
724
1177
  * Whether TypeScript reports that the end of a function can be reached although the function
725
1178
  * must return a value: TS2366 (the return type does not include `undefined`), TS2355 (a
@@ -729,6 +1182,182 @@ export type TypeQueries = {
729
1182
  * those in its body. Asks for the type errors of the function's file, once per file.
730
1183
  */
731
1184
  reportsReachableEnd(fn: ts.FunctionLikeDeclaration): boolean;
1185
+ /**
1186
+ * The constructor TypeScript writes into the decorator metadata of a parameter
1187
+ * (`design:paramtypes`) or a property (`design:type`), following the compiler's rules: unions
1188
+ * and intersections are `Object` unless every member gives the same, literal types give their
1189
+ * primitive, enums give the kind of their members, type aliases are resolved. `not-emitted` when
1190
+ * the file's tsconfig does not emit decorator metadata.
1191
+ */
1192
+ metadataTypeOf(node: ts.ParameterDeclaration | ts.PropertyDeclaration): DecoratorMetadata;
1193
+ /**
1194
+ * The classes whose instances the value of an expression can hold, after awaiting a promise:
1195
+ * each member of a union or an intersection, the elements of an array or a tuple, and, up to
1196
+ * `depth` levels, the properties of an object type that is not a class instance (a wrapper such
1197
+ * as `{ data: User[] }`). A class's own properties are not entered. `path` says where the
1198
+ * instance sits (`""` for the value itself, `"data[]"` for the elements of its `data`). `any` is
1199
+ * true when one of the types met is `any` or `unknown`: what it holds is not known.
1200
+ */
1201
+ instanceClassesOf(node: ts.Node, depth: number): InstanceClasses;
1202
+ /**
1203
+ * The nearest generic class or interface of a package that the type of an expression is, or
1204
+ * extends, with the type arguments it is given there: for `pkg` `typeorm` and the names
1205
+ * `Repository` and `MongoRepository`, a value typed `UserRepository` (which extends
1206
+ * `Repository<User>`) gives `Repository` and `User`. Read from the type and its base types,
1207
+ * nearest first, after removing `null` and `undefined`, up to 8 levels; `this` and a type
1208
+ * parameter are read as their constraint, and an intersection (`Repository<User> & { … }`, what
1209
+ * TypeORM's `extend` returns) as its members. Undefined when the type
1210
+ * is not one of them, or is a union of several types.
1211
+ */
1212
+ genericBaseOf(node: ts.Node, pkg: string, names: ReadonlySet<string>): GenericBase | undefined;
1213
+ /**
1214
+ * Whether the type of an expression is, or extends, one of `classes` (class and interface
1215
+ * declarations): read from the type and its base types after removing `null` and `undefined`,
1216
+ * up to 8 levels. A class itself (`Store.create()`) is read as its instances. False for a union
1217
+ * of several types, and for a type it cannot read.
1218
+ */
1219
+ isOrExtends(node: ts.Node, classes: ReadonlySet<ts.Node>): boolean;
1220
+ /**
1221
+ * The properties of the type of an expression or a type node (`Env` in `ConfigService<Env>`;
1222
+ * a type parameter widened to its constraint), each with its type as TypeScript prints it,
1223
+ * sorted by name. Undefined when the type is not an object type.
1224
+ */
1225
+ propertyTypesOf(node: ts.Node): readonly PropertyTypeText[] | undefined;
1226
+ /**
1227
+ * Whether argument `argumentIndex` of the call goes to a parameter declared `unknown`, or typed
1228
+ * by a type parameter of the function itself with no constraint or the constraint `unknown`
1229
+ * (`<T>(value: T)`, not the `V` of `Map<K, V>.set`): the
1230
+ * callee accepts any value and so must check it. Read from the declaration of the signature
1231
+ * TypeScript picks for the call, before its type parameters are filled in. False for a rest
1232
+ * parameter, an argument after a spread, and a call that does not resolve.
1233
+ */
1234
+ parameterTakesUnknown(call: ts.CallExpression, argumentIndex: number): boolean;
1235
+ /**
1236
+ * The type of an expression (`"type"`), the type the surrounding code expects for it
1237
+ * (`"contextual"`, as `contextualTypeTextOf`), or the type a type node names, as a check written
1238
+ * in code can test it (`TypeShape`). Undefined when such a check cannot be written from the type
1239
+ * alone: a generic type (other than an array), a function, a tuple, an index signature, an
1240
+ * intersection, an enum, a class with a private member, a type of the platform's lib other than
1241
+ * an array (`Date`, `Map`), `any`, `unknown`, `symbol`, or nesting deeper than 8 levels.
1242
+ */
1243
+ typeShapeOf(node: ts.Node, from: "type" | "contextual"): TypeShape | undefined;
1244
+ };
1245
+ /**
1246
+ * A type as a check written in code tests it (`TypeQueries.typeShapeOf`). `boolean` is a primitive,
1247
+ * not the union of `true` and `false`. An object's `text` is how the code can name its type: its
1248
+ * alias, interface or class name, or the object type written out. A `recursive` shape is a named
1249
+ * object type met again inside itself.
1250
+ */
1251
+ export type TypeShape = {
1252
+ readonly kind: "primitive";
1253
+ readonly name: "string" | "number" | "boolean" | "bigint";
1254
+ } | {
1255
+ readonly kind: "literal";
1256
+ readonly literal: Literal;
1257
+ } | {
1258
+ readonly kind: "union";
1259
+ readonly members: readonly TypeShape[];
1260
+ } | {
1261
+ readonly kind: "array";
1262
+ readonly element: TypeShape;
1263
+ } | {
1264
+ readonly kind: "object";
1265
+ /** The type's identity: where it is declared, so two types of one name differ. */
1266
+ readonly id: string;
1267
+ readonly name: string | undefined;
1268
+ readonly text: string;
1269
+ readonly properties: readonly TypeShapeProperty[];
1270
+ } | {
1271
+ readonly kind: "recursive";
1272
+ readonly id: string;
1273
+ readonly name: string;
1274
+ };
1275
+ /** One property of an object `TypeShape`, in declaration order. */
1276
+ export type TypeShapeProperty = {
1277
+ readonly name: string;
1278
+ readonly optional: boolean;
1279
+ readonly shape: TypeShape;
1280
+ };
1281
+ /** What `TypeQueries.genericBaseOf` finds: the base's name, and each type argument it is given. */
1282
+ export type GenericBase = {
1283
+ readonly name: string;
1284
+ readonly typeArguments: readonly TypeArgument[];
1285
+ };
1286
+ /**
1287
+ * A type argument: a class of the project or a package, with its declaration, or another type
1288
+ * (an interface, a type parameter, `any`), as TypeScript prints it.
1289
+ */
1290
+ export type TypeArgument = {
1291
+ readonly kind: "class";
1292
+ readonly name: string;
1293
+ readonly declaration: ts.ClassDeclaration;
1294
+ } | {
1295
+ readonly kind: "other";
1296
+ readonly text: string;
1297
+ };
1298
+ /** What `TypeQueries.instanceClassesOf` finds. */
1299
+ export type InstanceClasses = {
1300
+ readonly classes: readonly {
1301
+ readonly name: string;
1302
+ readonly declaration: ts.ClassDeclaration;
1303
+ readonly path: string;
1304
+ /** The class is the value's whole type there, not a member of an intersection with it. */
1305
+ readonly whole: boolean;
1306
+ }[];
1307
+ readonly any: boolean;
1308
+ };
1309
+ /** One property of a type, as `TypeQueries.propertyTypesOf` gives it. */
1310
+ export type PropertyTypeText = {
1311
+ readonly name: string;
1312
+ readonly text: string;
1313
+ readonly optional: boolean;
1314
+ /** The property's type is `any` or `unknown`. */
1315
+ readonly open: boolean;
1316
+ /**
1317
+ * The platform's own type of the property, `null` and `undefined` aside, as `platformTypeOf`
1318
+ * names it (`AbortSignal`); null for any other type.
1319
+ */
1320
+ readonly platform: string | null;
1321
+ /** The property's type includes `null` or `undefined` (an optional property's does). */
1322
+ readonly nullish: boolean;
1323
+ };
1324
+ /**
1325
+ * A constructor TypeScript writes for a declaration into the `design:type` and
1326
+ * `design:paramtypes` metadata under `emitDecoratorMetadata` (the compiler's `serializeTypeNode`).
1327
+ */
1328
+ export type MetadataType = {
1329
+ readonly kind: "global";
1330
+ readonly name: "String" | "Number" | "Boolean" | "Object" | "Array" | "Promise" | "Function" | "Symbol" | "BigInt";
1331
+ }
1332
+ /** `void 0`: `undefined`, `void`, `never`, `null`. */
1333
+ | {
1334
+ readonly kind: "undefined";
1335
+ }
1336
+ /** A class (or another value with construct signatures), by the name the code writes. */
1337
+ | {
1338
+ readonly kind: "class";
1339
+ readonly name: string;
1340
+ readonly symbol: SymbolRef | undefined;
1341
+ }
1342
+ /** A name that resolves to no type: emitted as `typeof X === "function" ? X : Object`. */
1343
+ | {
1344
+ readonly kind: "unresolved";
1345
+ readonly name: string;
1346
+ };
1347
+ /** What the decorator metadata of a parameter or property holds (`TypeQueries.metadataTypeOf`). */
1348
+ export type DecoratorMetadata =
1349
+ /** The project's tsconfig does not turn on `experimentalDecorators` and `emitDecoratorMetadata`. */
1350
+ {
1351
+ readonly kind: "not-emitted";
1352
+ } | {
1353
+ readonly kind: "emitted";
1354
+ /** What TypeScript writes. */
1355
+ readonly type: MetadataType;
1356
+ /**
1357
+ * The same rules with `null` and `undefined` left out of unions (as TypeScript does without
1358
+ * `strictNullChecks`): the runtime type the declaration names, `Number` for `number | undefined`.
1359
+ */
1360
+ readonly withoutNullish: MetadataType;
732
1361
  };
733
1362
  export type ReportProblem = {
734
1363
  message: string;
@@ -749,6 +1378,18 @@ export type ReportProblem = {
749
1378
  * are warnings. A severity the config gives this finding's kind still wins over it.
750
1379
  */
751
1380
  stated?: true;
1381
+ /**
1382
+ * The finding stands against a guarantee the code states: a proof counts it whatever its
1383
+ * severity (a rule set to `info`, a kind lowered or ignored by an override cannot make the
1384
+ * guarantee read proven), and a config that turns its kind `off` still reports it, as an info.
1385
+ * It changes no severity otherwise. `stated` implies it.
1386
+ *
1387
+ * Say which guarantee with the declaration that states it, a node or a symbol (`symbolAt`): the
1388
+ * finding is then linked to that guarantee (`Finding.guarantees`), however the code reaches the
1389
+ * value (an alias, a destructured import, a Provider in another file). With `true` the engine
1390
+ * links the finding from where it lies and its related notes, as far as they say.
1391
+ */
1392
+ against?: true | ts.Node | SymbolRef;
752
1393
  related?: readonly {
753
1394
  node: ts.Node;
754
1395
  message: string;
@@ -777,6 +1418,41 @@ export type FunctionFacts = {
777
1418
  * property (RTK Query's `cacheEntryRemoved`). An `await` of it is not a way out.
778
1419
  */
779
1420
  readonly neverRejects?: true;
1421
+ /**
1422
+ * The function given as argument `argument` is run by the library, and the function it returns
1423
+ * is called later as its cleanup (React's `useEffect`): a value released in that cleanup is
1424
+ * released, and what the callback starts is the library's rule's to check.
1425
+ */
1426
+ readonly cleanup?: {
1427
+ readonly argument: number;
1428
+ };
1429
+ /**
1430
+ * For a NestJS exception filter class of the package: the error classes it catches, as
1431
+ * `errors/throws` names classes (`package:axios#AxiosError`, or a bare name of the package or a
1432
+ * platform error such as `Error`); `["*"]` catches every error.
1433
+ */
1434
+ readonly catches?: readonly string[];
1435
+ /** For a NestJS guard class of the package: whether it authenticates the request. */
1436
+ readonly authenticates?: boolean;
1437
+ /**
1438
+ * The value comes from outside the program and is not checked: the result of a call of the
1439
+ * function (`Redis.get`), or the value of the property (`AxiosResponse.data`). Read like a
1440
+ * `JSON.parse` result by `node/external-data-not-validated`.
1441
+ */
1442
+ readonly external?: true;
1443
+ /**
1444
+ * For an error class of the package: the class it extends, as the package exports it
1445
+ * (`TypeORMError`) or a platform error (`Error`), so a reader can follow its parents
1446
+ * (`nestjs/error-becomes-500` looks for an `HttpException` or a `statusCode` field).
1447
+ */
1448
+ readonly extends?: string;
1449
+ /**
1450
+ * For a class of the package: `false` when a method it inherits does not do what the facts of
1451
+ * the class that declares it say (TypeORM's `MongoRepository` inherits `save` from `Repository`
1452
+ * but runs no SQL). A call on it, or on a class that extends it, then reads only its own lines
1453
+ * (`MongoRepository.save`).
1454
+ */
1455
+ readonly inheritedFacts?: false;
780
1456
  };
781
1457
  /**
782
1458
  * How a value with the release trait is released, as a `facts` line says it: `"release"`, call the
@@ -787,8 +1463,111 @@ export type ReleaseFact = "release" | {
787
1463
  readonly release: string;
788
1464
  };
789
1465
  export type PackageFactsConfig = Readonly<Record<string, Readonly<Record<string, FunctionFacts>>>>;
790
- /** Where a library fact comes from, in order of trust. */
791
- export type FactSource = "config" | "declared" | "inferred" | "unknown";
1466
+ /**
1467
+ * The config's `facts` as written: each package's lines, and optionally under `"@versions"` the
1468
+ * semver range of the package's versions they were stated for (`"^3.2.0"`). For a project that
1469
+ * runs another version, or one whose version is not known, the package's lines are not applied.
1470
+ */
1471
+ export type PackageFactsInput = Readonly<Record<string, PackageFactsTable>>;
1472
+ /** One package's lines in the config's `facts`, with the optional `"@versions"` range. */
1473
+ export type PackageFactsTable = {
1474
+ readonly "@versions"?: string;
1475
+ readonly [name: string]: FunctionFacts | string | undefined;
1476
+ };
1477
+ /**
1478
+ * The versions of a package a pack's shipped facts were verified on (`Plugin.factsVerified`): a
1479
+ * semver range (`">=0.3.17 <=1.1.2"`), and the evidence. For a project that runs another version,
1480
+ * or one whose version is not known, the pack's lines for the package are not applied.
1481
+ */
1482
+ export type VerifiedFacts = {
1483
+ readonly verified: string;
1484
+ readonly evidence: string;
1485
+ };
1486
+ /**
1487
+ * A package's facts lines that are not applied in a file: the project runs a version outside the
1488
+ * range they are for, or its version is not known. A call they would name is "not checked", with
1489
+ * `reason` after "not checked: … : " and `hint`.
1490
+ */
1491
+ export type WithheldFacts = {
1492
+ readonly package: string;
1493
+ readonly source: "config" | "shipped";
1494
+ readonly functions: Readonly<Record<string, FunctionFacts>>;
1495
+ readonly reason: string;
1496
+ readonly hint: string;
1497
+ };
1498
+ /** What a "not checked" finding needs a `facts` line to state of a package call. */
1499
+ export type FactSide = "throws" | "rejects";
1500
+ /**
1501
+ * A `facts` line that would decide a "not checked" finding (`Finding.needs`): the key that names
1502
+ * the call, at the function grain (`"typeorm"`, `"Repository.save"`), the package's version the
1503
+ * project runs, and what the line states. The editor and `check --fix` offer to write it, and
1504
+ * `stateward coverage --facts` ranks the calls by how many findings each would decide.
1505
+ */
1506
+ export type FactNeed = {
1507
+ readonly module: string;
1508
+ readonly name: string;
1509
+ /** The package's version the project runs; absent when it is not known. */
1510
+ readonly version?: string;
1511
+ readonly states: readonly FactSide[];
1512
+ };
1513
+ /**
1514
+ * A `facts` key for a declaration outside the project (`TypeQueries.factModuleOf`): its module
1515
+ * and name, `platform` when the module's types are the platform's; `unnamed` when no module
1516
+ * names it, with `through`, the module the reference is imported from, when it is imported.
1517
+ */
1518
+ export type FactModule = {
1519
+ readonly kind: "named";
1520
+ readonly module: string;
1521
+ readonly name: string;
1522
+ readonly platform: boolean;
1523
+ } | {
1524
+ readonly kind: "unnamed";
1525
+ readonly through?: string;
1526
+ };
1527
+ /**
1528
+ * The `facts` key for a call or a class outside the project (`factKeyOf`): its module, its name
1529
+ * there, and the version of the package that owns the module (absent for the platform's modules
1530
+ * and when it is not known); `unnamed` with the code as written and why no key can name it.
1531
+ */
1532
+ export type FactKey = {
1533
+ readonly kind: "named";
1534
+ readonly module: string;
1535
+ readonly name: string;
1536
+ readonly version?: string;
1537
+ } | {
1538
+ readonly kind: "unnamed";
1539
+ readonly name: string;
1540
+ readonly reason: string;
1541
+ };
1542
+ /** A call a finding depends on that no `facts` key can name (`Finding.unnamed`), and why. */
1543
+ export type UnnamedFact = {
1544
+ readonly name: string;
1545
+ readonly reason: string;
1546
+ };
1547
+ /**
1548
+ * Where a library fact comes from: the config's `facts`, the facts a pack ships (`Plugin.facts`),
1549
+ * or not known. A package's code and doc comments are never read for it (0041).
1550
+ */
1551
+ export type FactSource = "config" | "shipped" | "unknown";
1552
+ /**
1553
+ * What a `facts` key names in a program (`TypeQueries.factTarget`): the declarations of the
1554
+ * symbol it resolves to; `no-module` when its module does not resolve from the project;
1555
+ * `no-name` when the module has no such name.
1556
+ *
1557
+ * `declarations` holds what the key states on any call. A class or package key also names the
1558
+ * methods a class inherits: those are in `throughReceiver`, each with the class declarations its
1559
+ * receiver must be, or extend (`TypeQueries.isOrExtends`), for the key to state the call. A
1560
+ * `"Store.*"` line states `store.find()` on a `Store`, never `base.find()` on its plain `Base`.
1561
+ */
1562
+ export type FactTarget = {
1563
+ readonly kind: "found";
1564
+ readonly declarations: ReadonlySet<ts.Node>;
1565
+ readonly throughReceiver: ReadonlyMap<ts.Node, ReadonlySet<ts.Node>>;
1566
+ } | {
1567
+ readonly kind: "no-module";
1568
+ } | {
1569
+ readonly kind: "no-name";
1570
+ };
792
1571
  /**
793
1572
  * How a plugin knows the functions of one package the project calls, for `stateward deps`: each
794
1573
  * function by its name, where its facts come from, and why what is unknown is unknown.
@@ -826,8 +1605,8 @@ export type CoveredPlace = {
826
1605
  */
827
1606
  /**
828
1607
  * Where a trait is stated: a standard type that already says it (`Disposable`), the project's
829
- * marker type (`Owned<T>`), the config's `facts` line for a package, or the facts a plugin ships
830
- * for it (stateward's facts).
1608
+ * marker type (`Owned<T>`), the config's `facts` line for a package, the facts a plugin ships
1609
+ * for it (stateward's facts), or a JSDoc tag (`@neverRejects`, `RuleProves.tags`).
831
1610
  */
832
1611
  export type TraitSource = {
833
1612
  readonly kind: "type";
@@ -840,6 +1619,9 @@ export type TraitSource = {
840
1619
  } | {
841
1620
  readonly kind: "shipped";
842
1621
  readonly package: string;
1622
+ } | {
1623
+ readonly kind: "tag";
1624
+ readonly tag: string;
843
1625
  };
844
1626
  export type StatedGuarantee = {
845
1627
  /** The guarantee's name, as its marker property writes it: `required-context`. */
@@ -850,6 +1632,11 @@ export type StatedGuarantee = {
850
1632
  readonly marker: string;
851
1633
  /** The declaration that states it: `ThemeContext`. */
852
1634
  readonly name: string;
1635
+ /**
1636
+ * The id of the declaration (`declarationId(location)`): what `Finding.guarantees` names. A
1637
+ * finding is against this guarantee when it lists the id.
1638
+ */
1639
+ readonly declaration: string;
853
1640
  /**
854
1641
  * The declaration. Every error of `ruleId` about this guarantee has a related note here (the
855
1642
  * note that says where the guarantee is stated): that is how its errors are counted.
@@ -863,6 +1650,18 @@ export type StatedGuarantee = {
863
1650
  readonly covers: CoveredNoun;
864
1651
  /** The places the proof covers, in file and offset order; empty when nothing uses it. */
865
1652
  readonly covered: readonly CoveredPlace[];
1653
+ /**
1654
+ * Places that use the guarantee's value in a way the rule cannot follow (a change only in a
1655
+ * closure nothing calls, an `if` chain over an open value): none is proven, so the guarantee
1656
+ * reads "not checked" while one is left, never proven and never unused.
1657
+ */
1658
+ readonly unchecked?: readonly UncheckedPlace[];
1659
+ };
1660
+ /** A place a rule cannot follow, and what is in it, as `not checked: …` says it. */
1661
+ export type UncheckedPlace = {
1662
+ readonly location: Location;
1663
+ /** After "not checked: ": "changed only in `later`, which nothing calls". */
1664
+ readonly reason: string;
866
1665
  };
867
1666
  export type FileContext<O extends Options = Options> = {
868
1667
  readonly file: string;
@@ -873,6 +1672,12 @@ export type FileContext<O extends Options = Options> = {
873
1672
  * order. The config's own `facts` line for a function wins over a shipped one.
874
1673
  */
875
1674
  readonly shippedFacts: PackageFactsConfig;
1675
+ /**
1676
+ * The facts lines of `facts` and `shippedFacts` left out for this file because they are for
1677
+ * other versions of their package than the one its project runs (`"@versions"`,
1678
+ * `Plugin.factsVerified`); empty for most files. A call one would name is "not checked".
1679
+ */
1680
+ readonly withheldFacts: readonly WithheldFacts[];
876
1681
  /** The rule's options: the config's values with the defaults filled in; `{}` when it declares none. */
877
1682
  readonly options: O;
878
1683
  readonly sourceFile: ts.SourceFile;
@@ -880,16 +1685,43 @@ export type FileContext<O extends Options = Options> = {
880
1685
  /** The add-ons of this rule's plugin that the config switches on, without the plugin prefix. */
881
1686
  readonly addons: readonly string[];
882
1687
  report(problem: ReportProblem): void;
1688
+ /** `against`: the declaration whose proof stops here (as `ReportProblem.against`). */
883
1689
  unknown(input: {
884
1690
  message: string;
885
1691
  hint: string;
886
1692
  node: ts.Node;
1693
+ against?: ts.Node | SymbolRef;
1694
+ /** The `facts` lines that would decide it (`Finding.needs`). */
1695
+ needs?: readonly FactNeed[];
1696
+ /** The calls no `facts` key can name (`Finding.unnamed`). */
1697
+ unnamed?: readonly UnnamedFact[];
887
1698
  }): void;
1699
+ /**
1700
+ * The references in this file to the declarations that state a trait the active rules prove
1701
+ * (`RuleInfo.proves`), in offset order: the reference ledger. Empty in the editor's fast pass.
1702
+ */
1703
+ readonly ledger: readonly LedgerRef[];
1704
+ /**
1705
+ * Marks a reference of `ledger` as read by this rule, with what it found: a reference of a trait
1706
+ * the rule proves that it leaves unmarked reads "not checked" in the guarantee's proof. Marks are
1707
+ * kept with the rule's findings, so a run from the cache replays them.
1708
+ */
1709
+ read(ref: LedgerRef, outcome: ReadOutcome): void;
888
1710
  };
1711
+ /**
1712
+ * The analyses a project rule reads (`ProjectRule.reads`), by id `"<plugin>/<name>"`: each as JSON
1713
+ * in the shape its publisher's package exports (`{ "errors/throws": ThrowsAnalysis }`).
1714
+ */
1715
+ export type Analyses = Readonly<Record<string, Json>>;
889
1716
  /** Project rules decide from their JSON summaries alone, so their results can be cached. */
890
- export type ProjectContext<O extends Options = Options> = {
1717
+ export type ProjectContext<O extends Options = Options, A extends Analyses = Analyses> = {
891
1718
  /** The rule's options, as in `FileContext`. */
892
1719
  readonly options: O;
1720
+ /**
1721
+ * The analyses the rule reads (`ProjectRule.reads`), by id, computed once per check: the rule
1722
+ * runs only when every one of them is there. `{}` for a rule that reads none.
1723
+ */
1724
+ readonly analyses: A;
893
1725
  report(problem: {
894
1726
  message: string;
895
1727
  hint: string;
@@ -898,6 +1730,13 @@ export type ProjectContext<O extends Options = Options> = {
898
1730
  findingKind?: string;
899
1731
  /** As in `ReportProblem`. */
900
1732
  severity?: "info" | "warning";
1733
+ /** As in `ReportProblem`: against a guarantee the code states, so an error while the rule is on. */
1734
+ stated?: true;
1735
+ /**
1736
+ * As in `ReportProblem`; a rule that has only summaries names the declarations as locations
1737
+ * (the `location` of the `StatedGuarantee` they are listed as).
1738
+ */
1739
+ against?: true | readonly Location[];
901
1740
  related?: readonly RelatedLocation[];
902
1741
  fixes?: readonly Fix[];
903
1742
  }): void;
@@ -905,7 +1744,42 @@ export type ProjectContext<O extends Options = Options> = {
905
1744
  message: string;
906
1745
  hint: string;
907
1746
  location: Location;
1747
+ /** The declarations whose proof stops here, as `against` names them. */
1748
+ against?: readonly Location[];
1749
+ /** The `facts` lines that would decide it (`Finding.needs`). */
1750
+ needs?: readonly FactNeed[];
1751
+ /** The calls no `facts` key can name (`Finding.unnamed`). */
1752
+ unnamed?: readonly UnnamedFact[];
1753
+ }): void;
1754
+ /**
1755
+ * A place the rule judged on what is known, leaving out package calls whose errors no `facts`
1756
+ * line states (`CheckResult.unstated`): not a finding, and not "not checked". The run counts
1757
+ * these places in one line, and `stateward coverage --facts` lists the lines they need.
1758
+ */
1759
+ unstated(input: {
1760
+ location: Location;
1761
+ needs?: readonly FactNeed[];
1762
+ unnamed?: readonly UnnamedFact[];
908
1763
  }): void;
1764
+ /**
1765
+ * Settles a reference the rule's file side handed on (`ReadOutcome` `handed-on`), by its id and
1766
+ * trait as the summaries keep them: `decided`, `irrelevant` or `unchecked`.
1767
+ */
1768
+ read(ref: {
1769
+ readonly id: string;
1770
+ readonly trait: string;
1771
+ }, outcome: ReadOutcome): void;
1772
+ };
1773
+ /**
1774
+ * A place a rule judged on what is known, leaving out package calls whose errors no `facts` line
1775
+ * states (`ProjectContext.unstated`): the lines that would state them (`needs`), and the calls no
1776
+ * key can name (`unnamed`).
1777
+ */
1778
+ export type UnstatedPlace = {
1779
+ readonly ruleId: string;
1780
+ readonly location: Location;
1781
+ readonly needs?: readonly FactNeed[];
1782
+ readonly unnamed?: readonly UnnamedFact[];
909
1783
  };
910
1784
  export type FileRule<S extends OptionSpecs = OptionSpecs, G extends string = string> = {
911
1785
  kind: "file";
@@ -919,12 +1793,36 @@ export type FileRule<S extends OptionSpecs = OptionSpecs, G extends string = str
919
1793
  */
920
1794
  summarize?(ctx: FileContext<OptionsOf<S>>): Json | undefined;
921
1795
  };
922
- export type ProjectRule<Summary extends Json = Json, S extends OptionSpecs = OptionSpecs, G extends string = string> = {
1796
+ /**
1797
+ * Every order of the keys of `K`, each once: what `reads` lists for a rule that types its
1798
+ * analyses (`["errors/throws"]`, or both orders of two).
1799
+ */
1800
+ type EveryOrder<K extends string, All extends string = K> = [K] extends [never] ? [] : K extends K ? [K, ...EveryOrder<Exclude<All, K>>] : never;
1801
+ /**
1802
+ * A project rule's `reads` (`ProjectRule.reads`): any analysis ids for a rule that does not type
1803
+ * them; for a rule that names its analyses in its type (`{ "errors/throws": ThrowsAnalysis }`),
1804
+ * required and listing exactly those, so `ctx.analyses` holds every one the type promises.
1805
+ */
1806
+ export type ReadsOf<A extends Analyses> = string extends keyof A ? {
1807
+ /**
1808
+ * The analyses this rule reads, by id `"<plugin>/<name>"` (`Plugin.analyses`): core runs
1809
+ * each once per check, however many rules read it, and passes it in
1810
+ * `ProjectContext.analyses`; the rule is checked again when one changes. Without the
1811
+ * publisher in the config's plugins, the rule reports one "not checked" finding that names
1812
+ * the missing pack.
1813
+ */
1814
+ reads?: readonly string[];
1815
+ } : [keyof A] extends [never] ? {
1816
+ reads?: readonly [];
1817
+ } : {
1818
+ reads: Readonly<EveryOrder<Extract<keyof A, string>>>;
1819
+ };
1820
+ export type ProjectRule<Summary extends Json = Json, S extends OptionSpecs = OptionSpecs, G extends string = string, A extends Analyses = Analyses> = ReadsOf<A> & {
923
1821
  kind: "project";
924
1822
  meta: RuleMeta<S, G>;
925
1823
  /** Per file and cacheable, hence JSON. */
926
1824
  summarize(ctx: FileContext<OptionsOf<S>>): Summary | undefined;
927
- check(summaries: ReadonlyMap<string, Summary>, ctx: ProjectContext<OptionsOf<S>>): void;
1825
+ check(summaries: ReadonlyMap<string, Summary>, ctx: ProjectContext<OptionsOf<S>, A>): void;
928
1826
  /**
929
1827
  * For `stateward plan` and `coverage`: why this rule, though on, cannot report anything in this
930
1828
  * project, as a short phrase after "silent: "; undefined when it can. Only for a reason that is
@@ -1047,6 +1945,51 @@ export type EditorContributions = {
1047
1945
  projectSummaries(ruleId: string): ReadonlyMap<string, Json> | undefined;
1048
1946
  }): readonly StatedGuarantee[];
1049
1947
  };
1948
+ /** Where a place in a report is, as the developer reads it: a path from their folder, a 1-based line. */
1949
+ export type ReportPlace = {
1950
+ readonly file: string;
1951
+ readonly line: number;
1952
+ };
1953
+ /** What a plugin's report reads (`PluginReport.run`). */
1954
+ export type ReportInput = {
1955
+ /**
1956
+ * The summaries a project rule of the plugin produced in the check that ran just before, by
1957
+ * file, or undefined when that rule did not run (as in `EditorContributions.hover`).
1958
+ */
1959
+ readonly projectSummaries: (ruleId: string) => ReadonlyMap<string, Json> | undefined;
1960
+ /** Where a location is, for the text and the rows. */
1961
+ readonly place: (location: Location) => ReportPlace;
1962
+ };
1963
+ /** What a report gives: its rows as plain data (`--format json`), and the text to print. */
1964
+ export type ReportOutput = {
1965
+ readonly rows: readonly Json[];
1966
+ readonly text: string;
1967
+ };
1968
+ /**
1969
+ * A read-only report a plugin contributes (`Plugin.reports`), run as `stateward <name>` after a
1970
+ * check of the project. It decides no finding: it shows what the plugin's rules read.
1971
+ */
1972
+ export type PluginReport = {
1973
+ /** What it shows, in one sentence: the line of `stateward --help` and `stateward <name> --help`. */
1974
+ readonly help: string;
1975
+ readonly run: (input: ReportInput) => ReportOutput;
1976
+ };
1977
+ /**
1978
+ * What an analysis's `summarize` reads of a file: the file and its types, and the facts about
1979
+ * packages. It reports nothing: an analysis decides no finding.
1980
+ */
1981
+ export type AnalysisContext = Pick<FileContext, "file" | "sourceFile" | "types" | "facts" | "shippedFacts" | "withheldFacts">;
1982
+ /**
1983
+ * An analysis a plugin publishes for project rules to read (`Plugin.analyses`, `ProjectRule.reads`),
1984
+ * of any pack. Core runs it once per check when a rule that is on reads it, whether or not the
1985
+ * publisher's own rules are on. Its shape is a type the publisher's package exports.
1986
+ */
1987
+ export type PluginAnalysis<Summary extends Json = Json, Result extends Json = Json> = {
1988
+ /** One file in, JSON out, as a project rule's `summarize`: cached under the file's dependency fingerprint. */
1989
+ summarize(ctx: AnalysisContext): Summary | undefined;
1990
+ /** Every file's summary in (by file, in file order), the analysis out. Same summaries, same result. */
1991
+ solve(summaries: ReadonlyMap<string, Summary>): Result;
1992
+ };
1050
1993
  /** Rule ids are "<plugin name>/<rule key>". */
1051
1994
  export type Plugin = {
1052
1995
  name: string;
@@ -1060,6 +2003,43 @@ export type Plugin = {
1060
2003
  * Every rule reads them as `FileContext.shippedFacts`; the config's facts win over them.
1061
2004
  */
1062
2005
  facts?: PackageFactsConfig;
2006
+ /**
2007
+ * The versions of each package `facts` names that the facts were verified on, by package. A
2008
+ * project that runs another version, or one whose version is not known, does not get the
2009
+ * package's lines: a call they would name is "not checked". A package not listed here gets its
2010
+ * lines on every version.
2011
+ */
2012
+ factsVerified?: Readonly<Record<string, VerifiedFacts>>;
2013
+ /**
2014
+ * Read-only reports, by command name (kebab-case): the CLI runs each as `stateward <name>`
2015
+ * and lists it in `stateward --help`. The CLI's own commands come first: a report named like
2016
+ * one of them is not run.
2017
+ */
2018
+ reports?: Readonly<Record<string, PluginReport>>;
2019
+ /**
2020
+ * Analyses for project rules of any pack to read, by name (kebab-case); a rule reads one as
2021
+ * `"<plugin>/<name>"` (`ProjectRule.reads`).
2022
+ */
2023
+ analyses?: Readonly<Record<string, PluginAnalysis>>;
2024
+ /**
2025
+ * Test and fixture files the pack's library names in its own way (globs, as `exclude` writes
2026
+ * them), such as a framework's own fixture folder. They join the default `exclude` while the pack
2027
+ * is loaded, unless the config's own `exclude` leaves out one of `defaults.exclude`.
2028
+ */
2029
+ defaultExclude?: readonly string[];
2030
+ /**
2031
+ * Rule ids a release renamed, to the id the rule has now:
2032
+ * `{ "unions/default-hides-cases": "unions/non-exhaustive-switch" }`. A rule that moved to
2033
+ * another pack is listed by both packs. A config, an ignore comment, the rollout file and the
2034
+ * baseline that use the old id still work, with a warning that says what to rename.
2035
+ */
2036
+ renamed?: Readonly<Record<string, string>>;
2037
+ /**
2038
+ * Rule ids a release removed, with the add-ons of the same id that turned them on:
2039
+ * `["errors/narrow-try"]`. A config, an ignore comment, the rollout file and the baseline that
2040
+ * still name one keep working: the entry has no effect, and a warning says to delete it.
2041
+ */
2042
+ removed?: readonly string[];
1063
2043
  };
1064
2044
  /** A plugin that keeps its literal name and rule keys, as `definePlugin` returns it. */
1065
2045
  export type PluginOf<N extends string, R extends Readonly<Record<string, PluginRule>>> = {
@@ -1068,6 +2048,12 @@ export type PluginOf<N extends string, R extends Readonly<Record<string, PluginR
1068
2048
  rules: R;
1069
2049
  editor?: EditorContributions;
1070
2050
  facts?: PackageFactsConfig;
2051
+ factsVerified?: Readonly<Record<string, VerifiedFacts>>;
2052
+ reports?: Readonly<Record<string, PluginReport>>;
2053
+ analyses?: Readonly<Record<string, PluginAnalysis>>;
2054
+ defaultExclude?: readonly string[];
2055
+ renamed?: Readonly<Record<string, string>>;
2056
+ removed?: readonly string[];
1071
2057
  };
1072
2058
  /** Every rule id ("<plugin>/<rule key>") a plugin type offers; any string pair for a wide `Plugin`. */
1073
2059
  export type RuleIdOf<P extends Plugin> = P extends Plugin ? `${P["name"]}/${Extract<keyof P["rules"], string>}` : never;
@@ -1113,6 +2099,12 @@ export type Config = {
1113
2099
  */
1114
2100
  replacesDefaultExclude: boolean;
1115
2101
  plugins: readonly Plugin[];
2102
+ /**
2103
+ * Packages whose types are the platform, besides TypeScript's own lib and Node's types
2104
+ * (`@types/node`): `["bun-types", "@cloudflare/workers-types"]`. What they declare is read as
2105
+ * the platform's own (`TypeQueries.isPlatformName`), as Node's is. `[]` when the config adds none.
2106
+ */
2107
+ platform: readonly string[];
1116
2108
  /**
1117
2109
  * The preset that turns rules on by tier, or undefined: then only what `groups`, `rules` and
1118
2110
  * `addons` name is on (a plugin alone turns nothing on).
@@ -1120,6 +2112,12 @@ export type Config = {
1120
2112
  preset: Preset | undefined;
1121
2113
  /** Add-ons switched on, each "<plugin>/<addon>". */
1122
2114
  addons: readonly string[];
2115
+ /**
2116
+ * True turns on every convention rule of the loaded packs (tier `convention`) and every option
2117
+ * marked `convention`: checks of a team convention rather than facts about the code. False by
2118
+ * default; a convention rule can also be turned on alone by its id under `rules`.
2119
+ */
2120
+ conventions: boolean;
1123
2121
  rules: Readonly<Record<string, RuleSetting>>;
1124
2122
  /** A setting for every rule of a group, by "<plugin>/<group>"; an explicit `rules` entry wins over it. */
1125
2123
  groups: Readonly<Record<string, RuleSetting>>;
@@ -1135,16 +2133,23 @@ export type Config = {
1135
2133
  rollout: boolean;
1136
2134
  /** Absolute folder of the config file, where `stateward.rollout.json` lives. Set by `parseConfig`. */
1137
2135
  configDir: string;
1138
- /** What the developer says about packages' functions. */
2136
+ /** What the developer says about packages' functions, without `"@versions"`. */
1139
2137
  facts: PackageFactsConfig;
2138
+ /** The range of versions each package's facts are for (`"@versions"`), by package. */
2139
+ factVersions: Readonly<Record<string, string>>;
1140
2140
  /** Settings for some files, in the order they apply (the later one wins). */
1141
2141
  overrides: readonly ConfigOverride[];
1142
2142
  ignores: IgnoreOptions;
1143
2143
  /**
1144
- * What the config should change though it still works: an old rule, group or add-on id
1145
- * (`renamed.ts`), one line each. Empty for most configs; the CLI and the editor show them.
2144
+ * What the config should change though it still works: an old rule, group or add-on id, or a
2145
+ * removed one (`renamed.ts`), one line each. Empty for most configs; the CLI and the editor show them.
1146
2146
  */
1147
2147
  warnings: readonly string[];
2148
+ /**
2149
+ * What the config does that the developer may not expect, though it is valid: a rule turned on
2150
+ * in `rules` that a release made off by default. One line each; the CLI shows them as infos.
2151
+ */
2152
+ notes: readonly string[];
1148
2153
  /**
1149
2154
  * How the places stateward could not check (unknown findings) are shown: as infos (the
1150
2155
  * default), as warnings, or "off": left out of the list and the editor but still counted in the
@@ -1177,7 +2182,12 @@ export type PluginsOf<C, Depth extends readonly unknown[] = []> = Depth["length"
1177
2182
  } ? Own[number] | (C extends {
1178
2183
  extends?: infer Parents extends readonly unknown[];
1179
2184
  } ? PluginsOf<Parents[number], [...Depth, unknown]> : never) : never;
1180
- export type UserConfig<P extends readonly Plugin[] = readonly Plugin[], E extends readonly ExtendedConfig[] = readonly ExtendedConfig[]> = Partial<Omit<Config, "plugins" | "configDir" | "rules" | "groups" | "ruleOptions" | "overrides" | "ignores" | "replacesDefaultExclude" | "tsconfig" | "tsconfigAsWritten">> & {
2185
+ export type UserConfig<P extends readonly Plugin[] = readonly Plugin[], E extends readonly ExtendedConfig[] = readonly ExtendedConfig[]> = Partial<Omit<Config, "plugins" | "configDir" | "rules" | "groups" | "ruleOptions" | "overrides" | "ignores" | "replacesDefaultExclude" | "tsconfig" | "tsconfigAsWritten" | "facts" | "factVersions">> & {
2186
+ /**
2187
+ * What the developer says about packages' functions, by package; `"@versions"` in a package's
2188
+ * lines gives the range of its versions they are for.
2189
+ */
2190
+ facts?: PackageFactsInput;
1181
2191
  /**
1182
2192
  * The tsconfig to check, relative to this file's folder (`"tsconfig.json"` by default), or several,
1183
2193
  * with globs: each one found is checked as its own project.
@@ -1206,8 +2216,9 @@ export type UserConfig<P extends readonly Plugin[] = readonly Plugin[], E extend
1206
2216
  * A config another one extends. Its rule and group ids are not checked in the type (they are
1207
2217
  * checked against the merged plugins when the config loads).
1208
2218
  */
1209
- export type ExtendedConfig = Partial<Omit<Config, "plugins" | "configDir" | "rules" | "groups" | "ruleOptions" | "overrides" | "ignores" | "replacesDefaultExclude" | "tsconfig" | "tsconfigAsWritten">> & {
2219
+ export type ExtendedConfig = Partial<Omit<Config, "plugins" | "configDir" | "rules" | "groups" | "ruleOptions" | "overrides" | "ignores" | "replacesDefaultExclude" | "tsconfig" | "tsconfigAsWritten" | "facts" | "factVersions">> & {
1210
2220
  tsconfig?: string | readonly string[];
2221
+ facts?: PackageFactsInput;
1211
2222
  plugins?: readonly Plugin[];
1212
2223
  extends?: readonly ExtendedConfig[];
1213
2224
  rules?: Readonly<Record<string, RuleConfig>>;
@@ -1269,6 +2280,18 @@ export type CheckResult = {
1269
2280
  * `findings`. Counted, never hidden: the CLI says how many. Empty when ignores are not applied.
1270
2281
  */
1271
2282
  ignored?: readonly IgnoredFinding[];
2283
+ /**
2284
+ * Findings against a stated guarantee (`Finding.guarantees`) that a rule made where the config
2285
+ * turns the rule off: they are not in `findings`, and a proof reads the guarantee as not checked
2286
+ * there, never proven (`ProofInputs.silenced`). Absent when there are none.
2287
+ */
2288
+ silenced?: readonly Finding[];
2289
+ /**
2290
+ * The reference ledger of a full check (every reference to each stated declaration, and the
2291
+ * rules' marks on them), for the proofs (`ProofInputs.ledger`); absent from the editor's fast
2292
+ * pass. Not part of the JSON output.
2293
+ */
2294
+ ledger?: Ledger;
1272
2295
  stats: {
1273
2296
  files: number;
1274
2297
  durationMs: number;
@@ -1292,13 +2315,41 @@ export type CheckResult = {
1292
2315
  * What the run could not check as a whole, said once (not part of the JSON contract yet).
1293
2316
  * `missingTypes`: rules that ran where their library's types do not resolve
1294
2317
  * (`RuleInfo.needsTypes`), by library, rule ids sorted. `looseNulls`: the tsconfigs, absolute,
1295
- * whose projects check without `strictNullChecks`. Left out when there is nothing to say.
2318
+ * whose projects check without `strictNullChecks`. `unreadTestConfigs`: the test-runner configs,
2319
+ * absolute, whose test files could not be read, so those tests may be checked as code.
2320
+ * `unmatchedFacts`: the config's facts lines that name nothing in their package;
2321
+ * `factsNotChecked`: those whose package's types could not be read. Left out when there is
2322
+ * nothing to say.
1296
2323
  */
1297
2324
  notes?: CheckNotes;
2325
+ /**
2326
+ * The places rules judged on what is known, leaving out package calls whose errors no `facts`
2327
+ * line states (`ProjectContext.unstated`), sorted by file, start, rule id. Not findings: the run
2328
+ * says how many in one line, and `stateward coverage --facts` lists the lines they need. Absent
2329
+ * when there are none.
2330
+ */
2331
+ unstated?: readonly UnstatedPlace[];
1298
2332
  };
1299
2333
  export type CheckNotes = {
1300
2334
  readonly missingTypes: readonly MissingTypes[];
1301
2335
  readonly looseNulls: readonly string[];
2336
+ readonly unreadTestConfigs: readonly string[];
2337
+ /**
2338
+ * The config's `facts` lines whose name finds no declaration in their package's types, one
2339
+ * warning each, with the closest declared path when one is near; and those whose `throws` or
2340
+ * `rejects` fits none of the functions they name, with the kind that does.
2341
+ */
2342
+ readonly unmatchedFacts: readonly string[];
2343
+ /**
2344
+ * The config's `facts` lines whose package's types could not be read, so whether they name a
2345
+ * declaration is not known: "not checked: whether `ioredis` declares `Redis.hget`: <reason>".
2346
+ */
2347
+ readonly factsNotChecked: readonly string[];
2348
+ /**
2349
+ * The config's facts for a package that this project runs another version of than their
2350
+ * `"@versions"` says, or whose version is not known: they are not applied, one warning each.
2351
+ */
2352
+ readonly factsOutOfRange: readonly string[];
1302
2353
  };
1303
2354
  /** Rules that could not run because a library's types do not resolve, and the reason in words. */
1304
2355
  export type MissingTypes = {
@@ -1307,4 +2358,5 @@ export type MissingTypes = {
1307
2358
  readonly reason: string;
1308
2359
  readonly rules: readonly string[];
1309
2360
  };
2361
+ export {};
1310
2362
  //# sourceMappingURL=types.d.ts.map