@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/guarantees.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { compareFindings } from "./engine.js";
|
|
2
|
+
import { indexLedger } from "./ledger.js";
|
|
3
|
+
import { STATED_RULE_ID } from "./stated.js";
|
|
2
4
|
function sameStart(a, b) {
|
|
3
5
|
return a.file === b.file && a.start === b.start;
|
|
4
6
|
}
|
|
@@ -7,16 +9,26 @@ function compareStated(a, b) {
|
|
|
7
9
|
return a.location.file < b.location.file ? -1 : 1;
|
|
8
10
|
return a.location.start - b.location.start || (a.guarantee < b.guarantee ? -1 : 1);
|
|
9
11
|
}
|
|
12
|
+
function comparePlace(a, b) {
|
|
13
|
+
if (a.file !== b.file)
|
|
14
|
+
return a.file < b.file ? -1 : 1;
|
|
15
|
+
return a.start - b.start || a.end - b.end;
|
|
16
|
+
}
|
|
10
17
|
function contains(place, inner) {
|
|
11
18
|
return place.file === inner.file && inner.start >= place.start && inner.end <= place.end;
|
|
12
19
|
}
|
|
13
20
|
/**
|
|
14
|
-
*
|
|
15
|
-
* at its declaration; or, when it has a note at no
|
|
16
|
-
* place the guarantee covers (a file rule notes only
|
|
17
|
-
* at a Provider in another file names the context by
|
|
21
|
+
* The guarantees a finding is about when no rule said (`Finding.guarantees` is absent): a problem
|
|
22
|
+
* of the guarantee's rule with a related note at its declaration; or, when it has a note at no
|
|
23
|
+
* declaration of that rule, one that lies in a place the guarantee covers (a file rule notes only
|
|
24
|
+
* declarations in its own file, so a finding at a Provider in another file names the context by
|
|
25
|
+
* where it is). A guarantee no plugin lists (`STATED_RULE_ID`) is the one a note of any rule is at.
|
|
26
|
+
* This is the fallback for a rule that does not link its findings (`ReportProblem.against`).
|
|
18
27
|
*/
|
|
19
|
-
function
|
|
28
|
+
function aboutByPlace(finding, guarantee, declarations) {
|
|
29
|
+
if (guarantee.ruleId === STATED_RULE_ID) {
|
|
30
|
+
return finding.related.some((note) => sameStart(note.location, guarantee.location));
|
|
31
|
+
}
|
|
20
32
|
if (finding.ruleId !== guarantee.ruleId)
|
|
21
33
|
return false;
|
|
22
34
|
if (finding.related.some((note) => sameStart(note.location, guarantee.location)))
|
|
@@ -25,26 +37,122 @@ function isAbout(finding, guarantee, declarations) {
|
|
|
25
37
|
finding.related.some((note) => sameStart(note.location, other.location)));
|
|
26
38
|
return (!namesAnother && guarantee.covered.some((place) => contains(place.location, finding.location)));
|
|
27
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Whether a finding is about a guarantee: it names its declaration (`Finding.guarantees`), or, when
|
|
42
|
+
* no rule linked it, it lies where the guarantee is stated or covered (`aboutByPlace`).
|
|
43
|
+
*/
|
|
44
|
+
function isAbout(finding, guarantee, declarations) {
|
|
45
|
+
return finding.guarantees === undefined
|
|
46
|
+
? aboutByPlace(finding, guarantee, declarations)
|
|
47
|
+
: names(finding, guarantee);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Whether a finding names the guarantee: its declaration's id, and the rule that proves it (one
|
|
51
|
+
* declaration may state several guarantees, each proven by its own rule); a guarantee no plugin
|
|
52
|
+
* lists is named by a finding of any rule.
|
|
53
|
+
*/
|
|
54
|
+
function names(finding, guarantee) {
|
|
55
|
+
return (finding.guarantees?.includes(guarantee.declaration) === true &&
|
|
56
|
+
(guarantee.ruleId === STATED_RULE_ID || finding.ruleId === guarantee.ruleId));
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Whether a finding counts against a guarantee: any severity, if the rule says it is against one
|
|
60
|
+
* or names one (`Finding.guarantees`).
|
|
61
|
+
*/
|
|
62
|
+
function counts(finding) {
|
|
63
|
+
return (finding.against === true || (finding.guarantees?.length ?? 0) > 0 || finding.severity !== "info");
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The text of a place not checked from an `unknown` finding: its message without "not checked: ",
|
|
67
|
+
* then what to write instead, from its hint (the first way, when it lists several), so the line
|
|
68
|
+
* `stateward guarantees` prints says both.
|
|
69
|
+
*/
|
|
70
|
+
function reasonOf(message, hint) {
|
|
71
|
+
const what = message.startsWith(NOT_CHECKED) ? message.slice(NOT_CHECKED.length) : message;
|
|
72
|
+
const lines = hint.split("\n");
|
|
73
|
+
const way = lines.find((line) => line.startsWith("- "))?.slice(2) ?? lines[0] ?? "";
|
|
74
|
+
return way === "" ? what : `${what}: ${way}`;
|
|
75
|
+
}
|
|
76
|
+
const NOT_CHECKED = "not checked: ";
|
|
77
|
+
/** The `unknown` findings that name a guarantee, with the places they leave unchecked. */
|
|
78
|
+
function unknownPlaces(finding, guarantee) {
|
|
79
|
+
if (finding.kind !== "unknown" || !names(finding, guarantee))
|
|
80
|
+
return [];
|
|
81
|
+
return [{ location: finding.location, reason: reasonOf(finding.message, finding.hint) }];
|
|
82
|
+
}
|
|
28
83
|
/**
|
|
29
84
|
* Each stated guarantee with its status, in file and offset order. `findings` are a check's
|
|
30
|
-
* (after ignore comments, before a baseline: an accepted error still leaves it unproven)
|
|
31
|
-
* `
|
|
32
|
-
*
|
|
33
|
-
*
|
|
85
|
+
* (after ignore comments, before a baseline: an accepted error still leaves it unproven), and
|
|
86
|
+
* `inputs.ignored` the ones ignore comments hid: a guarantee is proven only when no finding
|
|
87
|
+
* stands against it before ignores and settings. `active` the rules that check
|
|
88
|
+
* ran. A finding is about a guarantee when it names its declaration (`Finding.guarantees`), or,
|
|
89
|
+
* for a finding no rule linked, lies where the guarantee is stated or covered (`aboutByPlace`); it
|
|
90
|
+
* counts at any severity once linked, and unless it is a weaker signal the rule judged an info.
|
|
91
|
+
* An `unknown` finding that names a guarantee leaves it "not checked" at its place, whatever the
|
|
92
|
+
* config's `unknowns` setting shows of it. With the check's reference ledger (`inputs.ledger`), so
|
|
93
|
+
* does every reference to a marked declaration its rule did not read (unmarked, marked unchecked,
|
|
94
|
+
* or only handed on), and it is unused only when it has no reference.
|
|
34
95
|
*/
|
|
35
|
-
export function proveGuarantees(stated, findings, active) {
|
|
96
|
+
export function proveGuarantees(stated, findings, active, inputs = {}) {
|
|
36
97
|
const problems = findings
|
|
37
98
|
.filter((finding) => finding.kind === "problem")
|
|
38
|
-
.filter(
|
|
99
|
+
.filter(counts);
|
|
100
|
+
const hidden = (inputs.ignored ?? []).flatMap(({ finding, reason }) => finding.kind === "problem" && counts(finding) ? [{ finding, reason }] : []);
|
|
101
|
+
const unknowns = [...findings, ...(inputs.ignored ?? []).map(({ finding }) => finding)].filter((finding) => finding.kind === "unknown");
|
|
102
|
+
const ledger = inputs.ledger === undefined ? undefined : indexLedger(inputs.ledger);
|
|
39
103
|
return [...stated].sort(compareStated).map((guarantee) => {
|
|
40
|
-
if (!active.has(guarantee.ruleId))
|
|
41
|
-
return { stated: guarantee, status: { kind: "off" } };
|
|
104
|
+
if (guarantee.ruleId !== STATED_RULE_ID && !active.has(guarantee.ruleId)) {
|
|
105
|
+
return { stated: guarantee, status: { kind: "off", places: [] } };
|
|
106
|
+
}
|
|
42
107
|
const errors = problems
|
|
43
108
|
.filter((finding) => isAbout(finding, guarantee, stated))
|
|
44
109
|
.sort(compareFindings);
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
110
|
+
const ignored = hidden
|
|
111
|
+
.filter(({ finding }) => isAbout(finding, guarantee, stated))
|
|
112
|
+
.sort((a, b) => compareFindings(a.finding, b.finding));
|
|
113
|
+
if (errors.length > 0 || ignored.length > 0) {
|
|
114
|
+
return { stated: guarantee, status: { kind: "unproven", errors, ignored } };
|
|
115
|
+
}
|
|
116
|
+
const off = [
|
|
117
|
+
...guarantee.covered
|
|
118
|
+
.filter((place) => inputs.ruleOffAt?.(guarantee.ruleId, place.location.file) === true)
|
|
119
|
+
.map((place) => place.location),
|
|
120
|
+
...(inputs.silenced ?? []).flatMap((finding) => finding.kind !== "failure" && names(finding, guarantee) ? [finding.location] : []),
|
|
121
|
+
];
|
|
122
|
+
if (off.length > 0)
|
|
123
|
+
return { stated: guarantee, status: { kind: "off", places: off } };
|
|
124
|
+
const own = guarantee.unchecked ?? [];
|
|
125
|
+
// A guarantee a marker states, of a trait the ledger lists: its references are all known.
|
|
126
|
+
const listed = ledger !== undefined &&
|
|
127
|
+
(guarantee.source === undefined ||
|
|
128
|
+
guarantee.source.kind === "marker" ||
|
|
129
|
+
guarantee.source.kind === "tag") &&
|
|
130
|
+
ledger.traits.has(guarantee.guarantee);
|
|
131
|
+
const refs = listed ? ledger.refsOf(guarantee.declaration, guarantee.guarantee) : [];
|
|
132
|
+
// Imports, exports and types run nothing: a declaration only they name is unused.
|
|
133
|
+
const importsOnly = refs.length > 0 &&
|
|
134
|
+
refs.every((ref) => ref.form === "import" || ref.form === "export" || ref.form === "type");
|
|
135
|
+
const known = [...own];
|
|
136
|
+
const more = [];
|
|
137
|
+
for (const place of [
|
|
138
|
+
...unknowns.flatMap((finding) => unknownPlaces(finding, guarantee)),
|
|
139
|
+
...(listed && !importsOnly ? ledger.uncheckedOf(guarantee, refs) : []),
|
|
140
|
+
]) {
|
|
141
|
+
if (known.some((one) => sameStart(one.location, place.location)))
|
|
142
|
+
continue;
|
|
143
|
+
known.push(place);
|
|
144
|
+
more.push(place);
|
|
145
|
+
}
|
|
146
|
+
const unchecked = more.length === 0
|
|
147
|
+
? own
|
|
148
|
+
: [...own, ...more].sort((a, b) => comparePlace(a.location, b.location));
|
|
149
|
+
if (unchecked.length > 0) {
|
|
150
|
+
return { stated: guarantee, status: { kind: "unchecked", places: unchecked } };
|
|
151
|
+
}
|
|
152
|
+
if (importsOnly)
|
|
153
|
+
return { stated: guarantee, status: { kind: "unused", importsOnly: true } };
|
|
154
|
+
const unused = listed ? refs.length === 0 : guarantee.covered.length === 0;
|
|
155
|
+
if (unused)
|
|
48
156
|
return { stated: guarantee, status: { kind: "unused" } };
|
|
49
157
|
return { stated: guarantee, status: { kind: "proven" } };
|
|
50
158
|
});
|
|
@@ -54,21 +162,43 @@ export function counted(count, noun) {
|
|
|
54
162
|
return `${String(count)} ${count === 1 ? noun.one : noun.many}`;
|
|
55
163
|
}
|
|
56
164
|
const ERROR = { one: "error", many: "errors" };
|
|
165
|
+
/** The reasons of the comments that hide findings, each once, in order: "lives as long as the app". */
|
|
166
|
+
function reasonsOf(ignored) {
|
|
167
|
+
const reasons = [
|
|
168
|
+
...new Set(ignored.map(({ reason }) => reason).filter((reason) => reason !== "")),
|
|
169
|
+
];
|
|
170
|
+
return reasons.length === 0 ? "" : ` — ${reasons.join("; ")}`;
|
|
171
|
+
}
|
|
57
172
|
/**
|
|
58
173
|
* The status in a few words, the same in `stateward guarantees` and the editor: "proven for 3
|
|
59
|
-
* readers", "not proven: 2 errors", "
|
|
174
|
+
* readers", "not proven: 2 errors", "not proven: 1 ignored — lives as long as the app", "unused:
|
|
175
|
+
* nothing reads it", "not checked: … is not on".
|
|
60
176
|
*/
|
|
61
177
|
export function describeStatus(proof) {
|
|
62
178
|
const { stated, status } = proof;
|
|
63
179
|
switch (status.kind) {
|
|
64
180
|
case "proven":
|
|
65
181
|
return `proven for ${counted(stated.covered.length, stated.covers)}`;
|
|
66
|
-
case "unproven":
|
|
67
|
-
|
|
182
|
+
case "unproven": {
|
|
183
|
+
const parts = [
|
|
184
|
+
...(status.errors.length > 0 ? [counted(status.errors.length, ERROR)] : []),
|
|
185
|
+
...(status.ignored.length > 0 ? [`${String(status.ignored.length)} ignored`] : []),
|
|
186
|
+
];
|
|
187
|
+
return `not proven: ${parts.join(", ")}${reasonsOf(status.ignored)}`;
|
|
188
|
+
}
|
|
189
|
+
case "unchecked": {
|
|
190
|
+
const [first] = status.places;
|
|
191
|
+
const more = status.places.length - 1;
|
|
192
|
+
return `not checked: ${first?.reason ?? "a place it cannot follow"}${more > 0 ? ` (and ${String(more)} more)` : ""}`;
|
|
193
|
+
}
|
|
68
194
|
case "unused":
|
|
69
|
-
return
|
|
195
|
+
return status.importsOnly === true
|
|
196
|
+
? "unused: referenced only by imports or types"
|
|
197
|
+
: `unused: no ${stated.covers.one}, so nothing to prove; use it or drop the marker`;
|
|
70
198
|
case "off":
|
|
71
|
-
return
|
|
199
|
+
return status.places.length === 0
|
|
200
|
+
? `not checked: ${stated.ruleId} is not on: turn it on in the config, or with \`stateward next\``
|
|
201
|
+
: `not checked: ${stated.ruleId} is off for ${counted(status.places.length, stated.covers)}: turn it on for them in the config`;
|
|
72
202
|
default: {
|
|
73
203
|
const unreachable = status;
|
|
74
204
|
return unreachable;
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export { defaults, defineConfig, parseConfig } from "./config.js";
|
|
|
2
2
|
export { matchesFile, matchesName, option } from "./options.js";
|
|
3
3
|
export type { ConfigOptionsOf, GroupConfigsOf, RuleConfigsOf } from "./options.js";
|
|
4
4
|
export { defineRule, definePlugin } from "./define.js";
|
|
5
|
+
export { declarationId } from "./stated.js";
|
|
5
6
|
export { lazyRule, moduleLoader } from "./lazy.js";
|
|
6
7
|
export type { ModuleLoader } from "./lazy.js";
|
|
7
8
|
export { check, createChecker } from "./checker.js";
|
|
@@ -12,6 +13,7 @@ export { highestUncovered, shortestPath } from "./tree.js";
|
|
|
12
13
|
export type { TreeEdge, Uncovered, WalkDown } from "./tree.js";
|
|
13
14
|
export { describeRelease, describeTraitSource, releaseCandidates, releaseTraitOf, } from "./release.js";
|
|
14
15
|
export { neverRejectsFactOf } from "./package-facts.js";
|
|
16
|
+
export { isSafePlatformCall, iteratesPlainly } from "./safe-calls.js";
|
|
15
17
|
export type { FactContext, PackageFact } from "./package-facts.js";
|
|
16
18
|
export type { ReleaseCandidate, ReleaseOptions, ReleaseTrait, ReleaseWay } from "./release.js";
|
|
17
19
|
export { packageCodeId } from "./implementation.js";
|
|
@@ -20,5 +22,5 @@ export type { PackageCacheKey } from "./package-cache.js";
|
|
|
20
22
|
export { findPackageRoot, reparsedWithJsDoc } from "./backend/package-source.js";
|
|
21
23
|
export { openPackageSource } from "./backend/typescript6.js";
|
|
22
24
|
export type { PackageSource } from "./backend/typescript6.js";
|
|
23
|
-
export type { BooleanOption, CheckNotes, CheckResult, Config, ConfigOverride, CoveredNoun, CoveredPlace, EditorAction, EditorContributions, EditorHint, ExtendedConfig, FileContext, FactSource, FileRule, Finding, FunctionFacts, LibraryTypes, LibraryUse, MissingTypes, PackageFactsConfig, Fix, FixForm, FixReview, FixSetReview, FixVerdict, RejectedFix, GroupIdOf, HiddenFindings, IgnoreOptions, IgnoredFinding, Json, Literal, NarrowedMembers, SignalParameter, StatedGuarantee, TraitSource, ReleaseFact, NoOptions, NumberOption, OptionSpec, RecordOption, SeveritiesOption, SeverityMap, StringListRecord, OptionSpecs, OptionValue, OptionValueOf, Options, OptionsOf, NarrowingTest, OverrideOf, Location, ParseResult, Plugin, PluginOf, PluginsOf, Preset, ProjectContext, ProjectRule, RelatedLocation, ReportProblem, LazyRule, PluginRule, Rule, RuleConfig, RuleDeclaration, RuleIdOf, RuleInfo, RuleMeta, RuleSelection, RuleSetting, RuleTier, Severity, StringOption, StringsOption, SymbolRef, AliasRef, TextEdit, TokenType, TypeQueries, UnknownsSetting, UserConfig, } from "./types.js";
|
|
25
|
+
export type { BooleanOption, CheckNotes, CheckResult, Config, ConfigOverride, CoveredNoun, CoveredPlace, EditorAction, EditorContributions, EditorHint, ExtendedConfig, FileContext, FactSource, FileRule, Finding, FunctionFacts, LibraryTypes, LibraryUse, MissingTypes, PackageFactsConfig, Fix, FixForm, FixReview, FixSetReview, FixVerdict, FlowKind, FlowVia, RejectedFix, GroupIdOf, HiddenFindings, IgnoreOptions, IgnoredFinding, Json, Ledger, LedgerMark, LedgerRef, Literal, NarrowedMembers, SignalParameter, StatedDeclaration, StatedGuarantee, StatedReference, UncheckedPlace, TraitSource, ReleaseFact, NoOptions, NumberOption, OptionSpec, RecordOption, SeveritiesOption, SeverityMap, StringListRecord, OptionSpecs, OptionValue, OptionValueOf, Options, OptionsOf, NarrowingTest, OverrideOf, Location, ParseResult, Plugin, PluginOf, PluginsOf, Preset, ProjectContext, ProjectRule, RelatedLocation, ReadOutcome, ReferenceForm, ReportProblem, LazyRule, PluginRule, Rule, RuleConfig, RuleDeclaration, RuleIdOf, RuleInfo, RuleMeta, RuleProves, RuleSelection, RuleSetting, RuleTier, Severity, StringOption, StringsOption, SymbolRef, AliasRef, TextEdit, TokenType, TypeQueries, UnknownsSetting, UserConfig, } from "./types.js";
|
|
24
26
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
export { defaults, defineConfig, parseConfig } from "./config.js";
|
|
5
5
|
export { matchesFile, matchesName, option } from "./options.js";
|
|
6
6
|
export { defineRule, definePlugin } from "./define.js";
|
|
7
|
+
// The id of a stated declaration, which `StatedGuarantee.declaration` and `Finding.guarantees` name.
|
|
8
|
+
export { declarationId } from "./stated.js";
|
|
7
9
|
export { lazyRule, moduleLoader } from "./lazy.js";
|
|
8
10
|
// Running a check from code: what the testing helper (`@stateward/core/testing`) is built on.
|
|
9
11
|
export { check, createChecker } from "./checker.js";
|
|
@@ -14,6 +16,8 @@ export { highestUncovered, shortestPath } from "./tree.js";
|
|
|
14
16
|
export { describeRelease, describeTraitSource, releaseCandidates, releaseTraitOf, } from "./release.js";
|
|
15
17
|
// Facts about packages: the config's and the shipped lines, and the promises they say never reject.
|
|
16
18
|
export { neverRejectsFactOf } from "./package-facts.js";
|
|
19
|
+
// The platform calls that do not throw: the closed list the proofs share.
|
|
20
|
+
export { isSafePlatformCall, iteratesPlainly } from "./safe-calls.js";
|
|
17
21
|
// What a pack learns about a library's code, cached outside the project.
|
|
18
22
|
export { packageCodeId } from "./implementation.js";
|
|
19
23
|
export { readPackageCache, writePackageCache } from "./package-cache.js";
|
package/dist/internal.d.ts
CHANGED
|
@@ -16,7 +16,8 @@ export { LOOSE_NULLS_FIX, MAX_FINDINGS_PER_RULE_PER_FILE, STRICT_NULLS_REMEDY, a
|
|
|
16
16
|
export type { CheckProgress } from "./engine.js";
|
|
17
17
|
export { SLICE_MS } from "./checker.js";
|
|
18
18
|
export { counted, describeStatus, guaranteeAt, proveGuarantees } from "./guarantees.js";
|
|
19
|
-
export
|
|
19
|
+
export { STATED_RULE_ID } from "./stated.js";
|
|
20
|
+
export type { GuaranteeProof, GuaranteeStatus, IgnoredProblem, ProofInputs } from "./guarantees.js";
|
|
20
21
|
export type { LongestStep, SliceOptions, SlicedCheck } from "./checker.js";
|
|
21
22
|
export { IGNORE_FIX_TITLE, IGNORE_RULE_ID, ignoreFix } from "./ignores.js";
|
|
22
23
|
export { CACHE_FORMAT, emptyCache, parseSnapshot, toSnapshot } from "./cache.js";
|
package/dist/internal.js
CHANGED
|
@@ -15,6 +15,7 @@ export { findConfigFile, findConfigUpward, loadConfig, loadConfigFile, reloadsLo
|
|
|
15
15
|
export { LOOSE_NULLS_FIX, MAX_FINDINGS_PER_RULE_PER_FILE, STRICT_NULLS_REMEDY, activeRuleIds, compareFindings, explain, limitFindings, } from "./engine.js";
|
|
16
16
|
export { SLICE_MS } from "./checker.js";
|
|
17
17
|
export { counted, describeStatus, guaranteeAt, proveGuarantees } from "./guarantees.js";
|
|
18
|
+
export { STATED_RULE_ID } from "./stated.js";
|
|
18
19
|
export { IGNORE_FIX_TITLE, IGNORE_RULE_ID, ignoreFix } from "./ignores.js";
|
|
19
20
|
export { CACHE_FORMAT, emptyCache, parseSnapshot, toSnapshot } from "./cache.js";
|
|
20
21
|
export { stronglyConnectedComponents } from "./graph.js";
|
package/dist/ledger.d.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { RuleMark, RuleResult } from "./cache.js";
|
|
2
|
+
import type { LedgerMark, LedgerRef, RuleProves, StatedGuarantee, TypeQueries, UncheckedPlace } from "./types.js";
|
|
3
|
+
import type ts from "typescript";
|
|
4
|
+
/** The traits the active rules prove, joined and sorted: what the ledger lists references for. */
|
|
5
|
+
export type JoinedProves = {
|
|
6
|
+
readonly traits: readonly string[];
|
|
7
|
+
readonly returns: readonly string[];
|
|
8
|
+
readonly made: readonly string[];
|
|
9
|
+
readonly holders: readonly string[];
|
|
10
|
+
readonly flows: {
|
|
11
|
+
readonly produced: readonly string[];
|
|
12
|
+
readonly decided: readonly string[];
|
|
13
|
+
readonly escaped: readonly string[];
|
|
14
|
+
};
|
|
15
|
+
/** JSDoc tag names, without `@` (`RuleProves.tags`). */
|
|
16
|
+
readonly tags: readonly string[];
|
|
17
|
+
};
|
|
18
|
+
/** The trait a JSDoc tag states in the ledger: `@neverRejects`. */
|
|
19
|
+
export declare function tagTrait(tag: string): string;
|
|
20
|
+
/** The traits the active rules prove, joined and sorted: what the ledger lists references for. */
|
|
21
|
+
export declare function provesOf(all: readonly (RuleProves | undefined)[]): JoinedProves;
|
|
22
|
+
/**
|
|
23
|
+
* The rule that proves each tag trait: the first of `rules` (sorted by id) whose `proves.tags`
|
|
24
|
+
* lists the tag.
|
|
25
|
+
*/
|
|
26
|
+
export declare function tagRulesOf(rules: readonly {
|
|
27
|
+
readonly id: string;
|
|
28
|
+
readonly proves: RuleProves | undefined;
|
|
29
|
+
}[]): Readonly<Record<string, string>> | undefined;
|
|
30
|
+
/** Every trait of `proves`, sorted and each once. */
|
|
31
|
+
export declare function ledgerTraits(proves: JoinedProves): readonly string[];
|
|
32
|
+
/** The key of a file's ledger in its cache entry: it changes with the traits it lists. */
|
|
33
|
+
export declare function ledgerKey(proves: JoinedProves): string;
|
|
34
|
+
/**
|
|
35
|
+
* The ledger of one file, read from its cache entry when it has it, else from the program (`read`
|
|
36
|
+
* gives the file's queries and source, and is only called then). A reference to a declaration of
|
|
37
|
+
* another file asks for that declaration (`declarationOf`), so the entry holds only while the
|
|
38
|
+
* declaring file is as it was: its offsets are in the ledger. `stored` is true when this call added
|
|
39
|
+
* it to `results`; a ledger of other traits is dropped then.
|
|
40
|
+
*/
|
|
41
|
+
export declare function fileLedger(results: Map<string, RuleResult>, key: string, read: () => {
|
|
42
|
+
types: TypeQueries;
|
|
43
|
+
sourceFile: ts.SourceFile;
|
|
44
|
+
} | undefined, proves: JoinedProves): {
|
|
45
|
+
refs: readonly LedgerRef[];
|
|
46
|
+
stored: boolean;
|
|
47
|
+
};
|
|
48
|
+
/** Whether a cache entry's key is a ledger's, not a rule's result. */
|
|
49
|
+
export declare function isLedgerKey(key: string): boolean;
|
|
50
|
+
/** A rule's marks with its id, for the run's ledger. */
|
|
51
|
+
export declare function withRule(ruleId: string, marks: readonly RuleMark[]): LedgerMark[];
|
|
52
|
+
/** Why a place past where the file's scan stopped is not checked: the uses after it are not read. */
|
|
53
|
+
export declare function stoppedReason(ref: LedgerRef): string;
|
|
54
|
+
/**
|
|
55
|
+
* "`w = watchPrices` (another name for it) is a use of `watchPrices` that stateward does not read
|
|
56
|
+
* for `Release`: write it the way `stateward explain ownership/resource-not-released` shows".
|
|
57
|
+
*/
|
|
58
|
+
export declare function unreadReason(ref: LedgerRef, ruleId: string): string;
|
|
59
|
+
/** The ledger as a proof reads it: the references of each declaration, and the marks on each. */
|
|
60
|
+
export type LedgerIndex = {
|
|
61
|
+
readonly traits: ReadonlySet<string>;
|
|
62
|
+
refsOf(declaration: string, trait: string): readonly LedgerRef[];
|
|
63
|
+
/** The places of a guarantee's references that its rule did not read. */
|
|
64
|
+
uncheckedOf(guarantee: StatedGuarantee, refs: readonly LedgerRef[]): readonly UncheckedPlace[];
|
|
65
|
+
};
|
|
66
|
+
export declare function indexLedger(ledger: {
|
|
67
|
+
readonly traits: readonly string[];
|
|
68
|
+
readonly refs: readonly LedgerRef[];
|
|
69
|
+
readonly marks: readonly LedgerMark[];
|
|
70
|
+
}): LedgerIndex;
|
|
71
|
+
/**
|
|
72
|
+
* A guarantee for each declaration the ledger has references to and no plugin or core scan lists
|
|
73
|
+
* (by its id and trait): it reads "not checked" (never "unused", never "proven") until a rule lists
|
|
74
|
+
* it. A tag trait's declaration is listed for the rule that proves the tag (`tagRules`).
|
|
75
|
+
*/
|
|
76
|
+
export declare function ledgerGuarantees(refs: readonly LedgerRef[], listed: readonly StatedGuarantee[], tagRules?: Readonly<Record<string, string>>): StatedGuarantee[];
|
|
77
|
+
//# sourceMappingURL=ledger.d.ts.map
|