@stateward/core 1.0.1-rc.1 → 1.1.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 +80 -4
- 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 +200 -15
- package/dist/cache.d.ts +5 -4
- package/dist/cache.js +2 -2
- package/dist/checker.d.ts +7 -1
- package/dist/checker.js +19 -3
- package/dist/config.js +47 -4
- package/dist/disk-cache.d.ts +24 -2
- package/dist/disk-cache.js +43 -5
- package/dist/engine.d.ts +11 -1
- package/dist/engine.js +150 -40
- package/dist/guarantees.d.ts +41 -0
- package/dist/guarantees.js +68 -0
- package/dist/ignores.d.ts +2 -2
- package/dist/ignores.js +11 -11
- package/dist/index.d.ts +1 -1
- package/dist/internal.d.ts +5 -3
- package/dist/internal.js +4 -3
- package/dist/plan.d.ts +17 -0
- package/dist/plan.js +22 -5
- 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 +13 -0
- package/dist/types.d.ts +121 -0
- package/package.json +1 -1
package/dist/plan.js
CHANGED
|
@@ -36,6 +36,11 @@ silent = new Map()) {
|
|
|
36
36
|
}
|
|
37
37
|
for (const entry of result.hidden)
|
|
38
38
|
bump(findings, entry.ruleId, entry.count);
|
|
39
|
+
const notChecked = new Map();
|
|
40
|
+
for (const missing of result.notes?.missingTypes ?? []) {
|
|
41
|
+
for (const ruleId of missing.rules)
|
|
42
|
+
notChecked.set(ruleId, missing.reason);
|
|
43
|
+
}
|
|
39
44
|
const candidates = config.plugins.flatMap((plugin, packIndex) => Object.entries(plugin.rules).flatMap(([key, rule]) => {
|
|
40
45
|
if (!ruleIsOn(config, plugin.name, key, rule.meta))
|
|
41
46
|
return [];
|
|
@@ -63,9 +68,16 @@ silent = new Map()) {
|
|
|
63
68
|
fixable: candidate.fixable,
|
|
64
69
|
protects: candidate.protects,
|
|
65
70
|
...(silent.has(candidate.ruleId) ? { silent: silent.get(candidate.ruleId) ?? "" } : {}),
|
|
71
|
+
...(notChecked.has(candidate.ruleId)
|
|
72
|
+
? { notChecked: notChecked.get(candidate.ruleId) ?? "" }
|
|
73
|
+
: {}),
|
|
66
74
|
})),
|
|
67
75
|
};
|
|
68
76
|
}
|
|
77
|
+
/** Whether a row has nothing to fix as far as anyone knows: no finding, and the rule ran. */
|
|
78
|
+
export function isClean(row) {
|
|
79
|
+
return row.findings === 0 && row.notChecked === undefined;
|
|
80
|
+
}
|
|
69
81
|
/** The next step from the rules turned on so far (in the order they were turned on). */
|
|
70
82
|
export function advance(plan, enabled, anyway) {
|
|
71
83
|
const off = plan.rules.filter((row) => !enabled.includes(row.ruleId));
|
|
@@ -75,15 +87,20 @@ export function advance(plan, enabled, anyway) {
|
|
|
75
87
|
const last = plan.rules.find((row) => row.ruleId === lastId);
|
|
76
88
|
if (!anyway && last !== undefined && last.findings > 0)
|
|
77
89
|
return { kind: "blocked", row: last };
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
};
|
|
90
|
+
const row = off.find((candidate) => candidate.findings > 0);
|
|
91
|
+
const clean = off.filter(isClean);
|
|
92
|
+
if (row === undefined && clean.length === 0)
|
|
93
|
+
return { kind: "not-checked", rows: off };
|
|
94
|
+
return { kind: "turn-on", row, clean };
|
|
83
95
|
}
|
|
84
96
|
function countOf(count, noun) {
|
|
85
97
|
return `${String(count)} ${noun}${count === 1 ? "" : "s"}`;
|
|
86
98
|
}
|
|
99
|
+
/** What `next` says when only rules that could not run are left, in one line. */
|
|
100
|
+
export function describeNotChecked(rows) {
|
|
101
|
+
const reasons = [...new Set(rows.map((row) => row.notChecked ?? ""))].join("; ");
|
|
102
|
+
return `the ${countOf(rows.length, "rule")} left could not run here: ${reasons}; then run \`stateward next\` again`;
|
|
103
|
+
}
|
|
87
104
|
/**
|
|
88
105
|
* The lines `stateward next` and the editor's "Turn on the next rule" tell the developer after a
|
|
89
106
|
* `turn-on` step: the clean rules that came along, the rule now on with what it protects, and
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** The compiler's complaints about the project at `dir` (its tsconfig.json), as `tsc -p dir` prints them. */
|
|
2
|
+
export declare function typeErrors(dir: string): string;
|
|
3
|
+
/**
|
|
4
|
+
* The type errors of each text, as `tsc` prints them with each text a file of its own
|
|
5
|
+
* ("a3.ts(1,2): error ..."); a text maps to "" when it compiles. The strict, NodeNext options of
|
|
6
|
+
* the old spawned check. Texts must be modules, or their top-level names would meet in one scope.
|
|
7
|
+
*/
|
|
8
|
+
export declare function typeErrorsOfTexts(texts: readonly string[]): ReadonlyMap<string, string>;
|
|
9
|
+
/** The type errors of one text (see `typeErrorsOfTexts`), "" when it compiles. */
|
|
10
|
+
export declare function typeErrorsOfText(text: string): string;
|
|
11
|
+
//# sourceMappingURL=testing-tsc.d.ts.map
|
|
@@ -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
|
@@ -141,6 +141,18 @@ export function messageProblems(finding) {
|
|
|
141
141
|
problems.push('headline must not start with "You"');
|
|
142
142
|
if (prose.includes("!"))
|
|
143
143
|
problems.push('headline must not contain "!"');
|
|
144
|
+
// M15, M16, M19: a fact about the code, with no pointing words and no question; a place not
|
|
145
|
+
// checked says so first, never "stateward cannot tell".
|
|
146
|
+
const pointing = /\b(?:this|here|you)\b/i.exec(prose);
|
|
147
|
+
if (pointing !== null)
|
|
148
|
+
problems.push(`headline must not point with "${pointing[0]}"`);
|
|
149
|
+
if (prose.includes("?"))
|
|
150
|
+
problems.push("headline must not be a question");
|
|
151
|
+
if (/\bstateward cannot\b/i.test(prose))
|
|
152
|
+
problems.push('headline must not say "stateward cannot"');
|
|
153
|
+
if (finding.kind === "unknown" && !prose.startsWith("not checked: ")) {
|
|
154
|
+
problems.push('a place not checked must start with "not checked: "');
|
|
155
|
+
}
|
|
144
156
|
if (finding.kind === "problem") {
|
|
145
157
|
finding.related.forEach((related, index) => {
|
|
146
158
|
problems.push(...lineProblems(`related message ${String(index + 1)}`, related.message, undefined));
|
|
@@ -162,4 +174,5 @@ export function expectMessageStandard(findings) {
|
|
|
162
174
|
throw new MessageStandardError(`${String(violations.length)} message standard violation(s):\n${violations.join("\n")}`);
|
|
163
175
|
}
|
|
164
176
|
}
|
|
177
|
+
export { typeErrors, typeErrorsOfText, typeErrorsOfTexts } from "./testing-tsc.js";
|
|
165
178
|
//# 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
|
|
@@ -393,6 +429,17 @@ export type TypeQueries = {
|
|
|
393
429
|
* recognised by where that symbol is declared.
|
|
394
430
|
*/
|
|
395
431
|
uniqueSymbolKeyFiles(node: ts.Node): readonly string[];
|
|
432
|
+
/**
|
|
433
|
+
* The guarantees a type states: the string literals of its optional `__guarantee` property
|
|
434
|
+
* (`Context<T> & { readonly __guarantee?: "required-context" }`), sorted. The type is the one
|
|
435
|
+
* of an expression or type node, or the declared type of a symbol (a variable's type, a type
|
|
436
|
+
* alias's type), resolved through aliases, generics and re-exports. A type parameter is widened
|
|
437
|
+
* to its constraint; `null` and `undefined` members are left out, and every other member of a
|
|
438
|
+
* union must state a guarantee for it to count. Empty for a type that states none, or whose
|
|
439
|
+
* `__guarantee` is required or not a string literal (that is a brand, not a guarantee). The
|
|
440
|
+
* names mean nothing to core; each plugin reads its own.
|
|
441
|
+
*/
|
|
442
|
+
guaranteesOf(target: ts.Node | SymbolRef): readonly string[];
|
|
396
443
|
/**
|
|
397
444
|
* The type alias a value's type is an instance of, found from its declaration: after awaiting a
|
|
398
445
|
* `Promise`, every member of the type must be written in the same alias (`Result<T, E>` and
|
|
@@ -588,6 +635,17 @@ export type TypeQueries = {
|
|
|
588
635
|
* The project's JSDoc is parsed only when a rule that is on sets `needsJsDoc`.
|
|
589
636
|
*/
|
|
590
637
|
calleeTags(call: ts.CallExpression): readonly string[];
|
|
638
|
+
/**
|
|
639
|
+
* Where the function a call resolves to takes an abort signal: the first parameter whose type
|
|
640
|
+
* (without `null` and `undefined`, a type parameter widened to its constraint) is a signal, or
|
|
641
|
+
* an object type with a writable `signal` property that is one (an options object; a `Request`,
|
|
642
|
+
* whose `signal` is readonly, is not). A signal is an object type with an
|
|
643
|
+
* `aborted` property of type `boolean`: the platform's `AbortSignal`, and a library's own
|
|
644
|
+
* (`GenericAbortSignal`). Read from the signature TypeScript picks for the call as written, so
|
|
645
|
+
* an optional parameter the call leaves out counts (`fetch(url)`). Undefined when no parameter
|
|
646
|
+
* takes one, the call does not resolve, or the parameter is a rest parameter.
|
|
647
|
+
*/
|
|
648
|
+
signalParameterOf(call: ts.CallExpression): SignalParameter | undefined;
|
|
591
649
|
};
|
|
592
650
|
export type ReportProblem = {
|
|
593
651
|
message: string;
|
|
@@ -641,6 +699,39 @@ export type LibraryUse = {
|
|
|
641
699
|
readonly unknown: readonly string[];
|
|
642
700
|
}[];
|
|
643
701
|
};
|
|
702
|
+
/** A place a stated guarantee covers: a reader of a required context, a writer of owned state. */
|
|
703
|
+
export type CoveredPlace = {
|
|
704
|
+
/** How the place is named in a list: `<Profile>`, `useTheme()`. */
|
|
705
|
+
readonly name: string;
|
|
706
|
+
readonly location: Location;
|
|
707
|
+
};
|
|
708
|
+
/**
|
|
709
|
+
* A guarantee stated in the project's code, as the plugin that proves it reads it
|
|
710
|
+
* (`EditorContributions.guarantees`): for `stateward guarantees` and the editor's hover and code
|
|
711
|
+
* lens. Whether it is proven is not said here: core counts the findings of `ruleId` that name the
|
|
712
|
+
* declaration (a related note at `location`), so the list and the check never disagree.
|
|
713
|
+
*/
|
|
714
|
+
export type StatedGuarantee = {
|
|
715
|
+
/** The guarantee's name, as `__guarantee` writes it: `required-context`. */
|
|
716
|
+
readonly guarantee: string;
|
|
717
|
+
/** The marker type as the declaration's type names it: `RequiredContext`. */
|
|
718
|
+
readonly marker: string;
|
|
719
|
+
/** The declaration that states it: `ThemeContext`. */
|
|
720
|
+
readonly name: string;
|
|
721
|
+
/**
|
|
722
|
+
* The declaration. Every error of `ruleId` about this guarantee has a related note here (the
|
|
723
|
+
* note that says where the guarantee is stated): that is how its errors are counted.
|
|
724
|
+
*/
|
|
725
|
+
readonly location: Location;
|
|
726
|
+
/** The rule that proves it. */
|
|
727
|
+
readonly ruleId: string;
|
|
728
|
+
/** What it promises, after "Guaranteed: ": "every reader is rendered under its Provider". */
|
|
729
|
+
readonly promise: string;
|
|
730
|
+
/** What `covered` holds, as a plural noun: "readers", "writers". */
|
|
731
|
+
readonly covers: string;
|
|
732
|
+
/** The places the proof covers, in file and offset order; empty when nothing uses it. */
|
|
733
|
+
readonly covered: readonly CoveredPlace[];
|
|
734
|
+
};
|
|
644
735
|
export type FileContext<O extends Options = Options> = {
|
|
645
736
|
readonly file: string;
|
|
646
737
|
/** The config's facts about packages (`facts`); `{}` when it gives none. */
|
|
@@ -745,6 +836,10 @@ export type EditorHint = {
|
|
|
745
836
|
export type EditorAction = {
|
|
746
837
|
title: string;
|
|
747
838
|
edits: readonly TextEdit[];
|
|
839
|
+
/** Other ways to write it, in order, as a fix's `alternatives`: the first that compiles is offered. */
|
|
840
|
+
alternatives?: readonly {
|
|
841
|
+
edits: readonly TextEdit[];
|
|
842
|
+
}[];
|
|
748
843
|
};
|
|
749
844
|
export type EditorContributions = {
|
|
750
845
|
/** Returns markdown. */
|
|
@@ -799,6 +894,14 @@ export type EditorContributions = {
|
|
|
799
894
|
libraryFacts?(input: {
|
|
800
895
|
projectSummaries(ruleId: string): ReadonlyMap<string, Json> | undefined;
|
|
801
896
|
}): readonly LibraryUse[];
|
|
897
|
+
/**
|
|
898
|
+
* The guarantees stated in the project that this plugin proves, from the last full check's
|
|
899
|
+
* summaries (as `hover`: no new type checking): `stateward guarantees`, and the editor's hover
|
|
900
|
+
* and code lens on a marked declaration. Each is listed even when nothing uses it.
|
|
901
|
+
*/
|
|
902
|
+
guarantees?(input: {
|
|
903
|
+
projectSummaries(ruleId: string): ReadonlyMap<string, Json> | undefined;
|
|
904
|
+
}): readonly StatedGuarantee[];
|
|
802
905
|
};
|
|
803
906
|
/** Rule ids are "<plugin name>/<rule key>". */
|
|
804
907
|
export type Plugin = {
|
|
@@ -1034,5 +1137,23 @@ export type CheckResult = {
|
|
|
1034
1137
|
files: number;
|
|
1035
1138
|
}[];
|
|
1036
1139
|
};
|
|
1140
|
+
/**
|
|
1141
|
+
* What the run could not check as a whole, said once (not part of the JSON contract yet).
|
|
1142
|
+
* `missingTypes`: rules that ran where their library's types do not resolve
|
|
1143
|
+
* (`RuleInfo.needsTypes`), by library, rule ids sorted. `looseNulls`: the tsconfigs, absolute,
|
|
1144
|
+
* whose projects check without `strictNullChecks`. Left out when there is nothing to say.
|
|
1145
|
+
*/
|
|
1146
|
+
notes?: CheckNotes;
|
|
1147
|
+
};
|
|
1148
|
+
export type CheckNotes = {
|
|
1149
|
+
readonly missingTypes: readonly MissingTypes[];
|
|
1150
|
+
readonly looseNulls: readonly string[];
|
|
1151
|
+
};
|
|
1152
|
+
/** Rules that could not run because a library's types do not resolve, and the reason in words. */
|
|
1153
|
+
export type MissingTypes = {
|
|
1154
|
+
readonly library: string;
|
|
1155
|
+
/** "React's types are not installed (install the app's dependencies)". */
|
|
1156
|
+
readonly reason: string;
|
|
1157
|
+
readonly rules: readonly string[];
|
|
1037
1158
|
};
|
|
1038
1159
|
//# sourceMappingURL=types.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stateward/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "The engine of stateward (exclusive states and predictable code paths for TypeScript) and the API for writing your own rules and packs.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|