@stateward/core 1.2.2 → 1.3.1

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/fingerprints.d.ts +3 -1
  4. package/dist/backend/fingerprints.js +198 -9
  5. package/dist/backend/program-record.d.ts +7 -0
  6. package/dist/backend/program-size.d.ts +32 -0
  7. package/dist/backend/program-size.js +166 -0
  8. package/dist/backend/typescript6.d.ts +62 -32
  9. package/dist/backend/typescript6.js +1615 -164
  10. package/dist/baseline.d.ts +1 -1
  11. package/dist/baseline.js +14 -10
  12. package/dist/cache.d.ts +92 -4
  13. package/dist/cache.js +257 -68
  14. package/dist/checker.d.ts +28 -3
  15. package/dist/checker.js +42 -8
  16. package/dist/class-id.d.ts +34 -0
  17. package/dist/class-id.js +93 -0
  18. package/dist/code-text.d.ts +8 -0
  19. package/dist/code-text.js +66 -0
  20. package/dist/config-file.js +7 -5
  21. package/dist/config.d.ts +10 -2
  22. package/dist/config.js +490 -48
  23. package/dist/define.d.ts +8 -2
  24. package/dist/disk-cache.d.ts +34 -2
  25. package/dist/disk-cache.js +82 -15
  26. package/dist/engine.d.ts +64 -3
  27. package/dist/engine.js +474 -59
  28. package/dist/fact-lines.d.ts +31 -0
  29. package/dist/fact-lines.js +197 -0
  30. package/dist/facts-versions.d.ts +27 -0
  31. package/dist/facts-versions.js +99 -0
  32. package/dist/fixes.js +4 -1
  33. package/dist/ignores.d.ts +11 -0
  34. package/dist/ignores.js +74 -27
  35. package/dist/implementation.d.ts +0 -6
  36. package/dist/implementation.js +0 -17
  37. package/dist/index.d.ts +9 -9
  38. package/dist/index.js +12 -7
  39. package/dist/internal.d.ts +13 -6
  40. package/dist/internal.js +7 -3
  41. package/dist/journal.d.ts +40 -0
  42. package/dist/journal.js +197 -0
  43. package/dist/lazy.d.ts +8 -1
  44. package/dist/lazy.js +27 -2
  45. package/dist/ledger.d.ts +2 -2
  46. package/dist/ledger.js +2 -2
  47. package/dist/memory-plan.d.ts +121 -0
  48. package/dist/memory-plan.js +174 -0
  49. package/dist/off-by-default.d.ts +13 -0
  50. package/dist/off-by-default.js +15 -0
  51. package/dist/options.d.ts +21 -5
  52. package/dist/options.js +22 -7
  53. package/dist/package-facts.d.ts +211 -17
  54. package/dist/package-facts.js +520 -38
  55. package/dist/plan.d.ts +1 -1
  56. package/dist/plan.js +7 -2
  57. package/dist/release.d.ts +12 -21
  58. package/dist/release.js +26 -38
  59. package/dist/renamed.d.ts +22 -3
  60. package/dist/renamed.js +50 -16
  61. package/dist/rollout.js +7 -4
  62. package/dist/severity.d.ts +1 -1
  63. package/dist/severity.js +17 -3
  64. package/dist/test-runner.d.ts +18 -0
  65. package/dist/test-runner.js +483 -0
  66. package/dist/testing.d.ts +3 -3
  67. package/dist/testing.js +5 -5
  68. package/dist/timing.d.ts +17 -7
  69. package/dist/timing.js +60 -38
  70. package/dist/types.d.ts +704 -20
  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
@@ -151,6 +151,10 @@ export type Finding = {
151
151
  * checked" at this place, whatever `shown` says.
152
152
  */
153
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[];
154
158
  }
155
159
  /** A rule threw: the check is incomplete, so it fails CI. */
