@stateward/core 1.0.1 → 1.2.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 (49) hide show
  1. package/dist/backend/fingerprints.d.ts +22 -2
  2. package/dist/backend/fingerprints.js +160 -18
  3. package/dist/backend/program-record.d.ts +1 -1
  4. package/dist/backend/qualified-ids.d.ts +6 -0
  5. package/dist/backend/qualified-ids.js +66 -10
  6. package/dist/backend/typescript6.d.ts +28 -9
  7. package/dist/backend/typescript6.js +564 -28
  8. package/dist/baseline.js +10 -0
  9. package/dist/cache.d.ts +5 -4
  10. package/dist/cache.js +2 -2
  11. package/dist/checker.d.ts +14 -2
  12. package/dist/checker.js +40 -12
  13. package/dist/config-file.d.ts +6 -0
  14. package/dist/config-file.js +21 -2
  15. package/dist/config.d.ts +3 -1
  16. package/dist/config.js +164 -17
  17. package/dist/define.d.ts +2 -1
  18. package/dist/disk-cache.d.ts +24 -2
  19. package/dist/disk-cache.js +43 -5
  20. package/dist/engine.d.ts +27 -3
  21. package/dist/engine.js +224 -57
  22. package/dist/guarantee-markers.d.ts +10 -0
  23. package/dist/guarantee-markers.js +66 -0
  24. package/dist/guarantees.d.ts +44 -0
  25. package/dist/guarantees.js +84 -0
  26. package/dist/hint-lines.d.ts +24 -0
  27. package/dist/hint-lines.js +36 -0
  28. package/dist/ignores.d.ts +2 -4
  29. package/dist/ignores.js +31 -16
  30. package/dist/implementation.js +2 -1
  31. package/dist/index.d.ts +5 -1
  32. package/dist/index.js +4 -0
  33. package/dist/internal.d.ts +8 -3
  34. package/dist/internal.js +6 -3
  35. package/dist/package-facts.d.ts +52 -0
  36. package/dist/package-facts.js +213 -0
  37. package/dist/plan.d.ts +17 -0
  38. package/dist/plan.js +22 -5
  39. package/dist/release.d.ts +68 -0
  40. package/dist/release.js +172 -0
  41. package/dist/renamed.d.ts +29 -0
  42. package/dist/renamed.js +48 -0
  43. package/dist/rollout.js +3 -1
  44. package/dist/testing-tsc.d.ts +11 -0
  45. package/dist/testing-tsc.js +125 -0
  46. package/dist/testing.d.ts +1 -0
  47. package/dist/testing.js +61 -8
  48. package/dist/types.d.ts +261 -2
  49. package/package.json +1 -1
