@stateward/plugin-errors 1.2.2 → 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.
- package/README.md +9 -8
- package/dist/catch-hides-unexpected.d.ts +4 -1
- package/dist/catch-hides-unexpected.js +12 -5
- package/dist/catch-misses-error.d.ts +1 -1
- package/dist/catch-misses-error.js +1 -1
- package/dist/finally-can-throw.js +3 -3
- package/dist/index.d.ts +3 -1
- package/dist/index.js +1 -0
- package/dist/inference/analysis.d.ts +109 -0
- package/dist/inference/analysis.js +170 -0
- package/dist/inference/builtins.d.ts +0 -2
- package/dist/inference/builtins.js +0 -33
- package/dist/inference/deps.js +2 -2
- package/dist/inference/needs.d.ts +16 -0
- package/dist/inference/needs.js +27 -0
- package/dist/inference/packages.d.ts +24 -32
- package/dist/inference/packages.js +156 -680
- package/dist/inference/project.d.ts +2 -2
- package/dist/inference/project.js +3 -2
- package/dist/inference/solve.d.ts +29 -4
- package/dist/inference/solve.js +34 -5
- package/dist/inference/summarize.d.ts +27 -15
- package/dist/inference/summarize.js +247 -130
- package/dist/inference/summary.d.ts +41 -5
- package/dist/inference/summary.js +84 -12
- package/dist/inference/unreachable.d.ts +5 -0
- package/dist/inference/unreachable.js +160 -0
- package/dist/must-handle-error.d.ts +2 -1
- package/dist/must-handle-error.js +4 -4
- package/dist/plugin.d.ts +12 -2
- package/dist/plugin.js +4 -2
- package/dist/react/tree.js +8 -4
- package/dist/render-throw-without-boundary.d.ts +13 -4
- package/dist/result-ignored.d.ts +4 -1
- package/dist/result-type.js +2 -2
- package/dist/result-unchecked.d.ts +4 -1
- package/dist/result-unchecked.js +139 -61
- package/dist/rules.meta.d.ts +26 -14
- package/dist/rules.meta.js +18 -14
- package/dist/syntax.d.ts +0 -13
- package/dist/syntax.js +0 -79
- package/dist/text.d.ts +5 -2
- package/dist/text.js +11 -5
- package/dist/throws-doc-mismatch.d.ts +1 -1
- package/dist/throws-doc-mismatch.js +7 -1
- package/package.json +2 -2
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/** Why a package's function is not (fully) known: fixed strings, shown as they are. */
|
|
2
|
+
export const UNKNOWN_REASONS = [
|
|
3
|
+
// No `facts` line, in the config or a pack, states what the package's function throws (0041).
|
|
4
|
+
"its errors are not stated",
|
|
5
|
+
// A line states what the call throws, and not what the promise it returns rejects with: kinds
|
|
6
|
+
// are strict, so a `throws` line (1.2's style) leaves the promise not stated.
|
|
7
|
+
"its `facts` line states no `rejects`, the kind its promise needs",
|
|
8
|
+
];
|
|
1
9
|
function isList(value) {
|
|
2
10
|
return Array.isArray(value);
|
|
3
11
|
}
|
|
@@ -42,24 +50,52 @@ function readSide(value) {
|
|
|
42
50
|
const f = value === undefined ? undefined : fieldsOf(value);
|
|
43
51
|
const classes = readStrings(f?.classes);
|
|
44
52
|
const unknown = readStrings(f?.unknown);
|
|
45
|
-
|
|
53
|
+
if (classes === undefined || unknown === undefined)
|
|
54
|
+
return undefined;
|
|
55
|
+
return { classes, unknown };
|
|
46
56
|
}
|
|
47
|
-
const SOURCES = ["config", "
|
|
57
|
+
const SOURCES = ["config", "shipped", "unknown"];
|
|
48
58
|
function readSource(value) {
|
|
49
59
|
return SOURCES.find((source) => source === value);
|
|
50
60
|
}
|
|
61
|
+
const FACT_SIDES = ["throws", "rejects"];
|
|
62
|
+
/** A `FactKey` as `PackageFacts.key` writes it; undefined for anything else. */
|
|
63
|
+
function readKey(value) {
|
|
64
|
+
const f = value === undefined ? undefined : fieldsOf(value);
|
|
65
|
+
if (f === undefined || !isString(f.name))
|
|
66
|
+
return undefined;
|
|
67
|
+
if (f.kind === "unnamed") {
|
|
68
|
+
return isString(f.reason) ? { kind: "unnamed", name: f.name, reason: f.reason } : undefined;
|
|
69
|
+
}
|
|
70
|
+
if (f.kind !== "named" || !isString(f.module))
|
|
71
|
+
return undefined;
|
|
72
|
+
if (f.version !== undefined && !isString(f.version))
|
|
73
|
+
return undefined;
|
|
74
|
+
return {
|
|
75
|
+
kind: "named",
|
|
76
|
+
module: f.module,
|
|
77
|
+
name: f.name,
|
|
78
|
+
...(f.version === undefined ? {} : { version: f.version }),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
51
81
|
/** Package facts as `PackageFacts` writes them; undefined for anything else. */
|
|
52
82
|
export function readPackageFacts(value) {
|
|
53
83
|
const f = value === undefined ? undefined : fieldsOf(value);
|
|
54
|
-
if (f === undefined || !isString(f.name) || !isString(f.version)
|
|
84
|
+
if (f === undefined || !isString(f.name) || !isString(f.version))
|
|
55
85
|
return undefined;
|
|
56
|
-
|
|
86
|
+
const key = readKey(f.key);
|
|
87
|
+
const side = FACT_SIDES.find((one) => one === f.side);
|
|
57
88
|
const source = readSource(f.source);
|
|
58
89
|
const throws = readSide(f.throws);
|
|
59
90
|
const rejects = readSide(f.rejects);
|
|
60
|
-
if (
|
|
91
|
+
if (key === undefined ||
|
|
92
|
+
side === undefined ||
|
|
93
|
+
source === undefined ||
|
|
94
|
+
throws === undefined ||
|
|
95
|
+
rejects === undefined) {
|
|
61
96
|
return undefined;
|
|
62
|
-
|
|
97
|
+
}
|
|
98
|
+
return { name: f.name, version: f.version, key, side, source, throws, rejects };
|
|
63
99
|
}
|
|
64
100
|
function readEffect(value) {
|
|
65
101
|
const f = fieldsOf(value);
|
|
@@ -67,10 +103,19 @@ function readEffect(value) {
|
|
|
67
103
|
if (f === undefined || at === undefined || !isString(f.k))
|
|
68
104
|
return undefined;
|
|
69
105
|
switch (f.k) {
|
|
70
|
-
case "class":
|
|
71
|
-
return isString(f.id) &&
|
|
72
|
-
|
|
106
|
+
case "class": {
|
|
107
|
+
return isString(f.id) &&
|
|
108
|
+
(f.text === null || isString(f.text)) &&
|
|
109
|
+
(f.platform === undefined || f.platform === true)
|
|
110
|
+
? {
|
|
111
|
+
k: "class",
|
|
112
|
+
id: f.id,
|
|
113
|
+
text: f.text,
|
|
114
|
+
at,
|
|
115
|
+
...(f.platform === true ? { platform: true } : {}),
|
|
116
|
+
}
|
|
73
117
|
: undefined;
|
|
118
|
+
}
|
|
74
119
|
case "unknown":
|
|
75
120
|
return isString(f.reason) && isString(f.text)
|
|
76
121
|
? { k: "unknown", reason: f.reason, text: f.text, at }
|
|
@@ -85,8 +130,16 @@ function readEffect(value) {
|
|
|
85
130
|
const facts = readPackageFacts(f.facts);
|
|
86
131
|
return facts !== undefined &&
|
|
87
132
|
isString(f.text) &&
|
|
88
|
-
(f.part === "throws" || f.part === "rejects")
|
|
89
|
-
|
|
133
|
+
(f.part === "throws" || f.part === "rejects") &&
|
|
134
|
+
(f.platform === undefined || f.platform === true)
|
|
135
|
+
? {
|
|
136
|
+
k: "package",
|
|
137
|
+
facts,
|
|
138
|
+
part: f.part,
|
|
139
|
+
text: f.text,
|
|
140
|
+
at,
|
|
141
|
+
...(f.platform === true ? { platform: true } : {}),
|
|
142
|
+
}
|
|
90
143
|
: undefined;
|
|
91
144
|
}
|
|
92
145
|
case "maybe": {
|
|
@@ -214,7 +267,26 @@ export function readClass(value) {
|
|
|
214
267
|
return undefined;
|
|
215
268
|
if ((f.parent !== null && !isString(f.parent)) || typeof f.open !== "boolean")
|
|
216
269
|
return undefined;
|
|
217
|
-
|
|
270
|
+
const fields = each(f.fields, (item) => (isString(item) ? item : undefined));
|
|
271
|
+
if (fields === undefined)
|
|
272
|
+
return undefined;
|
|
273
|
+
if (f.declared !== undefined && !isString(f.declared))
|
|
274
|
+
return undefined;
|
|
275
|
+
if (f.version !== undefined && !isString(f.version))
|
|
276
|
+
return undefined;
|
|
277
|
+
const key = f.key === undefined ? undefined : readKey(f.key);
|
|
278
|
+
if (f.key !== undefined && key === undefined)
|
|
279
|
+
return undefined;
|
|
280
|
+
return {
|
|
281
|
+
id: f.id,
|
|
282
|
+
name: f.name,
|
|
283
|
+
parent: f.parent,
|
|
284
|
+
open: f.open,
|
|
285
|
+
fields,
|
|
286
|
+
...(f.declared === undefined ? {} : { declared: f.declared }),
|
|
287
|
+
...(f.version === undefined ? {} : { version: f.version }),
|
|
288
|
+
...(key === undefined ? {} : { key }),
|
|
289
|
+
};
|
|
218
290
|
}
|
|
219
291
|
/** Read once per summary object: the engine hands out the same frozen object while it is unchanged. */
|
|
220
292
|
const read = new WeakMap();
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import ts from "@stateward/core/typescript";
|
|
2
|
+
import type { TypeQueries } from "@stateward/core";
|
|
3
|
+
/** Whether a `throw` cannot run while the types hold (see above). */
|
|
4
|
+
export declare function cannotRun(types: TypeQueries, node: ts.ThrowStatement): boolean;
|
|
5
|
+
//# sourceMappingURL=unreachable.d.ts.map
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import ts from "@stateward/core/typescript";
|
|
2
|
+
import { stripParentheses } from "../syntax.js";
|
|
3
|
+
/*
|
|
4
|
+
* A `throw` that cannot run because the value it is about has no case left: the `default` of a
|
|
5
|
+
* `switch` whose cases cover every value of its type, a `throw` after an `if` chain that returns
|
|
6
|
+
* for every value, or a `throw` that names a value TypeScript has narrowed to `never`. Code
|
|
7
|
+
* written to fail loudly if the type ever grows (`default: throw new Error("unknown kind")`) is not
|
|
8
|
+
* an error a caller can get while the types hold.
|
|
9
|
+
*/
|
|
10
|
+
function keyOf(literal) {
|
|
11
|
+
return `${typeof literal.value}:${String(literal.value)}`;
|
|
12
|
+
}
|
|
13
|
+
/** The values of `node`'s type, or undefined when they are not a finite set of literals. */
|
|
14
|
+
function valuesOf(types, node) {
|
|
15
|
+
const literals = types.literalsOf(node);
|
|
16
|
+
return literals === "not-finite" ? undefined : new Set(literals.map(keyOf));
|
|
17
|
+
}
|
|
18
|
+
/** Whether every value of `all` is in `covered`. */
|
|
19
|
+
function covers(covered, all) {
|
|
20
|
+
return [...all].every((value) => covered.has(value));
|
|
21
|
+
}
|
|
22
|
+
/** The `default` clause the statement sits in directly (in its statements, or a block of them). */
|
|
23
|
+
function defaultClauseOf(node) {
|
|
24
|
+
let at = node.parent;
|
|
25
|
+
while (ts.isBlock(at))
|
|
26
|
+
at = at.parent;
|
|
27
|
+
return ts.isDefaultClause(at) ? at : undefined;
|
|
28
|
+
}
|
|
29
|
+
/** A `default` that no value of the switched expression reaches: the cases cover its type. */
|
|
30
|
+
function unreachableDefault(types, clause) {
|
|
31
|
+
const clauses = clause.parent.clauses;
|
|
32
|
+
const index = clauses.indexOf(clause);
|
|
33
|
+
// A case with no statements just before it falls through into the default.
|
|
34
|
+
const before = index > 0 ? clauses[index - 1] : undefined;
|
|
35
|
+
if (before?.statements.length === 0)
|
|
36
|
+
return false;
|
|
37
|
+
const all = valuesOf(types, clause.parent.parent.expression);
|
|
38
|
+
if (all === undefined)
|
|
39
|
+
return false;
|
|
40
|
+
if (all.size === 0)
|
|
41
|
+
return false;
|
|
42
|
+
const covered = new Set();
|
|
43
|
+
for (const one of clauses) {
|
|
44
|
+
if (!ts.isCaseClause(one))
|
|
45
|
+
continue;
|
|
46
|
+
const values = valuesOf(types, one.expression);
|
|
47
|
+
if (values?.size !== 1)
|
|
48
|
+
return false;
|
|
49
|
+
for (const value of values)
|
|
50
|
+
covered.add(value);
|
|
51
|
+
}
|
|
52
|
+
return covers(covered, all);
|
|
53
|
+
}
|
|
54
|
+
/** `x === A`, `A === x`, or several joined by `||`: the reference's text and the tested values. */
|
|
55
|
+
function testedValues(types, condition) {
|
|
56
|
+
const node = stripParentheses(condition);
|
|
57
|
+
if (!ts.isBinaryExpression(node))
|
|
58
|
+
return undefined;
|
|
59
|
+
if (node.operatorToken.kind === ts.SyntaxKind.BarBarToken) {
|
|
60
|
+
const left = testedValues(types, node.left);
|
|
61
|
+
const right = testedValues(types, node.right);
|
|
62
|
+
if (left === undefined || left.text !== right?.text)
|
|
63
|
+
return undefined;
|
|
64
|
+
return { ...left, values: new Set([...left.values, ...right.values]) };
|
|
65
|
+
}
|
|
66
|
+
if (node.operatorToken.kind !== ts.SyntaxKind.EqualsEqualsEqualsToken &&
|
|
67
|
+
node.operatorToken.kind !== ts.SyntaxKind.EqualsEqualsToken) {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
for (const [reference, literal] of [
|
|
71
|
+
[node.left, node.right],
|
|
72
|
+
[node.right, node.left],
|
|
73
|
+
]) {
|
|
74
|
+
if (!ts.isIdentifier(reference) && !ts.isPropertyAccessExpression(reference))
|
|
75
|
+
continue;
|
|
76
|
+
const values = valuesOf(types, literal);
|
|
77
|
+
if (values?.size !== 1)
|
|
78
|
+
continue;
|
|
79
|
+
return { reference, text: reference.getText(), values };
|
|
80
|
+
}
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
function alwaysExits(node) {
|
|
84
|
+
if (ts.isBlock(node)) {
|
|
85
|
+
const last = node.statements.at(-1);
|
|
86
|
+
return last !== undefined && alwaysExits(last);
|
|
87
|
+
}
|
|
88
|
+
return ts.isReturnStatement(node) || ts.isThrowStatement(node);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* A `throw` after `if` statements of its block that test one value against literals and exit,
|
|
92
|
+
* covering every value of its type: `if (k === "a") return 1; if (k === "b") return 2; throw …`.
|
|
93
|
+
*/
|
|
94
|
+
function afterCoveringChain(types, node) {
|
|
95
|
+
const block = node.parent;
|
|
96
|
+
if (!ts.isBlock(block) && !ts.isSourceFile(block))
|
|
97
|
+
return false;
|
|
98
|
+
const index = block.statements.indexOf(node);
|
|
99
|
+
let first;
|
|
100
|
+
let text;
|
|
101
|
+
const covered = new Set();
|
|
102
|
+
for (let at = index - 1; at >= 0; at -= 1) {
|
|
103
|
+
const statement = block.statements[at];
|
|
104
|
+
if (statement === undefined || !ts.isIfStatement(statement))
|
|
105
|
+
break;
|
|
106
|
+
let chain = statement;
|
|
107
|
+
const ifs = [];
|
|
108
|
+
// `if … else if …` with every branch exiting, and no final `else`.
|
|
109
|
+
while (chain !== undefined) {
|
|
110
|
+
ifs.push(chain);
|
|
111
|
+
const next = chain.elseStatement;
|
|
112
|
+
chain = next !== undefined && ts.isIfStatement(next) ? next : undefined;
|
|
113
|
+
if (next !== undefined && !ts.isIfStatement(next))
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
for (const one of ifs) {
|
|
117
|
+
if (!alwaysExits(one.thenStatement))
|
|
118
|
+
return false;
|
|
119
|
+
const tested = testedValues(types, one.expression);
|
|
120
|
+
if (tested === undefined)
|
|
121
|
+
return false;
|
|
122
|
+
if (text !== undefined && tested.text !== text)
|
|
123
|
+
return false;
|
|
124
|
+
text = tested.text;
|
|
125
|
+
first = tested.reference;
|
|
126
|
+
for (const value of tested.values)
|
|
127
|
+
covered.add(value);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (first === undefined)
|
|
131
|
+
return false;
|
|
132
|
+
const all = valuesOf(types, first);
|
|
133
|
+
return all !== undefined && all.size > 0 && covers(covered, all);
|
|
134
|
+
}
|
|
135
|
+
/** A reference in the thrown expression whose type TypeScript has narrowed to `never`. */
|
|
136
|
+
function namesNever(types, node) {
|
|
137
|
+
let found = false;
|
|
138
|
+
const visit = (inner) => {
|
|
139
|
+
if (found || ts.isFunctionLike(inner))
|
|
140
|
+
return;
|
|
141
|
+
if ((ts.isIdentifier(inner) && !ts.isPropertyAccessExpression(inner.parent)) ||
|
|
142
|
+
ts.isPropertyAccessExpression(inner)) {
|
|
143
|
+
if (types.typeTextOf(inner) === "never") {
|
|
144
|
+
found = true;
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
ts.forEachChild(inner, visit);
|
|
149
|
+
};
|
|
150
|
+
visit(node.expression);
|
|
151
|
+
return found;
|
|
152
|
+
}
|
|
153
|
+
/** Whether a `throw` cannot run while the types hold (see above). */
|
|
154
|
+
export function cannotRun(types, node) {
|
|
155
|
+
const clause = defaultClauseOf(node);
|
|
156
|
+
if (clause !== undefined && unreachableDefault(types, clause))
|
|
157
|
+
return true;
|
|
158
|
+
return afterCoveringChain(types, node) || namesNever(types, node);
|
|
159
|
+
}
|
|
160
|
+
//# sourceMappingURL=unreachable.js.map
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Json } from "@stateward/core";
|
|
1
2
|
import type { Span, ThrowsSummary } from "./inference/summary.js";
|
|
2
3
|
/** The group the rule belongs to in the docs and in `stateward status`. */
|
|
3
4
|
export declare const GROUP = "callers";
|
|
@@ -50,6 +51,6 @@ export type MustHandleSummary = {
|
|
|
50
51
|
readonly throws: ThrowsSummary;
|
|
51
52
|
readonly mustHandle: MustHandleFacts;
|
|
52
53
|
};
|
|
53
|
-
export declare const mustHandleError: import("@stateward/core").ProjectRule<MustHandleSummary, Readonly<Record<string, never>>, "callers"
|
|
54
|
+
export declare const mustHandleError: import("@stateward/core").ProjectRule<MustHandleSummary, Readonly<Record<string, never>>, "callers", Readonly<Record<string, Json>>>;
|
|
54
55
|
export {};
|
|
55
56
|
//# sourceMappingURL=must-handle-error.d.ts.map
|
|
@@ -3,11 +3,11 @@ import { defineRule } from "@stateward/core";
|
|
|
3
3
|
import { catchName, className } from "./inference/format.js";
|
|
4
4
|
import { summarizeOnce } from "./inference/project.js";
|
|
5
5
|
import { analyse, evaluated, relation } from "./inference/solve.js";
|
|
6
|
-
import { ANONYMOUS,
|
|
6
|
+
import { ANONYMOUS, errorClassIdOf } from "./inference/summarize.js";
|
|
7
7
|
import { each, fieldsOf, isString, spanOf } from "./inference/summary.js";
|
|
8
8
|
import { throwsOf } from "./react/boundaries.js";
|
|
9
9
|
import { stripParentheses } from "./syntax.js";
|
|
10
|
-
import { fitted,
|
|
10
|
+
import { fitted, shorten, withExample } from "./text.js";
|
|
11
11
|
/** The group the rule belongs to in the docs and in `stateward status`. */
|
|
12
12
|
export const GROUP = "callers";
|
|
13
13
|
const EXPLAIN = `# errors/must-handle-error
|
|
@@ -170,7 +170,7 @@ function errorHelperOf(fn, id, types) {
|
|
|
170
170
|
const named = instanceofNames(first.expression, variable);
|
|
171
171
|
if (named === undefined || throwsVariable(first.thenStatement, variable))
|
|
172
172
|
continue;
|
|
173
|
-
const classes = named.map((one) =>
|
|
173
|
+
const classes = named.map((one) => errorClassIdOf(types, one));
|
|
174
174
|
if (classes.some((one) => one === undefined))
|
|
175
175
|
return undefined;
|
|
176
176
|
return { id, parameter, classes: classes.filter((one) => one !== undefined) };
|
|
@@ -226,7 +226,7 @@ function summarizeMustHandle(ctx) {
|
|
|
226
226
|
tags.push({
|
|
227
227
|
id: symbol.id,
|
|
228
228
|
name: symbol.name,
|
|
229
|
-
how:
|
|
229
|
+
how: (ts.getTextOfJSDocComment(tag.comment) ?? "").replace(/\s+/g, " ").trim(),
|
|
230
230
|
at: spanOfNode(tag),
|
|
231
231
|
});
|
|
232
232
|
}
|
package/dist/plugin.d.ts
CHANGED
|
@@ -66,7 +66,6 @@ export declare function errors(): import("@stateward/core").PluginOf<"errors", {
|
|
|
66
66
|
};
|
|
67
67
|
}, "render">;
|
|
68
68
|
readonly "must-handle-error": import("@stateward/core").LazyRule<Readonly<Record<string, import("@stateward/core").OptionSpec>>, "callers">;
|
|
69
|
-
readonly "narrow-try": import("@stateward/core").LazyRule<Readonly<Record<string, import("@stateward/core").OptionSpec>>, "catch">;
|
|
70
69
|
readonly "result-ignored": import("@stateward/core").LazyRule<{
|
|
71
70
|
readonly allowVoid: {
|
|
72
71
|
readonly kind: "boolean";
|
|
@@ -84,6 +83,17 @@ export declare function errors(): import("@stateward/core").PluginOf<"errors", {
|
|
|
84
83
|
readonly description: "Functions whose Result may be dropped, by the name they are called with (`logEvent`, `*.track`; globs allowed).";
|
|
85
84
|
};
|
|
86
85
|
}, "callers">;
|
|
87
|
-
readonly "result-unchecked": import("@stateward/core").LazyRule<
|
|
86
|
+
readonly "result-unchecked": import("@stateward/core").LazyRule<{
|
|
87
|
+
readonly failureNames: {
|
|
88
|
+
readonly kind: "strings";
|
|
89
|
+
readonly default: readonly [];
|
|
90
|
+
readonly description: "Names (or globs like isErr*) that are true when the call failed, besides the result's own `error`: a property of the result (`isError`), or a function called with it (`isFailure(result)`). Its type does not say what such a name means.";
|
|
91
|
+
};
|
|
92
|
+
readonly successNames: {
|
|
93
|
+
readonly kind: "strings";
|
|
94
|
+
readonly default: readonly [];
|
|
95
|
+
readonly description: "Names (or globs) that are true when the call worked, besides the result's own `data`, `ok` and `success`: a property of the result (`isSuccess`, `value`), or a function called with it (`isOk(result)`).";
|
|
96
|
+
};
|
|
97
|
+
}, "callers">;
|
|
88
98
|
}>;
|
|
89
99
|
//# sourceMappingURL=plugin.d.ts.map
|
package/dist/plugin.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { definePlugin, lazyRule, moduleLoader } from "@stateward/core";
|
|
2
2
|
import { codeActions } from "./refactors.js";
|
|
3
3
|
import { hover } from "./hover.js";
|
|
4
|
+
import { throws } from "./inference/analysis.js";
|
|
4
5
|
import { libraryFacts } from "./inference/deps.js";
|
|
5
6
|
import { inlayHints } from "./inlay.js";
|
|
6
7
|
import { RULES } from "./rules.meta.js";
|
|
@@ -12,7 +13,6 @@ const load = {
|
|
|
12
13
|
throwsDocMismatch: moduleLoader(() => import("./throws-doc-mismatch.js")),
|
|
13
14
|
renderThrowWithoutBoundary: moduleLoader(() => import("./render-throw-without-boundary.js")),
|
|
14
15
|
mustHandleError: moduleLoader(() => import("./must-handle-error.js")),
|
|
15
|
-
narrowTry: moduleLoader(() => import("./narrow-try.js")),
|
|
16
16
|
resultIgnored: moduleLoader(() => import("./result-ignored.js")),
|
|
17
17
|
resultUnchecked: moduleLoader(() => import("./result-unchecked.js")),
|
|
18
18
|
};
|
|
@@ -27,11 +27,13 @@ export function errors() {
|
|
|
27
27
|
"throws-doc-mismatch": lazyRule(RULES["throws-doc-mismatch"], load.throwsDocMismatch, (module) => module.throwsDocMismatch),
|
|
28
28
|
"render-throw-without-boundary": lazyRule(RULES["render-throw-without-boundary"], load.renderThrowWithoutBoundary, (module) => module.renderThrowWithoutBoundary),
|
|
29
29
|
"must-handle-error": lazyRule(RULES["must-handle-error"], load.mustHandleError, (module) => module.mustHandleError),
|
|
30
|
-
"narrow-try": lazyRule(RULES["narrow-try"], load.narrowTry, (module) => module.narrowTry),
|
|
31
30
|
"result-ignored": lazyRule(RULES["result-ignored"], load.resultIgnored, (module) => module.resultIgnored),
|
|
32
31
|
"result-unchecked": lazyRule(RULES["result-unchecked"], load.resultUnchecked, (module) => module.resultUnchecked),
|
|
33
32
|
},
|
|
34
33
|
editor: { hover, inlayHints, codeActions, libraryFacts },
|
|
34
|
+
analyses: { throws },
|
|
35
|
+
// Removed in R129: its precision followed the codebase's style (26% to 96%), not the rule.
|
|
36
|
+
removed: ["errors/narrow-try"],
|
|
35
37
|
});
|
|
36
38
|
}
|
|
37
39
|
//# sourceMappingURL=plugin.js.map
|
package/dist/react/tree.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import ts from "@stateward/core/typescript";
|
|
2
|
-
import {
|
|
2
|
+
import { packageNameOf } from "@stateward/core";
|
|
3
|
+
import { errorClassIdOf } from "../inference/summarize.js";
|
|
3
4
|
import { each, fieldsOf, isString, readStrings, spanOf } from "../inference/summary.js";
|
|
4
5
|
import { scanRunning, stripParentheses } from "../syntax.js";
|
|
5
6
|
import { ALL_GUARDS, guardThrows } from "./render-guards.js";
|
|
@@ -110,7 +111,7 @@ function classifyTag(types, tag, libraryBoundaries) {
|
|
|
110
111
|
}
|
|
111
112
|
if (!types.isOwnFile(declaration.file)) {
|
|
112
113
|
const library = packageNameOf(types, declaration.file);
|
|
113
|
-
const isLibraryBoundary = (libraryBoundaries[library] ?? []).includes(symbol.name);
|
|
114
|
+
const isLibraryBoundary = library !== undefined && (libraryBoundaries[library] ?? []).includes(symbol.name);
|
|
114
115
|
return { target: undefined, boundary: isLibraryBoundary ? { own: null } : undefined };
|
|
115
116
|
}
|
|
116
117
|
return {
|
|
@@ -370,7 +371,7 @@ function chainOf(types, fn, ref) {
|
|
|
370
371
|
return null;
|
|
371
372
|
const { classes, ...rest } = found;
|
|
372
373
|
const branches = classes.map((names) => {
|
|
373
|
-
const ids = names.map((name) =>
|
|
374
|
+
const ids = names.map((name) => errorClassIdOf(types, ts.isPropertyAccessExpression(name) ? name.name : name));
|
|
374
375
|
return ids.every((id) => id !== undefined) ? ids : null;
|
|
375
376
|
});
|
|
376
377
|
return { ...rest, file: fn.getSourceFile().fileName, branches };
|
|
@@ -634,7 +635,10 @@ export function summarizeTree(ctx, libraryBoundaries = LIBRARY_BOUNDARIES, skips
|
|
|
634
635
|
continue;
|
|
635
636
|
if (types.isOwnFile(declaration.file) || !BOUNDARY_NAME.test(symbol.name))
|
|
636
637
|
continue;
|
|
637
|
-
|
|
638
|
+
const library = packageNameOf(types, declaration.file);
|
|
639
|
+
if (library === undefined)
|
|
640
|
+
continue;
|
|
641
|
+
return { tag: symbol.name, package: library };
|
|
638
642
|
}
|
|
639
643
|
return undefined;
|
|
640
644
|
};
|
|
@@ -3,9 +3,18 @@ export declare const GROUP = "render";
|
|
|
3
3
|
/** The reason `plan` gives when a root boundary makes the rule silent. */
|
|
4
4
|
export declare const ROOT_BOUNDARY_SILENT = "your app's root has an error boundary";
|
|
5
5
|
export declare const renderThrowWithoutBoundary: import("@stateward/core").ProjectRule<import("./react/boundaries.js").ReactSummary, {
|
|
6
|
-
skipContextGuards: import("@stateward/core").BooleanOption
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
skipContextGuards: import("@stateward/core").BooleanOption & Pick<{
|
|
7
|
+
readonly default: true;
|
|
8
|
+
readonly description: "Leave out the usual check in a context hook: `if (!ctx) throw new Error(\"useAuth must be used within AuthProvider\")`.";
|
|
9
|
+
}, "internal">;
|
|
10
|
+
skipInputGuards: import("@stateward/core").BooleanOption & Pick<{
|
|
11
|
+
readonly default: true;
|
|
12
|
+
readonly description: "Leave out a throw when a prop or a parameter whose type rules it out, or a context hook's value, is missing (a mistake of the caller).";
|
|
13
|
+
}, "internal">;
|
|
14
|
+
rootBoundaryCounts: import("@stateward/core").BooleanOption & Pick<{
|
|
15
|
+
readonly default: false;
|
|
16
|
+
readonly description: "Count the error boundary around the whole app as handling the error. Off by default: the whole app is then replaced by its fallback, so the rule asks for a boundary nearer the page.";
|
|
17
|
+
}, "internal">;
|
|
9
18
|
boundaries: import("@stateward/core").RecordOption;
|
|
10
|
-
}, "render"
|
|
19
|
+
}, "render", Readonly<Record<string, import("@stateward/core").Json>>>;
|
|
11
20
|
//# sourceMappingURL=render-throw-without-boundary.d.ts.map
|
package/dist/result-ignored.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export declare const resultIgnored: import("@stateward/core").FileRule<{
|
|
2
|
-
allowVoid: import("@stateward/core").BooleanOption
|
|
2
|
+
allowVoid: import("@stateward/core").BooleanOption & Pick<{
|
|
3
|
+
readonly default: false;
|
|
4
|
+
readonly description: "Take `void save()` as dropping the Result on purpose, and stay quiet.";
|
|
5
|
+
}, "internal">;
|
|
3
6
|
resultTypes: import("@stateward/core").StringsOption;
|
|
4
7
|
ignore: import("@stateward/core").StringsOption;
|
|
5
8
|
}, "callers">;
|
package/dist/result-type.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { matchesName } from "@stateward/core";
|
|
1
|
+
import { codeOnOneLine, matchesName } from "@stateward/core";
|
|
2
2
|
/**
|
|
3
3
|
* Whether a property tells the members of a union apart by `true` and `false`. An object with
|
|
4
4
|
* `ok: boolean` (a fetch `Response`) is not a union, so it is not a Result.
|
|
@@ -45,7 +45,7 @@ export function resultShapeOf(node, types, names) {
|
|
|
45
45
|
}
|
|
46
46
|
/** Cuts `text` to `max` characters, ending in `…`, for a headline or an example line. */
|
|
47
47
|
export function shorten(text, max) {
|
|
48
|
-
const flat = text
|
|
48
|
+
const flat = codeOnOneLine(text);
|
|
49
49
|
return flat.length > max ? `${flat.slice(0, max - 1)}…` : flat;
|
|
50
50
|
}
|
|
51
51
|
/** A hint's example: indented 4 spaces, one line per entry. */
|
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
export declare const resultUnchecked: import("@stateward/core").FileRule<
|
|
1
|
+
export declare const resultUnchecked: import("@stateward/core").FileRule<{
|
|
2
|
+
failureNames: import("@stateward/core").StringsOption;
|
|
3
|
+
successNames: import("@stateward/core").StringsOption;
|
|
4
|
+
}, "callers">;
|
|
2
5
|
//# sourceMappingURL=result-unchecked.d.ts.map
|