@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.
- package/dist/backend/fingerprints.d.ts +22 -2
- package/dist/backend/fingerprints.js +160 -18
- package/dist/backend/program-record.d.ts +1 -1
- package/dist/backend/qualified-ids.d.ts +6 -0
- package/dist/backend/qualified-ids.js +66 -10
- package/dist/backend/typescript6.d.ts +28 -9
- package/dist/backend/typescript6.js +564 -28
- package/dist/baseline.js +10 -0
- package/dist/cache.d.ts +5 -4
- package/dist/cache.js +2 -2
- package/dist/checker.d.ts +14 -2
- package/dist/checker.js +40 -12
- package/dist/config-file.d.ts +6 -0
- package/dist/config-file.js +21 -2
- package/dist/config.d.ts +3 -1
- package/dist/config.js +164 -17
- package/dist/define.d.ts +2 -1
- package/dist/disk-cache.d.ts +24 -2
- package/dist/disk-cache.js +43 -5
- package/dist/engine.d.ts +27 -3
- package/dist/engine.js +224 -57
- package/dist/guarantee-markers.d.ts +10 -0
- package/dist/guarantee-markers.js +66 -0
- package/dist/guarantees.d.ts +44 -0
- package/dist/guarantees.js +84 -0
- package/dist/hint-lines.d.ts +24 -0
- package/dist/hint-lines.js +36 -0
- package/dist/ignores.d.ts +2 -4
- package/dist/ignores.js +31 -16
- package/dist/implementation.js +2 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +4 -0
- package/dist/internal.d.ts +8 -3
- package/dist/internal.js +6 -3
- package/dist/package-facts.d.ts +52 -0
- package/dist/package-facts.js +213 -0
- package/dist/plan.d.ts +17 -0
- package/dist/plan.js +22 -5
- package/dist/release.d.ts +68 -0
- package/dist/release.js +172 -0
- package/dist/renamed.d.ts +29 -0
- package/dist/renamed.js +48 -0
- package/dist/rollout.js +3 -1
- package/dist/testing-tsc.d.ts +11 -0
- package/dist/testing-tsc.js +125 -0
- package/dist/testing.d.ts +1 -0
- package/dist/testing.js +61 -8
- package/dist/types.d.ts +261 -2
- package/package.json +1 -1
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
/**
|
|
4
|
+
* What `tsc -p` prints for a project, computed in this process. A test that asks "does this code
|
|
5
|
+
* compile?" many times would otherwise spawn tsc for each question (seconds each, and a timeout
|
|
6
|
+
* when the machine is busy). Library files and the previous program of each option set are kept
|
|
7
|
+
* for the life of the module, so a later question costs only the files that changed. The text is
|
|
8
|
+
* the same as tsc's: same diagnostics, same order, same format, "" when the code compiles.
|
|
9
|
+
*/
|
|
10
|
+
const sourceFiles = new Map();
|
|
11
|
+
const lastPrograms = new Map();
|
|
12
|
+
function formatHostIn(directory) {
|
|
13
|
+
return {
|
|
14
|
+
getCurrentDirectory: () => directory,
|
|
15
|
+
getCanonicalFileName: (name) => name,
|
|
16
|
+
getNewLine: () => ts.sys.newLine,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/** A compiler host over the disk plus `overlay` (virtual files), reusing unchanged source files. */
|
|
20
|
+
function hostFor(options, overlay, currentDirectory) {
|
|
21
|
+
const base = ts.createCompilerHost(options, true);
|
|
22
|
+
const read = (fileName) => overlay.get(path.resolve(fileName)) ?? base.readFile(fileName);
|
|
23
|
+
return {
|
|
24
|
+
...base,
|
|
25
|
+
getCurrentDirectory: () => currentDirectory,
|
|
26
|
+
fileExists: (fileName) => overlay.has(path.resolve(fileName)) || base.fileExists(fileName),
|
|
27
|
+
readFile: read,
|
|
28
|
+
getSourceFile: (fileName, languageVersionOrOptions) => {
|
|
29
|
+
const text = read(fileName);
|
|
30
|
+
if (text === undefined)
|
|
31
|
+
return undefined;
|
|
32
|
+
const key = `${path.resolve(fileName)}\0${JSON.stringify(languageVersionOrOptions)}`;
|
|
33
|
+
const cached = sourceFiles.get(key);
|
|
34
|
+
if (cached?.text === text)
|
|
35
|
+
return cached.file;
|
|
36
|
+
const file = ts.createSourceFile(fileName, text, languageVersionOrOptions, true);
|
|
37
|
+
sourceFiles.set(key, { text, file });
|
|
38
|
+
return file;
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function compile(rootNames, options, overlay, configErrors, currentDirectory, cacheKey) {
|
|
43
|
+
const program = ts.createProgram(rootNames, options, hostFor(options, overlay, currentDirectory), lastPrograms.get(cacheKey), configErrors);
|
|
44
|
+
lastPrograms.set(cacheKey, program);
|
|
45
|
+
return { program, configErrors };
|
|
46
|
+
}
|
|
47
|
+
/** The diagnostics `tsc` reports, in its order: syntax first, the rest only when syntax is clean. */
|
|
48
|
+
function diagnosticsOf({ program, configErrors }, only) {
|
|
49
|
+
const syntactic = [...configErrors, ...program.getSyntacticDiagnostics(only)];
|
|
50
|
+
const all = syntactic.length > 0
|
|
51
|
+
? syntactic
|
|
52
|
+
: [
|
|
53
|
+
...program.getOptionsDiagnostics(),
|
|
54
|
+
...program.getGlobalDiagnostics(),
|
|
55
|
+
...program.getSemanticDiagnostics(only),
|
|
56
|
+
];
|
|
57
|
+
return [...ts.sortAndDeduplicateDiagnostics(all)];
|
|
58
|
+
}
|
|
59
|
+
/** The compiler's complaints about the project at `dir` (its tsconfig.json), as `tsc -p dir` prints them. */
|
|
60
|
+
export function typeErrors(dir) {
|
|
61
|
+
const configPath = path.resolve(dir, "tsconfig.json");
|
|
62
|
+
const parsed = ts.getParsedCommandLineOfConfigFile(configPath, {}, {
|
|
63
|
+
...ts.sys,
|
|
64
|
+
onUnRecoverableConfigFileDiagnostic: (diagnostic) => {
|
|
65
|
+
throw new Error(ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"));
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
if (parsed === undefined)
|
|
69
|
+
throw new Error(`cannot read ${configPath}`);
|
|
70
|
+
const compiled = compile(parsed.fileNames, parsed.options, new Map(), parsed.errors, ts.sys.getCurrentDirectory(), `project\0${JSON.stringify(parsed.options)}`);
|
|
71
|
+
const diagnostics = diagnosticsOf(compiled);
|
|
72
|
+
return diagnostics.length === 0
|
|
73
|
+
? ""
|
|
74
|
+
: ts.formatDiagnostics(diagnostics, formatHostIn(ts.sys.getCurrentDirectory()));
|
|
75
|
+
}
|
|
76
|
+
const TEXT_OPTIONS = {
|
|
77
|
+
strict: true,
|
|
78
|
+
module: ts.ModuleKind.NodeNext,
|
|
79
|
+
moduleResolution: ts.ModuleResolutionKind.NodeNext,
|
|
80
|
+
noEmit: true,
|
|
81
|
+
types: [],
|
|
82
|
+
};
|
|
83
|
+
/** Not a real folder: its files exist only as overlay text. */
|
|
84
|
+
const VIRTUAL_DIR = path.join(path.sep, "stateward-virtual-texts");
|
|
85
|
+
/**
|
|
86
|
+
* The type errors of each text, as `tsc` prints them with each text a file of its own
|
|
87
|
+
* ("a3.ts(1,2): error ..."); a text maps to "" when it compiles. The strict, NodeNext options of
|
|
88
|
+
* the old spawned check. Texts must be modules, or their top-level names would meet in one scope.
|
|
89
|
+
*/
|
|
90
|
+
export function typeErrorsOfTexts(texts) {
|
|
91
|
+
return typeErrorsOfNamed(texts, (index) => `a${String(index)}.ts`);
|
|
92
|
+
}
|
|
93
|
+
function typeErrorsOfNamed(texts, nameOf) {
|
|
94
|
+
const unique = [...new Set(texts)];
|
|
95
|
+
const notModules = unique.filter((text) => !/^(?:import|export)\b/m.test(text));
|
|
96
|
+
if (notModules.length > 0) {
|
|
97
|
+
throw new Error("a text with no top-level import or export cannot be compiled with the others");
|
|
98
|
+
}
|
|
99
|
+
const names = unique.map((_, index) => nameOf(index));
|
|
100
|
+
const overlay = new Map(unique.map((text, index) => [path.join(VIRTUAL_DIR, names[index] ?? ""), text]));
|
|
101
|
+
const compiled = compile([...overlay.keys()], TEXT_OPTIONS, overlay, [], VIRTUAL_DIR, "texts");
|
|
102
|
+
const diagnostics = diagnosticsOf(compiled);
|
|
103
|
+
const perFile = new Map();
|
|
104
|
+
const unplaced = [];
|
|
105
|
+
for (const diagnostic of diagnostics) {
|
|
106
|
+
const name = diagnostic.file === undefined ? undefined : path.basename(diagnostic.file.fileName);
|
|
107
|
+
if (name === undefined)
|
|
108
|
+
unplaced.push(diagnostic);
|
|
109
|
+
else
|
|
110
|
+
perFile.set(name, [...(perFile.get(name) ?? []), diagnostic]);
|
|
111
|
+
}
|
|
112
|
+
const show = (list) => ts.formatDiagnostics(list, formatHostIn(VIRTUAL_DIR)).replace(/\r?\n$/, "");
|
|
113
|
+
const unplacedText = show(unplaced);
|
|
114
|
+
return new Map(unique.map((text, index) => [
|
|
115
|
+
text,
|
|
116
|
+
[show(perFile.get(names[index] ?? "") ?? []), unplacedText]
|
|
117
|
+
.filter((s) => s !== "")
|
|
118
|
+
.join("\n"),
|
|
119
|
+
]));
|
|
120
|
+
}
|
|
121
|
+
/** The type errors of one text (see `typeErrorsOfTexts`), "" when it compiles. */
|
|
122
|
+
export function typeErrorsOfText(text) {
|
|
123
|
+
return typeErrorsOfNamed([text], () => "a.ts").get(text) ?? "";
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=testing-tsc.js.map
|
package/dist/testing.d.ts
CHANGED
|
@@ -30,4 +30,5 @@ export declare class MessageStandardError extends Error {
|
|
|
30
30
|
}
|
|
31
31
|
/** Throws a `MessageStandardError` listing every violation in `findings`; use it in rule tests. */
|
|
32
32
|
export declare function expectMessageStandard(findings: readonly Finding[]): void;
|
|
33
|
+
export { typeErrors, typeErrorsOfText, typeErrorsOfTexts } from "./testing-tsc.js";
|
|
33
34
|
//# sourceMappingURL=testing.d.ts.map
|
package/dist/testing.js
CHANGED
|
@@ -86,14 +86,18 @@ const MIN_EXAMPLE_INDENT = 4;
|
|
|
86
86
|
function withoutNames(line) {
|
|
87
87
|
return line.replace(/`[^`]*`/g, "");
|
|
88
88
|
}
|
|
89
|
-
/**
|
|
90
|
-
function
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
89
|
+
/** The words of one line of a fix, its names left out, must fit the fix line's limit. */
|
|
90
|
+
function wordsProblems(label, line) {
|
|
91
|
+
const words = withoutNames(line);
|
|
92
|
+
return words.length > MAX_HINT_LENGTH
|
|
93
|
+
? [
|
|
94
|
+
`${label} words are ${String(words.length)} characters without its names; at most ${String(MAX_HINT_LENGTH)}`,
|
|
95
|
+
]
|
|
96
|
+
: [];
|
|
97
|
+
}
|
|
98
|
+
/** A code example: up to four lines, each indented 4 spaces and at most 100 characters. */
|
|
99
|
+
function exampleProblems(example) {
|
|
100
|
+
const problems = [];
|
|
97
101
|
if (example.length > MAX_EXAMPLE_LINES) {
|
|
98
102
|
problems.push(`fix hint example has ${String(example.length)} lines; at most ${String(MAX_EXAMPLE_LINES)}`);
|
|
99
103
|
}
|
|
@@ -107,6 +111,42 @@ function hintProblems(hint) {
|
|
|
107
111
|
}
|
|
108
112
|
return problems;
|
|
109
113
|
}
|
|
114
|
+
/**
|
|
115
|
+
* A hint is one line, or one line and an indented code example of up to four lines (M2). With
|
|
116
|
+
* several ways to fix (M22) it is `one of`, then one `- ` line per way, each starting with its
|
|
117
|
+
* action in lowercase and every one after the first with `or`, each with its own example.
|
|
118
|
+
*/
|
|
119
|
+
function hintProblems(hint) {
|
|
120
|
+
const [first = "", ...rest] = hint.split(/\r?\n/);
|
|
121
|
+
const problems = lineProblems("fix hint", first, undefined);
|
|
122
|
+
problems.push(...wordsProblems("fix hint", first));
|
|
123
|
+
if (!rest.some((line) => line.startsWith("- ")))
|
|
124
|
+
return [...problems, ...exampleProblems(rest)];
|
|
125
|
+
if (first !== "one of")
|
|
126
|
+
problems.push('a fix hint with ways to fix must start with "one of"');
|
|
127
|
+
const ways = [];
|
|
128
|
+
for (const line of rest) {
|
|
129
|
+
const last = ways.at(-1);
|
|
130
|
+
if (line.startsWith("- "))
|
|
131
|
+
ways.push({ line, example: [] });
|
|
132
|
+
else if (last === undefined)
|
|
133
|
+
problems.push(`fix hint line "${line}" must follow a way to fix`);
|
|
134
|
+
else
|
|
135
|
+
last.example.push(line);
|
|
136
|
+
}
|
|
137
|
+
if (ways.length < 2)
|
|
138
|
+
problems.push('a fix hint with "one of" needs two ways to fix or more');
|
|
139
|
+
ways.forEach((way, index) => {
|
|
140
|
+
const text = way.line.slice(2);
|
|
141
|
+
problems.push(...wordsProblems("fix hint way", text), ...exampleProblems(way.example));
|
|
142
|
+
if (!/^[a-z]/.test(text))
|
|
143
|
+
problems.push(`fix hint way "${text}" must start in lowercase`);
|
|
144
|
+
if (index > 0 && !/^or\b/.test(text)) {
|
|
145
|
+
problems.push(`fix hint way "${text}" must start with "or"`);
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
return problems;
|
|
149
|
+
}
|
|
110
150
|
function lineProblems(label, text, maxLength) {
|
|
111
151
|
const problems = [];
|
|
112
152
|
if (text.trim().length === 0)
|
|
@@ -141,6 +181,18 @@ export function messageProblems(finding) {
|
|
|
141
181
|
problems.push('headline must not start with "You"');
|
|
142
182
|
if (prose.includes("!"))
|
|
143
183
|
problems.push('headline must not contain "!"');
|
|
184
|
+
// M15, M16, M19: a fact about the code, with no pointing words and no question; a place not
|
|
185
|
+
// checked says so first, never "stateward cannot tell".
|
|
186
|
+
const pointing = /\b(?:this|here|you)\b/i.exec(prose);
|
|
187
|
+
if (pointing !== null)
|
|
188
|
+
problems.push(`headline must not point with "${pointing[0]}"`);
|
|
189
|
+
if (prose.includes("?"))
|
|
190
|
+
problems.push("headline must not be a question");
|
|
191
|
+
if (/\bstateward cannot\b/i.test(prose))
|
|
192
|
+
problems.push('headline must not say "stateward cannot"');
|
|
193
|
+
if (finding.kind === "unknown" && !prose.startsWith("not checked: ")) {
|
|
194
|
+
problems.push('a place not checked must start with "not checked: "');
|
|
195
|
+
}
|
|
144
196
|
if (finding.kind === "problem") {
|
|
145
197
|
finding.related.forEach((related, index) => {
|
|
146
198
|
problems.push(...lineProblems(`related message ${String(index + 1)}`, related.message, undefined));
|
|
@@ -162,4 +214,5 @@ export function expectMessageStandard(findings) {
|
|
|
162
214
|
throw new MessageStandardError(`${String(violations.length)} message standard violation(s):\n${violations.join("\n")}`);
|
|
163
215
|
}
|
|
164
216
|
}
|
|
217
|
+
export { typeErrors, typeErrorsOfText, typeErrorsOfTexts } from "./testing-tsc.js";
|
|
165
218
|
//# sourceMappingURL=testing.js.map
|
package/dist/types.d.ts
CHANGED
|
@@ -24,6 +24,10 @@ export type TextEdit = {
|
|
|
24
24
|
*/
|
|
25
25
|
export type FixForm = {
|
|
26
26
|
title: string;
|
|
27
|
+
/**
|
|
28
|
+
* The edits, in any files. Edits at offset 0 of a file that does not exist create it (a helper
|
|
29
|
+
* file the fix writes once); the file's own errors then count against the fix.
|
|
30
|
+
*/
|
|
27
31
|
edits: readonly TextEdit[];
|
|
28
32
|
safe?: boolean;
|
|
29
33
|
/**
|
|
@@ -214,6 +218,11 @@ export type OptionsOf<S extends OptionSpecs> = {
|
|
|
214
218
|
*/
|
|
215
219
|
export type RuleInfo<S extends OptionSpecs = OptionSpecs, G extends string = string> = {
|
|
216
220
|
description: string;
|
|
221
|
+
/**
|
|
222
|
+
* What the rule finds, as a short phrase for the rules tables of the docs ("a `default` that
|
|
223
|
+
* hides cases of a union"); `description` is the sentence that opens the rule's page.
|
|
224
|
+
*/
|
|
225
|
+
summary?: string;
|
|
217
226
|
defaultSeverity: Severity;
|
|
218
227
|
tier: RuleTier;
|
|
219
228
|
/**
|
|
@@ -261,6 +270,25 @@ export type RuleInfo<S extends OptionSpecs = OptionSpecs, G extends string = str
|
|
|
261
270
|
* (`ctx.options` holds both). Only list options (`option.strings`) can be shared.
|
|
262
271
|
*/
|
|
263
272
|
sharedOptions?: Readonly<Record<string, string>>;
|
|
273
|
+
/**
|
|
274
|
+
* A library whose types the rule needs to see anything (`React` from `react`): where none of
|
|
275
|
+
* `modules` resolves to declarations from the project, the rule could not run there, and
|
|
276
|
+
* `check`, `plan` and `next` say so instead of calling it clean (never silent). Core only
|
|
277
|
+
* resolves the names; what they are is the pack's knowledge.
|
|
278
|
+
*/
|
|
279
|
+
needsTypes?: LibraryTypes;
|
|
280
|
+
/**
|
|
281
|
+
* The rule's fixes prove what they say only with `strictNullChecks` (a `Partial<…>` or a `??`
|
|
282
|
+
* TypeScript then checks): in a project without it, each finding's fix line says so.
|
|
283
|
+
*/
|
|
284
|
+
fixNeedsStrictNulls?: true;
|
|
285
|
+
};
|
|
286
|
+
/** A library a rule reads by its types: its name as people say it, and the modules that give them. */
|
|
287
|
+
export type LibraryTypes = {
|
|
288
|
+
/** As people say it: "React". */
|
|
289
|
+
readonly library: string;
|
|
290
|
+
/** The module names that bring its types, any one is enough: `["react"]`. */
|
|
291
|
+
readonly modules: readonly string[];
|
|
264
292
|
};
|
|
265
293
|
export type RuleMeta<S extends OptionSpecs = OptionSpecs, G extends string = string> = RuleInfo<S, G> & {
|
|
266
294
|
/** Markdown shown by `stateward explain`. */
|
|
@@ -297,6 +325,14 @@ export type NarrowedMembers = {
|
|
|
297
325
|
members: readonly string[];
|
|
298
326
|
removed: readonly string[];
|
|
299
327
|
};
|
|
328
|
+
/**
|
|
329
|
+
* Where a call's callee takes an abort signal: the index of the parameter, and `"signal"` when the
|
|
330
|
+
* signal is the `signal` property of an options object at that index (`fetch(url, { signal })`).
|
|
331
|
+
*/
|
|
332
|
+
export type SignalParameter = {
|
|
333
|
+
readonly index: number;
|
|
334
|
+
readonly property: "signal" | undefined;
|
|
335
|
+
};
|
|
300
336
|
/**
|
|
301
337
|
* `id` is the qualified id "<file relative to the project>#<path>" (`src/cart.ts#useCart.onAdd`;
|
|
302
338
|
* the module itself is "<file>#"): stable across runs and across edits that do not rename or move
|
|
@@ -343,7 +379,9 @@ export type TypeQueries = {
|
|
|
343
379
|
* `"not-object"` for a primitive, a union, an array, a tuple or an array-like (a number index and a numeric `length`, such as
|
|
344
380
|
* `RegExpMatchArray`): the rules that ask do not apply.
|
|
345
381
|
* `"generic"` when the keys depend on a type parameter (`Record<K, string>`, `{ [P in K]: n }`):
|
|
346
|
-
* the properties are not known until `K` is, so the type has no key list to judge.
|
|
382
|
+
* the properties are not known until `K` is, so the type has no key list to judge. Also when a
|
|
383
|
+
* mapped type takes its keys from a type that does not resolve (`keyof typeof NAMES` from a
|
|
384
|
+
* package that is not installed): TypeScript then gives it an index signature for every key.
|
|
347
385
|
*/
|
|
348
386
|
propertyKeysOf(node: ts.Node): {
|
|
349
387
|
required: readonly string[];
|
|
@@ -393,6 +431,74 @@ export type TypeQueries = {
|
|
|
393
431
|
* recognised by where that symbol is declared.
|
|
394
432
|
*/
|
|
395
433
|
uniqueSymbolKeyFiles(node: ts.Node): readonly string[];
|
|
434
|
+
/**
|
|
435
|
+
* The guarantees a type states: one name per optional `"__guarantee:<name>"` property
|
|
436
|
+
* (`Context<T> & { readonly "__guarantee:required-context"?: true }`), and the string literals of
|
|
437
|
+
* an optional `__guarantee` property (the 1.1.0 form, `{ readonly __guarantee?: "owned" }`),
|
|
438
|
+
* sorted. Traits combine by intersection: `Owned<Opaque<string, "Id">>` gives both. The type is
|
|
439
|
+
* the one of an expression or type node, or the declared type of a symbol (a variable's type, a
|
|
440
|
+
* type alias's type), resolved through aliases, generics and re-exports. A type parameter is
|
|
441
|
+
* widened to its constraint; `null` and `undefined` members are left out, and every other member
|
|
442
|
+
* of a union must state a guarantee for it to count. A required marker property, or a 1.1.0
|
|
443
|
+
* `__guarantee` that is not string literals, states none (that is a brand, not a guarantee). The
|
|
444
|
+
* names mean nothing to core; each plugin reads its own.
|
|
445
|
+
*/
|
|
446
|
+
guaranteesOf(target: ts.Node | SymbolRef): readonly string[];
|
|
447
|
+
/**
|
|
448
|
+
* The guarantees of the type the surrounding code expects for an expression (as
|
|
449
|
+
* `contextualTypeTextOf`), read as `guaranteesOf` reads a type: `{ … }` returned from a function
|
|
450
|
+
* typed `OrderId`, or passed to a parameter of that type. Empty when nothing is expected.
|
|
451
|
+
*/
|
|
452
|
+
contextualGuaranteesOf(node: ts.Expression): readonly string[];
|
|
453
|
+
/**
|
|
454
|
+
* The values a trait's marker property holds, sorted: `"OrderId"` for
|
|
455
|
+
* `Opaque<string, "OrderId">`, `true` for `Pending<boolean>`, `"saving"` for
|
|
456
|
+
* `Pending<Status, "saving">`. Read from the type of the node, of the symbol's declaration, or,
|
|
457
|
+
* with `contextual`, of the type the surrounding code expects for the expression. Undefined when
|
|
458
|
+
* the type does not state the trait; `"not-finite"` when the property's type is not literals.
|
|
459
|
+
*/
|
|
460
|
+
guaranteeValuesOf(target: ts.Node | SymbolRef, name: string, contextual?: boolean): readonly Literal[] | "not-finite" | undefined;
|
|
461
|
+
/**
|
|
462
|
+
* How a value is disposed when its type is a standard `Disposable` or `AsyncDisposable`: it has
|
|
463
|
+
* a `[Symbol.dispose]` (`"sync"`) or `[Symbol.asyncDispose]` (`"async"`) method, declared in
|
|
464
|
+
* `file`. Undefined for any other type, and for `any`.
|
|
465
|
+
*/
|
|
466
|
+
disposeOf(node: ts.Node): {
|
|
467
|
+
readonly kind: "sync" | "async";
|
|
468
|
+
readonly file: string;
|
|
469
|
+
} | undefined;
|
|
470
|
+
/**
|
|
471
|
+
* The type alias the surrounding code expects for an expression (`OrderId` for an argument of
|
|
472
|
+
* `save(id: OrderId)`; `OrderId | undefined` gives `OrderId`), as a symbol whose declaration
|
|
473
|
+
* `declarationOf` finds. Undefined when nothing is expected, the type is not one alias, or the
|
|
474
|
+
* alias is generic.
|
|
475
|
+
*/
|
|
476
|
+
contextualAliasOf(node: ts.Expression): SymbolRef | undefined;
|
|
477
|
+
/**
|
|
478
|
+
* The property a name destructured from an object reads: `cacheEntryRemoved` of the
|
|
479
|
+
* parameter's type for `{ cacheEntryRemoved }`, as a symbol whose declaration `declarationOf`
|
|
480
|
+
* finds. Undefined for a rest element, an array pattern, a computed key, or a type with no such
|
|
481
|
+
* property.
|
|
482
|
+
*/
|
|
483
|
+
bindingPropertyOf(element: ts.BindingElement): SymbolRef | undefined;
|
|
484
|
+
/**
|
|
485
|
+
* Whether any file of the program (the project's or a package's) writes the marker property of
|
|
486
|
+
* a trait, `"__guarantee:<name>"`: a rule skips work for a trait nobody states.
|
|
487
|
+
*/
|
|
488
|
+
declaresTrait(name: string): boolean;
|
|
489
|
+
/**
|
|
490
|
+
* Whether a file of the project declares a member named `[Symbol.dispose]` or
|
|
491
|
+
* `[Symbol.asyncDispose]` (a class, an interface, a type or an object literal), read from the
|
|
492
|
+
* syntax once per program: only such a member states the release trait by its type.
|
|
493
|
+
*/
|
|
494
|
+
declaresDispose(): boolean;
|
|
495
|
+
/**
|
|
496
|
+
* The other names the project's files give a binding, by the name they rename: `onSnapshot` →
|
|
497
|
+
* `listen` for `import { onSnapshot as listen }`, `export { onSnapshot as listen }`,
|
|
498
|
+
* `const listen = onSnapshot` (or `= db.onSnapshot`) and `const { onSnapshot: listen } = db`.
|
|
499
|
+
* Read from the syntax once per program.
|
|
500
|
+
*/
|
|
501
|
+
renamedBindings(): ReadonlyMap<string, ReadonlySet<string>>;
|
|
396
502
|
/**
|
|
397
503
|
* The type alias a value's type is an instance of, found from its declaration: after awaiting a
|
|
398
504
|
* `Promise`, every member of the type must be written in the same alias (`Result<T, E>` and
|
|
@@ -407,11 +513,13 @@ export type TypeQueries = {
|
|
|
407
513
|
/**
|
|
408
514
|
* The type alias that names the type of an expression as written (`TouchpointStatus` for
|
|
409
515
|
* `touchpointStatus()` declared to return it; a type parameter widened to its constraint), or
|
|
410
|
-
* undefined when the type has no alias or the alias takes type arguments.
|
|
516
|
+
* undefined when the type has no alias or the alias takes type arguments. `declaration` is the
|
|
517
|
+
* alias's declaration.
|
|
411
518
|
*/
|
|
412
519
|
typeAliasOf(node: ts.Node): {
|
|
413
520
|
readonly name: string;
|
|
414
521
|
readonly file: string;
|
|
522
|
+
readonly declaration: ts.TypeAliasDeclaration;
|
|
415
523
|
} | undefined;
|
|
416
524
|
/**
|
|
417
525
|
* Where `fromFile` would import the type alias `name` declared in `file` from, written as
|
|
@@ -588,6 +696,26 @@ export type TypeQueries = {
|
|
|
588
696
|
* The project's JSDoc is parsed only when a rule that is on sets `needsJsDoc`.
|
|
589
697
|
*/
|
|
590
698
|
calleeTags(call: ts.CallExpression): readonly string[];
|
|
699
|
+
/**
|
|
700
|
+
* Where the function a call resolves to takes an abort signal: the first parameter whose type
|
|
701
|
+
* (without `null` and `undefined`, a type parameter widened to its constraint) is a signal, or
|
|
702
|
+
* an object type with a writable `signal` property that is one (an options object; a `Request`,
|
|
703
|
+
* whose `signal` is readonly, is not). A signal is an object type with an
|
|
704
|
+
* `aborted` property of type `boolean`: the platform's `AbortSignal`, and a library's own
|
|
705
|
+
* (`GenericAbortSignal`). Read from the signature TypeScript picks for the call as written, so
|
|
706
|
+
* an optional parameter the call leaves out counts (`fetch(url)`). Undefined when no parameter
|
|
707
|
+
* takes one, the call does not resolve, or the parameter is a rest parameter.
|
|
708
|
+
*/
|
|
709
|
+
signalParameterOf(call: ts.CallExpression): SignalParameter | undefined;
|
|
710
|
+
/**
|
|
711
|
+
* Whether TypeScript reports that the end of a function can be reached although the function
|
|
712
|
+
* must return a value: TS2366 (the return type does not include `undefined`), TS2355 (a
|
|
713
|
+
* declared type that is not `void`, `any` or `undefined`), TS2534 (a function returning
|
|
714
|
+
* `never`) or TS7030 (`noImplicitReturns`: not all code paths return a value). Only the errors
|
|
715
|
+
* TypeScript reports on the function itself (its name, signature or return type) count, not
|
|
716
|
+
* those in its body. Asks for the type errors of the function's file, once per file.
|
|
717
|
+
*/
|
|
718
|
+
reportsReachableEnd(fn: ts.FunctionLikeDeclaration): boolean;
|
|
591
719
|
};
|
|
592
720
|
export type ReportProblem = {
|
|
593
721
|
message: string;
|
|
@@ -602,6 +730,12 @@ export type ReportProblem = {
|
|
|
602
730
|
* finding's kind (`option.severities`) still wins over it.
|
|
603
731
|
*/
|
|
604
732
|
severity?: "info" | "warning";
|
|
733
|
+
/**
|
|
734
|
+
* The finding is against a guarantee the code states (`Pending<T>`, `Owned<T>`): proven strictly,
|
|
735
|
+
* so it is an error while the rule is on, even for a heuristic rule whose shape-based findings
|
|
736
|
+
* are warnings. A severity the config gives this finding's kind still wins over it.
|
|
737
|
+
*/
|
|
738
|
+
stated?: true;
|
|
605
739
|
related?: readonly {
|
|
606
740
|
node: ts.Node;
|
|
607
741
|
message: string;
|
|
@@ -623,6 +757,21 @@ export type ReportProblem = {
|
|
|
623
757
|
export type FunctionFacts = {
|
|
624
758
|
readonly throws?: readonly string[];
|
|
625
759
|
readonly rejects?: readonly string[];
|
|
760
|
+
/** What the call returns must be released (the release trait): how it is released. */
|
|
761
|
+
readonly returns?: ReleaseFact;
|
|
762
|
+
/**
|
|
763
|
+
* The promise never rejects: the function's result, or the property itself for a promise
|
|
764
|
+
* property (RTK Query's `cacheEntryRemoved`). An `await` of it is not a way out.
|
|
765
|
+
*/
|
|
766
|
+
readonly neverRejects?: true;
|
|
767
|
+
};
|
|
768
|
+
/**
|
|
769
|
+
* How a value with the release trait is released, as a `facts` line says it: `"release"`, call the
|
|
770
|
+
* returned function (`onSnapshot`'s unsubscribe); `{ release: "unsubscribe" }`, call that method
|
|
771
|
+
* on the returned value (RxJS's `Subscription`).
|
|
772
|
+
*/
|
|
773
|
+
export type ReleaseFact = "release" | {
|
|
774
|
+
readonly release: string;
|
|
626
775
|
};
|
|
627
776
|
export type PackageFactsConfig = Readonly<Record<string, Readonly<Record<string, FunctionFacts>>>>;
|
|
628
777
|
/** Where a library fact comes from, in order of trust. */
|
|
@@ -641,10 +790,76 @@ export type LibraryUse = {
|
|
|
641
790
|
readonly unknown: readonly string[];
|
|
642
791
|
}[];
|
|
643
792
|
};
|
|
793
|
+
/**
|
|
794
|
+
* The noun for the places a guarantee covers, both forms written out ("switch", "switches"): a
|
|
795
|
+
* plural is never made by adding "s".
|
|
796
|
+
*/
|
|
797
|
+
export type CoveredNoun = {
|
|
798
|
+
readonly one: string;
|
|
799
|
+
readonly many: string;
|
|
800
|
+
};
|
|
801
|
+
/** A place a stated guarantee covers: a reader of a required context, a writer of owned state. */
|
|
802
|
+
export type CoveredPlace = {
|
|
803
|
+
/** How the place is named in a list: `<Profile>`, `useTheme()`. */
|
|
804
|
+
readonly name: string;
|
|
805
|
+
readonly location: Location;
|
|
806
|
+
};
|
|
807
|
+
/**
|
|
808
|
+
* A guarantee stated in the project's code, as the plugin that proves it reads it
|
|
809
|
+
* (`EditorContributions.guarantees`): for `stateward guarantees` and the editor's hover and code
|
|
810
|
+
* lens. Whether it is proven is not said here: core counts the findings of `ruleId` that name the
|
|
811
|
+
* declaration (a related note at `location`) or lie in a place it covers, so the list and the
|
|
812
|
+
* check never disagree.
|
|
813
|
+
*/
|
|
814
|
+
/**
|
|
815
|
+
* Where a trait is stated: a standard type that already says it (`Disposable`), the project's
|
|
816
|
+
* marker type (`Owned<T>`), the config's `facts` line for a package, or the facts a plugin ships
|
|
817
|
+
* for it (stateward's facts).
|
|
818
|
+
*/
|
|
819
|
+
export type TraitSource = {
|
|
820
|
+
readonly kind: "type";
|
|
821
|
+
readonly name: string;
|
|
822
|
+
} | {
|
|
823
|
+
readonly kind: "marker";
|
|
824
|
+
} | {
|
|
825
|
+
readonly kind: "config";
|
|
826
|
+
readonly package: string;
|
|
827
|
+
} | {
|
|
828
|
+
readonly kind: "shipped";
|
|
829
|
+
readonly package: string;
|
|
830
|
+
};
|
|
831
|
+
export type StatedGuarantee = {
|
|
832
|
+
/** The guarantee's name, as its marker property writes it: `required-context`. */
|
|
833
|
+
readonly guarantee: string;
|
|
834
|
+
/** Where the trait is stated; a marker when not given. */
|
|
835
|
+
readonly source?: TraitSource;
|
|
836
|
+
/** The marker type as the declaration's type names it: `RequiredContext`. */
|
|
837
|
+
readonly marker: string;
|
|
838
|
+
/** The declaration that states it: `ThemeContext`. */
|
|
839
|
+
readonly name: string;
|
|
840
|
+
/**
|
|
841
|
+
* The declaration. Every error of `ruleId` about this guarantee has a related note here (the
|
|
842
|
+
* note that says where the guarantee is stated): that is how its errors are counted.
|
|
843
|
+
*/
|
|
844
|
+
readonly location: Location;
|
|
845
|
+
/** The rule that proves it. */
|
|
846
|
+
readonly ruleId: string;
|
|
847
|
+
/** What it promises, after "Guaranteed: ": "every reader is rendered under its Provider". */
|
|
848
|
+
readonly promise: string;
|
|
849
|
+
/** What `covered` holds, as a noun in both forms: `{ one: "switch", many: "switches" }`. */
|
|
850
|
+
readonly covers: CoveredNoun;
|
|
851
|
+
/** The places the proof covers, in file and offset order; empty when nothing uses it. */
|
|
852
|
+
readonly covered: readonly CoveredPlace[];
|
|
853
|
+
};
|
|
644
854
|
export type FileContext<O extends Options = Options> = {
|
|
645
855
|
readonly file: string;
|
|
646
856
|
/** The config's facts about packages (`facts`); `{}` when it gives none. */
|
|
647
857
|
readonly facts: PackageFactsConfig;
|
|
858
|
+
/**
|
|
859
|
+
* The facts the loaded plugins ship for common packages (`Plugin.facts`), joined in plugin
|
|
860
|
+
* order. The config's own `facts` line for a function wins over a shipped one.
|
|
861
|
+
*/
|
|
862
|
+
readonly shippedFacts: PackageFactsConfig;
|
|
648
863
|
/** The rule's options: the config's values with the defaults filled in; `{}` when it declares none. */
|
|
649
864
|
readonly options: O;
|
|
650
865
|
readonly sourceFile: ts.SourceFile;
|
|
@@ -683,6 +898,13 @@ export type FileRule<S extends OptionSpecs = OptionSpecs, G extends string = str
|
|
|
683
898
|
kind: "file";
|
|
684
899
|
meta: RuleMeta<S, G>;
|
|
685
900
|
check(ctx: FileContext<OptionsOf<S>>): void;
|
|
901
|
+
/**
|
|
902
|
+
* What the plugin's editor contributions read of this file (`EditorContributions.guarantees`,
|
|
903
|
+
* `hover`), as JSON: run after `check` on the same file, cached with its findings, and handed
|
|
904
|
+
* out by `projectSummaries` like a project rule's. It decides no finding: the findings are
|
|
905
|
+
* `check`'s alone, so the editor's fast pass stays complete without it.
|
|
906
|
+
*/
|
|
907
|
+
summarize?(ctx: FileContext<OptionsOf<S>>): Json | undefined;
|
|
686
908
|
};
|
|
687
909
|
export type ProjectRule<Summary extends Json = Json, S extends OptionSpecs = OptionSpecs, G extends string = string> = {
|
|
688
910
|
kind: "project";
|
|
@@ -745,6 +967,10 @@ export type EditorHint = {
|
|
|
745
967
|
export type EditorAction = {
|
|
746
968
|
title: string;
|
|
747
969
|
edits: readonly TextEdit[];
|
|
970
|
+
/** Other ways to write it, in order, as a fix's `alternatives`: the first that compiles is offered. */
|
|
971
|
+
alternatives?: readonly {
|
|
972
|
+
edits: readonly TextEdit[];
|
|
973
|
+
}[];
|
|
748
974
|
};
|
|
749
975
|
export type EditorContributions = {
|
|
750
976
|
/** Returns markdown. */
|
|
@@ -799,6 +1025,14 @@ export type EditorContributions = {
|
|
|
799
1025
|
libraryFacts?(input: {
|
|
800
1026
|
projectSummaries(ruleId: string): ReadonlyMap<string, Json> | undefined;
|
|
801
1027
|
}): readonly LibraryUse[];
|
|
1028
|
+
/**
|
|
1029
|
+
* The guarantees stated in the project that this plugin proves, from the last full check's
|
|
1030
|
+
* summaries (as `hover`: no new type checking): `stateward guarantees`, and the editor's hover
|
|
1031
|
+
* and code lens on a marked declaration. Each is listed even when nothing uses it.
|
|
1032
|
+
*/
|
|
1033
|
+
guarantees?(input: {
|
|
1034
|
+
projectSummaries(ruleId: string): ReadonlyMap<string, Json> | undefined;
|
|
1035
|
+
}): readonly StatedGuarantee[];
|
|
802
1036
|
};
|
|
803
1037
|
/** Rule ids are "<plugin name>/<rule key>". */
|
|
804
1038
|
export type Plugin = {
|
|
@@ -807,6 +1041,12 @@ export type Plugin = {
|
|
|
807
1041
|
description: string;
|
|
808
1042
|
rules: Readonly<Record<string, PluginRule>>;
|
|
809
1043
|
editor?: EditorContributions;
|
|
1044
|
+
/**
|
|
1045
|
+
* Facts about common packages that the plugin ships (stateward's facts), in the config's
|
|
1046
|
+
* `facts` shape: `{ rxjs: { "Observable.subscribe": { returns: { release: "unsubscribe" } } } }`.
|
|
1047
|
+
* Every rule reads them as `FileContext.shippedFacts`; the config's facts win over them.
|
|
1048
|
+
*/
|
|
1049
|
+
facts?: PackageFactsConfig;
|
|
810
1050
|
};
|
|
811
1051
|
/** A plugin that keeps its literal name and rule keys, as `definePlugin` returns it. */
|
|
812
1052
|
export type PluginOf<N extends string, R extends Readonly<Record<string, PluginRule>>> = {
|
|
@@ -814,6 +1054,7 @@ export type PluginOf<N extends string, R extends Readonly<Record<string, PluginR
|
|
|
814
1054
|
description: string;
|
|
815
1055
|
rules: R;
|
|
816
1056
|
editor?: EditorContributions;
|
|
1057
|
+
facts?: PackageFactsConfig;
|
|
817
1058
|
};
|
|
818
1059
|
/** Every rule id ("<plugin>/<rule key>") a plugin type offers; any string pair for a wide `Plugin`. */
|
|
819
1060
|
export type RuleIdOf<P extends Plugin> = P extends Plugin ? `${P["name"]}/${Extract<keyof P["rules"], string>}` : never;
|
|
@@ -1034,5 +1275,23 @@ export type CheckResult = {
|
|
|
1034
1275
|
files: number;
|
|
1035
1276
|
}[];
|
|
1036
1277
|
};
|
|
1278
|
+
/**
|
|
1279
|
+
* What the run could not check as a whole, said once (not part of the JSON contract yet).
|
|
1280
|
+
* `missingTypes`: rules that ran where their library's types do not resolve
|
|
1281
|
+
* (`RuleInfo.needsTypes`), by library, rule ids sorted. `looseNulls`: the tsconfigs, absolute,
|
|
1282
|
+
* whose projects check without `strictNullChecks`. Left out when there is nothing to say.
|
|
1283
|
+
*/
|
|
1284
|
+
notes?: CheckNotes;
|
|
1285
|
+
};
|
|
1286
|
+
export type CheckNotes = {
|
|
1287
|
+
readonly missingTypes: readonly MissingTypes[];
|
|
1288
|
+
readonly looseNulls: readonly string[];
|
|
1289
|
+
};
|
|
1290
|
+
/** Rules that could not run because a library's types do not resolve, and the reason in words. */
|
|
1291
|
+
export type MissingTypes = {
|
|
1292
|
+
readonly library: string;
|
|
1293
|
+
/** "React's types are not installed (install the app's dependencies)". */
|
|
1294
|
+
readonly reason: string;
|
|
1295
|
+
readonly rules: readonly string[];
|
|
1037
1296
|
};
|
|
1038
1297
|
//# sourceMappingURL=types.d.ts.map
|
package/package.json
CHANGED