@stateward/core 1.2.1 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/dist/analyses.d.ts +37 -0
  2. package/dist/analyses.js +57 -0
  3. package/dist/backend/program-record.d.ts +7 -0
  4. package/dist/backend/typescript6.d.ts +35 -32
  5. package/dist/backend/typescript6.js +3804 -163
  6. package/dist/baseline.d.ts +1 -1
  7. package/dist/baseline.js +14 -10
  8. package/dist/cache.d.ts +89 -5
  9. package/dist/cache.js +271 -40
  10. package/dist/checker.d.ts +11 -1
  11. package/dist/checker.js +32 -2
  12. package/dist/class-id.d.ts +34 -0
  13. package/dist/class-id.js +93 -0
  14. package/dist/code-text.d.ts +8 -0
  15. package/dist/code-text.js +66 -0
  16. package/dist/config-file.js +7 -5
  17. package/dist/config.d.ts +10 -2
  18. package/dist/config.js +541 -49
  19. package/dist/define.d.ts +8 -2
  20. package/dist/disk-cache.d.ts +2 -0
  21. package/dist/disk-cache.js +77 -11
  22. package/dist/engine.d.ts +51 -1
  23. package/dist/engine.js +517 -42
  24. package/dist/fact-lines.d.ts +31 -0
  25. package/dist/fact-lines.js +197 -0
  26. package/dist/facts-versions.d.ts +27 -0
  27. package/dist/facts-versions.js +99 -0
  28. package/dist/fixes.js +9 -4
  29. package/dist/guarantees.d.ts +63 -11
  30. package/dist/guarantees.js +151 -21
  31. package/dist/ignores.d.ts +11 -0
  32. package/dist/ignores.js +74 -27
  33. package/dist/implementation.d.ts +0 -6
  34. package/dist/implementation.js +0 -17
  35. package/dist/index.d.ts +10 -9
  36. package/dist/index.js +14 -7
  37. package/dist/internal.d.ts +9 -5
  38. package/dist/internal.js +6 -3
  39. package/dist/lazy.d.ts +8 -1
  40. package/dist/lazy.js +27 -2
  41. package/dist/ledger.d.ts +77 -0
  42. package/dist/ledger.js +423 -0
  43. package/dist/off-by-default.d.ts +13 -0
  44. package/dist/off-by-default.js +15 -0
  45. package/dist/options.d.ts +21 -5
  46. package/dist/options.js +22 -7
  47. package/dist/package-facts.d.ts +211 -17
  48. package/dist/package-facts.js +520 -38
  49. package/dist/plan.d.ts +1 -1
  50. package/dist/plan.js +7 -2
  51. package/dist/release.d.ts +12 -21
  52. package/dist/release.js +28 -38
  53. package/dist/renamed.d.ts +22 -3
  54. package/dist/renamed.js +50 -16
  55. package/dist/rollout.js +7 -4
  56. package/dist/safe-calls.d.ts +26 -0
  57. package/dist/safe-calls.js +345 -0
  58. package/dist/severity.d.ts +1 -1
  59. package/dist/severity.js +17 -3
  60. package/dist/stated.d.ts +37 -0
  61. package/dist/stated.js +123 -0
  62. package/dist/test-runner.d.ts +18 -0
  63. package/dist/test-runner.js +483 -0
  64. package/dist/testing-tsc.d.ts +16 -0
  65. package/dist/testing-tsc.js +86 -0
  66. package/dist/testing.d.ts +5 -4
  67. package/dist/testing.js +6 -6
  68. package/dist/timing.d.ts +15 -0
  69. package/dist/timing.js +41 -2
  70. package/dist/types.d.ts +1068 -16
  71. package/dist/unread.d.ts +90 -0
  72. package/dist/unread.js +405 -0
  73. package/dist/vocabulary.d.ts +1 -1
  74. package/dist/vocabulary.js +1 -1
  75. package/package.json +4 -2