@@ -0,0 +1,10 @@
1
+ import ts from "typescript";
2
+ import type { EditorAction } from "./types.js";
3
+ /**
4
+ * "Rewrite the guarantee markers to the 1.2 form" on a 1.1.0 marker (`readonly __guarantee?:
5
+ * "owned"`): every one in the file becomes one optional property per trait
6
+ * (`readonly "__guarantee:owned"?: true`), so traits combine by intersection. Undefined when the
7
+ * range touches none. Both forms are read; this only lets a type state two traits.
8
+ */
9
+ export declare function legacyMarkerRewrite(sourceFile: ts.SourceFile, start: number, end: number): EditorAction | undefined;
10
+ //# sourceMappingURL=guarantee-markers.d.ts.map
@@ -0,0 +1,66 @@
1
+ import ts from "typescript";
2
+ /** The 1.1.0 marker property, `__guarantee?: "owned"`, and the prefix of the 1.2 one. */
3
+ const LEGACY = "__guarantee";
4
+ const PREFIX = "__guarantee:";
5
+ /** The names a 1.1.0 marker property states, or undefined when it is not one (required, not literals). */
6
+ function legacyNames(member) {
7
+ if (!ts.isPropertySignature(member) || member.questionToken === undefined)
8
+ return undefined;
9
+ const { name, type } = member;
10
+ if (!(ts.isIdentifier(name) || ts.isStringLiteral(name)) || name.text !== LEGACY)
11
+ return undefined;
12
+ if (type === undefined)
13
+ return undefined;
14
+ const parts = ts.isUnionTypeNode(type) ? type.types : [type];
15
+ const names = [];
16
+ for (const part of parts) {
17
+ if (!ts.isLiteralTypeNode(part) || !ts.isStringLiteral(part.literal))
18
+ return undefined;
19
+ names.push(part.literal.text);
20
+ }
21
+ return names;
22
+ }
23
+ /** Every 1.1.0 marker property in the file. */
24
+ function legacyMarkers(sourceFile) {
25
+ const found = [];
26
+ const visit = (node) => {
27
+ if (ts.isPropertySignature(node) && legacyNames(node) !== undefined)
28
+ found.push(node);
29
+ ts.forEachChild(node, visit);
30
+ };
31
+ visit(sourceFile);
32
+ return found;
33
+ }
34
+ /**
35
+ * "Rewrite the guarantee markers to the 1.2 form" on a 1.1.0 marker (`readonly __guarantee?:
36
+ * "owned"`): every one in the file becomes one optional property per trait
37
+ * (`readonly "__guarantee:owned"?: true`), so traits combine by intersection. Undefined when the
38
+ * range touches none. Both forms are read; this only lets a type state two traits.
39
+ */
40
+ export function legacyMarkerRewrite(sourceFile, start, end) {
41
+ const markers = legacyMarkers(sourceFile);
42
+ const touched = markers.some((marker) => marker.getStart(sourceFile) <= end && start <= marker.getEnd());
43
+ if (!touched)
44
+ return undefined;
45
+ const edits = markers.flatMap((marker) => {
46
+ const names = legacyNames(marker) ?? [];
47
+ const readonly = marker.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ReadonlyKeyword) ===
48
+ true;
49
+ const type = marker.type;
50
+ if (type === undefined)
51
+ return [];
52
+ const from = marker.name.getStart(sourceFile);
53
+ const text = names
54
+ .map((name, index) => `${index > 0 && readonly ? "readonly " : ""}"${PREFIX}${name}"?: true`)
55
+ .join("; ");
56
+ return [{ location: { file: sourceFile.fileName, start: from, end: type.end }, newText: text }];
57
+ });
58
+ const count = markers.length;
59
+ return {
60
+ title: count === 1
61
+ ? "Rewrite the guarantee marker to the 1.2 form (one property per trait)"
62
+ : `Rewrite the ${String(count)} guarantee markers to the 1.2 form (one property per trait)`,
63
+ edits,
64
+ };
65
+ }
66
+ //# sourceMappingURL=guarantee-markers.js.map
@@ -0,0 +1,44 @@
1
+ import type { CoveredNoun, Finding, StatedGuarantee } from "./types.js";
2
+ type Problem = Extract<Finding, {
3
+ kind: "problem";
4
+ }>;
5
+ /**
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.
11
+ */
12
+ export type GuaranteeStatus = {
13
+ readonly kind: "proven";
14
+ } | {
15
+ readonly kind: "unproven";
16
+ readonly errors: readonly Problem[];
17
+ } | {
18
+ readonly kind: "unused";
19
+ } | {
20
+ readonly kind: "off";
21
+ };
22
+ export type GuaranteeProof = {
23
+ readonly stated: StatedGuarantee;
24
+ readonly status: GuaranteeStatus;
25
+ };
26
+ /**
27
+ * 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`).
32
+ */
33
+ export declare function proveGuarantees(stated: readonly StatedGuarantee[], findings: readonly Finding[], active: ReadonlySet<string>): GuaranteeProof[];
34
+ /** "1 switch", "2 switches": the count and the noun in its form for it, as the noun gives both. */
35
+ export declare function counted(count: number, noun: CoveredNoun): string;
36
+ /**
37
+ * 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".
39
+ */
40
+ export declare function describeStatus(proof: GuaranteeProof): string;
41
+ /** The guarantee whose declaration covers `offset` of `file` (a TypeScript path), if any. */
42
+ export declare function guaranteeAt(proofs: readonly GuaranteeProof[], file: string, offset: number): GuaranteeProof | undefined;
43
+ export {};
44
+ //# sourceMappingURL=guarantees.d.ts.map
@@ -0,0 +1,84 @@
1
+ import { compareFindings } from "./engine.js";
2
+ function sameStart(a, b) {
3
+ return a.file === b.file && a.start === b.start;
4
+ }
5
+ function compareStated(a, b) {
6
+ if (a.location.file !== b.location.file)
7
+ return a.location.file < b.location.file ? -1 : 1;
8
+ return a.location.start - b.location.start || (a.guarantee < b.guarantee ? -1 : 1);
9
+ }
10
+ function contains(place, inner) {
11
+ return place.file === inner.file && inner.start >= place.start && inner.end <= place.end;
12
+ }
13
+ /**
14
+ * Whether a finding is about a guarantee: a problem of the guarantee's rule with a related note
15
+ * at its declaration; or, when it has a note at no declaration of that rule, one that lies in a
16
+ * place the guarantee covers (a file rule notes only declarations in its own file, so a finding
17
+ * at a Provider in another file names the context by where it is).
18
+ */
19
+ function isAbout(finding, guarantee, declarations) {
20
+ if (finding.ruleId !== guarantee.ruleId)
21
+ return false;
22
+ if (finding.related.some((note) => sameStart(note.location, guarantee.location)))
23
+ return true;
24
+ const namesAnother = declarations.some((other) => other.ruleId === finding.ruleId &&
25
+ finding.related.some((note) => sameStart(note.location, other.location)));
26
+ return (!namesAnother && guarantee.covered.some((place) => contains(place.location, finding.location)));
27
+ }
28
+ /**
29
+ * 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
+ * `active` the rules that check ran. A finding is about a guarantee when it is a problem of the
32
+ * guarantee's rule, not an info, that names its declaration in a note or lies in a place it
33
+ * covers (`isAbout`).
34
+ */
35
+ export function proveGuarantees(stated, findings, active) {
36
+ const problems = findings
37
+ .filter((finding) => finding.kind === "problem")
38
+ .filter((finding) => finding.severity !== "info");
39
+ return [...stated].sort(compareStated).map((guarantee) => {
40
+ if (!active.has(guarantee.ruleId))
41
+ return { stated: guarantee, status: { kind: "off" } };
42
+ const errors = problems
43
+ .filter((finding) => isAbout(finding, guarantee, stated))
44
+ .sort(compareFindings);
45
+ if (errors.length > 0)
46
+ return { stated: guarantee, status: { kind: "unproven", errors } };
47
+ if (guarantee.covered.length === 0)
48
+ return { stated: guarantee, status: { kind: "unused" } };
49
+ return { stated: guarantee, status: { kind: "proven" } };
50
+ });
51
+ }
52
+ /** "1 switch", "2 switches": the count and the noun in its form for it, as the noun gives both. */
53
+ export function counted(count, noun) {
54
+ return `${String(count)} ${count === 1 ? noun.one : noun.many}`;
55
+ }
56
+ const ERROR = { one: "error", many: "errors" };
57
+ /**
58
+ * The status in a few words, the same in `stateward guarantees` and the editor: "proven for 3
59
+ * readers", "not proven: 2 errors", "unused: nothing reads it", "not checked: … is not on".
60
+ */
61
+ export function describeStatus(proof) {
62
+ const { stated, status } = proof;
63
+ switch (status.kind) {
64
+ case "proven":
65
+ return `proven for ${counted(stated.covered.length, stated.covers)}`;
66
+ case "unproven":
67
+ return `not proven: ${counted(status.errors.length, ERROR)}`;
68
+ case "unused":
69
+ return `unused: no ${stated.covers.one}, so nothing to prove; use it or drop the marker`;
70
+ case "off":
71
+ return `not checked: ${stated.ruleId} is not on`;
72
+ default: {
73
+ const unreachable = status;
74
+ return unreachable;
75
+ }
76
+ }
77
+ }
78
+ /** The guarantee whose declaration covers `offset` of `file` (a TypeScript path), if any. */
79
+ export function guaranteeAt(proofs, file, offset) {
80
+ return proofs.find(({ stated }) => stated.location.file === file &&
81
+ offset >= stated.location.start &&
82
+ offset <= stated.location.end);
83
+ }
84
+ //# sourceMappingURL=guarantees.js.map
@@ -0,0 +1,24 @@
1
+ /**
2
+ * How a fix line (`Finding.hint`) is laid out (contract M2, M22): the first line is the fix, or
3
+ * `one of` when there are several ways; a line that starts with `- ` is one way; a line that
4
+ * starts with 4 spaces is a code example of the way above it, or of the first line.
5
+ */
6
+ export type HintLine = {
7
+ readonly kind: "text" | "bullet" | "example";
8
+ /** The line as the hint has it (an example keeps its 4 spaces). */
9
+ readonly text: string;
10
+ /** Whether the line follows a bullet: an example of that way, indented under it. */
11
+ readonly underBullet: boolean;
12
+ };
13
+ export declare function hintLines(hint: string): readonly HintLine[];
14
+ /**
15
+ * The hint as it is printed under a label (`= fix: `), each line after the first starting with
16
+ * `indent`: bullets 2 further in, their examples 4 further than the bullet's own.
17
+ */
18
+ export declare function laidOutHint(hint: string, indent: string): string;
19
+ /**
20
+ * The hint without its code examples, for a place that cannot show code (a GitHub annotation): the
21
+ * first line and each way on its own line, without their closing colons.
22
+ */
23
+ export declare function hintWithoutExamples(hint: string): string;
24
+ //# sourceMappingURL=hint-lines.d.ts.map
@@ -0,0 +1,36 @@
1
+ export function hintLines(hint) {
2
+ let inBullet = false;
3
+ return hint.split("\n").map((text) => {
4
+ if (text.startsWith("- ")) {
5
+ inBullet = true;
6
+ return { kind: "bullet", text, underBullet: false };
7
+ }
8
+ if (text.startsWith(" "))
9
+ return { kind: "example", text, underBullet: inBullet };
10
+ inBullet = false;
11
+ return { kind: "text", text, underBullet: false };
12
+ });
13
+ }
14
+ /**
15
+ * The hint as it is printed under a label (`= fix: `), each line after the first starting with
16
+ * `indent`: bullets 2 further in, their examples 4 further than the bullet's own.
17
+ */
18
+ export function laidOutHint(hint, indent) {
19
+ return hintLines(hint)
20
+ .map((line, index) => {
21
+ const shift = line.kind === "bullet" ? " " : line.underBullet ? " " : "";
22
+ return index === 0 ? line.text : `${indent}${shift}${line.text}`;
23
+ })
24
+ .join("\n");
25
+ }
26
+ /**
27
+ * The hint without its code examples, for a place that cannot show code (a GitHub annotation): the
28
+ * first line and each way on its own line, without their closing colons.
29
+ */
30
+ export function hintWithoutExamples(hint) {
31
+ return hintLines(hint)
32
+ .filter((line, index) => index === 0 || line.kind === "bullet")
33
+ .map((line) => line.text.replace(/:$/, ""))
34
+ .join("\n");
35
+ }
36
+ //# sourceMappingURL=hint-lines.js.map
package/dist/ignores.d.ts CHANGED
@@ -44,8 +44,6 @@ export declare function fileDirectives(unit: ProjectUnit, file: string, results:
44
44
  directives: readonly IgnoreDirective[];
45
45
  stored: boolean;
46
46
  };
