@stateward/core 1.2.2 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyses.d.ts +37 -0
- package/dist/analyses.js +57 -0
- package/dist/backend/fingerprints.d.ts +3 -1
- package/dist/backend/fingerprints.js +198 -9
- package/dist/backend/program-record.d.ts +7 -0
- package/dist/backend/program-size.d.ts +32 -0
- package/dist/backend/program-size.js +166 -0
- package/dist/backend/typescript6.d.ts +62 -32
- package/dist/backend/typescript6.js +1615 -164
- package/dist/baseline.d.ts +1 -1
- package/dist/baseline.js +14 -10
- package/dist/cache.d.ts +92 -4
- package/dist/cache.js +257 -68
- package/dist/checker.d.ts +28 -3
- package/dist/checker.js +42 -8
- 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 +490 -48
- package/dist/define.d.ts +8 -2
- package/dist/disk-cache.d.ts +34 -2
- package/dist/disk-cache.js +82 -15
- package/dist/engine.d.ts +64 -3
- package/dist/engine.js +474 -59
- 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 +4 -1
- 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 +9 -9
- package/dist/index.js +12 -7
- package/dist/internal.d.ts +13 -6
- package/dist/internal.js +7 -3
- package/dist/journal.d.ts +40 -0
- package/dist/journal.js +197 -0
- package/dist/lazy.d.ts +8 -1
- package/dist/lazy.js +27 -2
- package/dist/ledger.d.ts +2 -2
- package/dist/ledger.js +2 -2
- package/dist/memory-plan.d.ts +121 -0
- package/dist/memory-plan.js +174 -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 +26 -38
- package/dist/renamed.d.ts +22 -3
- package/dist/renamed.js +50 -16
- package/dist/rollout.js +7 -4
- package/dist/severity.d.ts +1 -1
- package/dist/severity.js +17 -3
- package/dist/test-runner.d.ts +18 -0
- package/dist/test-runner.js +483 -0
- package/dist/testing.d.ts +3 -3
- package/dist/testing.js +5 -5
- package/dist/timing.d.ts +17 -7
- package/dist/timing.js +60 -38
- package/dist/types.d.ts +704 -20
- 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
package/dist/baseline.d.ts
CHANGED
|
@@ -94,7 +94,7 @@ export declare function applyBaseline(baseline: Baseline | undefined, result: Ch
|
|
|
94
94
|
* The baseline, or undefined when there is no file. A file that cannot be read or understood
|
|
95
95
|
* throws `BaselineError`, never "no baseline" (C35).
|
|
96
96
|
*/
|
|
97
|
-
export declare function readBaseline(config: Pick<Config, "configDir">): Baseline | undefined;
|
|
97
|
+
export declare function readBaseline(config: Pick<Config, "configDir" | "plugins">): Baseline | undefined;
|
|
98
98
|
/**
|
|
99
99
|
* Saves the baseline, sorted, in the current version (legacy entries kept, marked `"legacy"`).
|
|
100
100
|
* Atomic: the text goes to a temp file beside the target, then one rename replaces it, so a crash
|
package/dist/baseline.js
CHANGED
|
@@ -2,7 +2,8 @@ import { createHash } from "node:crypto";
|
|
|
2
2
|
import { readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { limitFindings } from "./engine.js";
|
|
5
|
-
import {
|
|
5
|
+
import { IGNORE_RULE_ID } from "./ignores.js";
|
|
6
|
+
import { renamedRule, renamesOf } from "./renamed.js";
|
|
6
7
|
export const BASELINE_FILE = "stateward.baseline.json";
|
|
7
8
|
/**
|
|
8
9
|
* Version 2 fingerprints a finding by its rule, file and code only, so rewording a message never
|
|
@@ -118,11 +119,13 @@ function fingerprinter(context) {
|
|
|
118
119
|
};
|
|
119
120
|
}
|
|
120
121
|
/**
|
|
121
|
-
* Only problems are accepted. A place not checked (an unknown) is not a problem to
|
|
122
|
-
* rule failure means stateward is broken there.
|
|
122
|
+
* Only problems of the rules are accepted. A place not checked (an unknown) is not a problem to
|
|
123
|
+
* accept, and a rule failure means stateward is broken there. A finding about an ignore comment
|
|
124
|
+
* (`stateward/ignore`) is not accepted either: the comment is the developer's own, and its fix is
|
|
125
|
+
* an edit of it, which `check --fix` makes.
|
|
123
126
|
*/
|
|
124
127
|
function isAcceptable(finding) {
|
|
125
|
-
return finding.kind === "problem";
|
|
128
|
+
return finding.kind === "problem" && finding.ruleId !== IGNORE_RULE_ID;
|
|
126
129
|
}
|
|
127
130
|
/** The baseline that accepts exactly the problems in `findings` (unknowns and failures are left out). */
|
|
128
131
|
export function baselineOf(findings, context) {
|
|
@@ -148,7 +151,8 @@ export function baselineOf(findings, context) {
|
|
|
148
151
|
* not run this time (off, or not yet on in the rollout) keep what they had.
|
|
149
152
|
*/
|
|
150
153
|
export function mergeBaseline(existing, ran, built) {
|
|
151
|
-
|
|
154
|
+
// Entries of ignore comments an older stateward wrote never match (`isAcceptable`): dropped.
|
|
155
|
+
const kept = (existing?.entries ?? []).filter((entry) => !ran.has(entry.ruleId) && entry.ruleId !== IGNORE_RULE_ID);
|
|
152
156
|
return { entries: [...kept, ...built.entries].sort(compareEntries) };
|
|
153
157
|
}
|
|
154
158
|
/** How many findings a baseline accepts and in how many files. */
|
|
@@ -213,7 +217,7 @@ export function applyBaseline(baseline, result, context) {
|
|
|
213
217
|
});
|
|
214
218
|
return { fresh: capped(fresh), baselined, fixed, pruned: { entries } };
|
|
215
219
|
}
|
|
216
|
-
function parseEntry(value, file, version) {
|
|
220
|
+
function parseEntry(value, file, version, renames) {
|
|
217
221
|
if (!isRecord(value)) {
|
|
218
222
|
throw broken(file, "has a finding that is not an object", REPAIR);
|
|
219
223
|
}
|
|
@@ -249,7 +253,7 @@ function parseEntry(value, file, version) {
|
|
|
249
253
|
]);
|
|
250
254
|
// An entry of a renamed rule: its fingerprint hashed the old id, so it is matched by rule and
|
|
251
255
|
// file, under the new id, until the next `baseline` writes it again.
|
|
252
|
-
const renamed = renamedRule(ruleId);
|
|
256
|
+
const renamed = renamedRule(renames, ruleId);
|
|
253
257
|
if (renamed !== undefined) {
|
|
254
258
|
return {
|
|
255
259
|
entry: { kind: "legacy", ruleId: renamed, file: entryFile, message, count },
|
|
@@ -279,7 +283,7 @@ function combineLegacy(entries) {
|
|
|
279
283
|
}
|
|
280
284
|
return [...combined.values()];
|
|
281
285
|
}
|
|
282
|
-
function parseBaseline(text, file) {
|
|
286
|
+
function parseBaseline(text, file, renames) {
|
|
283
287
|
let parsed;
|
|
284
288
|
try {
|
|
285
289
|
parsed = JSON.parse(text);
|
|
@@ -302,7 +306,7 @@ function parseBaseline(text, file) {
|
|
|
302
306
|
throw broken(file, '"findings" must be a list', REPAIR);
|
|
303
307
|
const seen = new Set();
|
|
304
308
|
const entries = findings.map((value) => {
|
|
305
|
-
const { entry, key } = parseEntry(value, file, version);
|
|
309
|
+
const { entry, key } = parseEntry(value, file, version, renames);
|
|
306
310
|
if (seen.has(key)) {
|
|
307
311
|
throw broken(file, `lists the same ${entry.ruleId} finding in ${entry.file} twice`, 'remove one of the two and raise "count" on the other, or run `stateward baseline` to write the file again');
|
|
308
312
|
}
|
|
@@ -326,7 +330,7 @@ export function readBaseline(config) {
|
|
|
326
330
|
return undefined;
|
|
327
331
|
throw new BaselineError(`${path.basename(file)} cannot be read (${reasonOf(error)}); fix the file or its permissions, then run again`, { cause: error });
|
|
328
332
|
}
|
|
329
|
-
return parseBaseline(text, file);
|
|
333
|
+
return parseBaseline(text, file, renamesOf(config.plugins));
|
|
330
334
|
}
|
|
331
335
|
function writtenEntry(entry) {
|
|
332
336
|
const count = entry.count > 1 ? { count: entry.count } : {};
|
package/dist/cache.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ProgramRecord } from "./backend/program-record.js";
|
|
2
|
-
import type { Finding, FixVerdict, Json, ReadOutcome, Rule, Severity } from "./types.js";
|
|
2
|
+
import type { UnstatedPlace, Finding, FixVerdict, Json, PluginAnalysis, ReadOutcome, Rule, Severity } from "./types.js";
|
|
3
3
|
/**
|
|
4
4
|
* The results a checker keeps between runs, by content:
|
|
5
5
|
*
|
|
@@ -7,8 +7,11 @@ import type { Finding, FixVerdict, Json, ReadOutcome, Rule, Severity } from "./t
|
|
|
7
7
|
* its rule key (`ruleKey`): the findings the rule reported on that file, and a project rule's
|
|
8
8
|
* summary; with the hash of each declaration (or whole file) of another file the rules read there. A
|
|
9
9
|
* file whose fingerprint and reads are unchanged is not looked at again.
|
|
10
|
-
* - per
|
|
11
|
-
*
|
|
10
|
+
* - per analysis a rule reads (`Plugin.analyses`), under its key (`analysisKey`): a hash of its
|
|
11
|
+
* summaries, and the fingerprint of what it solved from them; a project rule that reads it has
|
|
12
|
+
* that fingerprint in its inputs, so it is checked again only when the analysis changes.
|
|
13
|
+
* - per project rule, under its rule key: a hash of all its summaries (and of the analyses it
|
|
14
|
+
* reads), and the findings its check produced from them. Equal summaries give equal findings (a project rule decides from its
|
|
12
15
|
* summaries and options alone), so an edit that leaves every summary as it was does not run
|
|
13
16
|
* the check again (early cut-off).
|
|
14
17
|
*
|
|
@@ -16,7 +19,7 @@ import type { Finding, FixVerdict, Json, ReadOutcome, Rule, Severity } from "./t
|
|
|
16
19
|
* server save it to disk between runs as a `CacheSnapshot` (disk-cache.ts).
|
|
17
20
|
*/
|
|
18
21
|
/** Bumped whenever what is stored, or how a key is computed, changes. */
|
|
19
|
-
export declare const CACHE_FORMAT =
|
|
22
|
+
export declare const CACHE_FORMAT = 18;
|
|
20
23
|
/**
|
|
21
24
|
* A project rule's summary of one file: the hash of its JSON text, and either that text or, once a
|
|
22
25
|
* rule or a hover needed the value (a run whose summaries are all unchanged never does), the parsed
|
|
@@ -48,6 +51,8 @@ export type RuleResult = {
|
|
|
48
51
|
summary?: CachedSummary;
|
|
49
52
|
marks?: readonly RuleMark[];
|
|
50
53
|
};
|
|
54
|
+
/** Frozen all the way down: a cached summary is shared between runs, so no rule may change it. */
|
|
55
|
+
export declare function deepFreeze(value: Json): Json;
|
|
51
56
|
/**
|
|
52
57
|
* A summary as JSON stores it (a Map becomes `{}`, `undefined` members disappear): a project rule
|
|
53
58
|
* cannot depend on a value JSON drops, and equal texts are equal summaries.
|
|
@@ -57,6 +62,12 @@ export declare function summaryOf(value: Json): CachedSummary;
|
|
|
57
62
|
export declare function summaryFromText(text: string, hash: string): CachedSummary;
|
|
58
63
|
/** The summary's value, parsed from its text once and frozen; the text is then let go. */
|
|
59
64
|
export declare function summaryValue(summary: CachedSummary): Json;
|
|
65
|
+
/**
|
|
66
|
+
* The hash of the JSON text of a summary the engine handed to a project rule's `check`, an
|
|
67
|
+
* analysis's `solve` or an editor contribution: equal hashes are equal summaries. Undefined for a
|
|
68
|
+
* value the engine did not hand out (one a test built), and for `null` or a primitive.
|
|
69
|
+
*/
|
|
70
|
+
export declare function summaryHash(value: Json): string | undefined;
|
|
60
71
|
/**
|
|
61
72
|
* The summary's JSON text: kept, or written again from the parsed value. JSON text parsed and
|
|
62
73
|
* written again is the same text (`JSON.stringify` wrote it), so the hash still matches it.
|
|
@@ -76,6 +87,8 @@ export type ProjectEntry = {
|
|
|
76
87
|
/** Hash of the rule's summaries, by file. */
|
|
77
88
|
inputs: string;
|
|
78
89
|
findings: readonly Finding[];
|
|
90
|
+
/** The places the rule judged leaving out unstated package calls (`ProjectContext.unstated`). */
|
|
91
|
+
unstated?: readonly UnstatedPlace[];
|
|
79
92
|
/** The rule's marks on the references its file sides handed on (`ProjectContext.read`). */
|
|
80
93
|
marks?: readonly RuleMark[];
|
|
81
94
|
/**
|
|
@@ -84,9 +97,25 @@ export type ProjectEntry = {
|
|
|
84
97
|
*/
|
|
85
98
|
summaries?: ReadonlyMap<string, Json>;
|
|
86
99
|
};
|
|
100
|
+
/** An analysis's last result (`ResultCache.analyses`). */
|
|
101
|
+
export type AnalysisEntry = {
|
|
102
|
+
/** Hash of the analysis's summaries, by file. */
|
|
103
|
+
inputs: string;
|
|
104
|
+
/** Hash of the JSON text of what `solve` returned from them. */
|
|
105
|
+
fingerprint: string;
|
|
106
|
+
/** That value, kept in memory only (undefined when the entry came from disk). */
|
|
107
|
+
value?: Json;
|
|
108
|
+
/**
|
|
109
|
+
* The summaries it was solved from, as `solve` and the publisher's own rules received them:
|
|
110
|
+
* the same map while they are unchanged, so a solver's memo keyed by the map holds. Kept in
|
|
111
|
+
* memory only.
|
|
112
|
+
*/
|
|
113
|
+
summaries?: ReadonlyMap<string, Json>;
|
|
114
|
+
};
|
|
87
115
|
export type ResultCache = {
|
|
88
116
|
files: Map<string, FileEntry>;
|
|
89
117
|
projects: Map<string, ProjectEntry>;
|
|
118
|
+
analyses: Map<string, AnalysisEntry>;
|
|
90
119
|
/** By tsconfig path: what its program was built from (backend/program-record.ts). */
|
|
91
120
|
programs: Map<string, ProgramRecord>;
|
|
92
121
|
/**
|
|
@@ -99,7 +128,36 @@ export type ResultCache = {
|
|
|
99
128
|
}>>;
|
|
100
129
|
/** Set when a run stored or dropped anything: only then is there something new to save. */
|
|
101
130
|
changed: boolean;
|
|
131
|
+
/** This run's number: one more than the run that saved the cache read back, 1 for a new one. */
|
|
132
|
+
run: number;
|
|
133
|
+
/**
|
|
134
|
+
* The last run that used each key (`useKey`): a rule's key, an analysis's, a fix verdict's.
|
|
135
|
+
* Entries under a key no recent run used are dropped when the cache is saved (`pruneUnused`).
|
|
136
|
+
*/
|
|
137
|
+
used: Map<string, number>;
|
|
138
|
+
/**
|
|
139
|
+
* Told of each file as the file phase starts it and once its results are final, so a run that
|
|
140
|
+
* dies keeps what it finished (the CLI's journal, disk-cache.ts). Absent: nobody is told.
|
|
141
|
+
*/
|
|
142
|
+
progress?: FileProgress | undefined;
|
|
102
143
|
};
|
|
144
|
+
/** What the file phase tells of each file (`ResultCache.progress`). */
|
|
145
|
+
export type FileProgress = {
|
|
146
|
+
started(file: string): void;
|
|
147
|
+
/** `entry` holds `file`'s results of this run, final. */
|
|
148
|
+
finished(file: string, entry: FileEntry): void;
|
|
149
|
+
};
|
|
150
|
+
/** Entries no run among the last this many used are dropped when the cache is saved. */
|
|
151
|
+
export declare const KEEP_RUNS = 3;
|
|
152
|
+
/** Notes that this run uses the entries under `key`, so a save keeps them. */
|
|
153
|
+
export declare function useKey(cache: ResultCache, key: string): void;
|
|
154
|
+
/**
|
|
155
|
+
* Drops the entries under keys that none of the last `runs` runs used (`KEEP_RUNS` by default):
|
|
156
|
+
* the results of a rule or an analysis under an earlier config or code, and verdicts of fixes no
|
|
157
|
+
* longer shown. Without it, a cache kept every key it ever held and grew past what can be written.
|
|
158
|
+
* `runs = 1` keeps only what this run used. Returns whether anything was dropped.
|
|
159
|
+
*/
|
|
160
|
+
export declare function pruneUnused(cache: ResultCache, runs?: number): boolean;
|
|
103
161
|
export declare function emptyCache(): ResultCache;
|
|
104
162
|
export declare function sha1(text: string): string;
|
|
105
163
|
/**
|
|
@@ -118,6 +176,15 @@ export declare function ruleKey(input: {
|
|
|
118
176
|
/** The config's facts about packages: a rule that reads them decides differently when they change. */
|
|
119
177
|
facts?: unknown;
|
|
120
178
|
}): string;
|
|
179
|
+
/**
|
|
180
|
+
* What an analysis's results depend on besides the files: its id, its code, the facts about
|
|
181
|
+
* packages its `summarize` reads, and the cache format.
|
|
182
|
+
*/
|
|
183
|
+
export declare function analysisKey(input: {
|
|
184
|
+
id: string;
|
|
185
|
+
analysis: PluginAnalysis;
|
|
186
|
+
facts: unknown;
|
|
187
|
+
}): string;
|
|
121
188
|
/** The cache as plain JSON. Read back with `parseSnapshot`, which checks every field. */
|
|
122
189
|
export type CacheSnapshot = {
|
|
123
190
|
format: number;
|
|
@@ -136,18 +203,39 @@ export type CacheSnapshot = {
|
|
|
136
203
|
projects: Record<string, {
|
|
137
204
|
inputs: string;
|
|
138
205
|
findings: readonly Finding[];
|
|
206
|
+
unstated?: readonly UnstatedPlace[];
|
|
139
207
|
marks?: readonly RuleMark[];
|
|
140
208
|
}>;
|
|
209
|
+
/** `ResultCache.analyses`, without the values. */
|
|
210
|
+
analyses?: Record<string, {
|
|
211
|
+
inputs: string;
|
|
212
|
+
fingerprint: string;
|
|
213
|
+
}>;
|
|
141
214
|
programs: Record<string, ProgramRecord>;
|
|
142
215
|
/** `ResultCache.verdicts`: `null` for a fix that compiles, else TypeScript's message. */
|
|
143
216
|
verdicts?: Record<string, string | null>;
|
|
217
|
+
/** `ResultCache.run` of the run that saved it. */
|
|
218
|
+
run: number;
|
|
219
|
+
/** `ResultCache.used`. */
|
|
220
|
+
used: Record<string, number>;
|
|
144
221
|
};
|
|
222
|
+
type FileSnapshot = CacheSnapshot["files"][string];
|
|
223
|
+
/** One file's results as plain JSON (`CacheSnapshot.files`); read back with `parseFileEntry`. */
|
|
224
|
+
export declare function fileSnapshot(entry: FileEntry): FileSnapshot;
|
|
145
225
|
export declare function toSnapshot(cache: ResultCache): CacheSnapshot;
|
|
226
|
+
/**
|
|
227
|
+
* The snapshot's JSON text in pieces, for a writer that never holds the whole text (a large
|
|
228
|
+
* project's is more than one string can hold): `toSnapshot`'s value, one file's results per piece.
|
|
229
|
+
*/
|
|
230
|
+
export declare function snapshotChunks(cache: ResultCache): Generator<string>;
|
|
146
231
|
export declare function isJson(value: unknown): value is Json;
|
|
147
232
|
export declare function parseFinding(value: unknown): Finding | undefined;
|
|
233
|
+
/** One file's results as `fileSnapshot` wrote them; undefined when anything has another shape. */
|
|
234
|
+
export declare function parseFileEntry(entry: unknown): FileEntry | undefined;
|
|
148
235
|
/**
|
|
149
236
|
* A cache read back from JSON. Anything that does not have the expected shape, or another format,
|
|
150
237
|
* is an empty cache: a broken cache costs a cold run, never findings (workspace C35).
|
|
151
238
|
*/
|
|
152
239
|
export declare function parseSnapshot(value: unknown): ResultCache;
|
|
240
|
+
export {};
|
|
153
241
|
//# sourceMappingURL=cache.d.ts.map
|