@@ -0,0 +1,31 @@
1
+ import type { FactNeed } from "./types.js";
2
+ /** Which line to write: the call throws nothing, or it throws a class the developer names. */
3
+ export type FactChoice = "nothing" | "classes";
4
+ export declare const FACT_CHOICES: readonly FactChoice[];
5
+ /** One edit to the config file's text: replace `start`–`end` with `newText`. */
6
+ export type ConfigEdit = {
7
+ readonly start: number;
8
+ readonly end: number;
9
+ readonly newText: string;
10
+ };
11
+ /** A line offered for a need: its title, as the editor's menu and `check --fix` show it, and its edit. */
12
+ export type FactLineFix = {
13
+ readonly title: string;
14
+ readonly need: FactNeed;
15
+ readonly choice: FactChoice;
16
+ readonly edit: ConfigEdit;
17
+ };
18
+ /** The title of a choice: "state that `Repository.save` throws nothing". */
19
+ export declare function factChoiceTitle(need: FactNeed, choice: FactChoice): string;
20
+ /** How keys are written: quoted in JSON, as identifiers where they can be in code. */
21
+ type Style = "json" | "code";
22
+ /** The value of a line: `{ throws: [] }`, or `{ rejects: ["ErrorClass"] }`. */
23
+ export declare function factValueText(need: FactNeed, choice: FactChoice, style?: Style): string;
24
+ /** The edit that writes `need`'s line into the config text, or undefined when it cannot be placed. */
25
+ export declare function factLineEdit(configFile: string, text: string, need: FactNeed, choice: FactChoice): ConfigEdit | undefined;
26
+ /** The lines offered for a finding's needs, each choice of each need that can be placed. */
27
+ export declare function factLineFixes(configFile: string, text: string, needs: readonly FactNeed[]): FactLineFix[];
28
+ /** The text with one edit made. */
29
+ export declare function applyConfigEdit(text: string, edit: ConfigEdit): string;
30
+ export {};
31
+ //# sourceMappingURL=fact-lines.d.ts.map
@@ -0,0 +1,197 @@
1
+ /**
2
+ * The `facts` lines a "not checked" finding needs (`Finding.needs`), written into the config file
3
+ * (R128): a line that says the call throws nothing, or one that leaves the class for the developer
4
+ * (`PLACEHOLDER_CLASS`). stateward never chooses a class. The edit is made only where the config
5
+ * states its `facts` as plain object literals; anything computed (a spread, a computed key, a value
6
+ * from elsewhere) gives no edit, as the line could not be placed safely.
7
+ */
8
+ import ts from "typescript";
9
+ import { VERSIONS_KEY } from "./config.js";
10
+ import { PLACEHOLDER_CLASS, factKeyText } from "./package-facts.js";
11
+ export const FACT_CHOICES = ["nothing", "classes"];
12
+ /** `throws`, `rejects`, or both, as the title names them. */
13
+ function verbOf(need) {
14
+ const throws = need.states.includes("throws");
15
+ const rejects = need.states.includes("rejects");
16
+ return throws && rejects ? "throws or rejects with" : throws ? "throws" : "rejects with";
17
+ }
18
+ /** The title of a choice: "state that `Repository.save` throws nothing". */
19
+ export function factChoiceTitle(need, choice) {
20
+ return choice === "nothing"
21
+ ? `state that \`${need.name}\` ${verbOf(need)} nothing`
22
+ : `state what \`${need.name}\` ${verbOf(need)}…`;
23
+ }
24
+ function keyText(key, style) {
25
+ return style === "code" ? factKeyText(key) : JSON.stringify(key);
26
+ }
27
+ /** The value of a line: `{ throws: [] }`, or `{ rejects: ["ErrorClass"] }`. */
28
+ export function factValueText(need, choice, style = "code") {
29
+ const list = choice === "nothing" ? "[]" : `[${JSON.stringify(PLACEHOLDER_CLASS)}]`;
30
+ return `{ ${need.states.map((side) => `${keyText(side, style)}: ${list}`).join(", ")} }`;
31
+ }
32
+ /** The property of the line under its module: `"Repository.save": { rejects: [] }`. */
33
+ function lineText(need, choice, style) {
34
+ return `${keyText(need.name, style)}: ${factValueText(need, choice, style)}`;
35
+ }
36
+ /** The module's properties for a new table: its version first, when known, then the line. */
37
+ function tableText(need, choice, style) {
38
+ const version = need.version === undefined
39
+ ? []
40
+ : [`${keyText(VERSIONS_KEY, style)}: ${JSON.stringify(need.version)}`];
41
+ return `{ ${[...version, lineText(need, choice, style)].join(", ")} }`;
42
+ }
43
+ function unwrapped(node) {
44
+ let current = node;
45
+ while (ts.isParenthesizedExpression(current) ||
46
+ ts.isAsExpression(current) ||
47
+ ts.isSatisfiesExpression(current) ||
48
+ ts.isTypeAssertionExpression(current)) {
49
+ current = current.expression;
50
+ }
51
+ return current;
52
+ }
53
+ /** The `const` a name of the file is declared with, when it has an initializer. */
54
+ function constInitializer(file, name) {
55
+ for (const statement of file.statements) {
56
+ if (!ts.isVariableStatement(statement))
57
+ continue;
58
+ if ((statement.declarationList.flags & ts.NodeFlags.Const) === 0)
59
+ continue;
60
+ for (const declaration of statement.declarationList.declarations) {
61
+ if (ts.isIdentifier(declaration.name) && declaration.name.text === name) {
62
+ return declaration.initializer;
63
+ }
64
+ }
65
+ }
66
+ return undefined;
67
+ }
68
+ /**
69
+ * The object literal a config expression is: the literal itself, the one argument of a call
70
+ * (`defineConfig({ … })`), or the literal a `const` of the file holds.
71
+ */
72
+ function objectOf(file, node) {
73
+ const expression = unwrapped(node);
74
+ if (ts.isObjectLiteralExpression(expression))
75
+ return expression;
76
+ if (ts.isCallExpression(expression) && expression.arguments.length === 1) {
77
+ const [only] = expression.arguments;
78
+ return only === undefined ? undefined : objectOf(file, only);
79
+ }
80
+ if (ts.isIdentifier(expression)) {
81
+ const initializer = constInitializer(file, expression.text);
82
+ return initializer === undefined ? undefined : objectOf(file, initializer);
83
+ }
84
+ return undefined;
85
+ }
86
+ /** The config's object: the JSON's root, `export default …` or `module.exports = …`. */
87
+ function configObject(file, style) {
88
+ for (const statement of file.statements) {
89
+ if (style === "json" && ts.isExpressionStatement(statement)) {
90
+ return objectOf(file, statement.expression);
91
+ }
92
+ if (ts.isExportAssignment(statement))
93
+ return objectOf(file, statement.expression);
94
+ if (ts.isExpressionStatement(statement) &&
95
+ ts.isBinaryExpression(statement.expression) &&
96
+ statement.expression.operatorToken.kind === ts.SyntaxKind.EqualsToken &&
97
+ statement.expression.left.getText(file) === "module.exports") {
98
+ return objectOf(file, statement.expression.right);
99
+ }
100
+ }
101
+ return undefined;
102
+ }
103
+ function nameOf(property) {
104
+ if (!ts.isPropertyAssignment(property) && !ts.isShorthandPropertyAssignment(property)) {
105
+ return undefined;
106
+ }
107
+ const { name } = property;
108
+ return ts.isIdentifier(name) ||
109
+ ts.isStringLiteral(name) ||
110
+ ts.isNoSubstitutionTemplateLiteral(name)
111
+ ? name.text
112
+ : undefined;
113
+ }
114
+ /**
115
+ * The property named `key` of an object whose every property has a plain name: `found` with its
116
+ * value when it is an object literal, `absent`, or undefined when the object cannot be read safely
117
+ * (a spread, a computed name, a method) or the value is not an object literal.
118
+ */
119
+ function propertyOf(object, key) {
120
+ if (object.properties.some((property) => nameOf(property) === undefined))
121
+ return undefined;
122
+ const property = object.properties.find((one) => nameOf(one) === key);
123
+ if (property === undefined)
124
+ return { kind: "absent" };
125
+ if (!ts.isPropertyAssignment(property))
126
+ return undefined;
127
+ const value = unwrapped(property.initializer);
128
+ return ts.isObjectLiteralExpression(value) ? { kind: "found", value } : undefined;
129
+ }
130
+ /** The indentation of the line `offset` is on. */
131
+ function indentAt(text, offset) {
132
+ const start = text.lastIndexOf("\n", offset - 1) + 1;
133
+ return /^[ \t]*/.exec(text.slice(start))?.[0] ?? "";
134
+ }
135
+ /**
136
+ * The edit that adds `property` to `object`: after its last property (with a comma), on a new
137
+ * line with the same indentation when the object spans lines, or inside `{}` when it is empty.
138
+ */
139
+ function insertInto(file, object, property) {
140
+ const text = file.text;
141
+ const last = object.properties.at(-1);
142
+ const close = object.getEnd() - 1;
143
+ if (last === undefined) {
144
+ return { start: object.getStart(file), end: object.getEnd(), newText: `{ ${property} }` };
145
+ }
146
+ const comma = object.properties.hasTrailingComma;
147
+ const after = last.getEnd() + (comma ? text.indexOf(",", last.getEnd()) - last.getEnd() + 1 : 0);
148
+ const multiline = text.slice(object.getStart(file), close).includes("\n");
149
+ if (!multiline)
150
+ return { start: last.getEnd(), end: last.getEnd(), newText: `, ${property}` };
151
+ const indent = indentAt(text, last.getStart(file));
152
+ return {
153
+ start: after,
154
+ end: after,
155
+ newText: `${comma ? "" : ","}\n${indent}${property}${comma ? "," : ""}`,
156
+ };
157
+ }
158
+ /** The edit that writes `need`'s line into the config text, or undefined when it cannot be placed. */
159
+ export function factLineEdit(configFile, text, need, choice) {
160
+ const style = configFile.endsWith(".json") ? "json" : "code";
161
+ const file = ts.createSourceFile(configFile, text, ts.ScriptTarget.Latest, true, style === "json" ? ts.ScriptKind.JSON : ts.ScriptKind.TS);
162
+ const config = configObject(file, style);
163
+ if (config === undefined)
164
+ return undefined;
165
+ const facts = propertyOf(config, "facts");
166
+ if (facts === undefined)
167
+ return undefined;
168
+ if (facts.kind === "absent") {
169
+ const table = `${keyText(need.module, style)}: ${tableText(need, choice, style)}`;
170
+ return insertInto(file, config, `${keyText("facts", style)}: { ${table} }`);
171
+ }
172
+ const table = propertyOf(facts.value, need.module);
173
+ if (table === undefined)
174
+ return undefined;
175
+ if (table.kind === "absent") {
176
+ return insertInto(file, facts.value, `${keyText(need.module, style)}: ${tableText(need, choice, style)}`);
177
+ }
178
+ const line = propertyOf(table.value, need.name);
179
+ // A line for the call is there already: it is not stated twice.
180
+ if (line === undefined || line.kind === "found")
181
+ return undefined;
182
+ return insertInto(file, table.value, lineText(need, choice, style));
183
+ }
184
+ /** The lines offered for a finding's needs, each choice of each need that can be placed. */
185
+ export function factLineFixes(configFile, text, needs) {
186
+ return needs.flatMap((need) => FACT_CHOICES.flatMap((choice) => {
187
+ const edit = factLineEdit(configFile, text, need, choice);
188
+ return edit === undefined
189
+ ? []
190
+ : [{ title: factChoiceTitle(need, choice), need, choice, edit }];
191
+ }));
192
+ }
193
+ /** The text with one edit made. */
194
+ export function applyConfigEdit(text, edit) {
195
+ return text.slice(0, edit.start) + edit.newText + text.slice(edit.end);
196
+ }
197
+ //# sourceMappingURL=fact-lines.js.map
@@ -0,0 +1,27 @@
1
+ import type { PackageFactsConfig, VerifiedFacts, WithheldFacts } from "./types.js";
2
+ /** The facts a file's rules read: those that hold for its project's versions, and those left out. */
3
+ export type FileFacts = {
4
+ readonly facts: PackageFactsConfig;
5
+ readonly shippedFacts: PackageFactsConfig;
6
+ readonly withheldFacts: readonly WithheldFacts[];
7
+ };
8
+ /** The facts of each file, and what they depend on besides the file, for the cache key. */
9
+ export type FactsGate = {
10
+ at(file: string): FileFacts;
11
+ /** The ranges, and what they decide at the config's folder. */
12
+ readonly key: unknown;
13
+ };
14
+ /** `` `0.3.17` to `1.1.2` `` for `>=0.3.17 <=1.1.2`; any other range as written, in backticks. */
15
+ export declare function rangeText(range: string): string;
16
+ /**
17
+ * The gate of a check: `facts` (the config's, `versions` by package) and `shipped` (the packs',
18
+ * `verified` by package), decided once per folder.
19
+ */
20
+ export declare function factsGate(input: {
21
+ readonly facts: PackageFactsConfig;
22
+ readonly versions: Readonly<Record<string, string>>;
23
+ readonly shipped: PackageFactsConfig;
24
+ readonly verified: Readonly<Record<string, VerifiedFacts>>;
25
+ readonly configDir: string;
26
+ }): FactsGate;
27
+ //# sourceMappingURL=facts-versions.d.ts.map
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Facts lines are tied to the versions of their package they hold for: the config's by
3
+ * `"@versions"`, a pack's by `Plugin.factsVerified`. In a file whose project runs another version,
4
+ * or one whose version is not known, a package's lines are left out (`WithheldFacts`), so a call
5
+ * they would name is "not checked" instead of read with facts of another version.
6
+ */
7
+ import path from "node:path";
8
+ import { packageOfModule } from "./package-facts.js";
9
+ import { packageVersionOf, versionSatisfies } from "./unread.js";
10
+ /** `` `0.3.17` to `1.1.2` `` for `>=0.3.17 <=1.1.2`; any other range as written, in backticks. */
11
+ export function rangeText(range) {
12
+ const bounds = /^>=\s*(\S+)\s+<=\s*(\S+)$/.exec(range.trim());
13
+ return bounds?.[1] !== undefined && bounds[2] !== undefined
14
+ ? `\`${bounds[1]}\` to \`${bounds[2]}\``
15
+ : `\`${range}\``;
16
+ }
17
+ /** What the project runs, after "; ": `the project has \`3.4.1\``. */
18
+ function runsText(read) {
19
+ if (read.kind === "exact")
20
+ return `the project has \`${read.version}\``;
21
+ if (read.kind === "range")
22
+ return `the project's package.json allows \`${read.range}\``;
23
+ return read.reason;
24
+ }
25
+ function withheld(source, key, range, functions, read, answer) {
26
+ const runs = runsText(read);
27
+ // Outside the range: what to change in the facts. Not known: what makes the version known.
28
+ const notKnown = answer === false
29
+ ? undefined
30
+ : (answer.hint ?? `install \`${key}\`, so the version it runs is known`);
31
+ if (source === "config") {
32
+ return {
33
+ package: key,
34
+ source,
35
+ functions,
36
+ reason: `the facts stated for \`${key}\` are for ${rangeText(range)}; ${runs}`,
37
+ hint: notKnown ??
38
+ `check the facts for \`${key}\` against the version the project runs, then add that version to their \`"@versions"\``,
39
+ };
40
+ }
41
+ return {
42
+ package: key,
43
+ source,
44
+ functions,
45
+ reason: `stateward's facts for \`${key}\` were verified on ${rangeText(range)}; ${runs}`,
46
+ hint: notKnown ??
47
+ `state the facts for \`${key}\` in the config's \`facts\`, with \`"@versions"\` set to the versions they hold for`,
48
+ };
49
+ }
50
+ /**
51
+ * The gate of a check: `facts` (the config's, `versions` by package) and `shipped` (the packs',
52
+ * `verified` by package), decided once per folder.
53
+ */
54
+ export function factsGate(input) {
55
+ const ranged = (facts, rangeOf) => Object.keys(facts).flatMap((key) => {
56
+ const range = rangeOf(key);
57
+ return range === undefined ? [] : [[key, range]];
58
+ });
59
+ const own = ranged(input.facts, (key) => input.versions[key]);
60
+ const packs = ranged(input.shipped, (key) => (input.verified[key] ?? input.verified[packageOfModule(key)])?.verified);
61
+ const all = { facts: input.facts, shippedFacts: input.shipped, withheldFacts: [] };
62
+ if (own.length === 0 && packs.length === 0)
63
+ return { at: () => all, key: [] };
64
+ const byFolder = new Map();
65
+ const decide = (file) => {
66
+ const folder = path.dirname(file);
67
+ const known = byFolder.get(folder);
68
+ if (known !== undefined)
69
+ return known;
70
+ const left = [];
71
+ const filter = (source, facts, pairs) => {
72
+ const out = new Set();
73
+ for (const [key, range] of pairs) {
74
+ const read = packageVersionOf({ file }, packageOfModule(key));
75
+ const answer = versionSatisfies(read, range);
76
+ if (answer === true)
77
+ continue;
78
+ out.add(key);
79
+ left.push(withheld(source, key, range, facts[key] ?? {}, read, answer));
80
+ }
81
+ return out.size === 0
82
+ ? facts
83
+ : Object.fromEntries(Object.entries(facts).filter(([key]) => !out.has(key)));
84
+ };
85
+ const made = {
86
+ facts: filter("config", input.facts, own),
87
+ shippedFacts: filter("shipped", input.shipped, packs),
88
+ withheldFacts: left,
89
+ };
90
+ byFolder.set(folder, made);
91
+ return made;
92
+ };
93
+ const atConfig = decide(path.join(input.configDir, "stateward.config.ts"));
94
+ return {
95
+ at: decide,
96
+ key: [own, packs, atConfig.withheldFacts.map((one) => [one.source, one.package, one.reason])],
97
+ };
98
+ }
99
+ //# sourceMappingURL=facts-versions.js.map
package/dist/fixes.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { toTypeScriptPath } from "./backend/typescript6.js";
2
- import { sha1 } from "./cache.js";
2
+ import { sha1, useKey } from "./cache.js";
3
3
  function spanOf(edit) {
4
4
  const { file, start, end } = edit.location;
5
5
  return { file: toTypeScriptPath(file), start, end, newText: edit.newText };
@@ -87,6 +87,8 @@ function tryInUnit(unit, trials, cache) {
87
87
  }
88
88
  const key = verdictKey(unit, form);
89
89
  const known = key === undefined ? undefined : cache.verdicts.get(key);
90
+ if (key !== undefined)
91
+ useKey(cache, key);
90
92
  if (known !== undefined)
91
93
  settle(trial, known);
92
94
  }
