@stateward/core 1.2.0 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/backend/typescript6.d.ts +2 -0
- package/dist/backend/typescript6.js +2463 -89
- package/dist/cache.d.ts +17 -3
- package/dist/cache.js +74 -17
- package/dist/checker.d.ts +5 -0
- package/dist/checker.js +22 -2
- package/dist/config.js +51 -1
- package/dist/engine.d.ts +19 -1
- package/dist/engine.js +180 -25
- package/dist/fixes.js +5 -3
- package/dist/guarantees.d.ts +63 -11
- package/dist/guarantees.js +151 -21
- package/dist/index.d.ts +3 -1
- package/dist/index.js +4 -0
- package/dist/internal.d.ts +2 -1
- package/dist/internal.js +1 -0
- package/dist/ledger.d.ts +77 -0
- package/dist/ledger.js +423 -0
- package/dist/release.js +2 -0
- package/dist/safe-calls.d.ts +26 -0
- package/dist/safe-calls.js +345 -0
- package/dist/stated.d.ts +37 -0
- package/dist/stated.js +123 -0
- package/dist/testing-tsc.d.ts +16 -0
- package/dist/testing-tsc.js +86 -0
- package/dist/testing.d.ts +2 -1
- package/dist/testing.js +1 -1
- package/dist/timing.d.ts +7 -0
- package/dist/timing.js +6 -1
- package/dist/types.d.ts +395 -3
- package/package.json +1 -1
package/dist/timing.js
CHANGED
|
@@ -5,6 +5,7 @@ export function createTimingRecorder({ secondPass = false, } = {}) {
|
|
|
5
5
|
let started = performance.now();
|
|
6
6
|
let programMs = 0;
|
|
7
7
|
let fingerprintMs = 0;
|
|
8
|
+
let ledgerMs = 0;
|
|
8
9
|
/** The type time of the rule that is running; undefined between rules. */
|
|
9
10
|
let current;
|
|
10
11
|
const wrapped = new WeakMap();
|
|
@@ -55,6 +56,9 @@ export function createTimingRecorder({ secondPass = false, } = {}) {
|
|
|
55
56
|
fingerprint(ms) {
|
|
56
57
|
fingerprintMs += ms;
|
|
57
58
|
},
|
|
59
|
+
ledger(ms) {
|
|
60
|
+
ledgerMs += ms;
|
|
61
|
+
},
|
|
58
62
|
fileSide(ruleId, kind, run) {
|
|
59
63
|
const cost = costOf(ruleId, kind);
|
|
60
64
|
cost.files += 1;
|
|
@@ -131,7 +135,8 @@ export function createTimingRecorder({ secondPass = false, } = {}) {
|
|
|
131
135
|
programMs,
|
|
132
136
|
typeMs,
|
|
133
137
|
fingerprintMs,
|
|
134
|
-
|
|
138
|
+
ledgerMs,
|
|
139
|
+
otherMs: Math.max(0, totalMs - programMs - fingerprintMs - ledgerMs - ruleMs),
|
|
135
140
|
secondPassMs: secondPass ? warmMs : undefined,
|
|
136
141
|
rules: costs,
|
|
137
142
|
};
|
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,11 @@ 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[];
|
|
136
154
|
}
|
|
137
155
|
/** A rule threw: the check is incomplete, so it fails CI. */
|
|
138
156
|
| {
|
|
@@ -282,6 +300,13 @@ export type RuleInfo<S extends OptionSpecs = OptionSpecs, G extends string = str
|
|
|
282
300
|
* TypeScript then checks): in a project without it, each finding's fix line says so.
|
|
283
301
|
*/
|
|
284
302
|
fixNeedsStrictNulls?: true;
|
|
303
|
+
/**
|
|
304
|
+
* The traits this rule proves. The engine lists every reference to each declaration that states
|
|
305
|
+
* one (the reference ledger, `FileContext.ledger`); the rule marks each reference it reads with
|
|
306
|
+
* `FileContext.read`, and a reference it leaves unmarked reads "not checked" in the guarantee's
|
|
307
|
+
* proof.
|
|
308
|
+
*/
|
|
309
|
+
proves?: RuleProves;
|
|
285
310
|
};
|
|
286
311
|
/** A library a rule reads by its types: its name as people say it, and the modules that give them. */
|
|
287
312
|
export type LibraryTypes = {
|
|
@@ -342,6 +367,175 @@ export type SymbolRef = {
|
|
|
342
367
|
readonly id: string;
|
|
343
368
|
readonly name: string;
|
|
344
369
|
};
|
|
370
|
+
/**
|
|
371
|
+
* A declaration whose written type states guarantees (`TypeQueries.statedDeclarationsIn`):
|
|
372
|
+
* `start` is where its node starts, the place a plugin lists it at (`StatedGuarantee.location`).
|
|
373
|
+
*/
|
|
374
|
+
export type StatedDeclaration = {
|
|
375
|
+
readonly file: string;
|
|
376
|
+
readonly start: number;
|
|
377
|
+
/** The end of the declaration's head: its name and written type, not an initializer or a body. */
|
|
378
|
+
readonly headEnd: number;
|
|
379
|
+
readonly end: number;
|
|
380
|
+
readonly name: string;
|
|
381
|
+
/** The marker type as written: `Pending`. */
|
|
382
|
+
readonly marker: string;
|
|
383
|
+
/** The guarantee names the type states, sorted: `["pending"]`. */
|
|
384
|
+
readonly guarantees: readonly string[];
|
|
385
|
+
};
|
|
386
|
+
/**
|
|
387
|
+
* How a reference uses a stated declaration, as the reference ledger lists it (closed: a form not
|
|
388
|
+
* listed here is `other`). `call`: the callee of a call or `new`; `read`: read in place (a member
|
|
389
|
+
* read, an operand, a condition); `write`: assigned, changed with `++`, deleted, or a property given
|
|
390
|
+
* its value in an object literal; `alias`: copied to another name (a variable, a field, a default,
|
|
391
|
+
* a destructured name); `import` and `export`: named in an import or export; `argument`: passed to a
|
|
392
|
+
* call or to JSX; `stored`: put in an array or object literal; `returned`: returned or yielded;
|
|
393
|
+
* `jsx-tag` and `jsx-attribute`: a JSX element's tag or attribute name; `type`: named in a type;
|
|
394
|
+
* `computed`: used as a computed key; `other`: anything else (a branch of `?:`, `??`, a `for…of`);
|
|
395
|
+
* `tag`: the JSDoc tag that states the trait (`RuleProves.tags`), standing for the declaration's own
|
|
396
|
+
* body or definition, which its rule reads. The typed flows (`TypeQueries.typedFlowsIn`) are listed by their kind (`FlowKind`).
|
|
397
|
+
*/
|
|
398
|
+
export type ReferenceForm = "call" | "read" | "write" | "alias" | "import" | "export" | "argument" | "stored" | "returned" | "jsx-tag" | "jsx-attribute" | "type" | "computed" | "other" | "tag" | FlowKind;
|
|
399
|
+
/**
|
|
400
|
+
* How a value of a stated type flows (`TypeQueries.typedFlowsIn`): `produced`, a place typed with
|
|
401
|
+
* it gets a value whose own type does not hold it (a cast, an `any`, a plain value, a generic call
|
|
402
|
+
* that returns it); `decided`, the code decides by it (a `switch` subject, a comparison, a key, an
|
|
403
|
+
* `in` test); `escaped`, an object holding a stated member is written in a way no reference names
|
|
404
|
+
* (`Object.assign(this, …)`, a literal for a state whose setter also takes a function).
|
|
405
|
+
*/
|
|
406
|
+
export type FlowKind = "produced" | "decided" | "escaped";
|
|
407
|
+
/**
|
|
408
|
+
* What a typed flow goes through (`StatedReference.via`): `value`, a value given to a typed place;
|
|
409
|
+
* `cast`, `as`, `<T>` or `satisfies`; `any`, an `any` value; `overload`, a return of an overload's
|
|
410
|
+
* implementation; `override`, a value a class member gives where the member it overrides or
|
|
411
|
+
* implements is typed (`override id() { return "x" }` over `id(): OrderId`); `function-type`, a function given where one returning the type is expected;
|
|
412
|
+
* `generic-call`, a call whose type arguments give the type its arguments do not hold;
|
|
413
|
+
* `indirect-call`, `.call`, `.apply`, `.bind`, `Reflect.apply` or `Reflect.construct`; `spread`, a
|
|
414
|
+
* spread argument, attribute or property; `reflect`, `Object.assign`, `Object.defineProperty`,
|
|
415
|
+
* `Reflect.set` or a computed key; `literal`, an object literal; `for-of`, the target of a
|
|
416
|
+
* `for…of`; `derived`, a value made from one by a method (`switch (s.toLowerCase())`);
|
|
417
|
+
* `call`, a value given to a call that decides by it (`list.includes(s)`, `map.get(s)`,
|
|
418
|
+
* `Object.is(s, …)`); `stopped`, the flow scan of the file stopped at its budget here, so the flows after it
|
|
419
|
+
* are not listed.
|
|
420
|
+
*/
|
|
421
|
+
export type FlowVia = "value" | "cast" | "any" | "overload" | "override" | "function-type" | "generic-call" | "indirect-call" | "spread" | "reflect" | "literal" | "for-of" | "derived" | "call" | "stopped";
|
|
422
|
+
/**
|
|
423
|
+
* What a rule proves (`RuleInfo.proves`): the reference ledger lists every reference to each
|
|
424
|
+
* declaration that states one of these, and the rule marks the ones it reads (`FileContext.read`).
|
|
425
|
+
*/
|
|
426
|
+
export type RuleProves = {
|
|
427
|
+
/** Traits a value, property or parameter states by its written type (`Owned<T>`). */
|
|
428
|
+
readonly traits?: readonly string[];
|
|
429
|
+
/**
|
|
430
|
+
* Traits a function states by its written return type (`(): Release<…>`, or a promise of one): the
|
|
431
|
+
* function is the stated declaration, and each call a reference to it.
|
|
432
|
+
*/
|
|
433
|
+
readonly returns?: readonly string[];
|
|
434
|
+
/**
|
|
435
|
+
* Traits a module variable with no written type states by the type of the call that makes it
|
|
436
|
+
* (`const ThemeContext = requiredContext<Theme>()`): the variable is the stated declaration.
|
|
437
|
+
*/
|
|
438
|
+
readonly made?: readonly string[];
|
|
439
|
+
/**
|
|
440
|
+
* Traits a variable declared by an array destructuring states by a type written on it or on the
|
|
441
|
+
* call that makes it (`const [saving, setSaving] = useState<Pending<boolean>>(false)`): every
|
|
442
|
+
* element whose type holds the trait (as itself, or in a union member, a parameter or a return of
|
|
443
|
+
* a function, up to three levels) refers to one stated declaration, the variable declaration.
|
|
444
|
+
*/
|
|
445
|
+
readonly holders?: readonly string[];
|
|
446
|
+
/**
|
|
447
|
+
* Traits whose typed flows enter the ledger, by kind (`TypeQueries.typedFlowsIn`): a type alias
|
|
448
|
+
* stating a trait of `produced` or `decided` is a stated declaration (each name of it in a type
|
|
449
|
+
* a reference), with its flows of that kind; a member stating a trait of `escaped` has its holder's
|
|
450
|
+
* escapes. Listed only when a file of the project declares the trait.
|
|
451
|
+
*/
|
|
452
|
+
readonly flows?: {
|
|
453
|
+
readonly produced?: readonly string[];
|
|
454
|
+
readonly decided?: readonly string[];
|
|
455
|
+
readonly escaped?: readonly string[];
|
|
456
|
+
};
|
|
457
|
+
/**
|
|
458
|
+
* JSDoc tags (without `@`) whose declarations enter the ledger under the trait `@<tag>`: a
|
|
459
|
+
* function, a method, a variable holding a function, a property or method of a type, or a type
|
|
460
|
+
* alias the tag is written on. Each reference to it is listed, and the tag itself as a reference
|
|
461
|
+
* of form `tag`, which stands for the declaration's body: the rule reads it there.
|
|
462
|
+
*/
|
|
463
|
+
readonly tags?: readonly string[];
|
|
464
|
+
};
|
|
465
|
+
/** A reference to a stated declaration (`TypeQueries.statedReferencesIn`, `typedFlowsIn`). */
|
|
466
|
+
export type StatedReference = {
|
|
467
|
+
/** The id of the declaration (`declarationId`). */
|
|
468
|
+
readonly declaration: string;
|
|
469
|
+
/** The declaration as a symbol: `declarationOf` finds it. */
|
|
470
|
+
readonly symbol: SymbolRef;
|
|
471
|
+
/** The declaration's name, and its marker type as written (`Release`). */
|
|
472
|
+
readonly name: string;
|
|
473
|
+
readonly marker: string;
|
|
474
|
+
/** The trait the reference is listed for: one entry per trait the declaration states. */
|
|
475
|
+
readonly trait: string;
|
|
476
|
+
/** The identifier, private name or string key that refers to it; for a flow, the expression. */
|
|
477
|
+
readonly node: ts.Node;
|
|
478
|
+
readonly form: ReferenceForm;
|
|
479
|
+
/** For a typed flow (a `FlowKind` form): what it goes through. */
|
|
480
|
+
readonly via?: FlowVia;
|
|
481
|
+
/** The code around it, short and on one line: `w = watchPrices`. */
|
|
482
|
+
readonly text: string;
|
|
483
|
+
};
|
|
484
|
+
/** A reference in the ledger: a `StatedReference` without its node, as the cache keeps it. */
|
|
485
|
+
export type LedgerRef = {
|
|
486
|
+
/** `<file>#<start>` of the reference; `<file>#<start>-<end>` of a typed flow. */
|
|
487
|
+
readonly id: string;
|
|
488
|
+
readonly declaration: string;
|
|
489
|
+
readonly name: string;
|
|
490
|
+
readonly marker: string;
|
|
491
|
+
readonly trait: string;
|
|
492
|
+
readonly form: ReferenceForm;
|
|
493
|
+
readonly via?: FlowVia;
|
|
494
|
+
readonly location: Location;
|
|
495
|
+
readonly text: string;
|
|
496
|
+
};
|
|
497
|
+
/**
|
|
498
|
+
* What a rule says of a reference it read (`FileContext.read`): `decided`, the rule read it
|
|
499
|
+
* completely (a finding says when it is wrong); `irrelevant`, nothing the guarantee promises
|
|
500
|
+
* depends on it (an import, a read of a part that cannot change it); `handed-on`, the value goes
|
|
501
|
+
* to `to`, which the rule's project side settles (`ProjectContext.read`); `unchecked`, the rule
|
|
502
|
+
* cannot follow it, and `reason` says what it is (after "not checked: ").
|
|
503
|
+
*/
|
|
504
|
+
export type ReadOutcome = {
|
|
505
|
+
readonly kind: "decided";
|
|
506
|
+
} | {
|
|
507
|
+
readonly kind: "irrelevant";
|
|
508
|
+
} | {
|
|
509
|
+
readonly kind: "handed-on";
|
|
510
|
+
readonly to: string;
|
|
511
|
+
} | {
|
|
512
|
+
readonly kind: "unchecked";
|
|
513
|
+
readonly reason: string;
|
|
514
|
+
};
|
|
515
|
+
/** One rule's mark on a reference of the ledger. */
|
|
516
|
+
export type LedgerMark = {
|
|
517
|
+
readonly ruleId: string;
|
|
518
|
+
/** `LedgerRef.id`. */
|
|
519
|
+
readonly ref: string;
|
|
520
|
+
readonly trait: string;
|
|
521
|
+
readonly outcome: ReadOutcome;
|
|
522
|
+
};
|
|
523
|
+
/**
|
|
524
|
+
* Every reference to each stated declaration of a check, and what the rules said of them: a
|
|
525
|
+
* proof reads a reference its rule did not mark as not checked (`proveGuarantees`).
|
|
526
|
+
*/
|
|
527
|
+
export type Ledger = {
|
|
528
|
+
/** The traits the ledger lists references for (the active rules' `proves`), sorted. */
|
|
529
|
+
readonly traits: readonly string[];
|
|
530
|
+
/** In file and offset order. */
|
|
531
|
+
readonly refs: readonly LedgerRef[];
|
|
532
|
+
readonly marks: readonly LedgerMark[];
|
|
533
|
+
/**
|
|
534
|
+
* The rule that proves each tag trait (`@neverRejects`, from `RuleProves.tags`): the first active
|
|
535
|
+
* rule, by id, that lists the tag. Absent when no active rule proves a tag.
|
|
536
|
+
*/
|
|
537
|
+
readonly tagRules?: Readonly<Record<string, string>>;
|
|
538
|
+
};
|
|
345
539
|
/** A type alias by its name and the file that declares it. */
|
|
346
540
|
export type AliasRef = {
|
|
347
541
|
readonly name: string;
|
|
@@ -405,6 +599,19 @@ export type TypeQueries = {
|
|
|
405
599
|
isDiscriminant(object: ts.Node, propertyName: string): boolean;
|
|
406
600
|
/** The type of an expression as TypeScript prints it, on one line (`Record<string, string>`). */
|
|
407
601
|
typeTextOf(node: ts.Node): string;
|
|
602
|
+
/**
|
|
603
|
+
* Whether two expressions have the same type: each is assignable to the other. Two types that
|
|
604
|
+
* print the same name (a local `Phase` and an imported one) can differ; this compares the types.
|
|
605
|
+
* False when either is `any`, written or from a type that does not resolve.
|
|
606
|
+
*/
|
|
607
|
+
sameType(a: ts.Node, b: ts.Node): boolean;
|
|
608
|
+
/**
|
|
609
|
+
* Whether the type an object declares for the entry an element access reads, before any
|
|
610
|
+
* narrowing, already admits a missing value: `unknown`, `any`, or a union with `undefined`
|
|
611
|
+
* (`Record<string, unknown>`). TypeScript then makes the code check the value before using it.
|
|
612
|
+
* False when the entry's declared type cannot be found.
|
|
613
|
+
*/
|
|
614
|
+
declaredEntryCanBeMissing(access: ts.ElementAccessExpression): boolean;
|
|
408
615
|
/**
|
|
409
616
|
* The type the surrounding code expects for an expression, as `typeTextOf` prints it: for a
|
|
410
617
|
* function written as a JSX attribute, the declared type of that prop (`() => Promise<void>`);
|
|
@@ -474,6 +681,15 @@ export type TypeQueries = {
|
|
|
474
681
|
* alias is generic.
|
|
475
682
|
*/
|
|
476
683
|
contextualAliasOf(node: ts.Expression): SymbolRef | undefined;
|
|
684
|
+
/**
|
|
685
|
+
* The type aliases (not generic ones) that the type of an expression, or with `contextual` the
|
|
686
|
+
* type the surrounding code expects for it, holds inside: the elements and type arguments of an
|
|
687
|
+
* array, tuple, `Map`, `Set` or `Promise`, and the properties of an object type, up to three
|
|
688
|
+
* levels down (`OrderId` in `OrderId[]`, `Map<string, OrderId>`, `{ id: OrderId }`). The type
|
|
689
|
+
* itself is not listed (`contextualAliasOf` gives it), and an alias is not entered. Sorted by
|
|
690
|
+
* name; each once.
|
|
691
|
+
*/
|
|
692
|
+
heldAliasesOf(node: ts.Expression, contextual?: boolean): readonly SymbolRef[];
|
|
477
693
|
/**
|
|
478
694
|
* The property a name destructured from an object reads: `cacheEntryRemoved` of the
|
|
479
695
|
* parameter's type for `{ cacheEntryRemoved }`, as a symbol whose declaration `declarationOf`
|
|
@@ -486,6 +702,51 @@ export type TypeQueries = {
|
|
|
486
702
|
* a trait, `"__guarantee:<name>"`: a rule skips work for a trait nobody states.
|
|
487
703
|
*/
|
|
488
704
|
declaresTrait(name: string): boolean;
|
|
705
|
+
/**
|
|
706
|
+
* The declarations of `sourceFile` that state a guarantee in their written type: a variable, a
|
|
707
|
+
* property (a `#private` field, a member of an object type), a parameter of a function with a
|
|
708
|
+
* body, or a type alias (not a generic one, which is how a marker is defined), whose annotation
|
|
709
|
+
* names a type that states one or more guarantees. Empty when no file of the program writes a
|
|
710
|
+
* marker. In source order.
|
|
711
|
+
*/
|
|
712
|
+
statedDeclarationsIn(sourceFile: ts.SourceFile): readonly StatedDeclaration[];
|
|
713
|
+
/**
|
|
714
|
+
* Every reference in `sourceFile` to a declaration of the project that states a trait of
|
|
715
|
+
* `proves` (the reference ledger): an identifier, private name, string key, JSX name, import or
|
|
716
|
+
* export name, shorthand property, destructured name or contextually typed property name whose
|
|
717
|
+
* symbol, after aliases and to its root, is such a declaration. A value, property or parameter
|
|
718
|
+
* states a trait by its written type (a rest parameter by its elements), a function by its
|
|
719
|
+
* written return type or a promise of it (`proves.returns`), a declaration with a JSDoc tag of
|
|
720
|
+
* `proves.tags` by the tag (and the tag itself, form `tag`). Each with its form. Sorted by
|
|
721
|
+
* offset, then declaration and trait. Empty when no file of the program writes a marker or a tag.
|
|
722
|
+
*/
|
|
723
|
+
statedReferencesIn(sourceFile: ts.SourceFile, proves: RuleProves): readonly StatedReference[];
|
|
724
|
+
/**
|
|
725
|
+
* The typed flows in `sourceFile` of the traits `proves.flows` lists (the reference ledger's
|
|
726
|
+
* flows): at a return, an argument (a spread one too), an initializer, an assignment, a property
|
|
727
|
+
* or element of a literal, a JSX attribute or spread, a `yield`, a cast and a `for…of` target, each
|
|
728
|
+
* value given to a place whose type holds a stated type alias its own type does not (`produced`);
|
|
729
|
+
* each value of a stated alias the code decides by (`decided`: a `switch` subject, a comparison, a
|
|
730
|
+
* key, an `in` test); each holder of a stated member written by reflection or in an object literal
|
|
731
|
+
* whose members no reference names (`escaped`). Only in a file whose imports reach a declaring
|
|
732
|
+
* file. Past `budget` type questions (default `FLOW_BUDGET`), the scan stops: one flow of `via`
|
|
733
|
+
* `stopped` for each stated declaration, at the node where it stopped. Sorted by offset, then end,
|
|
734
|
+
* declaration and trait. Empty when no file of the program declares a flow trait.
|
|
735
|
+
*/
|
|
736
|
+
typedFlowsIn(sourceFile: ts.SourceFile, proves: RuleProves, budget?: number): readonly StatedReference[];
|
|
737
|
+
/**
|
|
738
|
+
* Whether every value the node's type can hold is a primitive, or an array or tuple of them (up to
|
|
739
|
+
* three levels): a copy of it shares nothing that can be changed.
|
|
740
|
+
*/
|
|
741
|
+
holdsOnlyPrimitives(node: ts.Node): boolean;
|
|
742
|
+
/**
|
|
743
|
+
* The declaration a value is, as far as its type says: the function, class or method whose type
|
|
744
|
+
* `node` has (`w` in `const w = watchPrices` and `watchPrices` in `const { watchPrices } = await
|
|
745
|
+
* import(…)` both give `watchPrices`). Undefined when the type belongs to no declaration (a
|
|
746
|
+
* union, a primitive, an object literal type). It follows no assignment: a wrapper function is
|
|
747
|
+
* its own declaration.
|
|
748
|
+
*/
|
|
749
|
+
valueOriginOf(node: ts.Node): SymbolRef | undefined;
|
|
489
750
|
/**
|
|
490
751
|
* Whether a file of the project declares a member named `[Symbol.dispose]` or
|
|
491
752
|
* `[Symbol.asyncDispose]` (a class, an interface, a type or an object literal), read from the
|
|
@@ -630,6 +891,13 @@ export type TypeQueries = {
|
|
|
630
891
|
* type (`Readonly<T>`). False for anything that is not a property access chain.
|
|
631
892
|
*/
|
|
632
893
|
isReadonlyPath(node: ts.Expression): boolean;
|
|
894
|
+
/**
|
|
895
|
+
* Whether the prop a JSX attribute gives its value to is declared in the project with a type no
|
|
896
|
+
* code can change through: every property `readonly` (declared so, or by `Readonly<T>`), with a
|
|
897
|
+
* primitive or such a type in turn; a `ReadonlyArray` of such values; no method, no function, no
|
|
898
|
+
* mutable array, `Map` or `Set`. False for a prop declared in a package, or with no declaration.
|
|
899
|
+
*/
|
|
900
|
+
propIsDeeplyReadonly(attribute: ts.JsxAttribute): boolean;
|
|
633
901
|
/**
|
|
634
902
|
* Whether the call may change what it is given: `argument` is the index of an argument, or
|
|
635
903
|
* `"receiver"` for the object a method is called on. True only when the callee's declaration is
|
|
@@ -662,6 +930,56 @@ export type TypeQueries = {
|
|
|
662
930
|
* time is still the same value. False for objects, functions, symbols, `any` and `unknown`.
|
|
663
931
|
*/
|
|
664
932
|
isPrimitive(node: ts.Node): boolean;
|
|
933
|
+
/**
|
|
934
|
+
* Whether every value of an expression's type is a number: `number`, a number literal or a
|
|
935
|
+
* numeric enum (a type parameter widened to its constraint; a branded `number & {…}` counts).
|
|
936
|
+
* False for `bigint`, `any` and `unknown`: dividing a `bigint` by zero throws.
|
|
937
|
+
*/
|
|
938
|
+
isNumber(node: ts.Node): boolean;
|
|
939
|
+
/**
|
|
940
|
+
* The platform's own type of an expression's value, by its name in TypeScript's lib or Node's
|
|
941
|
+
* types (`Array`, `Map`, `String` for a string or a branded string, `Math`, `MapConstructor` for
|
|
942
|
+
* `Map` itself), when
|
|
943
|
+
* every member of its type (`null` and `undefined` aside) is that one type and no class or
|
|
944
|
+
* interface of the project extends or implements it (a value typed `Map` may then be the
|
|
945
|
+
* project's subclass). A tuple is `Array`. Undefined for anything else: a type of the project or
|
|
946
|
+
* a package, a union of two types, `any`, `unknown`.
|
|
947
|
+
*/
|
|
948
|
+
platformTypeOf(node: ts.Node): string | undefined;
|
|
949
|
+
/**
|
|
950
|
+
* For an expression whose type is the platform's array or a tuple (every member of a union), and
|
|
951
|
+
* so iterates without running code of the project: `"primitives"` when every element type is one
|
|
952
|
+
* `isPrimitive` accepts, `"values"` otherwise. Undefined when the type is anything else
|
|
953
|
+
* (`Iterable<T>`, a `Set`, a union with one).
|
|
954
|
+
*/
|
|
955
|
+
arrayElementsOf(node: ts.Node): "primitives" | "values" | undefined;
|
|
956
|
+
/**
|
|
957
|
+
* Whether a property read, an element read or a destructured property runs no code and cannot
|
|
958
|
+
* throw, as far as the declared types say: the member is declared a property (never an accessor)
|
|
959
|
+
* of a class, an interface, an object type, a mapped type such as `Record`, an enum or a module
|
|
960
|
+
* (a class that gives an interface's property as a getter is not seen); or a property of the
|
|
961
|
+
* platform's types on its closed list (`length` of an array or string, `size` of a `Map`).
|
|
962
|
+
* An element read is plain with a literal index inside a tuple, a literal key of such a member, or
|
|
963
|
+
* a key of an index signature whose value is a primitive and is not read further (`xs[0].length`
|
|
964
|
+
* throws on an empty array). An array pattern is plain on an array.
|
|
965
|
+
*/
|
|
966
|
+
readIsPlain(node: ts.PropertyAccessExpression | ts.ElementAccessExpression | ts.BindingElement): boolean;
|
|
967
|
+
/**
|
|
968
|
+
* Whether reading or writing a property may run a getter or setter of the project: the member is
|
|
969
|
+
* declared as one, with a body. A member declared as a property is read as one, as far as the
|
|
970
|
+
* declared types say (a class that gives an interface's property as a getter is not seen).
|
|
971
|
+
*/
|
|
972
|
+
readMayRunAccessor(node: ts.PropertyAccessExpression): boolean;
|
|
973
|
+
/**
|
|
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`).
|
|
976
|
+
*/
|
|
977
|
+
isPlatformName(node: ts.Node): boolean;
|
|
978
|
+
/**
|
|
979
|
+
* Whether the type of the right side of `instanceof` is a class the test cannot run code of: a
|
|
980
|
+
* constructor of the platform, or a class of the project with no static `Symbol.hasInstance`.
|
|
981
|
+
*/
|
|
982
|
+
isPlainClass(node: ts.Expression): boolean;
|
|
665
983
|
/**
|
|
666
984
|
* Whether the type of an expression is declared outside the project: in a package (a file found
|
|
667
985
|
* through node_modules) or in TypeScript's own lib. What is asked is where the type is named: its
|
|
@@ -736,6 +1054,18 @@ export type ReportProblem = {
|
|
|
736
1054
|
* are warnings. A severity the config gives this finding's kind still wins over it.
|
|
737
1055
|
*/
|
|
738
1056
|
stated?: true;
|
|
1057
|
+
/**
|
|
1058
|
+
* The finding stands against a guarantee the code states: a proof counts it whatever its
|
|
1059
|
+
* severity (a rule set to `info`, a kind lowered or ignored by an override cannot make the
|
|
1060
|
+
* guarantee read proven), and a config that turns its kind `off` still reports it, as an info.
|
|
1061
|
+
* It changes no severity otherwise. `stated` implies it.
|
|
1062
|
+
*
|
|
1063
|
+
* Say which guarantee with the declaration that states it, a node or a symbol (`symbolAt`): the
|
|
1064
|
+
* finding is then linked to that guarantee (`Finding.guarantees`), however the code reaches the
|
|
1065
|
+
* value (an alias, a destructured import, a Provider in another file). With `true` the engine
|
|
1066
|
+
* links the finding from where it lies and its related notes, as far as they say.
|
|
1067
|
+
*/
|
|
1068
|
+
against?: true | ts.Node | SymbolRef;
|
|
739
1069
|
related?: readonly {
|
|
740
1070
|
node: ts.Node;
|
|
741
1071
|
message: string;
|
|
@@ -813,8 +1143,8 @@ export type CoveredPlace = {
|
|
|
813
1143
|
*/
|
|
814
1144
|
/**
|
|
815
1145
|
* Where a trait is stated: a standard type that already says it (`Disposable`), the project's
|
|
816
|
-
* marker type (`Owned<T>`), the config's `facts` line for a package,
|
|
817
|
-
* for it (stateward's facts).
|
|
1146
|
+
* marker type (`Owned<T>`), the config's `facts` line for a package, the facts a plugin ships
|
|
1147
|
+
* for it (stateward's facts), or a JSDoc tag (`@neverRejects`, `RuleProves.tags`).
|
|
818
1148
|
*/
|
|
819
1149
|
export type TraitSource = {
|
|
820
1150
|
readonly kind: "type";
|
|
@@ -827,6 +1157,9 @@ export type TraitSource = {
|
|
|
827
1157
|
} | {
|
|
828
1158
|
readonly kind: "shipped";
|
|
829
1159
|
readonly package: string;
|
|
1160
|
+
} | {
|
|
1161
|
+
readonly kind: "tag";
|
|
1162
|
+
readonly tag: string;
|
|
830
1163
|
};
|
|
831
1164
|
export type StatedGuarantee = {
|
|
832
1165
|
/** The guarantee's name, as its marker property writes it: `required-context`. */
|
|
@@ -837,6 +1170,11 @@ export type StatedGuarantee = {
|
|
|
837
1170
|
readonly marker: string;
|
|
838
1171
|
/** The declaration that states it: `ThemeContext`. */
|
|
839
1172
|
readonly name: string;
|
|
1173
|
+
/**
|
|
1174
|
+
* The id of the declaration (`declarationId(location)`): what `Finding.guarantees` names. A
|
|
1175
|
+
* finding is against this guarantee when it lists the id.
|
|
1176
|
+
*/
|
|
1177
|
+
readonly declaration: string;
|
|
840
1178
|
/**
|
|
841
1179
|
* The declaration. Every error of `ruleId` about this guarantee has a related note here (the
|
|
842
1180
|
* note that says where the guarantee is stated): that is how its errors are counted.
|
|
@@ -850,6 +1188,18 @@ export type StatedGuarantee = {
|
|
|
850
1188
|
readonly covers: CoveredNoun;
|
|
851
1189
|
/** The places the proof covers, in file and offset order; empty when nothing uses it. */
|
|
852
1190
|
readonly covered: readonly CoveredPlace[];
|
|
1191
|
+
/**
|
|
1192
|
+
* Places that use the guarantee's value in a way the rule cannot follow (a release only in a
|
|
1193
|
+
* closure nothing calls, an `if` chain over an open value): none is proven, so the guarantee
|
|
1194
|
+
* reads "not checked" while one is left, never proven and never unused.
|
|
1195
|
+
*/
|
|
1196
|
+
readonly unchecked?: readonly UncheckedPlace[];
|
|
1197
|
+
};
|
|
1198
|
+
/** A place a rule cannot follow, and what is in it, as `not checked: …` says it. */
|
|
1199
|
+
export type UncheckedPlace = {
|
|
1200
|
+
readonly location: Location;
|
|
1201
|
+
/** After "not checked: ": "released only in `later`, which nothing calls". */
|
|
1202
|
+
readonly reason: string;
|
|
853
1203
|
};
|
|
854
1204
|
export type FileContext<O extends Options = Options> = {
|
|
855
1205
|
readonly file: string;
|
|
@@ -867,11 +1217,24 @@ export type FileContext<O extends Options = Options> = {
|
|
|
867
1217
|
/** The add-ons of this rule's plugin that the config switches on, without the plugin prefix. */
|
|
868
1218
|
readonly addons: readonly string[];
|
|
869
1219
|
report(problem: ReportProblem): void;
|
|
1220
|
+
/** `against`: the declaration whose proof stops here (as `ReportProblem.against`). */
|
|
870
1221
|
unknown(input: {
|
|
871
1222
|
message: string;
|
|
872
1223
|
hint: string;
|
|
873
1224
|
node: ts.Node;
|
|
1225
|
+
against?: ts.Node | SymbolRef;
|
|
874
1226
|
}): void;
|
|
1227
|
+
/**
|
|
1228
|
+
* The references in this file to the declarations that state a trait the active rules prove
|
|
1229
|
+
* (`RuleInfo.proves`), in offset order: the reference ledger. Empty in the editor's fast pass.
|
|
1230
|
+
*/
|
|
1231
|
+
readonly ledger: readonly LedgerRef[];
|
|
1232
|
+
/**
|
|
1233
|
+
* Marks a reference of `ledger` as read by this rule, with what it found: a reference of a trait
|
|
1234
|
+
* the rule proves that it leaves unmarked reads "not checked" in the guarantee's proof. Marks are
|
|
1235
|
+
* kept with the rule's findings, so a run from the cache replays them.
|
|
1236
|
+
*/
|
|
1237
|
+
read(ref: LedgerRef, outcome: ReadOutcome): void;
|
|
875
1238
|
};
|
|
876
1239
|
/** Project rules decide from their JSON summaries alone, so their results can be cached. */
|
|
877
1240
|
export type ProjectContext<O extends Options = Options> = {
|
|
@@ -885,6 +1248,13 @@ export type ProjectContext<O extends Options = Options> = {
|
|
|
885
1248
|
findingKind?: string;
|
|
886
1249
|
/** As in `ReportProblem`. */
|
|
887
1250
|
severity?: "info" | "warning";
|
|
1251
|
+
/** As in `ReportProblem`: against a guarantee the code states, so an error while the rule is on. */
|
|
1252
|
+
stated?: true;
|
|
1253
|
+
/**
|
|
1254
|
+
* As in `ReportProblem`; a rule that has only summaries names the declarations as locations
|
|
1255
|
+
* (the `location` of the `StatedGuarantee` they are listed as).
|
|
1256
|
+
*/
|
|
1257
|
+
against?: true | readonly Location[];
|
|
888
1258
|
related?: readonly RelatedLocation[];
|
|
889
1259
|
fixes?: readonly Fix[];
|
|
890
1260
|
}): void;
|
|
@@ -892,7 +1262,17 @@ export type ProjectContext<O extends Options = Options> = {
|
|
|
892
1262
|
message: string;
|
|
893
1263
|
hint: string;
|
|
894
1264
|
location: Location;
|
|
1265
|
+
/** The declarations whose proof stops here, as `against` names them. */
|
|
1266
|
+
against?: readonly Location[];
|
|
895
1267
|
}): void;
|
|
1268
|
+
/**
|
|
1269
|
+
* Settles a reference the rule's file side handed on (`ReadOutcome` `handed-on`), by its id and
|
|
1270
|
+
* trait as the summaries keep them: `decided`, `irrelevant` or `unchecked`.
|
|
1271
|
+
*/
|
|
1272
|
+
read(ref: {
|
|
1273
|
+
readonly id: string;
|
|
1274
|
+
readonly trait: string;
|
|
1275
|
+
}, outcome: ReadOutcome): void;
|
|
896
1276
|
};
|
|
897
1277
|
export type FileRule<S extends OptionSpecs = OptionSpecs, G extends string = string> = {
|
|
898
1278
|
kind: "file";
|
|
@@ -1256,6 +1636,18 @@ export type CheckResult = {
|
|
|
1256
1636
|
* `findings`. Counted, never hidden: the CLI says how many. Empty when ignores are not applied.
|
|
1257
1637
|
*/
|
|
1258
1638
|
ignored?: readonly IgnoredFinding[];
|
|
1639
|
+
/**
|
|
1640
|
+
* Findings against a stated guarantee (`Finding.guarantees`) that a rule made where the config
|
|
1641
|
+
* turns the rule off: they are not in `findings`, and a proof reads the guarantee as not checked
|
|
1642
|
+
* there, never proven (`ProofInputs.silenced`). Absent when there are none.
|
|
1643
|
+
*/
|
|
1644
|
+
silenced?: readonly Finding[];
|
|
1645
|
+
/**
|
|
1646
|
+
* The reference ledger of a full check (every reference to each stated declaration, and the
|
|
1647
|
+
* rules' marks on them), for the proofs (`ProofInputs.ledger`); absent from the editor's fast
|
|
1648
|
+
* pass. Not part of the JSON output.
|
|
1649
|
+
*/
|
|
1650
|
+
ledger?: Ledger;
|
|
1259
1651
|
stats: {
|
|
1260
1652
|
files: number;
|
|
1261
1653
|
durationMs: number;
|
package/package.json
CHANGED