@stateward/core 1.2.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyses.d.ts +37 -0
- package/dist/analyses.js +57 -0
- package/dist/backend/program-record.d.ts +7 -0
- package/dist/backend/typescript6.d.ts +35 -32
- package/dist/backend/typescript6.js +3804 -163
- package/dist/baseline.d.ts +1 -1
- package/dist/baseline.js +14 -10
- package/dist/cache.d.ts +89 -5
- package/dist/cache.js +271 -40
- package/dist/checker.d.ts +11 -1
- package/dist/checker.js +32 -2
- package/dist/class-id.d.ts +34 -0
- package/dist/class-id.js +93 -0
- package/dist/code-text.d.ts +8 -0
- package/dist/code-text.js +66 -0
- package/dist/config-file.js +7 -5
- package/dist/config.d.ts +10 -2
- package/dist/config.js +541 -49
- package/dist/define.d.ts +8 -2
- package/dist/disk-cache.d.ts +2 -0
- package/dist/disk-cache.js +77 -11
- package/dist/engine.d.ts +51 -1
- package/dist/engine.js +517 -42
- package/dist/fact-lines.d.ts +31 -0
- package/dist/fact-lines.js +197 -0
- package/dist/facts-versions.d.ts +27 -0
- package/dist/facts-versions.js +99 -0
- package/dist/fixes.js +9 -4
- package/dist/guarantees.d.ts +63 -11
- package/dist/guarantees.js +151 -21
- package/dist/ignores.d.ts +11 -0
- package/dist/ignores.js +74 -27
- package/dist/implementation.d.ts +0 -6
- package/dist/implementation.js +0 -17
- package/dist/index.d.ts +10 -9
- package/dist/index.js +14 -7
- package/dist/internal.d.ts +9 -5
- package/dist/internal.js +6 -3
- package/dist/lazy.d.ts +8 -1
- package/dist/lazy.js +27 -2
- package/dist/ledger.d.ts +77 -0
- package/dist/ledger.js +423 -0
- package/dist/off-by-default.d.ts +13 -0
- package/dist/off-by-default.js +15 -0
- package/dist/options.d.ts +21 -5
- package/dist/options.js +22 -7
- package/dist/package-facts.d.ts +211 -17
- package/dist/package-facts.js +520 -38
- package/dist/plan.d.ts +1 -1
- package/dist/plan.js +7 -2
- package/dist/release.d.ts +12 -21
- package/dist/release.js +28 -38
- package/dist/renamed.d.ts +22 -3
- package/dist/renamed.js +50 -16
- package/dist/rollout.js +7 -4
- package/dist/safe-calls.d.ts +26 -0
- package/dist/safe-calls.js +345 -0
- package/dist/severity.d.ts +1 -1
- package/dist/severity.js +17 -3
- package/dist/stated.d.ts +37 -0
- package/dist/stated.js +123 -0
- package/dist/test-runner.d.ts +18 -0
- package/dist/test-runner.js +483 -0
- package/dist/testing-tsc.d.ts +16 -0
- package/dist/testing-tsc.js +86 -0
- package/dist/testing.d.ts +5 -4
- package/dist/testing.js +6 -6
- package/dist/timing.d.ts +15 -0
- package/dist/timing.js +41 -2
- package/dist/types.d.ts +1068 -16
- package/dist/unread.d.ts +90 -0
- package/dist/unread.js +405 -0
- package/dist/vocabulary.d.ts +1 -1
- package/dist/vocabulary.js +1 -1
- package/package.json +4 -2
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calls of the platform that do not throw on values their types allow: the closed list the proofs
|
|
3
|
+
* share. An entry holds only on the platform's own types, as the type checker sees them: the value
|
|
4
|
+
* a method is called on is typed by the platform's type itself (not an interface or a class of the
|
|
5
|
+
* project, and not a type the project extends), and the arguments' types make the call safe
|
|
6
|
+
* (`String(x)` on a primitive, `join` on an array of primitives). Every other call of the platform
|
|
7
|
+
* or a package may throw (`new URL("x")`, `[].reduce(add)`, `JSON.parse(text)`, `n.toString(36)`,
|
|
8
|
+
* `headers.set(…)`). A function of the project is not on the list: a proof reads it, or counts it
|
|
9
|
+
* as a call that may throw. Core knows no library; these are the language's own built-ins.
|
|
10
|
+
*/
|
|
11
|
+
import ts from "typescript";
|
|
12
|
+
/** Global functions, by name. */
|
|
13
|
+
const GLOBALS = new Map([
|
|
14
|
+
["setTimeout", "any"],
|
|
15
|
+
["clearTimeout", "any"],
|
|
16
|
+
["setInterval", "any"],
|
|
17
|
+
["clearInterval", "any"],
|
|
18
|
+
["queueMicrotask", "any"],
|
|
19
|
+
["String", "primitive"],
|
|
20
|
+
["Number", "primitive"],
|
|
21
|
+
["Boolean", "any"],
|
|
22
|
+
["isNaN", "number"],
|
|
23
|
+
["isFinite", "number"],
|
|
24
|
+
["parseInt", "primitive"],
|
|
25
|
+
["parseFloat", "primitive"],
|
|
26
|
+
]);
|
|
27
|
+
/** Constructors, by the platform's name of the constructor's type. */
|
|
28
|
+
const CONSTRUCTORS = new Map([
|
|
29
|
+
["PromiseConstructor", "any"],
|
|
30
|
+
["MapConstructor", "none"],
|
|
31
|
+
["SetConstructor", "primitive-array"],
|
|
32
|
+
["WeakMapConstructor", "none"],
|
|
33
|
+
["WeakSetConstructor", "none"],
|
|
34
|
+
["ErrorConstructor", "primitive"],
|
|
35
|
+
["DateConstructor", "primitive"],
|
|
36
|
+
["AbortControllerConstructor", "none"],
|
|
37
|
+
]);
|
|
38
|
+
/** Methods, by the platform's name of the type they are called on, then by name. */
|
|
39
|
+
const METHOD_TABLE = {
|
|
40
|
+
Console: [["*", "any"]],
|
|
41
|
+
Math: [["*", "number"]],
|
|
42
|
+
ObjectConstructor: [
|
|
43
|
+
["keys", "known"],
|
|
44
|
+
["values", "known"],
|
|
45
|
+
["entries", "known"],
|
|
46
|
+
["freeze", "any"],
|
|
47
|
+
["is", "any"],
|
|
48
|
+
],
|
|
49
|
+
ArrayConstructor: [
|
|
50
|
+
["isArray", "any"],
|
|
51
|
+
["from", "iterated"],
|
|
52
|
+
],
|
|
53
|
+
DateConstructor: [["now", "none"]],
|
|
54
|
+
NumberConstructor: [
|
|
55
|
+
["isFinite", "any"],
|
|
56
|
+
["isNaN", "any"],
|
|
57
|
+
["isInteger", "any"],
|
|
58
|
+
["isSafeInteger", "any"],
|
|
59
|
+
["parseInt", "primitive"],
|
|
60
|
+
["parseFloat", "primitive"],
|
|
61
|
+
],
|
|
62
|
+
PromiseConstructor: [
|
|
63
|
+
["resolve", "primitive"],
|
|
64
|
+
["allSettled", "any"],
|
|
65
|
+
],
|
|
66
|
+
Promise: [
|
|
67
|
+
["then", "any"],
|
|
68
|
+
["catch", "any"],
|
|
69
|
+
["finally", "any"],
|
|
70
|
+
],
|
|
71
|
+
AbortController: [["abort", "any"]],
|
|
72
|
+
Array: arrayMethods(),
|
|
73
|
+
ReadonlyArray: arrayMethods(),
|
|
74
|
+
Map: mapMethods(),
|
|
75
|
+
ReadonlyMap: [
|
|
76
|
+
["get", "any"],
|
|
77
|
+
["has", "any"],
|
|
78
|
+
["keys", "none"],
|
|
79
|
+
["values", "none"],
|
|
80
|
+
["entries", "none"],
|
|
81
|
+
],
|
|
82
|
+
Set: [
|
|
83
|
+
["add", "any"],
|
|
84
|
+
["has", "any"],
|
|
85
|
+
["delete", "any"],
|
|
86
|
+
["clear", "none"],
|
|
87
|
+
["keys", "none"],
|
|
88
|
+
["values", "none"],
|
|
89
|
+
["entries", "none"],
|
|
90
|
+
["forEach", "any"],
|
|
91
|
+
],
|
|
92
|
+
ReadonlySet: [
|
|
93
|
+
["has", "any"],
|
|
94
|
+
["keys", "none"],
|
|
95
|
+
["values", "none"],
|
|
96
|
+
["entries", "none"],
|
|
97
|
+
],
|
|
98
|
+
WeakMap: [
|
|
99
|
+
["get", "any"],
|
|
100
|
+
["set", "any"],
|
|
101
|
+
["has", "any"],
|
|
102
|
+
["delete", "any"],
|
|
103
|
+
],
|
|
104
|
+
WeakSet: [
|
|
105
|
+
["add", "any"],
|
|
106
|
+
["has", "any"],
|
|
107
|
+
["delete", "any"],
|
|
108
|
+
],
|
|
109
|
+
String: [
|
|
110
|
+
["toUpperCase", "none"],
|
|
111
|
+
["toLowerCase", "none"],
|
|
112
|
+
["trim", "none"],
|
|
113
|
+
["trimStart", "none"],
|
|
114
|
+
["trimEnd", "none"],
|
|
115
|
+
["startsWith", "primitive"],
|
|
116
|
+
["endsWith", "primitive"],
|
|
117
|
+
["includes", "primitive"],
|
|
118
|
+
["indexOf", "primitive"],
|
|
119
|
+
["split", "primitive-or-callback"],
|
|
120
|
+
["replace", "primitive-or-callback"],
|
|
121
|
+
["replaceAll", "primitive"],
|
|
122
|
+
["padStart", "primitive"],
|
|
123
|
+
["padEnd", "primitive"],
|
|
124
|
+
["charAt", "primitive"],
|
|
125
|
+
["charCodeAt", "primitive"],
|
|
126
|
+
["substring", "primitive"],
|
|
127
|
+
["slice", "primitive"],
|
|
128
|
+
["at", "primitive"],
|
|
129
|
+
["concat", "primitive"],
|
|
130
|
+
["toString", "none"],
|
|
131
|
+
],
|
|
132
|
+
// The getters of a date: an invalid date gives `NaN`, it does not throw (`toISOString` does).
|
|
133
|
+
Date: [
|
|
134
|
+
"getTime",
|
|
135
|
+
"getFullYear",
|
|
136
|
+
"getMonth",
|
|
137
|
+
"getDate",
|
|
138
|
+
"getDay",
|
|
139
|
+
"getHours",
|
|
140
|
+
"getMinutes",
|
|
141
|
+
"getSeconds",
|
|
142
|
+
"getMilliseconds",
|
|
143
|
+
"getTimezoneOffset",
|
|
144
|
+
"getUTCFullYear",
|
|
145
|
+
"getUTCMonth",
|
|
146
|
+
"getUTCDate",
|
|
147
|
+
"getUTCDay",
|
|
148
|
+
"getUTCHours",
|
|
149
|
+
"getUTCMinutes",
|
|
150
|
+
"getUTCSeconds",
|
|
151
|
+
"getUTCMilliseconds",
|
|
152
|
+
].map((name) => [name, "none"]),
|
|
153
|
+
Number: [
|
|
154
|
+
["toFixed", "digits"],
|
|
155
|
+
["toString", "none"],
|
|
156
|
+
["valueOf", "none"],
|
|
157
|
+
],
|
|
158
|
+
Boolean: [
|
|
159
|
+
["toString", "none"],
|
|
160
|
+
["valueOf", "none"],
|
|
161
|
+
],
|
|
162
|
+
};
|
|
163
|
+
const METHODS = new Map(Object.entries(METHOD_TABLE).map(([owner, methods]) => [
|
|
164
|
+
owner,
|
|
165
|
+
new Map(methods),
|
|
166
|
+
]));
|
|
167
|
+
function arrayMethods() {
|
|
168
|
+
return [
|
|
169
|
+
["map", "any"],
|
|
170
|
+
["filter", "any"],
|
|
171
|
+
["forEach", "any"],
|
|
172
|
+
["some", "any"],
|
|
173
|
+
["every", "any"],
|
|
174
|
+
["find", "any"],
|
|
175
|
+
["findIndex", "any"],
|
|
176
|
+
["findLast", "any"],
|
|
177
|
+
["findLastIndex", "any"],
|
|
178
|
+
["includes", "any"],
|
|
179
|
+
["indexOf", "any"],
|
|
180
|
+
["lastIndexOf", "any"],
|
|
181
|
+
["slice", "any"],
|
|
182
|
+
["push", "any"],
|
|
183
|
+
["pop", "none"],
|
|
184
|
+
["shift", "none"],
|
|
185
|
+
["unshift", "any"],
|
|
186
|
+
["flat", "any"],
|
|
187
|
+
["flatMap", "any"],
|
|
188
|
+
["keys", "none"],
|
|
189
|
+
["values", "none"],
|
|
190
|
+
["entries", "none"],
|
|
191
|
+
["at", "any"],
|
|
192
|
+
["reverse", "none"],
|
|
193
|
+
];
|
|
194
|
+
}
|
|
195
|
+
function mapMethods() {
|
|
196
|
+
return [
|
|
197
|
+
["get", "any"],
|
|
198
|
+
["set", "any"],
|
|
199
|
+
["has", "any"],
|
|
200
|
+
["delete", "any"],
|
|
201
|
+
["clear", "none"],
|
|
202
|
+
["keys", "none"],
|
|
203
|
+
["values", "none"],
|
|
204
|
+
["entries", "none"],
|
|
205
|
+
["forEach", "any"],
|
|
206
|
+
];
|
|
207
|
+
}
|
|
208
|
+
function stripped(expression) {
|
|
209
|
+
let node = expression;
|
|
210
|
+
while (ts.isParenthesizedExpression(node) || ts.isNonNullExpression(node)) {
|
|
211
|
+
node = node.expression;
|
|
212
|
+
}
|
|
213
|
+
return node;
|
|
214
|
+
}
|
|
215
|
+
function isWrittenFunction(node) {
|
|
216
|
+
const inner = stripped(node);
|
|
217
|
+
return ts.isArrowFunction(inner) || ts.isFunctionExpression(inner);
|
|
218
|
+
}
|
|
219
|
+
function argumentsAllowed(call, allowed, types) {
|
|
220
|
+
const given = call.arguments ?? [];
|
|
221
|
+
if (given.some(ts.isSpreadElement))
|
|
222
|
+
return false;
|
|
223
|
+
switch (allowed) {
|
|
224
|
+
case "any":
|
|
225
|
+
return true;
|
|
226
|
+
case "none":
|
|
227
|
+
return given.length === 0;
|
|
228
|
+
case "primitive":
|
|
229
|
+
// A value typed `never` is in code the types say does not run (`String(unexpected)`).
|
|
230
|
+
return given.every((one) => types.isPrimitive(one) || types.typeTextOf(one) === "never");
|
|
231
|
+
case "number":
|
|
232
|
+
return given.every((one) => types.isNumber(one));
|
|
233
|
+
case "primitive-array":
|
|
234
|
+
return given.every((one) => types.arrayElementsOf(one) === "primitives");
|
|
235
|
+
case "primitive-or-callback":
|
|
236
|
+
return given.every((one) => types.isPrimitive(one) ||
|
|
237
|
+
isWrittenFunction(one) ||
|
|
238
|
+
types.platformTypeOf(one) === "RegExp");
|
|
239
|
+
case "known":
|
|
240
|
+
return given.length === 1 && given.every((one) => !OPEN_TYPES.has(types.typeTextOf(one)));
|
|
241
|
+
case "digits":
|
|
242
|
+
return given.length === 1 && given.every(isDigits);
|
|
243
|
+
case "iterated":
|
|
244
|
+
return (given.length === 1 &&
|
|
245
|
+
given.every((one) => types.arrayElementsOf(one) !== undefined || isCollectionIterator(one, types)));
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
/** Types that say nothing of the value. */
|
|
249
|
+
const OPEN_TYPES = new Set(["any", "unknown"]);
|
|
250
|
+
/** A whole number literal from 0 to 100, as `toFixed` accepts. */
|
|
251
|
+
function isDigits(node) {
|
|
252
|
+
const inner = stripped(node);
|
|
253
|
+
if (!ts.isNumericLiteral(inner))
|
|
254
|
+
return false;
|
|
255
|
+
const value = Number(inner.text);
|
|
256
|
+
return Number.isInteger(value) && value >= 0 && value <= 100;
|
|
257
|
+
}
|
|
258
|
+
/** The collections whose `keys()`, `values()` and `entries()` iterate without running code. */
|
|
259
|
+
const COLLECTIONS = new Set(["Map", "ReadonlyMap", "Set", "ReadonlySet"]);
|
|
260
|
+
/**
|
|
261
|
+
* Whether an expression is `keys()`, `values()` or `entries()` called on the platform's own
|
|
262
|
+
* `Map` or `Set` (`m.values()`): an iterator that runs no code of the project.
|
|
263
|
+
*/
|
|
264
|
+
function isCollectionIterator(node, types) {
|
|
265
|
+
const call = stripped(node);
|
|
266
|
+
if (!ts.isCallExpression(call) || call.arguments.length > 0)
|
|
267
|
+
return false;
|
|
268
|
+
const callee = stripped(call.expression);
|
|
269
|
+
if (!ts.isPropertyAccessExpression(callee) || !ts.isIdentifier(callee.name))
|
|
270
|
+
return false;
|
|
271
|
+
const owner = types.platformTypeOf(stripped(callee.expression));
|
|
272
|
+
return (["keys", "values", "entries"].includes(callee.name.text) &&
|
|
273
|
+
owner !== undefined &&
|
|
274
|
+
COLLECTIONS.has(owner) &&
|
|
275
|
+
types.isPlatformName(callee.name));
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Whether a `for…of` over an expression runs no code of the project and cannot throw: over the
|
|
279
|
+
* platform's array, a string, or an iterator of a `Map` or `Set` (`for (const v of m.values())`).
|
|
280
|
+
*/
|
|
281
|
+
export function iteratesPlainly(node, types) {
|
|
282
|
+
return (types.arrayElementsOf(node) !== undefined ||
|
|
283
|
+
types.platformTypeOf(node) === "String" ||
|
|
284
|
+
isCollectionIterator(node, types));
|
|
285
|
+
}
|
|
286
|
+
/** The methods of an array whose arguments decide whether they can throw. */
|
|
287
|
+
function arrayCallIsSafe(call, name, receiver, types) {
|
|
288
|
+
const given = call.arguments;
|
|
289
|
+
switch (name) {
|
|
290
|
+
// Converts each element to a string.
|
|
291
|
+
case "join":
|
|
292
|
+
case "toString":
|
|
293
|
+
return (types.arrayElementsOf(receiver) === "primitives" &&
|
|
294
|
+
given.every((one) => types.isPrimitive(one)));
|
|
295
|
+
// An empty array with no first value throws.
|
|
296
|
+
case "reduce":
|
|
297
|
+
case "reduceRight":
|
|
298
|
+
return given.length === 2;
|
|
299
|
+
// With no comparer, each element is converted to a string.
|
|
300
|
+
case "sort":
|
|
301
|
+
return given.length === 1 || types.arrayElementsOf(receiver) === "primitives";
|
|
302
|
+
// Reads `Symbol.isConcatSpreadable` of each argument.
|
|
303
|
+
case "concat":
|
|
304
|
+
return given.every((one) => types.isPrimitive(one) || types.arrayElementsOf(one) !== undefined);
|
|
305
|
+
default:
|
|
306
|
+
return undefined;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Whether a call or `new` is on the closed list of the platform's calls that do not throw, on the
|
|
311
|
+
* platform's own types: `console.log(…)`, `Math.max(a, b)` on numbers, `Object.keys(…)` on a
|
|
312
|
+
* known type, `new Map()`, `list.push(…)` on an array, `String(x)` on a primitive, `d.getTime()`,
|
|
313
|
+
* `n.toFixed(2)`, `Array.from(xs)` on an array, a string method on a branded string. The caller checks what a
|
|
314
|
+
* callback given to the call does.
|
|
315
|
+
*/
|
|
316
|
+
export function isSafePlatformCall(node, types) {
|
|
317
|
+
const callee = stripped(node.expression);
|
|
318
|
+
if (ts.isNewExpression(node)) {
|
|
319
|
+
const owner = types.platformTypeOf(callee);
|
|
320
|
+
const allowed = owner === undefined ? undefined : CONSTRUCTORS.get(owner);
|
|
321
|
+
return allowed !== undefined && argumentsAllowed(node, allowed, types);
|
|
322
|
+
}
|
|
323
|
+
if (ts.isIdentifier(callee)) {
|
|
324
|
+
const allowed = GLOBALS.get(callee.text);
|
|
325
|
+
return (allowed !== undefined &&
|
|
326
|
+
types.isPlatformName(callee) &&
|
|
327
|
+
argumentsAllowed(node, allowed, types));
|
|
328
|
+
}
|
|
329
|
+
if (!ts.isPropertyAccessExpression(callee) || !ts.isIdentifier(callee.name))
|
|
330
|
+
return false;
|
|
331
|
+
const name = callee.name.text;
|
|
332
|
+
const receiver = stripped(callee.expression);
|
|
333
|
+
const owner = types.platformTypeOf(receiver);
|
|
334
|
+
if (owner === undefined || !types.isPlatformName(callee.name))
|
|
335
|
+
return false;
|
|
336
|
+
if (owner === "Array" || owner === "ReadonlyArray") {
|
|
337
|
+
const decided = arrayCallIsSafe(node, name, receiver, types);
|
|
338
|
+
if (decided !== undefined)
|
|
339
|
+
return decided;
|
|
340
|
+
}
|
|
341
|
+
const methods = METHODS.get(owner);
|
|
342
|
+
const allowed = methods?.get(name) ?? methods?.get("*");
|
|
343
|
+
return allowed !== undefined && argumentsAllowed(node, allowed, types);
|
|
344
|
+
}
|
|
345
|
+
//# sourceMappingURL=safe-calls.js.map
|
package/dist/severity.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Config, ConfigOverride, Plugin, RuleInfo, RuleSetting } from "./types.js";
|
|
2
|
-
type Settings = Pick<Config, "preset" | "addons" | "rules" | "groups"> & Partial<Pick<Config, "overrides" | "configDir">>;
|
|
2
|
+
type Settings = Pick<Config, "preset" | "addons" | "rules" | "groups"> & Partial<Pick<Config, "overrides" | "configDir" | "conventions">>;
|
|
3
3
|
/**
|
|
4
4
|
* What the config says, then each of `applied` in order; the last layer that speaks wins. A
|
|
5
5
|
* default (an override's preset or add-on) does not undo a setting some layer named: a folder
|
package/dist/severity.js
CHANGED
|
@@ -4,11 +4,17 @@ import { matchingOverrides } from "./overrides.js";
|
|
|
4
4
|
* the one below: the preset's tier default, then the add-ons the
|
|
5
5
|
* layer turns on, then `groups`, then `rules` (the last one that speaks wins). The config itself
|
|
6
6
|
* always speaks: an add-on that is not listed is off. An override speaks only about what it names.
|
|
7
|
+
* A convention rule is on only by its id or with `conventions` (the config's): no preset or group
|
|
8
|
+
* alone turns it on. One marked `whenStated` is on like a core rule: it reports only what the
|
|
9
|
+
* project states.
|
|
7
10
|
*/
|
|
8
|
-
function layerSetting(layer, base, pluginName, key, meta) {
|
|
11
|
+
function layerSetting(layer, base, conventions, pluginName, key, meta) {
|
|
9
12
|
const explicit = layer.rules[`${pluginName}/${key}`];
|
|
10
13
|
if (explicit !== undefined)
|
|
11
14
|
return { setting: explicit, named: true };
|
|
15
|
+
if (meta.tier === "convention" && !conventions && meta.whenStated !== true) {
|
|
16
|
+
return base ? { setting: "off", named: false } : undefined;
|
|
17
|
+
}
|
|
12
18
|
const grouped = layer.groups[`${pluginName}/${meta.group}`];
|
|
13
19
|
if (grouped !== undefined)
|
|
14
20
|
return { setting: grouped, named: true };
|
|
@@ -18,6 +24,9 @@ function layerSetting(layer, base, pluginName, key, meta) {
|
|
|
18
24
|
}
|
|
19
25
|
return { setting: heuristicCap(meta.defaultSeverity, meta), named: false };
|
|
20
26
|
}
|
|
27
|
+
if (meta.tier === "convention") {
|
|
28
|
+
return base ? { setting: heuristicCap(meta.defaultSeverity, meta), named: false } : undefined;
|
|
29
|
+
}
|
|
21
30
|
if (layer.preset === undefined)
|
|
22
31
|
return undefined;
|
|
23
32
|
return { setting: heuristicCap(tierSeverity(layer.preset, meta), meta), named: false };
|
|
@@ -32,9 +41,13 @@ function heuristicCap(setting, meta) {
|
|
|
32
41
|
* that is `strict` still keeps the severity you gave a rule for the whole project.
|
|
33
42
|
*/
|
|
34
43
|
export function ruleSettingWith(config, applied, pluginName, key, meta) {
|
|
35
|
-
|
|
44
|
+
const conventions = config.conventions === true;
|
|
45
|
+
let said = layerSetting(config, true, conventions, pluginName, key, meta) ?? {
|
|
46
|
+
setting: "off",
|
|
47
|
+
named: false,
|
|
48
|
+
};
|
|
36
49
|
for (const override of applied) {
|
|
37
|
-
const next = layerSetting(override, false, pluginName, key, meta);
|
|
50
|
+
const next = layerSetting(override, false, conventions, pluginName, key, meta);
|
|
38
51
|
if (next !== undefined && (next.named || !said.named))
|
|
39
52
|
said = next;
|
|
40
53
|
}
|
|
@@ -72,6 +85,7 @@ export function addonsWith(config, applied) {
|
|
|
72
85
|
function tierSeverity(preset, meta) {
|
|
73
86
|
switch (meta.tier) {
|
|
74
87
|
case "core":
|
|
88
|
+
case "convention":
|
|
75
89
|
case "addon":
|
|
76
90
|
return meta.defaultSeverity;
|
|
77
91
|
case "coverage":
|
package/dist/stated.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { RuleResult } from "./cache.js";
|
|
2
|
+
import type { StatedDeclaration, StatedGuarantee, TypeQueries } from "./types.js";
|
|
3
|
+
import type ts from "typescript";
|
|
4
|
+
/** The rule id of a guarantee no plugin lists (`unlistedGuarantees`): core states it, no rule runs it. */
|
|
5
|
+
export declare const STATED_RULE_ID = "stateward/stated";
|
|
6
|
+
/**
|
|
7
|
+
* The id of a stated declaration: `<file>#<offset>` of where its node starts, the place a plugin
|
|
8
|
+
* lists it at (`StatedGuarantee.location`). A finding names the guarantees it is against by it
|
|
9
|
+
* (`Finding.guarantees`).
|
|
10
|
+
*/
|
|
11
|
+
export declare function declarationId(at: {
|
|
12
|
+
readonly file: string;
|
|
13
|
+
readonly start: number;
|
|
14
|
+
}): string;
|
|
15
|
+
/**
|
|
16
|
+
* The declarations of one file that state a guarantee in their written type, read from the cache
|
|
17
|
+
* entry when it has them, else from the program (`read` gives the file's queries and source, and
|
|
18
|
+
* is only called then). `stored` is true when this call added them to `results`.
|
|
19
|
+
*/
|
|
20
|
+
export declare function fileStated(results: Map<string, RuleResult>, read: () => {
|
|
21
|
+
types: TypeQueries;
|
|
22
|
+
sourceFile: ts.SourceFile;
|
|
23
|
+
} | undefined): {
|
|
24
|
+
stated: readonly StatedDeclaration[];
|
|
25
|
+
stored: boolean;
|
|
26
|
+
};
|
|
27
|
+
/** The reason a synthesised guarantee reads "not checked": no rule checks the marker there. */
|
|
28
|
+
export declare function noRuleChecks(marker: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* A guarantee for each stated declaration (and each guarantee it states) that no plugin lists:
|
|
31
|
+
* a rule that proves it would list it, so nothing here proves it, and it reads "not checked"
|
|
32
|
+
* (never "unused", never "proven") until a rule does, or a finding is against it. A plugin lists a
|
|
33
|
+
* declaration at where it starts, so a listed guarantee of the same name that starts inside the
|
|
34
|
+
* declaration's head is the same one.
|
|
35
|
+
*/
|
|
36
|
+
export declare function unlistedGuarantees(scanned: readonly StatedDeclaration[], listed: readonly StatedGuarantee[]): StatedGuarantee[];
|
|
37
|
+
//# sourceMappingURL=stated.d.ts.map
|
package/dist/stated.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { summaryOf, summaryValue } from "./cache.js";
|
|
2
|
+
/**
|
|
3
|
+
* Where a file's stated declarations are kept in its entry of the cache (`results`), under the
|
|
4
|
+
* same fingerprint as its findings: that covers the file's text and what it imports, which is all
|
|
5
|
+
* a written type depends on. Like the ignore comments, it is not a rule's result.
|
|
6
|
+
*/
|
|
7
|
+
const STATED_KEY = "stateward/stated";
|
|
8
|
+
/** The rule id of a guarantee no plugin lists (`unlistedGuarantees`): core states it, no rule runs it. */
|
|
9
|
+
export const STATED_RULE_ID = "stateward/stated";
|
|
10
|
+
/**
|
|
11
|
+
* The id of a stated declaration: `<file>#<offset>` of where its node starts, the place a plugin
|
|
12
|
+
* lists it at (`StatedGuarantee.location`). A finding names the guarantees it is against by it
|
|
13
|
+
* (`Finding.guarantees`).
|
|
14
|
+
*/
|
|
15
|
+
export function declarationId(at) {
|
|
16
|
+
return `${at.file}#${String(at.start)}`;
|
|
17
|
+
}
|
|
18
|
+
function isRecord(value) {
|
|
19
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
20
|
+
}
|
|
21
|
+
function parseOne(value) {
|
|
22
|
+
if (!isRecord(value))
|
|
23
|
+
return undefined;
|
|
24
|
+
const { file, start, headEnd, end, name, marker, guarantees } = value;
|
|
25
|
+
if (typeof file !== "string" ||
|
|
26
|
+
typeof start !== "number" ||
|
|
27
|
+
typeof headEnd !== "number" ||
|
|
28
|
+
typeof end !== "number" ||
|
|
29
|
+
typeof name !== "string" ||
|
|
30
|
+
typeof marker !== "string" ||
|
|
31
|
+
!isList(guarantees) ||
|
|
32
|
+
!guarantees.every((one) => typeof one === "string")) {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
return { file, start, headEnd, end, name, marker, guarantees };
|
|
36
|
+
}
|
|
37
|
+
function isList(value) {
|
|
38
|
+
return Array.isArray(value);
|
|
39
|
+
}
|
|
40
|
+
function parseAll(value) {
|
|
41
|
+
if (!isList(value))
|
|
42
|
+
return undefined;
|
|
43
|
+
const found = [];
|
|
44
|
+
for (const item of value) {
|
|
45
|
+
const one = parseOne(item);
|
|
46
|
+
if (one === undefined)
|
|
47
|
+
return undefined;
|
|
48
|
+
found.push(one);
|
|
49
|
+
}
|
|
50
|
+
return found;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The declarations of one file that state a guarantee in their written type, read from the cache
|
|
54
|
+
* entry when it has them, else from the program (`read` gives the file's queries and source, and
|
|
55
|
+
* is only called then). `stored` is true when this call added them to `results`.
|
|
56
|
+
*/
|
|
57
|
+
export function fileStated(results, read) {
|
|
58
|
+
const kept = results.get(STATED_KEY);
|
|
59
|
+
if (kept !== undefined) {
|
|
60
|
+
if (kept.summary === undefined)
|
|
61
|
+
return { stated: [], stored: false };
|
|
62
|
+
const parsed = parseAll(summaryValue(kept.summary));
|
|
63
|
+
if (parsed !== undefined)
|
|
64
|
+
return { stated: parsed, stored: false };
|
|
65
|
+
}
|
|
66
|
+
const opened = read();
|
|
67
|
+
const stated = opened === undefined ? [] : opened.types.statedDeclarationsIn(opened.sourceFile);
|
|
68
|
+
results.set(STATED_KEY, stated.length === 0
|
|
69
|
+
? { findings: [] }
|
|
70
|
+
: {
|
|
71
|
+
findings: [],
|
|
72
|
+
summary: summaryOf(stated.map((one) => ({
|
|
73
|
+
file: one.file,
|
|
74
|
+
start: one.start,
|
|
75
|
+
headEnd: one.headEnd,
|
|
76
|
+
end: one.end,
|
|
77
|
+
name: one.name,
|
|
78
|
+
marker: one.marker,
|
|
79
|
+
guarantees: [...one.guarantees],
|
|
80
|
+
}))),
|
|
81
|
+
});
|
|
82
|
+
return { stated, stored: true };
|
|
83
|
+
}
|
|
84
|
+
/** The reason a synthesised guarantee reads "not checked": no rule checks the marker there. */
|
|
85
|
+
export function noRuleChecks(marker) {
|
|
86
|
+
return `\`${marker}\` is stated on a declaration no rule checks: state it where its pack's page shows`;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* A guarantee for each stated declaration (and each guarantee it states) that no plugin lists:
|
|
90
|
+
* a rule that proves it would list it, so nothing here proves it, and it reads "not checked"
|
|
91
|
+
* (never "unused", never "proven") until a rule does, or a finding is against it. A plugin lists a
|
|
92
|
+
* declaration at where it starts, so a listed guarantee of the same name that starts inside the
|
|
93
|
+
* declaration's head is the same one.
|
|
94
|
+
*/
|
|
95
|
+
export function unlistedGuarantees(scanned, listed) {
|
|
96
|
+
const found = [];
|
|
97
|
+
for (const one of scanned) {
|
|
98
|
+
for (const name of one.guarantees) {
|
|
99
|
+
const known = listed.some((guarantee) => guarantee.guarantee === name &&
|
|
100
|
+
guarantee.location.file === one.file &&
|
|
101
|
+
guarantee.location.start >= one.start &&
|
|
102
|
+
guarantee.location.start <= one.headEnd);
|
|
103
|
+
if (known)
|
|
104
|
+
continue;
|
|
105
|
+
const location = { file: one.file, start: one.start, end: one.end };
|
|
106
|
+
found.push({
|
|
107
|
+
guarantee: name,
|
|
108
|
+
source: { kind: "marker" },
|
|
109
|
+
marker: one.marker,
|
|
110
|
+
name: one.name,
|
|
111
|
+
declaration: declarationId(location),
|
|
112
|
+
location,
|
|
113
|
+
ruleId: STATED_RULE_ID,
|
|
114
|
+
promise: "nothing yet: no rule proves it",
|
|
115
|
+
covers: { one: "place", many: "places" },
|
|
116
|
+
covered: [],
|
|
117
|
+
unchecked: [{ location, reason: noRuleChecks(one.marker) }],
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return found;
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=stated.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The test files a project's own test runner names, read from its config as data: Jest's
|
|
3
|
+
* `testMatch` and `testRegex` (`jest.config.*`, the `jest` key of `package.json`, or the file a
|
|
4
|
+
* `package.json` script passes to `jest --config`), and Vitest's `test.include`
|
|
5
|
+
* (`vitest.config.*`, `vite.config.*`, or the file a script passes to `vitest --config`). A config
|
|
6
|
+
* file that is code is read where its values are written as literals; a value it computes is not
|
|
7
|
+
* read, and the file is named in `unread` (`stateward coverage` says so), as is a `package.json`
|
|
8
|
+
* whose script gives a config stateward cannot read.
|
|
9
|
+
*/
|
|
10
|
+
export type TestRunnerFiles = {
|
|
11
|
+
/** Whether an absolute file path is a test file by one of the configs read. */
|
|
12
|
+
readonly matches: (file: string) => boolean;
|
|
13
|
+
/** The config files, absolute, that hold test-file settings stateward could not read. */
|
|
14
|
+
readonly unread: readonly string[];
|
|
15
|
+
};
|
|
16
|
+
/** The test files the test-runner configs in each of `dirs` name (see `TestRunnerFiles`). */
|
|
17
|
+
export declare function testRunnerFiles(dirs: readonly string[]): TestRunnerFiles;
|
|
18
|
+
//# sourceMappingURL=test-runner.d.ts.map
|