@@ -116,6 +118,7 @@ function tryInUnit(unit, trials, cache) {
116
118
  const plain = verdict.kind !== "compiles" || verdict.removesImports === undefined;
117
119
  if (key !== undefined && verdict.kind !== "unchecked" && plain) {
118
120
  cache.verdicts.set(key, verdict);
121
+ useKey(cache, key);
119
122
  cache.changed = true;
120
123
  }
121
124
  settle(trial, verdict);
@@ -171,13 +174,15 @@ export function reviewFixes(findings, units, cache) {
171
174
  unchecked.push(outcome.form);
172
175
  }
173
176
  const rejected = mine.flatMap((trial) => trial.rejected);
174
- const [first] = rejected;
175
- const noFix = offered.length === 0 && unchecked.length === 0 && first !== undefined;
177
+ // The last form of the first fix is the one that goes furthest (it also writes what the
178
+ // earlier forms expect to find), so its error is the one that is left to fix.
179
+ const last = mine.find((trial) => trial.rejected.length > 0)?.rejected.at(-1);
180
+ const noFix = offered.length === 0 && unchecked.length === 0 && last !== undefined;
176
181
  return {
177
182
  finding: {
178
183
  ...finding,
179
184
  fixes: offered,
180
- hint: noFix ? `${finding.hint}\nno automatic fix: ${first.reason}` : finding.hint,
185
+ hint: noFix ? `${finding.hint}\nno automatic fix: ${last.reason}` : finding.hint,
181
186
  },
182
187
  unchecked,
183
188
  rejected,
@@ -1,41 +1,93 @@
1
- import type { CoveredNoun, Finding, StatedGuarantee } from "./types.js";
1
+ import type { CoveredNoun, Finding, IgnoredFinding, Ledger, Location, StatedGuarantee, UncheckedPlace } from "./types.js";
2
2
  type Problem = Extract<Finding, {
3
3
  kind: "problem";
4
4
  }>;
5
5
  /**
6
6
  * Where a stated guarantee stands after a check:
7
- * - `proven`: its rule ran and reported nothing about it;
8
- * - `unproven`: its rule reported these errors about it (each names the declaration);
9
- * - `unused`: nothing uses it, so there is nothing to prove (a dead marker);
10
- * - `off`: its rule is not on (the rollout has not reached it), so nothing proves it.
7
+ * - `proven`: its rule ran everywhere the guarantee reaches and no finding stands against it,
8
+ * whatever the ignore comments and settings say;
9
+ * - `unproven`: its rule reported these errors about it (each names the declaration), or an
10
+ * ignore comment hides these findings (`ignored`, each with the comment's reason): hidden from
11
+ * `check`, still not proven;
12
+ * - `unchecked`: a place uses the value in a way the rule cannot follow (`places`);
13
+ * - `unused`: no code refers to it (with a ledger, no reference to its declaration, or only
14
+ * imports, exports and types, `importsOnly`; without one, no place it covers), so there is
15
+ * nothing to prove (a dead marker);
16
+ * - `off`: its rule is not on (the rollout has not reached it), or is off for these places the
17
+ * guarantee covers (`places`, empty when off everywhere), so nothing proves it.
11
18
  */
12
19
  export type GuaranteeStatus = {
13
20
  readonly kind: "proven";
14
21
  } | {
15
22
  readonly kind: "unproven";
16
23
  readonly errors: readonly Problem[];
24
+ readonly ignored: readonly IgnoredProblem[];
25
+ } | {
26
+ readonly kind: "unchecked";
27
+ readonly places: readonly UncheckedPlace[];
17
28
  } | {
18
29
  readonly kind: "unused";
30
+ /** Only imports, exports and types refer to it: nothing that runs uses it. */
31
+ readonly importsOnly?: true;
19
32
  } | {
20
33
  readonly kind: "off";
34
+ readonly places: readonly Location[];
35
+ };
36
+ /** A finding an ignore comment hides, and the reason the comment gives ("" when it gives none). */
37
+ export type IgnoredProblem = {
38
+ readonly finding: Problem;
39
+ readonly reason: string;
21
40
  };
22
41
  export type GuaranteeProof = {
23
42
  readonly stated: StatedGuarantee;
24
43
  readonly status: GuaranteeStatus;
25
44
  };
45
+ /** What a proof reads besides the check's findings. */
46
+ export type ProofInputs = {
47
+ /**
48
+ * The findings ignore comments hide (`CheckResult.ignored`): they still stand against the
49
+ * guarantee. Empty when the check applied no ignores.
50
+ */
51
+ readonly ignored?: readonly IgnoredFinding[];
52
+ /**
53
+ * Whether the config turns a rule off for a file (an `overrides` entry, or the rule off): the
54
+ * rule never looked at the places the guarantee covers there. Absent: nowhere.
55
+ */
56
+ readonly ruleOffAt?: (ruleId: string, file: string) => boolean;
57
+ /**
58
+ * The findings of a rule the config turned off for the file they lie in, which the check left
59
+ * out (`CheckResult.silenced`): a guarantee one is linked to reads "not checked" there, never
60
+ * proven. Absent: none.
61
+ */
62
+ readonly silenced?: readonly Finding[];
63
+ /**
64
+ * The check's reference ledger (`CheckResult.ledger`): for a guarantee stated by a marker of a
65
+ * trait it lists, every reference its rule did not mark, marked not checked or only handed on is
66
+ * a place not checked, and the guarantee is unused only when it has no reference. Absent (a
67
+ * caller with no ledger): unused when the guarantee covers no place.
68
+ */
69
+ readonly ledger?: Ledger;
70
+ };
26
71
  /**
27
72
  * Each stated guarantee with its status, in file and offset order. `findings` are a check's
28
- * (after ignore comments, before a baseline: an accepted error still leaves it unproven);
29
- * `active` the rules that check ran. A finding is about a guarantee when it is a problem of the
30
- * guarantee's rule, not an info, that names its declaration in a note or lies in a place it
31
- * covers (`isAbout`).
73
+ * (after ignore comments, before a baseline: an accepted error still leaves it unproven), and
74
+ * `inputs.ignored` the ones ignore comments hid: a guarantee is proven only when no finding
75
+ * stands against it before ignores and settings. `active` the rules that check
76
+ * ran. A finding is about a guarantee when it names its declaration (`Finding.guarantees`), or,
77
+ * for a finding no rule linked, lies where the guarantee is stated or covered (`aboutByPlace`); it
78
+ * counts at any severity once linked, and unless it is a weaker signal the rule judged an info.
79
+ * An `unknown` finding that names a guarantee leaves it "not checked" at its place, whatever the
80
+ * config's `unknowns` setting shows of it. With the check's reference ledger (`inputs.ledger`), so
81
+ * does every reference to a marked declaration its rule did not read (unmarked, marked unchecked,
82
+ * or only handed on), and it is unused only when it has no reference.
32
83
  */
33
- export declare function proveGuarantees(stated: readonly StatedGuarantee[], findings: readonly Finding[], active: ReadonlySet<string>): GuaranteeProof[];
84
+ export declare function proveGuarantees(stated: readonly StatedGuarantee[], findings: readonly Finding[], active: ReadonlySet<string>, inputs?: ProofInputs): GuaranteeProof[];
34
85
  /** "1 switch", "2 switches": the count and the noun in its form for it, as the noun gives both. */
35
86
  export declare function counted(count: number, noun: CoveredNoun): string;
36
87
  /**
37
88
  * The status in a few words, the same in `stateward guarantees` and the editor: "proven for 3
38
- * readers", "not proven: 2 errors", "unused: nothing reads it", "not checked: … is not on".
89
+ * readers", "not proven: 2 errors", "not proven: 1 ignored — lives as long as the app", "unused:
90
+ * nothing reads it", "not checked: … is not on".
39
91
  */
40
92
  export declare function describeStatus(proof: GuaranteeProof): string;
41
93
  /** The guarantee whose declaration covers `offset` of `file` (a TypeScript path), if any. */