@stateward/plugin-errors 1.3.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/catch-misses-error.js +6 -3
- package/dist/hover.js +6 -9
- package/dist/inference/analysis.js +2 -2
- package/dist/inference/deps.d.ts +13 -2
- package/dist/inference/deps.js +22 -11
- package/dist/inference/project.d.ts +3 -3
- package/dist/inference/project.js +4 -16
- package/dist/inference/solve.js +8 -7
- package/dist/inlay.d.ts +1 -5
- package/dist/inlay.js +1 -12
- package/dist/must-handle-error.d.ts +2 -2
- package/dist/must-handle-error.js +6 -9
- package/dist/react/boundaries.d.ts +9 -7
- package/dist/react/boundaries.js +16 -24
- package/dist/refactors.js +1 -1
- package/dist/render-throw-without-boundary.js +4 -2
- package/dist/throws-doc-mismatch.d.ts +1 -1
- package/dist/throws-doc-mismatch.js +6 -4
- package/package.json +2 -2
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { defineRule, matchesName, option } from "@stateward/core";
|
|
2
2
|
import { catchName, className } from "./inference/format.js";
|
|
3
3
|
import { analyse, everyCatch } from "./inference/solve.js";
|
|
4
|
-
import {
|
|
4
|
+
import { THROWS_ANALYSIS } from "./inference/deps.js";
|
|
5
|
+
import { modelOf, summarizeReact } from "./react/boundaries.js";
|
|
5
6
|
import { checkFallbacks } from "./react/fallbacks.js";
|
|
6
7
|
import { codeList, fitted, withExample } from "./text.js";
|
|
7
8
|
/** The group the rule belongs to in the docs and in `stateward status`. */
|
|
@@ -225,15 +226,17 @@ export const catchMissesError = defineRule({
|
|
|
225
226
|
},
|
|
226
227
|
explain: EXPLAIN,
|
|
227
228
|
},
|
|
229
|
+
reads: [THROWS_ANALYSIS],
|
|
228
230
|
summarize: (ctx) => summarizeReact(ctx),
|
|
229
231
|
check(summaries, ctx) {
|
|
230
|
-
const
|
|
232
|
+
const throws = ctx.analysisSummaries(THROWS_ANALYSIS);
|
|
233
|
+
const analysis = analyse(throws);
|
|
231
234
|
for (const seen of everyCatch(analysis)) {
|
|
232
235
|
report(seen, analysis.classes, ctx.options.ignoreClasses, (problem) => {
|
|
233
236
|
ctx.report(problem);
|
|
234
237
|
});
|
|
235
238
|
}
|
|
236
|
-
checkFallbacks(modelOf(summaries), ctx.options.ignoreClasses, (problem) => {
|
|
239
|
+
checkFallbacks(modelOf(summaries, throws), ctx.options.ignoreClasses, (problem) => {
|
|
237
240
|
ctx.report(problem);
|
|
238
241
|
});
|
|
239
242
|
},
|
package/dist/hover.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import ts from "@stateward/core/typescript";
|
|
2
|
-
import {
|
|
2
|
+
import { factSummaries } from "./inference/deps.js";
|
|
3
3
|
import { resultLines } from "./inference/format.js";
|
|
4
4
|
import { analyse } from "./inference/solve.js";
|
|
5
|
-
import { TREE_RULES, boundaryLines, modelOf
|
|
5
|
+
import { TREE_RULES, boundaryLines, modelOf } from "./react/boundaries.js";
|
|
6
6
|
/** The identifier that covers `offset`, if any. */
|
|
7
7
|
function identifierAt(root, offset) {
|
|
8
8
|
if (offset < root.getStart() || offset >= root.getEnd())
|
|
@@ -32,20 +32,17 @@ function isFunctionName(identifier) {
|
|
|
32
32
|
* not the project's own. On an error boundary's tag, what it catches (`boundaryLines`).
|
|
33
33
|
*/
|
|
34
34
|
export const hover = (input) => {
|
|
35
|
+
const summaries = factSummaries(input);
|
|
36
|
+
if (summaries === undefined)
|
|
37
|
+
return undefined;
|
|
35
38
|
let trees;
|
|
36
39
|
for (const ruleId of TREE_RULES)
|
|
37
40
|
trees ??= input.projectSummaries(ruleId);
|
|
38
41
|
if (trees !== undefined) {
|
|
39
|
-
const lines = boundaryLines(modelOf(trees), input.sourceFile.fileName, input.offset);
|
|
42
|
+
const lines = boundaryLines(modelOf(trees, summaries), input.sourceFile.fileName, input.offset);
|
|
40
43
|
if (lines !== undefined)
|
|
41
44
|
return lines.join("\n\n");
|
|
42
45
|
}
|
|
43
|
-
let summaries;
|
|
44
|
-
for (const ruleId of FACT_RULES)
|
|
45
|
-
summaries ??= input.projectSummaries(ruleId);
|
|
46
|
-
summaries ??= trees === undefined ? undefined : throwsOf(trees);
|
|
47
|
-
if (summaries === undefined)
|
|
48
|
-
return undefined;
|
|
49
46
|
const identifier = identifierAt(input.sourceFile, input.offset);
|
|
50
47
|
if (identifier === undefined || !isFunctionName(identifier))
|
|
51
48
|
return undefined;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { builtinName, builtinParent, isBuiltin } from "./builtins.js";
|
|
2
|
-
import {
|
|
2
|
+
import { summarizeWithPackages } from "./project.js";
|
|
3
3
|
import { analyse } from "./solve.js";
|
|
4
4
|
function unknownOf(source) {
|
|
5
5
|
return {
|
|
@@ -164,7 +164,7 @@ function classesOf(functions, known) {
|
|
|
164
164
|
}
|
|
165
165
|
/** `Plugin.analyses.throws` of the errors pack. */
|
|
166
166
|
export const throws = {
|
|
167
|
-
summarize: (ctx) =>
|
|
167
|
+
summarize: (ctx) => summarizeWithPackages(ctx),
|
|
168
168
|
solve: throwsAnalysis,
|
|
169
169
|
};
|
|
170
170
|
//# sourceMappingURL=analysis.js.map
|
package/dist/inference/deps.d.ts
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
import type { EditorContributions, Json, LibraryUse } from "@stateward/core";
|
|
2
2
|
type LibraryFacts = NonNullable<EditorContributions["libraryFacts"]>;
|
|
3
|
-
/**
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* The analysis whose summaries hold the throws facts: the pack's rules, its editor contributions
|
|
5
|
+
* and other packs (through its solved value) all read this one copy.
|
|
6
|
+
*/
|
|
7
|
+
export declare const THROWS_ANALYSIS = "errors/throws";
|
|
8
|
+
/**
|
|
9
|
+
* The throws facts of the last full check (`errors/throws`'s summaries), when one of the rules
|
|
10
|
+
* that show them ran; undefined otherwise. Another rule that reads the analysis (`must-handle-error`)
|
|
11
|
+
* does not turn the hover and hints on.
|
|
12
|
+
*/
|
|
13
|
+
export declare function factSummaries(input: {
|
|
14
|
+
projectSummaries(ruleId: string): ReadonlyMap<string, Json> | undefined;
|
|
15
|
+
}): ReadonlyMap<string, Json> | undefined;
|
|
5
16
|
/**
|
|
6
17
|
* Every package function the project calls, with where its throws facts come from and why what
|
|
7
18
|
* is unknown is unknown (`stateward deps`), from the last full check.
|
package/dist/inference/deps.js
CHANGED
|
@@ -1,7 +1,25 @@
|
|
|
1
|
-
import { TREE_RULES, throwsOf } from "../react/boundaries.js";
|
|
2
1
|
import { readSummary } from "./summary.js";
|
|
3
|
-
/**
|
|
4
|
-
|
|
2
|
+
/**
|
|
3
|
+
* The analysis whose summaries hold the throws facts: the pack's rules, its editor contributions
|
|
4
|
+
* and other packs (through its solved value) all read this one copy.
|
|
5
|
+
*/
|
|
6
|
+
export const THROWS_ANALYSIS = "errors/throws";
|
|
7
|
+
/** The rules whose results the editor shows the throws facts for: when one of them ran. */
|
|
8
|
+
const FACT_RULES = [
|
|
9
|
+
"errors/throws-doc-mismatch",
|
|
10
|
+
"errors/render-throw-without-boundary",
|
|
11
|
+
"errors/catch-misses-error",
|
|
12
|
+
];
|
|
13
|
+
/**
|
|
14
|
+
* The throws facts of the last full check (`errors/throws`'s summaries), when one of the rules
|
|
15
|
+
* that show them ran; undefined otherwise. Another rule that reads the analysis (`must-handle-error`)
|
|
16
|
+
* does not turn the hover and hints on.
|
|
17
|
+
*/
|
|
18
|
+
export function factSummaries(input) {
|
|
19
|
+
return FACT_RULES.some((ruleId) => input.projectSummaries(ruleId) !== undefined)
|
|
20
|
+
? input.projectSummaries(THROWS_ANALYSIS)
|
|
21
|
+
: undefined;
|
|
22
|
+
}
|
|
5
23
|
function collect(effects, into) {
|
|
6
24
|
for (const effect of effects) {
|
|
7
25
|
if (effect.k === "package")
|
|
@@ -66,14 +84,7 @@ export function packagesCalled(summaries) {
|
|
|
66
84
|
}));
|
|
67
85
|
}
|
|
68
86
|
export const libraryFacts = (input) => {
|
|
69
|
-
|
|
70
|
-
for (const ruleId of FACT_RULES)
|
|
71
|
-
summaries ??= input.projectSummaries(ruleId);
|
|
72
|
-
for (const ruleId of TREE_RULES) {
|
|
73
|
-
const trees = summaries === undefined ? input.projectSummaries(ruleId) : undefined;
|
|
74
|
-
if (trees !== undefined)
|
|
75
|
-
summaries = throwsOf(trees);
|
|
76
|
-
}
|
|
87
|
+
const summaries = factSummaries(input);
|
|
77
88
|
return summaries === undefined ? [] : packagesCalled(summaries);
|
|
78
89
|
};
|
|
79
90
|
//# sourceMappingURL=deps.js.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { AnalysisContext } from "@stateward/core";
|
|
2
2
|
import type { ThrowsSummary } from "./summary.js";
|
|
3
3
|
/**
|
|
4
|
-
* `summarizeThrows` with the facts of the packages the file calls (packages.ts)
|
|
5
|
-
*
|
|
4
|
+
* `summarizeThrows` with the facts of the packages the file calls (packages.ts): the file side
|
|
5
|
+
* of the `errors/throws` analysis, whose summaries the pack's rules read (`analysisSummaries`).
|
|
6
6
|
*/
|
|
7
|
-
export declare function
|
|
7
|
+
export declare function summarizeWithPackages(ctx: AnalysisContext): ThrowsSummary;
|
|
8
8
|
//# sourceMappingURL=project.d.ts.map
|
|
@@ -1,23 +1,11 @@
|
|
|
1
1
|
import { packageResolver, quietCalls } from "./packages.js";
|
|
2
2
|
import { summarizeThrows } from "./summarize.js";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* Only the last file is kept: kept for every file, the summaries stayed in memory for the whole
|
|
7
|
-
* run next to the engine's own copies.
|
|
4
|
+
* `summarizeThrows` with the facts of the packages the file calls (packages.ts): the file side
|
|
5
|
+
* of the `errors/throws` analysis, whose summaries the pack's rules read (`analysisSummaries`).
|
|
8
6
|
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* `summarizeThrows` with the facts of the packages the file calls (packages.ts), computed once
|
|
12
|
-
* per file when its rules run one after the other.
|
|
13
|
-
*/
|
|
14
|
-
export function summarizeOnce(ctx) {
|
|
15
|
-
const known = last.get(ctx.types);
|
|
16
|
-
if (known?.sourceFile === ctx.sourceFile)
|
|
17
|
-
return known.summary;
|
|
7
|
+
export function summarizeWithPackages(ctx) {
|
|
18
8
|
const quiet = quietCalls(ctx);
|
|
19
|
-
|
|
20
|
-
last.set(ctx.types, { sourceFile: ctx.sourceFile, summary });
|
|
21
|
-
return summary;
|
|
9
|
+
return summarizeThrows(ctx, quiet.test, packageResolver(ctx));
|
|
22
10
|
}
|
|
23
11
|
//# sourceMappingURL=project.js.map
|
package/dist/inference/solve.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createPropagationMemo, propagate } from "@stateward/core";
|
|
1
|
+
import { createPropagationMemo, propagate, summaryHash } from "@stateward/core";
|
|
2
2
|
import { builtinParent, isBuiltin } from "./builtins.js";
|
|
3
3
|
import { ANONYMOUS, REASON } from "./summarize.js";
|
|
4
4
|
import { UNKNOWN_REASONS, readSummary } from "./summary.js";
|
|
@@ -416,9 +416,10 @@ const memo = createPropagationMemo();
|
|
|
416
416
|
/** One analysis per summaries map: the engine hands out the same map until they change. */
|
|
417
417
|
const analyses = new WeakMap();
|
|
418
418
|
/**
|
|
419
|
-
* The summaries of the last analysis, by
|
|
420
|
-
*
|
|
421
|
-
*
|
|
419
|
+
* The summaries of the last analysis, by the engine's hash of their JSON text (`summaryHash`), or
|
|
420
|
+
* the text itself for a value the engine did not hand out (a test's). A summary the next full
|
|
421
|
+
* pass computes again from an unchanged file is a new object with the same hash: mapping it to
|
|
422
|
+
* the last one lets the solve find the facts unchanged by identity.
|
|
422
423
|
*/
|
|
423
424
|
let canonical = new Map();
|
|
424
425
|
let last;
|
|
@@ -434,9 +435,9 @@ export function analyse(summaries) {
|
|
|
434
435
|
const parsed = readSummary(value);
|
|
435
436
|
if (parsed === undefined || typeof value !== "object" || value === null)
|
|
436
437
|
continue;
|
|
437
|
-
const
|
|
438
|
-
const summary = canonical.get(
|
|
439
|
-
next.set(
|
|
438
|
+
const key = summaryHash(value) ?? textOf(value);
|
|
439
|
+
const summary = canonical.get(key) ?? next.get(key) ?? parsed;
|
|
440
|
+
next.set(key, summary);
|
|
440
441
|
files.push(file);
|
|
441
442
|
read.push(summary);
|
|
442
443
|
}
|
package/dist/inlay.d.ts
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import type { EditorContributions
|
|
1
|
+
import type { EditorContributions } from "@stateward/core";
|
|
2
2
|
type InlayHints = NonNullable<EditorContributions["inlayHints"]>;
|
|
3
3
|
/** The two kinds of hint, as the `stateward.inlayHints.<kind>` settings name them. */
|
|
4
4
|
export declare const HINT_KINDS: {
|
|
5
5
|
readonly throws: "throws";
|
|
6
6
|
readonly catchVariable: "catchVariable";
|
|
7
7
|
};
|
|
8
|
-
/** The summaries that hold the throws facts, from the rules that ran (as the hover reads them). */
|
|
9
|
-
export declare function factSummaries(input: {
|
|
10
|
-
projectSummaries(ruleId: string): ReadonlyMap<string, Json> | undefined;
|
|
11
|
-
}): ReadonlyMap<string, Json> | undefined;
|
|
12
8
|
/**
|
|
13
9
|
* Two kinds of hint, from the last full check's solve (no recomputation, as the hover):
|
|
14
10
|
* `throws A | B` or `throws (unknown from \`fetchAvatar\`)` after a named function's signature (the hover's facts, `rejects` for what its
|
package/dist/inlay.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import ts from "@stateward/core/typescript";
|
|
2
|
-
import {
|
|
2
|
+
import { factSummaries } from "./inference/deps.js";
|
|
3
3
|
import { catchesOf } from "./inference/catches.js";
|
|
4
4
|
import { className, rejectsShown, resultLines, thrownText } from "./inference/format.js";
|
|
5
5
|
import { analyse, toThrown } from "./inference/solve.js";
|
|
6
|
-
import { TREE_RULES, throwsOf } from "./react/boundaries.js";
|
|
7
6
|
/** The two kinds of hint, as the `stateward.inlayHints.<kind>` settings name them. */
|
|
8
7
|
export const HINT_KINDS = { throws: "throws", catchVariable: "catchVariable" };
|
|
9
8
|
/** At most this many class names are listed in a hint; the rest are counted (`+2`). */
|
|
@@ -94,16 +93,6 @@ function isFunctionWithBody(node) {
|
|
|
94
93
|
ts.isFunctionExpression(node)) &&
|
|
95
94
|
node.body !== undefined);
|
|
96
95
|
}
|
|
97
|
-
/** The summaries that hold the throws facts, from the rules that ran (as the hover reads them). */
|
|
98
|
-
export function factSummaries(input) {
|
|
99
|
-
let summaries;
|
|
100
|
-
for (const ruleId of FACT_RULES)
|
|
101
|
-
summaries ??= input.projectSummaries(ruleId);
|
|
102
|
-
let trees;
|
|
103
|
-
for (const ruleId of TREE_RULES)
|
|
104
|
-
trees ??= input.projectSummaries(ruleId);
|
|
105
|
-
return summaries ?? (trees === undefined ? undefined : throwsOf(trees));
|
|
106
|
-
}
|
|
107
96
|
/**
|
|
108
97
|
* Two kinds of hint, from the last full check's solve (no recomputation, as the hover):
|
|
109
98
|
* `throws A | B` or `throws (unknown from \`fetchAvatar\`)` after a named function's signature (the hover's facts, `rejects` for what its
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Json } from "@stateward/core";
|
|
2
|
-
import type { Span
|
|
2
|
+
import type { Span } from "./inference/summary.js";
|
|
3
3
|
/** The group the rule belongs to in the docs and in `stateward status`. */
|
|
4
4
|
export declare const GROUP = "callers";
|
|
5
5
|
/** A class marked `@mustHandle`: its id, its name, the author's sentence and the tag's span. */
|
|
@@ -47,8 +47,8 @@ type MustHandleFacts = {
|
|
|
47
47
|
readonly helpers: readonly ErrorHelper[];
|
|
48
48
|
readonly passes: readonly Pass[];
|
|
49
49
|
};
|
|
50
|
+
/** The rule's summary of one file; the throws facts it solves with are `errors/throws`'s summaries. */
|
|
50
51
|
export type MustHandleSummary = {
|
|
51
|
-
readonly throws: ThrowsSummary;
|
|
52
52
|
readonly mustHandle: MustHandleFacts;
|
|
53
53
|
};
|
|
54
54
|
export declare const mustHandleError: import("@stateward/core").ProjectRule<MustHandleSummary, Readonly<Record<string, never>>, "callers", Readonly<Record<string, Json>>>;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import ts from "@stateward/core/typescript";
|
|
2
2
|
import { defineRule } from "@stateward/core";
|
|
3
3
|
import { catchName, className } from "./inference/format.js";
|
|
4
|
-
import {
|
|
4
|
+
import { THROWS_ANALYSIS } from "./inference/deps.js";
|
|
5
5
|
import { analyse, evaluated, relation } from "./inference/solve.js";
|
|
6
6
|
import { ANONYMOUS, errorClassIdOf } from "./inference/summarize.js";
|
|
7
7
|
import { each, fieldsOf, isString, spanOf } from "./inference/summary.js";
|
|
8
|
-
import { throwsOf } from "./react/boundaries.js";
|
|
9
8
|
import { stripParentheses } from "./syntax.js";
|
|
10
9
|
import { fitted, shorten, withExample } from "./text.js";
|
|
11
10
|
/** The group the rule belongs to in the docs and in `stateward status`. */
|
|
@@ -677,8 +676,8 @@ function report(met, model, out) {
|
|
|
677
676
|
}
|
|
678
677
|
}
|
|
679
678
|
}
|
|
680
|
-
function modelOf(summaries) {
|
|
681
|
-
const analysis = analyse(
|
|
679
|
+
function modelOf(summaries, throws) {
|
|
680
|
+
const analysis = analyse(throws);
|
|
682
681
|
const tags = new Map();
|
|
683
682
|
const anchors = new Map();
|
|
684
683
|
const helpers = new Map();
|
|
@@ -714,12 +713,10 @@ export const mustHandleError = defineRule({
|
|
|
714
713
|
listUnknowns: true,
|
|
715
714
|
explain: EXPLAIN,
|
|
716
715
|
},
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
mustHandle: summarizeMustHandle(ctx),
|
|
720
|
-
}),
|
|
716
|
+
reads: [THROWS_ANALYSIS],
|
|
717
|
+
summarize: (ctx) => ({ mustHandle: summarizeMustHandle(ctx) }),
|
|
721
718
|
check(summaries, ctx) {
|
|
722
|
-
const { model, untracked } = modelOf(summaries);
|
|
719
|
+
const { model, untracked } = modelOf(summaries, ctx.analysisSummaries(THROWS_ANALYSIS));
|
|
723
720
|
for (const location of untracked) {
|
|
724
721
|
ctx.unknown({
|
|
725
722
|
message: "not checked: the calls that meet `@mustHandle` on a type: only an error class is followed",
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { FileContext, Json, Location, StringListRecord } from "@stateward/core";
|
|
2
2
|
import type { Analysis, Source } from "../inference/solve.js";
|
|
3
|
-
import type { ThrowsSummary } from "../inference/summary.js";
|
|
4
3
|
import { type GuardSkips } from "./render-guards.js";
|
|
5
4
|
import type { BoundaryElement, TreeFunction, TreeRender, TreeSummary } from "./tree.js";
|
|
6
5
|
/**
|
|
@@ -9,9 +8,11 @@ import type { BoundaryElement, TreeFunction, TreeRender, TreeSummary } from "./t
|
|
|
9
8
|
* each boundary can catch. Handlers, timers and async code are left out: a boundary never sees
|
|
10
9
|
* their errors.
|
|
11
10
|
*/
|
|
12
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* The summary of the pack's React rules: the render tree of one file. The throws facts they solve
|
|
13
|
+
* with it are the `errors/throws` analysis's summaries (`ProjectContext.analysisSummaries`).
|
|
14
|
+
*/
|
|
13
15
|
export type ReactSummary = {
|
|
14
|
-
readonly throws: ThrowsSummary;
|
|
15
16
|
readonly tree: TreeSummary;
|
|
16
17
|
};
|
|
17
18
|
/** The rules whose summaries hold a render tree; the first that ran is read. */
|
|
@@ -69,10 +70,11 @@ export type Model = {
|
|
|
69
70
|
readonly labels: ReadonlyMap<string, string>;
|
|
70
71
|
};
|
|
71
72
|
};
|
|
72
|
-
/**
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
/**
|
|
74
|
+
* The pack's view of the app's render tree, built once per pair of summaries maps: the React
|
|
75
|
+
* rule's trees, and the throws facts (`errors/throws`'s summaries).
|
|
76
|
+
*/
|
|
77
|
+
export declare function modelOf(summaries: ReadonlyMap<string, Json>, throws: ReadonlyMap<string, Json>): Model;
|
|
76
78
|
/** The line every boundary hover ends with: what no boundary ever catches. */
|
|
77
79
|
export declare const NOT_CAUGHT = "not caught by a boundary: errors in event handlers and async code";
|
|
78
80
|
/**
|
package/dist/react/boundaries.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { propagate } from "@stateward/core";
|
|
2
|
-
import { summarizeOnce } from "../inference/project.js";
|
|
3
2
|
import { analyse, evaluated } from "../inference/solve.js";
|
|
4
3
|
import { className, unknownText } from "../inference/format.js";
|
|
5
4
|
import { fieldsOf } from "../inference/summary.js";
|
|
@@ -13,7 +12,7 @@ export const TREE_RULES = [
|
|
|
13
12
|
/**
|
|
14
13
|
* The last file's trees by program, then by the boundaries the rule's config adds (as JSON): the
|
|
15
14
|
* pack's two React rules summarize the same file one after the other. Only the last file is
|
|
16
|
-
* kept
|
|
15
|
+
* kept.
|
|
17
16
|
*/
|
|
18
17
|
const last = new WeakMap();
|
|
19
18
|
export function summarizeReact(ctx, libraryBoundaries = LIBRARY_BOUNDARIES, skips = ALL_GUARDS) {
|
|
@@ -28,27 +27,12 @@ export function summarizeReact(ctx, libraryBoundaries = LIBRARY_BOUNDARIES, skip
|
|
|
28
27
|
tree = summarizeTree(ctx, libraryBoundaries, skips);
|
|
29
28
|
known.trees.set(key, tree);
|
|
30
29
|
}
|
|
31
|
-
return {
|
|
30
|
+
return { tree };
|
|
32
31
|
}
|
|
33
32
|
/** What `nearest` answers for a render stateward cannot follow to where it is placed. */
|
|
34
33
|
const UNFOLLOWED = "?";
|
|
34
|
+
/** By the trees' summaries map, then the throws summaries map. */
|
|
35
35
|
const models = new WeakMap();
|
|
36
|
-
const throwsMaps = new WeakMap();
|
|
37
|
-
/** The throws part of each summary: the same facts `catch-misses-error` solves. */
|
|
38
|
-
export function throwsOf(summaries) {
|
|
39
|
-
let known = throwsMaps.get(summaries);
|
|
40
|
-
if (known === undefined) {
|
|
41
|
-
const made = new Map();
|
|
42
|
-
for (const [file, value] of summaries) {
|
|
43
|
-
const throws = fieldsOf(value)?.throws;
|
|
44
|
-
if (throws !== undefined)
|
|
45
|
-
made.set(file, throws);
|
|
46
|
-
}
|
|
47
|
-
known = made;
|
|
48
|
-
throwsMaps.set(summaries, known);
|
|
49
|
-
}
|
|
50
|
-
return known;
|
|
51
|
-
}
|
|
52
36
|
function compareSites(a, b) {
|
|
53
37
|
if (a.file !== b.file)
|
|
54
38
|
return a.file < b.file ? -1 : 1;
|
|
@@ -57,12 +41,20 @@ function compareSites(a, b) {
|
|
|
57
41
|
function stepOf(text) {
|
|
58
42
|
return text.endsWith("(…)") ? text.slice(0, -"(…)".length) : text;
|
|
59
43
|
}
|
|
60
|
-
/**
|
|
61
|
-
|
|
62
|
-
|
|
44
|
+
/**
|
|
45
|
+
* The pack's view of the app's render tree, built once per pair of summaries maps: the React
|
|
46
|
+
* rule's trees, and the throws facts (`errors/throws`'s summaries).
|
|
47
|
+
*/
|
|
48
|
+
export function modelOf(summaries, throws) {
|
|
49
|
+
let byThrows = models.get(summaries);
|
|
50
|
+
if (byThrows === undefined) {
|
|
51
|
+
byThrows = new WeakMap();
|
|
52
|
+
models.set(summaries, byThrows);
|
|
53
|
+
}
|
|
54
|
+
const known = byThrows.get(throws);
|
|
63
55
|
if (known !== undefined)
|
|
64
56
|
return known;
|
|
65
|
-
const analysis = analyse(
|
|
57
|
+
const analysis = analyse(throws);
|
|
66
58
|
const functions = new Map();
|
|
67
59
|
const boundaries = new Map();
|
|
68
60
|
const byFile = new Map();
|
|
@@ -339,7 +331,7 @@ export function modelOf(summaries) {
|
|
|
339
331
|
needs,
|
|
340
332
|
catches,
|
|
341
333
|
};
|
|
342
|
-
|
|
334
|
+
byThrows.set(throws, model);
|
|
343
335
|
return model;
|
|
344
336
|
}
|
|
345
337
|
/** The line every boundary hover ends with: what no boundary ever catches. */
|
package/dist/refactors.js
CHANGED
|
@@ -2,7 +2,7 @@ import ts from "@stateward/core/typescript";
|
|
|
2
2
|
import { catchesOf } from "./inference/catches.js";
|
|
3
3
|
import { catchName } from "./inference/format.js";
|
|
4
4
|
import { analyse } from "./inference/solve.js";
|
|
5
|
-
import { factSummaries } from "./
|
|
5
|
+
import { factSummaries } from "./inference/deps.js";
|
|
6
6
|
/** The title of the refactoring that wraps a catch-all for the errors its `try` can throw. */
|
|
7
7
|
export const HANDLE_KNOWN_TITLE = "Handle the known errors, rethrow the rest";
|
|
8
8
|
/**
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { defineRule, highestUncovered, option, shortestPath } from "@stateward/core";
|
|
2
2
|
import { className } from "./inference/format.js";
|
|
3
|
+
import { THROWS_ANALYSIS } from "./inference/deps.js";
|
|
3
4
|
import { modelOf, summarizeReact } from "./react/boundaries.js";
|
|
4
5
|
import { LIBRARY_BOUNDARIES } from "./react/tree.js";
|
|
5
6
|
import { codeList, fitted, waysHint } from "./text.js";
|
|
@@ -268,6 +269,7 @@ export const renderThrowWithoutBoundary = defineRule({
|
|
|
268
269
|
},
|
|
269
270
|
explain: EXPLAIN,
|
|
270
271
|
},
|
|
272
|
+
reads: [THROWS_ANALYSIS],
|
|
271
273
|
summarize: (ctx) => summarizeReact(ctx, ctx.options.boundaries, {
|
|
272
274
|
contextGuards: ctx.options.skipContextGuards,
|
|
273
275
|
inputGuards: ctx.options.skipInputGuards,
|
|
@@ -275,13 +277,13 @@ export const renderThrowWithoutBoundary = defineRule({
|
|
|
275
277
|
silentReason(summaries, ctx) {
|
|
276
278
|
if (!ctx.options.rootBoundaryCounts)
|
|
277
279
|
return undefined;
|
|
278
|
-
const model = modelOf(summaries);
|
|
280
|
+
const model = modelOf(summaries, ctx.analysisSummaries(THROWS_ANALYSIS));
|
|
279
281
|
return model.entries.length > 0 && model.entries.every((entry) => rootBoundaryOf(model, entry))
|
|
280
282
|
? ROOT_BOUNDARY_SILENT
|
|
281
283
|
: undefined;
|
|
282
284
|
},
|
|
283
285
|
check(summaries, ctx) {
|
|
284
|
-
const model = modelOf(summaries);
|
|
286
|
+
const model = modelOf(summaries, ctx.analysisSummaries(THROWS_ANALYSIS));
|
|
285
287
|
const classes = model.analysis.classes;
|
|
286
288
|
const walk = (roots, open = []) => highestUncovered({
|
|
287
289
|
roots,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** The group the rule belongs to in the docs and in `stateward status`. */
|
|
2
2
|
export declare const GROUP = "callers";
|
|
3
|
-
export declare const throwsDocMismatch: import("@stateward/core").ProjectRule<import("
|
|
3
|
+
export declare const throwsDocMismatch: import("@stateward/core").ProjectRule<import("@stateward/core").Json, {
|
|
4
4
|
severities: import("@stateward/core").SeveritiesOption<"missing" | "extra">;
|
|
5
5
|
ignoreClasses: import("@stateward/core").StringsOption;
|
|
6
6
|
}, "callers", Readonly<Record<string, import("@stateward/core").Json>>>;
|
|
@@ -3,7 +3,7 @@ import { catchName, className } from "./inference/format.js";
|
|
|
3
3
|
import { analyse, collected, evaluated, relation } from "./inference/solve.js";
|
|
4
4
|
import { REASON } from "./inference/summarize.js";
|
|
5
5
|
import { decidingFacts } from "./inference/needs.js";
|
|
6
|
-
import {
|
|
6
|
+
import { THROWS_ANALYSIS } from "./inference/deps.js";
|
|
7
7
|
import { codeList, fitted } from "./text.js";
|
|
8
8
|
import { markThrowsReferences } from "./throws-reads.js";
|
|
9
9
|
/** The group the rule belongs to in the docs and in `stateward status`. */
|
|
@@ -219,12 +219,14 @@ export const throwsDocMismatch = defineRule({
|
|
|
219
219
|
explain: EXPLAIN,
|
|
220
220
|
proves: { tags: ["throws"] },
|
|
221
221
|
},
|
|
222
|
+
reads: [THROWS_ANALYSIS],
|
|
223
|
+
// The file side only marks the references to `@throws` tags; the facts are the analysis's.
|
|
222
224
|
summarize: (ctx) => {
|
|
223
225
|
markThrowsReferences(ctx);
|
|
224
|
-
return
|
|
226
|
+
return undefined;
|
|
225
227
|
},
|
|
226
|
-
check(
|
|
227
|
-
const analysis = analyse(
|
|
228
|
+
check(_summaries, ctx) {
|
|
229
|
+
const analysis = analyse(ctx.analysisSummaries(THROWS_ANALYSIS));
|
|
228
230
|
const reported = new Set();
|
|
229
231
|
for (const entry of analysis.functions.values())
|
|
230
232
|
check(entry, analysis, ctx, reported);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stateward/plugin-errors",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "stateward rules for errors: errors are handled where they can happen.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -32,6 +32,6 @@
|
|
|
32
32
|
"!dist/**/*.tsbuildinfo"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@stateward/core": "1.3.
|
|
35
|
+
"@stateward/core": "1.3.1"
|
|
36
36
|
}
|
|
37
37
|
}
|