156
160
  | {
@@ -165,13 +169,26 @@ export type Json = null | boolean | number | string | readonly Json[] | {
165
169
  };
166
170
  /**
167
171
  * Where a rule sits in its pack: `core` carries the guarantee, `coverage` finds
168
- * 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.
169
175
  */
170
176
  export type RuleTier = (typeof RULE_TIERS)[number];
171
177
  export type BooleanOption = {
172
178
  kind: "boolean";
173
179
  default: boolean;
174
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;
175
192
  };
176
193
  export type NumberOption = {
177
194
  kind: "number";
@@ -251,6 +268,13 @@ export type RuleInfo<S extends OptionSpecs = OptionSpecs, G extends string = str
251
268
  group: G;
252
269
  /** The add-on this rule belongs to (kebab-case); present exactly when `tier` is "addon". */
253
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;
254
278
  /**
255
279
  * Add-ons (kebab-case) that widen what this core or coverage rule checks. The rule reads which
256
280
  * are on from `FileContext.addons`; they count as add-ons of the plugin, so a config may list them.
@@ -258,6 +282,12 @@ export type RuleInfo<S extends OptionSpecs = OptionSpecs, G extends string = str
258
282
  widenedBy?: readonly string[];
259
283
  /** A guess, never an error: its severity is capped at "warning" unless the config sets it. */
260
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;
261
291
  /**
262
292
  * The rule reads JSDoc in TypeScript files (`@throws`). Files are parsed as tsc parses them,
263
293
  * without the JSDoc of TypeScript files, unless a rule that is on asks for it: parsing it costs
@@ -308,6 +338,13 @@ export type RuleInfo<S extends OptionSpecs = OptionSpecs, G extends string = str
308
338
  */
309
339
  proves?: RuleProves;
310
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;
347
+ };
311
348
  /** A library a rule reads by its types: its name as people say it, and the modules that give them. */
312
349
  export type LibraryTypes = {
313
350
  /** As people say it: "React". */
@@ -324,6 +361,8 @@ export type Literal = {
324
361
  value: string | number | boolean | null | undefined;
325
362
  label: string;
326
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";
327
366
  /**
328
367
  * A test that narrows a reference by the kind of value it holds rather than by a literal:
329
368
  * `typeof x === "string"`, `"p" in x`, `x instanceof C` and a call to a user type guard.
@@ -427,7 +466,7 @@ export type RuleProves = {
427
466
  /** Traits a value, property or parameter states by its written type (`Owned<T>`). */
428
467
  readonly traits?: readonly string[];
429
468
  /**
430
- * Traits a function states by its written return type (`(): Release<…>`, or a promise of one): the
469
+ * Traits a function states by its written return type (`(): Marker<…>`, or a promise of one): the
431
470
  * function is the stated declaration, and each call a reference to it.
432
471
  */
433
472
  readonly returns?: readonly string[];
@@ -468,7 +507,7 @@ export type StatedReference = {
468
507
  readonly declaration: string;
469
508
  /** The declaration as a symbol: `declarationOf` finds it. */
470
509
  readonly symbol: SymbolRef;
471
- /** The declaration's name, and its marker type as written (`Release`). */
510
+ /** The declaration's name, and its marker type as written (`Owned`). */
472
511
  readonly name: string;
473
512
  readonly marker: string;
474
513
  /** The trait the reference is listed for: one entry per trait the declaration states. */
@@ -562,6 +601,45 @@ export type TypeQueries = {
562
601
  * through the program, so a renamed package changes the dependency fingerprints.
563
602
  */
564
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;
565
643
  /**
566
644
  * The finite literal union of the node's type (a type parameter is widened to its constraint),
567
645
  * sorted by label so the order does not depend on what TypeScript checked earlier.
@@ -586,6 +664,8 @@ export type TypeQueries = {
586
664
  canBeUndefined(node: ts.Node): boolean;
587
665
  /** Whether the type of an expression includes `null`; `any` and `unknown` count as yes. */
588
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;
589
669
  /**
590
670
  * Whether `propertyName` discriminates the type of the object expression (a type parameter
591
671
  * widened to its constraint): the type is a union, every member is an object type (an
@@ -626,6 +706,13 @@ export type TypeQueries = {
626
706
  * nothing gives one.
627
707
  */
628
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;
629
716
  /**
630
717
  * Whether argument `argumentIndex` of the call goes to a parameter that the called function's
631
718
  * declaration types as the `never` keyword. A rest parameter or a missing declaration is false.
@@ -664,6 +751,13 @@ export type TypeQueries = {
664
751
  * with `contextual`, of the type the surrounding code expects for the expression. Undefined when
665
752
  * the type does not state the trait; `"not-finite"` when the property's type is not literals.
666
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;
667
761
  guaranteeValuesOf(target: ts.Node | SymbolRef, name: string, contextual?: boolean): readonly Literal[] | "not-finite" | undefined;
668
762
  /**
669
763
  * How a value is disposed when its type is a standard `Disposable` or `AsyncDisposable`: it has
@@ -800,6 +894,15 @@ export type TypeQueries = {
800
894
  * are assignable to everything and so prove nothing.
801
895
  */
802
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;
803
906
  /**
804
907
  * Whether argument `argumentIndex` of the call goes to a parameter through which the callee
805
908
  * cannot add, change or remove a key: `Readonly<Record<string, V>>`, a type with a `readonly`
@@ -830,6 +933,24 @@ export type TypeQueries = {
830
933
  * says the type is unknown here, so a rule must not read it as `string` or as anything else.
831
934
  */
832
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;
833
954
  /**
834
955
  * Whether the type of an expression is promise-like: awaiting it gives another type
835
956
  * (`Promise<T>`, a thenable, `Promise<T> | undefined`). `any` and `unknown` are false.
@@ -837,6 +958,19 @@ export type TypeQueries = {
837
958
  isPromiseLike(node: ts.Node): boolean;
838
959
  /** As `isPromiseLike`, for what a function declaration, function expression, arrow or method returns (declared or inferred). */
839
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;
840
974
  /**
841
975
  * Whether the type of an expression surely has property `name` with a value: every member of
842
976
  * its type (a type parameter widened to its constraint) declares it, not optional, and its type
@@ -953,6 +1087,13 @@ export type TypeQueries = {
953
1087
  * (`Iterable<T>`, a `Set`, a union with one).
954
1088
  */
955
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;
956
1097
  /**
957
1098
  * Whether a property read, an element read or a destructured property runs no code and cannot
958
1099
  * throw, as far as the declared types say: the member is declared a property (never an accessor)
@@ -971,10 +1112,17 @@ export type TypeQueries = {
971
1112
  */
972
1113
  readMayRunAccessor(node: ts.PropertyAccessExpression): boolean;
973
1114
  /**
974
- * Whether a name is declared by the platform only: TypeScript's lib or Node's types, not the
975
- * project or a package (`String`, `setTimeout`).
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`).
976
1117
  */
977
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[];
978
1126
  /**
979
1127
  * Whether the type of the right side of `instanceof` is a class the test cannot run code of: a
980
1128
  * constructor of the platform, or a class of the project with no static `Symbol.hasInstance`.
@@ -1024,7 +1172,7 @@ export type TypeQueries = {
1024
1172
  * an optional parameter the call leaves out counts (`fetch(url)`). Undefined when no parameter
1025
1173
  * takes one, the call does not resolve, or the parameter is a rest parameter.
1026
1174
  */
1027
- signalParameterOf(call: ts.CallExpression): SignalParameter | undefined;
1175
+ signalParameterOf(call: ts.CallExpression | ts.NewExpression): SignalParameter | undefined;
1028
1176
  /**
1029
1177
  * Whether TypeScript reports that the end of a function can be reached although the function
1030
1178
  * must return a value: TS2366 (the return type does not include `undefined`), TS2355 (a
@@ -1034,6 +1182,182 @@ export type TypeQueries = {
1034
1182
  * those in its body. Asks for the type errors of the function's file, once per file.
1035
1183
  */
1036
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;
1037
1361
  };
1038
1362
  export type ReportProblem = {
1039
1363
  message: string;
@@ -1094,6 +1418,41 @@ export type FunctionFacts = {
1094
1418
  * property (RTK Query's `cacheEntryRemoved`). An `await` of it is not a way out.
1095
1419
  */
1096
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;
1097
1456
  };
1098
1457
  /**
1099
1458
  * How a value with the release trait is released, as a `facts` line says it: `"release"`, call the
@@ -1104,8 +1463,111 @@ export type ReleaseFact = "release" | {
1104
1463
  readonly release: string;
1105
1464
  };
1106
1465
  export type PackageFactsConfig = Readonly<Record<string, Readonly<Record<string, FunctionFacts>>>>;
1107
- /** Where a library fact comes from, in order of trust. */
1108
- 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
+ };
1109
1571
  /**
1110
1572
  * How a plugin knows the functions of one package the project calls, for `stateward deps`: each
1111
1573
  * function by its name, where its facts come from, and why what is unknown is unknown.
@@ -1189,7 +1651,7 @@ export type StatedGuarantee = {
1189
1651
  /** The places the proof covers, in file and offset order; empty when nothing uses it. */
1190
1652
  readonly covered: readonly CoveredPlace[];
1191
1653
  /**
1192
- * Places that use the guarantee's value in a way the rule cannot follow (a release only in a
1654
+ * Places that use the guarantee's value in a way the rule cannot follow (a change only in a
1193
1655
  * closure nothing calls, an `if` chain over an open value): none is proven, so the guarantee
1194
1656
  * reads "not checked" while one is left, never proven and never unused.
1195
1657
  */
@@ -1198,7 +1660,7 @@ export type StatedGuarantee = {
1198
1660
  /** A place a rule cannot follow, and what is in it, as `not checked: …` says it. */
1199
1661
  export type UncheckedPlace = {
1200
1662
  readonly location: Location;
1201
- /** After "not checked: ": "released only in `later`, which nothing calls". */
1663
+ /** After "not checked: ": "changed only in `later`, which nothing calls". */
1202
1664
  readonly reason: string;
1203
1665
  };
1204
1666
  export type FileContext<O extends Options = Options> = {
@@ -1210,6 +1672,12 @@ export type FileContext<O extends Options = Options> = {
1210
1672
  * order. The config's own `facts` line for a function wins over a shipped one.
1211
1673
  */
1212
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[];
1213
1681
  /** The rule's options: the config's values with the defaults filled in; `{}` when it declares none. */
1214
1682
  readonly options: O;
1215
1683
  readonly sourceFile: ts.SourceFile;
@@ -1223,6 +1691,10 @@ export type FileContext<O extends Options = Options> = {
1223
1691
  hint: string;
1224
1692
  node: ts.Node;
1225
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[];
1226
1698
  }): void;
1227
1699
  /**
1228
1700
  * The references in this file to the declarations that state a trait the active rules prove
@@ -1236,10 +1708,28 @@ export type FileContext<O extends Options = Options> = {
1236
1708
  */
1237
1709
  read(ref: LedgerRef, outcome: ReadOutcome): void;
1238
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>>;
1239
1716
  /** Project rules decide from their JSON summaries alone, so their results can be cached. */
1240
- export type ProjectContext<O extends Options = Options> = {
1717
+ export type ProjectContext<O extends Options = Options, A extends Analyses = Analyses> = {
1241
1718
  /** The rule's options, as in `FileContext`. */
1242
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;
1725
+ /**
1726
+ * The per-file summaries of an analysis the rule reads that its own plugin publishes, as that
1727
+ * analysis's `solve` receives them: the same map for every rule of the plugin in one check, so
1728
+ * a pack's rules share one copy of the facts instead of each keeping its own. The format of the
1729
+ * summaries is the plugin's own; a rule of another plugin reads only `analyses` (and is refused
1730
+ * here). The rule is checked again when any of these summaries changes.
1731
+ */
1732
+ analysisSummaries(id: Extract<keyof A, string>): ReadonlyMap<string, Json>;
1243
1733
  report(problem: {
1244
1734
  message: string;
1245
1735
  hint: string;
@@ -1264,6 +1754,20 @@ export type ProjectContext<O extends Options = Options> = {
1264
1754
  location: Location;
1265
1755
  /** The declarations whose proof stops here, as `against` names them. */
1266
1756
  against?: readonly Location[];
1757
+ /** The `facts` lines that would decide it (`Finding.needs`). */
1758
+ needs?: readonly FactNeed[];
1759
+ /** The calls no `facts` key can name (`Finding.unnamed`). */
1760
+ unnamed?: readonly UnnamedFact[];
1761
+ }): void;
1762
+ /**
1763
+ * A place the rule judged on what is known, leaving out package calls whose errors no `facts`
1764
+ * line states (`CheckResult.unstated`): not a finding, and not "not checked". The run counts
1765
+ * these places in one line, and `stateward coverage --facts` lists the lines they need.
1766
+ */
1767
+ unstated(input: {
1768
+ location: Location;
1769
+ needs?: readonly FactNeed[];
1770
+ unnamed?: readonly UnnamedFact[];
1267
1771
  }): void;
1268
1772
  /**
1269
1773
  * Settles a reference the rule's file side handed on (`ReadOutcome` `handed-on`), by its id and
@@ -1274,6 +1778,17 @@ export type ProjectContext<O extends Options = Options> = {
1274
1778
  readonly trait: string;
1275
1779
  }, outcome: ReadOutcome): void;
1276
1780
  };
1781
+ /**
1782
+ * A place a rule judged on what is known, leaving out package calls whose errors no `facts` line
1783
+ * states (`ProjectContext.unstated`): the lines that would state them (`needs`), and the calls no
1784
+ * key can name (`unnamed`).
1785
+ */
1786
+ export type UnstatedPlace = {
1787
+ readonly ruleId: string;
1788
+ readonly location: Location;
1789
+ readonly needs?: readonly FactNeed[];
1790
+ readonly unnamed?: readonly UnnamedFact[];
1791
+ };
1277
1792
  export type FileRule<S extends OptionSpecs = OptionSpecs, G extends string = string> = {
1278
1793
  kind: "file";
1279
1794
  meta: RuleMeta<S, G>;
@@ -1286,12 +1801,36 @@ export type FileRule<S extends OptionSpecs = OptionSpecs, G extends string = str
1286
1801
  */
1287
1802
  summarize?(ctx: FileContext<OptionsOf<S>>): Json | undefined;
1288
1803
  };
1289
- export type ProjectRule<Summary extends Json = Json, S extends OptionSpecs = OptionSpecs, G extends string = string> = {
1804
+ /**
1805
+ * Every order of the keys of `K`, each once: what `reads` lists for a rule that types its
1806
+ * analyses (`["errors/throws"]`, or both orders of two).
1807
+ */
1808
+ type EveryOrder<K extends string, All extends string = K> = [K] extends [never] ? [] : K extends K ? [K, ...EveryOrder<Exclude<All, K>>] : never;
1809
+ /**
1810
+ * A project rule's `reads` (`ProjectRule.reads`): any analysis ids for a rule that does not type
1811
+ * them; for a rule that names its analyses in its type (`{ "errors/throws": ThrowsAnalysis }`),
1812
+ * required and listing exactly those, so `ctx.analyses` holds every one the type promises.
1813
+ */
1814
+ export type ReadsOf<A extends Analyses> = string extends keyof A ? {
1815
+ /**
1816
+ * The analyses this rule reads, by id `"<plugin>/<name>"` (`Plugin.analyses`): core runs
1817
+ * each once per check, however many rules read it, and passes it in
1818
+ * `ProjectContext.analyses`; the rule is checked again when one changes. Without the
1819
+ * publisher in the config's plugins, the rule reports one "not checked" finding that names
1820
+ * the missing pack.
1821
+ */
1822
+ reads?: readonly string[];
1823
+ } : [keyof A] extends [never] ? {
1824
+ reads?: readonly [];
1825
+ } : {
1826
+ reads: Readonly<EveryOrder<Extract<keyof A, string>>>;
1827
+ };
1828
+ export type ProjectRule<Summary extends Json = Json, S extends OptionSpecs = OptionSpecs, G extends string = string, A extends Analyses = Analyses> = ReadsOf<A> & {
1290
1829
  kind: "project";
1291
1830
  meta: RuleMeta<S, G>;
1292
1831
  /** Per file and cacheable, hence JSON. */
1293
1832
  summarize(ctx: FileContext<OptionsOf<S>>): Summary | undefined;
1294
- check(summaries: ReadonlyMap<string, Summary>, ctx: ProjectContext<OptionsOf<S>>): void;
1833
+ check(summaries: ReadonlyMap<string, Summary>, ctx: ProjectContext<OptionsOf<S>, A>): void;
1295
1834
  /**
1296
1835
  * For `stateward plan` and `coverage`: why this rule, though on, cannot report anything in this
1297
1836
  * project, as a short phrase after "silent: "; undefined when it can. Only for a reason that is
@@ -1299,6 +1838,8 @@ export type ProjectRule<Summary extends Json = Json, S extends OptionSpecs = Opt
1299
1838
  */
1300
1839
  silentReason?(summaries: ReadonlyMap<string, Summary>, ctx: {
1301
1840
  readonly options: OptionsOf<S>;
1841
+ /** As `ProjectContext.analysisSummaries`: empty when the analysis did not run. */
1842
+ analysisSummaries(id: Extract<keyof A, string>): ReadonlyMap<string, Json>;
1302
1843
  }): string | undefined;
1303
1844
  };
1304
1845
  export type Rule = FileRule | ProjectRule;
@@ -1363,7 +1904,8 @@ export type EditorContributions = {
1363
1904
  * The summaries a project rule produced in the last full `check` (JSON, by file), or undefined
1364
1905
  * when that rule did not run or no full check ran yet. The same `Map` object is handed out
1365
1906
  * until a full check produces different summaries, so a plugin may cache what it derives
1366
- * from it.
1907
+ * from it. An analysis's id (`errors/throws`) gives the analysis's summaries, when a rule
1908
+ * read it in that check.
1367
1909
  */
1368
1910
  projectSummaries(ruleId: string): ReadonlyMap<string, Json> | undefined;
1369
1911
  }): string | undefined;
@@ -1414,6 +1956,51 @@ export type EditorContributions = {
1414
1956
  projectSummaries(ruleId: string): ReadonlyMap<string, Json> | undefined;
1415
1957
  }): readonly StatedGuarantee[];
1416
1958
  };
1959
+ /** Where a place in a report is, as the developer reads it: a path from their folder, a 1-based line. */
1960
+ export type ReportPlace = {
1961
+ readonly file: string;
1962
+ readonly line: number;
1963
+ };
1964
+ /** What a plugin's report reads (`PluginReport.run`). */
1965
+ export type ReportInput = {
1966
+ /**
1967
+ * The summaries a project rule of the plugin produced in the check that ran just before, by
1968
+ * file, or undefined when that rule did not run (as in `EditorContributions.hover`).
1969
+ */
1970
+ readonly projectSummaries: (ruleId: string) => ReadonlyMap<string, Json> | undefined;
1971
+ /** Where a location is, for the text and the rows. */
1972
+ readonly place: (location: Location) => ReportPlace;
1973
+ };
1974
+ /** What a report gives: its rows as plain data (`--format json`), and the text to print. */
1975
+ export type ReportOutput = {
1976
+ readonly rows: readonly Json[];
1977
+ readonly text: string;
1978
+ };
1979
+ /**
1980
+ * A read-only report a plugin contributes (`Plugin.reports`), run as `stateward <name>` after a
1981
+ * check of the project. It decides no finding: it shows what the plugin's rules read.
1982
+ */
1983
+ export type PluginReport = {
1984
+ /** What it shows, in one sentence: the line of `stateward --help` and `stateward <name> --help`. */
1985
+ readonly help: string;
1986
+ readonly run: (input: ReportInput) => ReportOutput;
1987
+ };
1988
+ /**
1989
+ * What an analysis's `summarize` reads of a file: the file and its types, and the facts about
1990
+ * packages. It reports nothing: an analysis decides no finding.
1991
+ */
1992
+ export type AnalysisContext = Pick<FileContext, "file" | "sourceFile" | "types" | "facts" | "shippedFacts" | "withheldFacts">;
1993
+ /**
1994
+ * An analysis a plugin publishes for project rules to read (`Plugin.analyses`, `ProjectRule.reads`),
1995
+ * of any pack. Core runs it once per check when a rule that is on reads it, whether or not the
1996
+ * publisher's own rules are on. Its shape is a type the publisher's package exports.
1997
+ */
1998
+ export type PluginAnalysis<Summary extends Json = Json, Result extends Json = Json> = {
1999
+ /** One file in, JSON out, as a project rule's `summarize`: cached under the file's dependency fingerprint. */
2000
+ summarize(ctx: AnalysisContext): Summary | undefined;
2001
+ /** Every file's summary in (by file, in file order), the analysis out. Same summaries, same result. */
2002
+ solve(summaries: ReadonlyMap<string, Summary>): Result;
2003
+ };
1417
2004
  /** Rule ids are "<plugin name>/<rule key>". */
1418
2005
  export type Plugin = {
1419
2006
  name: string;
@@ -1427,6 +2014,43 @@ export type Plugin = {
1427
2014
  * Every rule reads them as `FileContext.shippedFacts`; the config's facts win over them.
1428
2015
  */
1429
2016
  facts?: PackageFactsConfig;
2017
+ /**
2018
+ * The versions of each package `facts` names that the facts were verified on, by package. A
2019
+ * project that runs another version, or one whose version is not known, does not get the
2020
+ * package's lines: a call they would name is "not checked". A package not listed here gets its
2021
+ * lines on every version.
2022
+ */
2023
+ factsVerified?: Readonly<Record<string, VerifiedFacts>>;
2024
+ /**
2025
+ * Read-only reports, by command name (kebab-case): the CLI runs each as `stateward <name>`
2026
+ * and lists it in `stateward --help`. The CLI's own commands come first: a report named like
2027
+ * one of them is not run.
2028
+ */
2029
+ reports?: Readonly<Record<string, PluginReport>>;
2030
+ /**
2031
+ * Analyses for project rules of any pack to read, by name (kebab-case); a rule reads one as
2032
+ * `"<plugin>/<name>"` (`ProjectRule.reads`).
2033
+ */
2034
+ analyses?: Readonly<Record<string, PluginAnalysis>>;
2035
+ /**
2036
+ * Test and fixture files the pack's library names in its own way (globs, as `exclude` writes
2037
+ * them), such as a framework's own fixture folder. They join the default `exclude` while the pack
2038
+ * is loaded, unless the config's own `exclude` leaves out one of `defaults.exclude`.
2039
+ */
2040
+ defaultExclude?: readonly string[];
2041
+ /**
2042
+ * Rule ids a release renamed, to the id the rule has now:
2043
+ * `{ "unions/default-hides-cases": "unions/non-exhaustive-switch" }`. A rule that moved to
2044
+ * another pack is listed by both packs. A config, an ignore comment, the rollout file and the
2045
+ * baseline that use the old id still work, with a warning that says what to rename.
2046
+ */
2047
+ renamed?: Readonly<Record<string, string>>;
2048
+ /**
2049
+ * Rule ids a release removed, with the add-ons of the same id that turned them on:
2050
+ * `["errors/narrow-try"]`. A config, an ignore comment, the rollout file and the baseline that
2051
+ * still name one keep working: the entry has no effect, and a warning says to delete it.
2052
+ */
2053
+ removed?: readonly string[];
1430
2054
  };
1431
2055
  /** A plugin that keeps its literal name and rule keys, as `definePlugin` returns it. */
1432
2056
  export type PluginOf<N extends string, R extends Readonly<Record<string, PluginRule>>> = {
@@ -1435,6 +2059,12 @@ export type PluginOf<N extends string, R extends Readonly<Record<string, PluginR
1435
2059
  rules: R;
1436
2060
  editor?: EditorContributions;
1437
2061
  facts?: PackageFactsConfig;
2062
+ factsVerified?: Readonly<Record<string, VerifiedFacts>>;
2063
+ reports?: Readonly<Record<string, PluginReport>>;
2064
+ analyses?: Readonly<Record<string, PluginAnalysis>>;
2065
+ defaultExclude?: readonly string[];
2066
+ renamed?: Readonly<Record<string, string>>;
2067
+ removed?: readonly string[];
1438
2068
  };
1439
2069
  /** Every rule id ("<plugin>/<rule key>") a plugin type offers; any string pair for a wide `Plugin`. */
1440
2070
  export type RuleIdOf<P extends Plugin> = P extends Plugin ? `${P["name"]}/${Extract<keyof P["rules"], string>}` : never;
@@ -1480,6 +2110,12 @@ export type Config = {
1480
2110
  */
1481
2111
  replacesDefaultExclude: boolean;
1482
2112
  plugins: readonly Plugin[];
2113
+ /**
2114
+ * Packages whose types are the platform, besides TypeScript's own lib and Node's types
2115
+ * (`@types/node`): `["bun-types", "@cloudflare/workers-types"]`. What they declare is read as
2116
+ * the platform's own (`TypeQueries.isPlatformName`), as Node's is. `[]` when the config adds none.
2117
+ */
2118
+ platform: readonly string[];
1483
2119
  /**
1484
2120
  * The preset that turns rules on by tier, or undefined: then only what `groups`, `rules` and
1485
2121
  * `addons` name is on (a plugin alone turns nothing on).
@@ -1487,6 +2123,12 @@ export type Config = {
1487
2123
  preset: Preset | undefined;
1488
2124
  /** Add-ons switched on, each "<plugin>/<addon>". */
1489
2125
  addons: readonly string[];
2126
+ /**
2127
+ * True turns on every convention rule of the loaded packs (tier `convention`) and every option
2128
+ * marked `convention`: checks of a team convention rather than facts about the code. False by
2129
+ * default; a convention rule can also be turned on alone by its id under `rules`.
2130
+ */
2131
+ conventions: boolean;
1490
2132
  rules: Readonly<Record<string, RuleSetting>>;
1491
2133
  /** A setting for every rule of a group, by "<plugin>/<group>"; an explicit `rules` entry wins over it. */
1492
2134
  groups: Readonly<Record<string, RuleSetting>>;
@@ -1502,16 +2144,23 @@ export type Config = {
1502
2144
  rollout: boolean;
1503
2145
  /** Absolute folder of the config file, where `stateward.rollout.json` lives. Set by `parseConfig`. */
1504
2146
  configDir: string;
1505
- /** What the developer says about packages' functions. */
2147
+ /** What the developer says about packages' functions, without `"@versions"`. */
1506
2148
  facts: PackageFactsConfig;
2149
+ /** The range of versions each package's facts are for (`"@versions"`), by package. */
2150
+ factVersions: Readonly<Record<string, string>>;
1507
2151
  /** Settings for some files, in the order they apply (the later one wins). */
1508
2152
  overrides: readonly ConfigOverride[];
1509
2153
  ignores: IgnoreOptions;
1510
2154
  /**
1511
- * What the config should change though it still works: an old rule, group or add-on id
1512
- * (`renamed.ts`), one line each. Empty for most configs; the CLI and the editor show them.
2155
+ * What the config should change though it still works: an old rule, group or add-on id, or a
2156
+ * removed one (`renamed.ts`), one line each. Empty for most configs; the CLI and the editor show them.
1513
2157
  */
1514
2158
  warnings: readonly string[];
2159
+ /**
2160
+ * What the config does that the developer may not expect, though it is valid: a rule turned on
2161
+ * in `rules` that a release made off by default. One line each; the CLI shows them as infos.
2162
+ */
2163
+ notes: readonly string[];
1515
2164
  /**
1516
2165
  * How the places stateward could not check (unknown findings) are shown: as infos (the
1517
2166
  * default), as warnings, or "off": left out of the list and the editor but still counted in the
@@ -1544,7 +2193,12 @@ export type PluginsOf<C, Depth extends readonly unknown[] = []> = Depth["length"
1544
2193
  } ? Own[number] | (C extends {
1545
2194
  extends?: infer Parents extends readonly unknown[];
1546
2195
  } ? PluginsOf<Parents[number], [...Depth, unknown]> : never) : never;
1547
- 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">> & {
2196
+ 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">> & {
2197
+ /**
2198
+ * What the developer says about packages' functions, by package; `"@versions"` in a package's
2199
+ * lines gives the range of its versions they are for.
2200
+ */
2201
+ facts?: PackageFactsInput;
1548
2202
  /**
1549
2203
  * The tsconfig to check, relative to this file's folder (`"tsconfig.json"` by default), or several,
1550
2204
  * with globs: each one found is checked as its own project.
@@ -1573,8 +2227,9 @@ export type UserConfig<P extends readonly Plugin[] = readonly Plugin[], E extend
1573
2227
  * A config another one extends. Its rule and group ids are not checked in the type (they are
1574
2228
  * checked against the merged plugins when the config loads).
1575
2229
  */
1576
- export type ExtendedConfig = Partial<Omit<Config, "plugins" | "configDir" | "rules" | "groups" | "ruleOptions" | "overrides" | "ignores" | "replacesDefaultExclude" | "tsconfig" | "tsconfigAsWritten">> & {
2230
+ export type ExtendedConfig = Partial<Omit<Config, "plugins" | "configDir" | "rules" | "groups" | "ruleOptions" | "overrides" | "ignores" | "replacesDefaultExclude" | "tsconfig" | "tsconfigAsWritten" | "facts" | "factVersions">> & {
1577
2231
  tsconfig?: string | readonly string[];
2232
+ facts?: PackageFactsInput;
1578
2233
  plugins?: readonly Plugin[];
1579
2234
  extends?: readonly ExtendedConfig[];
1580
2235
  rules?: Readonly<Record<string, RuleConfig>>;
@@ -1671,13 +2326,41 @@ export type CheckResult = {
1671
2326
  * What the run could not check as a whole, said once (not part of the JSON contract yet).
1672
2327
  * `missingTypes`: rules that ran where their library's types do not resolve
1673
2328
  * (`RuleInfo.needsTypes`), by library, rule ids sorted. `looseNulls`: the tsconfigs, absolute,
1674
- * whose projects check without `strictNullChecks`. Left out when there is nothing to say.
2329
+ * whose projects check without `strictNullChecks`. `unreadTestConfigs`: the test-runner configs,
2330
+ * absolute, whose test files could not be read, so those tests may be checked as code.
2331
+ * `unmatchedFacts`: the config's facts lines that name nothing in their package;
2332
+ * `factsNotChecked`: those whose package's types could not be read. Left out when there is
2333
+ * nothing to say.
1675
2334
  */
1676
2335
  notes?: CheckNotes;
2336
+ /**
2337
+ * The places rules judged on what is known, leaving out package calls whose errors no `facts`
2338
+ * line states (`ProjectContext.unstated`), sorted by file, start, rule id. Not findings: the run
2339
+ * says how many in one line, and `stateward coverage --facts` lists the lines they need. Absent
2340
+ * when there are none.
2341
+ */
2342
+ unstated?: readonly UnstatedPlace[];
1677
2343
  };
1678
2344
  export type CheckNotes = {
1679
2345
  readonly missingTypes: readonly MissingTypes[];
1680
2346
  readonly looseNulls: readonly string[];
2347
+ readonly unreadTestConfigs: readonly string[];
2348
+ /**
2349
+ * The config's `facts` lines whose name finds no declaration in their package's types, one
2350
+ * warning each, with the closest declared path when one is near; and those whose `throws` or
2351
+ * `rejects` fits none of the functions they name, with the kind that does.
2352
+ */
2353
+ readonly unmatchedFacts: readonly string[];
2354
+ /**
2355
+ * The config's `facts` lines whose package's types could not be read, so whether they name a
2356
+ * declaration is not known: "not checked: whether `ioredis` declares `Redis.hget`: <reason>".
2357
+ */
2358
+ readonly factsNotChecked: readonly string[];
2359
+ /**
2360
+ * The config's facts for a package that this project runs another version of than their
2361
+ * `"@versions"` says, or whose version is not known: they are not applied, one warning each.
2362
+ */
2363
+ readonly factsOutOfRange: readonly string[];
1681
2364
  };
1682
2365
  /** Rules that could not run because a library's types do not resolve, and the reason in words. */
1683
2366
  export type MissingTypes = {
@@ -1686,4 +2369,5 @@ export type MissingTypes = {
1686
2369
  readonly reason: string;
1687
2370
  readonly rules: readonly string[];
1688
2371
  };
2372
+ export {};
1689
2373
  //# sourceMappingURL=types.d.ts.map