47
- /** The ignore comments of one file, read now (the fast pass has no cache to keep them in). */
48
- export declare function readFileDirectives(unit: ProjectUnit, file: string): readonly IgnoreDirective[];
49
47
  /** The ids a comment may name, and the ones whose rule ran, for "nothing to ignore" to be a fair judgement. */
50
48
  export type IgnoreScope = {
51
49
  /** Every rule id of the config's plugins, and the ids stateward reports itself. */
@@ -65,8 +63,8 @@ export declare function applyIgnores(findings: readonly Finding[], directives: R
65
63
  ignored: IgnoredFinding[];
66
64
  };
67
65
  /** The page `stateward explain stateward/ignore` shows. */
68
- export declare const IGNORE_EXPLAIN = "# stateward/ignore\n\nA `stateward-ignore` comment is missing its reason, names a rule that does not exist, or ignores nothing.\n\n## Why\n\nA comment that ignores one case should say why the case is fine, and should go when the case is fixed.\nOtherwise the next person cannot tell an intended exception from a forgotten one, and old comments\npile up. stateward checks the comments the way it checks your code.\n\n## When to use it\n\nPut a comment on the line above a finding that is intended, with the rule and the reason:\n\n // stateward-ignore records/lookup-misses-key: keys come from the server's fixed list\n const label = labels[status];\n\nSeveral rules go in one comment, separated by commas. For a whole file, put\n`// stateward-ignore-file <rule>: <reason>` above its first statement. Comment lines between the\nignore and the code are fine. In VS Code, the quick fix \"Ignore this case here\" writes the comment.\n\n## What it catches\n\n- an ignore with no reason after the colon (it still works; this is a warning)\n- an ignore that no longer covers a finding: the code was fixed or moved (a warning; the quick fix removes it)\n- a rule id that does not exist, with the closest one (an error: the ignore does nothing)\n- `stateward-ignore-file` below the first statement, and an ignore with no rule\n\n## What it does not catch\n\nWhether the reason is a good one. A comment is not the same as a baseline: the baseline says \"fix\nlater\", a comment says \"this is intended\". Both stay. Findings of this rule cannot be ignored.\n\n## Turn it on or off\n\nIt is always on. `stateward check --no-ignores` shows the findings that comments cover, and the\nsummary counts them (\"2 ignored in the code\"). Fix a comment, or remove it, to clear its finding.\n";
69
- export declare const IGNORE_FIX_TITLE = "Ignore this case here";
66
+ export declare const IGNORE_EXPLAIN = "# stateward/ignore\n\nA `stateward-ignore` comment is missing its reason, names a rule that does not exist, or ignores nothing.\n\n## Why\n\nA comment that ignores one case should say why the case is fine, and should go when the case is fixed.\nOtherwise the next person cannot tell an intended exception from a forgotten one, and old comments\npile up. stateward checks the comments the way it checks your code.\n\n## When to use it\n\nPut a comment on the line above a finding that is intended, with the rule and the reason:\n\n // stateward-ignore records/lookup-misses-key: keys come from the server's fixed list\n const label = labels[status];\n\nSeveral rules go in one comment, separated by commas. For a whole file, put\n`// stateward-ignore-file <rule>: <reason>` above its first statement. Comment lines between the\nignore and the code are fine. In VS Code, the quick fix \"Add an ignore comment\" writes it.\n\n## What it catches\n\n- an ignore with no reason after the colon (it still works; this is a warning)\n- an ignore that no longer covers a finding: the code was fixed or moved (a warning; the quick fix removes it)\n- a rule id that does not exist, with the closest one (an error: the ignore does nothing)\n- `stateward-ignore-file` below the first statement, and an ignore with no rule\n\n## What it does not catch\n\nWhether the reason is a good one. A comment is not the same as a baseline: the baseline says \"fix\nlater\", a comment says \"this is intended\". Both stay. Findings of this rule cannot be ignored.\n\n## Turn it on or off\n\nIt is always on. `stateward check --no-ignores` shows the findings that comments cover, and the\nsummary counts them (\"2 ignored in the code\"). Fix a comment, or remove it, to clear its finding.\n";
67
+ export declare const IGNORE_FIX_TITLE = "Add an ignore comment";
70
68
  /**
71
69
  * "Ignore this case here": `// stateward-ignore <rule>: ` on the line above the finding, indented
72
70
  * like it, so the warning about the missing reason asks for the reason at once. Undefined for a
package/dist/ignores.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { summaryOf, summaryValue } from "./cache.js";
2
+ import { renamedRule } from "./renamed.js";
2
3
  /**
3
4
  * Ignore comments: `// stateward-ignore <rule>[, <rule>]:
4
5
  * <reason>` covers the findings that start on the next line of code, and
@@ -233,10 +234,6 @@ export function fileDirectives(unit, file, results) {
233
234
  results.set(COMMENTS_KEY, { findings: [], summary: summaryOf(directives) });
234
235
  return { directives, stored: true };
235
236
  }
236
- /** The ignore comments of one file, read now (the fast pass has no cache to keep them in). */
237
- export function readFileDirectives(unit, file) {
238
- return readDirectives(unit, file);
239
- }
240
237
  function distance(a, b) {
241
238
  let previous = Array.from({ length: b.length + 1 }, (_, i) => i);
242
239
  for (let i = 1; i <= a.length; i++) {
@@ -298,7 +295,7 @@ function judge(file, directive, used, scope) {
298
295
  const form = directive.file ? "stateward-ignore-file" : "stateward-ignore";
299
296
  if (directive.rules.length === 0) {
300
297
  return [
301
- commentFinding(file, here, "warning", "this ignore does not name a rule", `write the rule, then why: \`// ${form} <rule>: <why this case is fine>\``, []),
298
+ commentFinding(file, here, "warning", "ignore comment does not name a rule", `write the rule, then why: \`// ${form} <rule>: <why this case is fine>\``, []),
302
299
  ];
303
300
  }
304
301
  if (directive.file && !directive.placed) {
@@ -312,11 +309,29 @@ function judge(file, directive, used, scope) {
312
309
  if (rule.id === IGNORE_RULE_ID) {
313
310
  found.push(commentFinding(file, rule, "error", "`stateward/ignore` findings cannot be ignored", "fix the comment the finding points at, or remove it", []));
314
311
  }
312
+ else if (!scope.known.has(rule.id) && renamedRule(rule.id) !== undefined) {
313
+ // A renamed rule: the comment still works under the old id.
314
+ const now = renamedRule(rule.id) ?? rule.id;
315
+ // One cause, one message: an ignore that is not needed is removed, not renamed; two fixes on
316
+ // one comment would also clash in `--fix`.
317
+ if (!used.has(now) && scope.ran.has(now)) {
318
+ unused.push(rule.id);
319
+ if (scope.options.reportUnused !== "off")
320
+ continue;
321
+ }
322
+ found.push(commentFinding(file, rule, "warning", fits(`\`${rule.id}\` is now \`${now}\`; rename it in this ignore`, MAX_HEADLINE, "ignore comment names a rule by its old id"), fits(`change it to \`${now}\` (quick fix); the old id still works`, MAX_HINT, "change it to the new id (quick fix); the old id still works"), [
323
+ {
324
+ title: `Change to \`${now}\``,
325
+ safe: true,
326
+ edits: [{ location: { file, start: rule.start, end: rule.end }, newText: now }],
327
+ },
328
+ ]));
329
+ }
315
330
  else if (!scope.known.has(rule.id)) {
316
331
  const guess = closest(rule.id, scope.known);
317
- found.push(commentFinding(file, rule, "error", fits(`\`${rule.id}\` is not a stateward rule`, MAX_HEADLINE, "this ignore names a rule that does not exist"), fits(guess === undefined
318
- ? "write a rule id as a finding shows it, such as `records/lookup-misses-key`; this ignore does nothing until then"
319
- : `did you mean \`${guess}\`? this ignore does nothing until the id is right`, MAX_HINT, "check the rule id; this ignore does nothing until it is right"), guess === undefined
332
+ found.push(commentFinding(file, rule, "error", fits(`\`${rule.id}\` is not a stateward rule`, MAX_HEADLINE, "ignore comment names a rule that does not exist"), fits(guess === undefined
333
+ ? "write a rule id as a finding shows it, such as `records/lookup-misses-key`; until then the comment ignores nothing"
334
+ : `write \`${guess}\`, the rule with the nearest name; until then the comment ignores nothing`, MAX_HINT, "check the rule id; until it is right the comment ignores nothing"), guess === undefined
320
335
  ? []
321
336
  : [
322
337
  {
@@ -332,11 +347,11 @@ function judge(file, directive, used, scope) {
332
347
  if (unused.length > 0 && scope.options.reportUnused !== "off") {
333
348
  const everything = unused.length === directive.rules.length;
334
349
  const keep = directive.rules.map((rule) => rule.id).filter((id) => !unused.includes(id));
335
- const where = directive.file ? "in this file" : "here";
336
- found.push(commentFinding(file, here, scope.options.reportUnused, fits(`this ignore is not needed: ${names(unused)} finds nothing ${where}`, MAX_HEADLINE, `this ignore is not needed: ${String(unused.length)} of its rules find nothing ${where}`), "remove it (quick fix); the code it covered is fixed, or has moved", [
350
+ const where = directive.file ? "in the file" : "in the code it covers";
351
+ found.push(commentFinding(file, here, scope.options.reportUnused, fits(`ignore comment is not needed: ${names(unused)} finds nothing ${where}`, MAX_HEADLINE, `ignore comment is not needed: ${String(unused.length)} of its rules find nothing ${where}`), "remove it (quick fix); the code it covered is fixed, or has moved", [
337
352
  everything
338
353
  ? {
339
- title: "Remove this ignore",
354
+ title: "Remove the ignore comment",
340
355
  safe: true,
341
356
  edits: [
342
357
  {
@@ -346,7 +361,7 @@ function judge(file, directive, used, scope) {
346
361
  ],
347
362
  }
348
363
  : {
349
- title: `Remove ${names(unused)} from this ignore`,
364
+ title: `Remove ${names(unused)} from the ignore comment`,
350
365
  safe: true,
351
366
  edits: [{ location: { file, ...here }, newText: rebuilt(directive, keep) }],
352
367
  },
@@ -354,7 +369,7 @@ function judge(file, directive, used, scope) {
354
369
  }
355
370
  if (directive.reason === "" && scope.options.requireReason) {
356
371
  const first = directive.rules[0]?.id ?? "<rule>";
357
- found.push(commentFinding(file, here, "warning", "this ignore does not say why the case is fine", fits(`add the reason after a colon: \`// ${form} ${first}: <why this case is fine>\``, MAX_HINT, "add the reason after a colon, and say why this case is fine"), []));
372
+ found.push(commentFinding(file, here, "warning", "ignore comment does not say why the case is fine", fits(`add the reason after a colon: \`// ${form} ${first}: <why this case is fine>\``, MAX_HINT, "add the reason after a colon, and say why this case is fine"), []));
358
373
  }
359
374
  return found;
360
375
  }
@@ -392,7 +407,7 @@ function coveredBy(list, ruleId, start, used) {
392
407
  for (const directive of list) {
393
408
  if (directive.file && !directive.placed)
394
409
  continue;
395
- if (!directive.rules.some((rule) => rule.id === ruleId))
410
+ if (!directive.rules.some((rule) => (renamedRule(rule.id) ?? rule.id) === ruleId))
396
411
  continue;
397
412
  const covers = directive.file || (directive.coverStart <= start && start <= directive.coverEnd);
398
413
  if (!covers)
@@ -424,7 +439,7 @@ Put a comment on the line above a finding that is intended, with the rule and th
424
439
 
425
440
  Several rules go in one comment, separated by commas. For a whole file, put
426
441
  \`// stateward-ignore-file <rule>: <reason>\` above its first statement. Comment lines between the
427
- ignore and the code are fine. In VS Code, the quick fix "Ignore this case here" writes the comment.
442
+ ignore and the code are fine. In VS Code, the quick fix "Add an ignore comment" writes it.
428
443
 
429
444
  ## What it catches
430
445
 
@@ -443,7 +458,7 @@ later", a comment says "this is intended". Both stay. Findings of this rule cann
443
458
  It is always on. \`stateward check --no-ignores\` shows the findings that comments cover, and the
444
459
  summary counts them ("2 ignored in the code"). Fix a comment, or remove it, to clear its finding.
445
460
  `;
446
- export const IGNORE_FIX_TITLE = "Ignore this case here";
461
+ export const IGNORE_FIX_TITLE = "Add an ignore comment";
447
462
  /**
448
463
  * "Ignore this case here": `// stateward-ignore <rule>: ` on the line above the finding, indented
449
464
  * like it, so the warning about the missing reason asks for the reason at once. Undefined for a
@@ -278,7 +278,8 @@ export function foreignTypeScriptWarnings(configFile) {
278
278
  continue;
279
279
  const version = stringField(jsonOf(path.join(root, "package.json")), "version");
280
280
  const shortVersion = /^\d+\.\d+/.exec(version)?.[0] ?? version;
281
- const shown = path.relative(configDir, file).split(path.sep).join("/");
281
+ // Both sides real: the local files are, and a config reached through a link is not.
282
+ const shown = path.relative(real(configDir), real(file)).split(path.sep).join("/");
282
283
  warnings.push(`\`${shown}\` imports the app's TypeScript ${shortVersion}; use \`@stateward/core/typescript\`, or it may see nothing`);
283
284
  }
284
285
  return warnings;
package/dist/index.d.ts CHANGED
@@ -10,11 +10,15 @@ export { createPropagationMemo, propagate } from "./graph.js";
10
10
  export type { Propagation, PropagationMemo } from "./graph.js";
11
11
  export { highestUncovered, shortestPath } from "./tree.js";
12
12
  export type { TreeEdge, Uncovered, WalkDown } from "./tree.js";
13
+ export { describeRelease, describeTraitSource, releaseCandidates, releaseTraitOf, } from "./release.js";
14
+ export { neverRejectsFactOf } from "./package-facts.js";
15
+ export type { FactContext, PackageFact } from "./package-facts.js";
16
+ export type { ReleaseCandidate, ReleaseOptions, ReleaseTrait, ReleaseWay } from "./release.js";
13
17
  export { packageCodeId } from "./implementation.js";
14
18
  export { readPackageCache, writePackageCache } from "./package-cache.js";
15
19
  export type { PackageCacheKey } from "./package-cache.js";
16
20
  export { findPackageRoot, reparsedWithJsDoc } from "./backend/package-source.js";
17
21
  export { openPackageSource } from "./backend/typescript6.js";
18
22
  export type { PackageSource } from "./backend/typescript6.js";
19
- export type { BooleanOption, CheckResult, Config, ConfigOverride, EditorAction, EditorContributions, EditorHint, ExtendedConfig, FileContext, FactSource, FileRule, Finding, FunctionFacts, LibraryUse, PackageFactsConfig, Fix, FixForm, FixReview, FixSetReview, FixVerdict, RejectedFix, GroupIdOf, HiddenFindings, IgnoreOptions, IgnoredFinding, Json, Literal, NarrowedMembers, 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";
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";
20
24
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -10,6 +10,10 @@ export { check, createChecker } from "./checker.js";
10
10
  // Helpers for project rules that follow calls across files.
11
11
  export { createPropagationMemo, propagate } from "./graph.js";
12
12
  export { highestUncovered, shortestPath } from "./tree.js";
13
+ // The release trait: where a call's result is stated to need releasing (type, marker, facts).
14
+ export { describeRelease, describeTraitSource, releaseCandidates, releaseTraitOf, } from "./release.js";
15
+ // Facts about packages: the config's and the shipped lines, and the promises they say never reject.
16
+ export { neverRejectsFactOf } from "./package-facts.js";
13
17
  // What a pack learns about a library's code, cached outside the project.
14
18
  export { packageCodeId } from "./implementation.js";
15
19
  export { readPackageCache, writePackageCache } from "./package-cache.js";
@@ -9,12 +9,14 @@ export { matchingOverrides } from "./overrides.js";
9
9
  export { ROLLOUT_FILE, RolloutError, readRollout, rolloutFile, writeRollout } from "./rollout.js";
10
10
  export { BASELINE_FILE, BaselineError, OUTDATED_BASELINE, applyBaseline, baselineFile, baselineOf, fingerprintOf, isOutdated, mergeBaseline, readBaseline, sizeOf, writeBaseline, } from "./baseline.js";
11
11
  export type { Baseline, BaselineEntry, BaselineView, FingerprintContext } from "./baseline.js";
12
- export { advance, buildPlan, describeTurnOn } from "./plan.js";
12
+ export { advance, buildPlan, describeNotChecked, describeTurnOn, isClean } from "./plan.js";
13
13
  export type { Advance, Plan, PlanRow } from "./plan.js";
14
14
  export { findConfigFile, findConfigUpward, loadConfig, loadConfigFile, reloadsLocalImports, } from "./config-file.js";
15
- export { MAX_FINDINGS_PER_RULE_PER_FILE, activeRuleIds, compareFindings, explain, limitFindings, } from "./engine.js";
15
+ export { LOOSE_NULLS_FIX, MAX_FINDINGS_PER_RULE_PER_FILE, STRICT_NULLS_REMEDY, activeRuleIds, compareFindings, explain, limitFindings, } from "./engine.js";
16
16
  export type { CheckProgress } from "./engine.js";
17
17
  export { SLICE_MS } from "./checker.js";
18
+ export { counted, describeStatus, guaranteeAt, proveGuarantees } from "./guarantees.js";
19
+ export type { GuaranteeProof, GuaranteeStatus } from "./guarantees.js";
18
20
  export type { LongestStep, SliceOptions, SlicedCheck } from "./checker.js";
19
21
  export { IGNORE_FIX_TITLE, IGNORE_RULE_ID, ignoreFix } from "./ignores.js";
20
22
  export { CACHE_FORMAT, emptyCache, parseSnapshot, toSnapshot } from "./cache.js";
@@ -26,8 +28,11 @@ export type { PackageCacheClean, PackageCacheStats } from "./package-cache.js";
26
28
  export { NothingToCheckError, TsconfigError, TypeScriptLibMissingError, missingDefaultLib, toTypeScriptPath, tsconfigDirectory, } from "./backend/typescript6.js";
27
29
  export { createTimingRecorder } from "./timing.js";
28
30
  export { cacheEntries, dropLeastRecentlyUsed, limitBytes, markUsed } from "./disk-limits.js";
29
- export { CACHE_SUBDIR, RESULTS_CACHE_DEFAULT_MB, cleanResultsCache, defaultCacheDir, openDiskCache, resultsCacheLimit, resultsCacheStats, } from "./disk-cache.js";
31
+ export { CACHE_SUBDIR, PROJECT_CACHE_DIR, RESULTS_CACHE_DEFAULT_MB, cleanResultsCache, defaultCacheDir, userCacheDir, openDiskCache, resultsCacheLimit, resultsCacheStats, } from "./disk-cache.js";
30
32
  export type { DiskCache, ResultsCacheStats } from "./disk-cache.js";
31
33
  export type { CacheEntry } from "./disk-limits.js";
32
34
  export type { RuleCost, RunTiming, TimingRecorder } from "./timing.js";
35
+ export { hintLines, hintWithoutExamples, laidOutHint } from "./hint-lines.js";
36
+ export type { HintLine } from "./hint-lines.js";
37
+ export { renameNotice, renamedIdsIn, renamedRule } from "./renamed.js";
33
38
  //# sourceMappingURL=internal.d.ts.map
package/dist/internal.js CHANGED
@@ -10,10 +10,11 @@ export { displayPath, slashed } from "./display-path.js";
10
10
  export { matchingOverrides } from "./overrides.js";
11
11
  export { ROLLOUT_FILE, RolloutError, readRollout, rolloutFile, writeRollout } from "./rollout.js";
12
12
  export { BASELINE_FILE, BaselineError, OUTDATED_BASELINE, applyBaseline, baselineFile, baselineOf, fingerprintOf, isOutdated, mergeBaseline, readBaseline, sizeOf, writeBaseline, } from "./baseline.js";
13
- export { advance, buildPlan, describeTurnOn } from "./plan.js";
13
+ export { advance, buildPlan, describeNotChecked, describeTurnOn, isClean } from "./plan.js";
14
14
  export { findConfigFile, findConfigUpward, loadConfig, loadConfigFile, reloadsLocalImports, } from "./config-file.js";
15
- export { MAX_FINDINGS_PER_RULE_PER_FILE, activeRuleIds, compareFindings, explain, limitFindings, } from "./engine.js";
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
+ export { counted, describeStatus, guaranteeAt, proveGuarantees } from "./guarantees.js";
17
18
  export { IGNORE_FIX_TITLE, IGNORE_RULE_ID, ignoreFix } from "./ignores.js";
18
19
  export { CACHE_FORMAT, emptyCache, parseSnapshot, toSnapshot } from "./cache.js";
19
20
  export { stronglyConnectedComponents } from "./graph.js";
@@ -22,5 +23,7 @@ export { PACKAGE_CACHE_DEFAULT_MB, PACKAGE_CACHE_MARKER, cleanPackageCache, pack
22
23
  export { NothingToCheckError, TsconfigError, TypeScriptLibMissingError, missingDefaultLib, toTypeScriptPath, tsconfigDirectory, } from "./backend/typescript6.js";
23
24
  export { createTimingRecorder } from "./timing.js";
24
25
  export { cacheEntries, dropLeastRecentlyUsed, limitBytes, markUsed } from "./disk-limits.js";
25
- export { CACHE_SUBDIR, RESULTS_CACHE_DEFAULT_MB, cleanResultsCache, defaultCacheDir, openDiskCache, resultsCacheLimit, resultsCacheStats, } from "./disk-cache.js";
26
+ export { CACHE_SUBDIR, PROJECT_CACHE_DIR, RESULTS_CACHE_DEFAULT_MB, cleanResultsCache, defaultCacheDir, userCacheDir, openDiskCache, resultsCacheLimit, resultsCacheStats, } from "./disk-cache.js";
27
+ export { hintLines, hintWithoutExamples, laidOutHint } from "./hint-lines.js";
28
+ export { renameNotice, renamedIdsIn, renamedRule } from "./renamed.js";
26
29
  //# sourceMappingURL=internal.js.map
@@ -0,0 +1,52 @@
1
+ /**
2
+ * The `facts` line for a package function or property: the config's first, then the facts the
3
+ * loaded plugins ship. Core reads the lines and knows no library; each line names a declaration
4
+ * by its path in the package's types (`Observable.subscribe`) or by its own name (`onSnapshot`).
5
+ */
6
+ import ts from "typescript";
7
+ import type { FileContext, FunctionFacts } from "./types.js";
8
+ /** What a lookup reads: the program's types, both sets of facts, and the file the code is in. */
9
+ export type FactContext = Pick<FileContext, "types" | "facts" | "shippedFacts" | "sourceFile">;
10
+ /** The facts line a declaration has, the package it is listed under, and which set it is from. */
11
+ export type PackageFact = {
12
+ readonly package: string;
13
+ readonly fact: FunctionFacts;
14
+ readonly source: "config" | "shipped";
15
+ };
16
+ /** The declaration's path in its package's types: `["Observable", "subscribe"]`. */
17
+ export declare function pathOf(node: ts.Node): string[];
18
+ /** The name the call is made through: `onSnapshot` of `onSnapshot(…)`, `subscribe` of `a.subscribe(…)`. */
19
+ export declare function calleeName(call: ts.CallExpression | ts.NewExpression): ts.Identifier | undefined;
20
+ /** The module a file imports a name from: `"firebase/firestore"` for `onSnapshot`. */
21
+ export declare function importedFrom(sourceFile: ts.SourceFile, name: string): string | undefined;
22
+ /** The leftmost name of a callee: `db` of `db.users.watch`. */
23
+ export declare function rootName(expression: ts.Expression): string | undefined;
24
+ /**
25
+ * The facts line for `declared`, a declaration in a package's types, reached in the file through
26
+ * `through` (the callee or the object a property is read from, whose import names the package):
27
+ * the config's line when it has one for the declaration, else a shipped one. Undefined for a
28
+ * declaration of the project, or one no line names.
29
+ */
30
+ export declare function packageFactOf(declared: {
31
+ readonly file: string;
32
+ readonly node: ts.Node;
33
+ }, through: ts.Expression | undefined, ctx: FactContext): PackageFact | undefined;
34
+ /**
35
+ * The package function a name of the project stands for: `listen` in `const listen = onSnapshot`,
36
+ * `const listen = db.onSnapshot` or `const { onSnapshot: listen } = firestore`. Only a name or a
37
+ * property read is followed, never a call: `const stop = onSnapshot(…)` holds what the call
38
+ * returned, not the function.
39
+ */
40
+ export declare function packageFunctionOf(name: ts.Identifier, ctx: FactContext): {
41
+ declared: {
42
+ file: string;
43
+ node: ts.Node;
44
+ };
45
+ through: ts.Expression | undefined;
46
+ } | undefined;
47
+ /**
48
+ * The facts line that says an awaited promise never rejects (`neverRejects: true`), when one
49
+ * does: an `await` of it is then not a way out of the function. Undefined otherwise.
50
+ */
51
+ export declare function neverRejectsFactOf(expression: ts.Expression, ctx: FactContext): PackageFact | undefined;
52
+ //# sourceMappingURL=package-facts.d.ts.map