@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
package/dist/engine.js
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { readRollout } from "./rollout.js";
|
|
3
|
-
import {
|
|
3
|
+
import { missingAnalysis, readTarget } from "./analyses.js";
|
|
4
|
+
import { analysisKey, deepFreeze, ruleKey, sha1, summaryOf, summaryText, summaryValue, useKey, } from "./cache.js";
|
|
5
|
+
import { fileLedger, ledgerKey, ledgerTraits, provesOf, tagRulesOf, withRule } from "./ledger.js";
|
|
4
6
|
import { defaultOptions } from "./options.js";
|
|
7
|
+
import { declarationId, fileStated } from "./stated.js";
|
|
5
8
|
import { codeOf, loadRule } from "./lazy.js";
|
|
6
9
|
import { IGNORE_EXPLAIN, IGNORE_RULE_ID, applyIgnores, fileDirectives } from "./ignores.js";
|
|
7
10
|
import { addonsWith, appliedOverrides, ruleIsOn, ruleSetting, ruleSettingWith, } from "./severity.js";
|
|
8
11
|
import { matchingOverrides } from "./overrides.js";
|
|
9
|
-
import {
|
|
12
|
+
import { unmatchedFacts } from "./package-facts.js";
|
|
13
|
+
import { factsGate } from "./facts-versions.js";
|
|
14
|
+
import { defaults, packExcludes } from "./config.js";
|
|
15
|
+
import { removedOf, renamesOf } from "./renamed.js";
|
|
10
16
|
import picomatch from "picomatch";
|
|
11
17
|
import { isGlob } from "./tsconfigs.js";
|
|
12
18
|
const RULE_SETTINGS = ["error", "warning", "info", "off"];
|
|
@@ -96,28 +102,57 @@ export function missingTypesReason(library) {
|
|
|
96
102
|
}
|
|
97
103
|
/**
|
|
98
104
|
* What the run cannot check as a whole (`CheckResult.notes`): the rules among `rules` whose
|
|
99
|
-
* library's types do not resolve in some project with files, and the projects without
|
|
100
|
-
* `strictNullChecks
|
|
105
|
+
* library's types do not resolve in some project with files that import it, and the projects without
|
|
106
|
+
* `strictNullChecks`, and the test-runner configs whose test files could not be read. Undefined
|
|
107
|
+
* when there is nothing to say.
|
|
101
108
|
*/
|
|
102
|
-
function notesOf(units, rules) {
|
|
109
|
+
function notesOf(units, rules, facts, gate) {
|
|
103
110
|
const missing = new Map();
|
|
104
111
|
const looseNulls = [];
|
|
112
|
+
const unreadTestConfigs = new Set();
|
|
105
113
|
for (const unit of units) {
|
|
106
114
|
if (unit.files.length === 0)
|
|
107
115
|
continue;
|
|
108
116
|
if (!unit.strictNullChecks)
|
|
109
117
|
looseNulls.push(unit.tsconfig);
|
|
118
|
+
for (const file of unit.unreadTestConfigs)
|
|
119
|
+
unreadTestConfigs.add(file);
|
|
110
120
|
for (const entry of rules) {
|
|
111
121
|
const needs = entry.rule.meta.needsTypes;
|
|
112
122
|
if (needs === undefined || needs.modules.some((module) => unit.typesResolve(module)))
|
|
113
123
|
continue;
|
|
124
|
+
// A project that uses none of the library's modules has nothing for the rule to check:
|
|
125
|
+
// installing the types would not change that, so there is nothing to say.
|
|
126
|
+
if (!needs.modules.some((module) => unit.importsModule(module)))
|
|
127
|
+
continue;
|
|
114
128
|
const ids = missing.get(needs.library) ?? new Set();
|
|
115
129
|
ids.add(entry.id);
|
|
116
130
|
missing.set(needs.library, ids);
|
|
117
131
|
}
|
|
118
132
|
}
|
|
119
|
-
|
|
133
|
+
// A line one project's types resolve is matched (0041: keys resolve through the type checker).
|
|
134
|
+
const matched = unmatchedFacts(Object.keys(facts).length === 0
|
|
135
|
+
? []
|
|
136
|
+
: units.filter((unit) => unit.files.length > 0).map((unit) => unit.factKeys(facts)), facts);
|
|
137
|
+
// The config's facts a project's version leaves out, once each: by the first file of each project.
|
|
138
|
+
const outOfRange = new Set();
|
|
139
|
+
for (const unit of units) {
|
|
140
|
+
const [first] = unit.files;
|
|
141
|
+
if (first === undefined)
|
|
142
|
+
continue;
|
|
143
|
+
for (const left of gate.at(first).withheldFacts) {
|
|
144
|
+
if (left.source === "config")
|
|
145
|
+
outOfRange.add(`${left.reason}; they are not applied`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (missing.size === 0 &&
|
|
149
|
+
looseNulls.length === 0 &&
|
|
150
|
+
unreadTestConfigs.size === 0 &&
|
|
151
|
+
matched.unmatched.length === 0 &&
|
|
152
|
+
matched.notChecked.length === 0 &&
|
|
153
|
+
outOfRange.size === 0) {
|
|
120
154
|
return undefined;
|
|
155
|
+
}
|
|
121
156
|
const missingTypes = [...missing]
|
|
122
157
|
.sort(([a], [b]) => compareText(a, b))
|
|
123
158
|
.map(([library, ids]) => ({
|
|
@@ -125,7 +160,14 @@ function notesOf(units, rules) {
|
|
|
125
160
|
reason: missingTypesReason(library),
|
|
126
161
|
rules: [...ids].sort(compareText),
|
|
127
162
|
}));
|
|
128
|
-
return {
|
|
163
|
+
return {
|
|
164
|
+
missingTypes,
|
|
165
|
+
looseNulls,
|
|
166
|
+
unreadTestConfigs: [...unreadTestConfigs].sort(compareText),
|
|
167
|
+
unmatchedFacts: matched.unmatched,
|
|
168
|
+
factsNotChecked: matched.notChecked,
|
|
169
|
+
factsOutOfRange: [...outOfRange].sort(compareText),
|
|
170
|
+
};
|
|
129
171
|
}
|
|
130
172
|
/** The own files of the projects without `strictNullChecks`. */
|
|
131
173
|
function looseNullFiles(units) {
|
|
@@ -156,9 +198,28 @@ function ignoreScope(config, ran) {
|
|
|
156
198
|
known,
|
|
157
199
|
ran: new Set([SYNTAX_RULE_ID, IMPORTS_RULE_ID, ...ran.map((entry) => entry.id)]),
|
|
158
200
|
options: config.ignores,
|
|
201
|
+
renames: renamesOf(config.plugins),
|
|
202
|
+
removed: removedOf(config.plugins),
|
|
203
|
+
offOptions: offOptionsOf(ran),
|
|
159
204
|
};
|
|
160
205
|
}
|
|
206
|
+
/** `IgnoreScope.offOptions`: each rule's convention options that are off in the options it ran with. */
|
|
207
|
+
function offOptionsOf(ran) {
|
|
208
|
+
const found = new Map();
|
|
209
|
+
for (const entry of ran) {
|
|
210
|
+
const off = Object.entries(entry.rule.meta.options ?? {})
|
|
211
|
+
.filter(([name, spec]) => spec.kind === "boolean" && spec.convention === true && entry.options[name] === false)
|
|
212
|
+
.map(([name]) => name);
|
|
213
|
+
if (off.length > 0)
|
|
214
|
+
found.set(entry.id, off);
|
|
215
|
+
}
|
|
216
|
+
return found;
|
|
217
|
+
}
|
|
161
218
|
const FAILURE_HINT = "report this to the rule's authors; the rest of the check ran normally";
|
|
219
|
+
/** The default `exclude` of a config: core's test patterns, then those its packs add. */
|
|
220
|
+
function defaultExcludes(config) {
|
|
221
|
+
return [...new Set([...defaults.exclude, ...packExcludes(config.plugins)])];
|
|
222
|
+
}
|
|
162
223
|
/**
|
|
163
224
|
* The facts every loaded plugin ships, joined in plugin order: per package, per function; a later
|
|
164
225
|
* plugin's line for the same function wins.
|
|
@@ -172,12 +233,61 @@ function shippedFactsOf(plugins) {
|
|
|
172
233
|
}
|
|
173
234
|
return joined;
|
|
174
235
|
}
|
|
236
|
+
/**
|
|
237
|
+
* The gate of a check's facts: the config's by their `"@versions"`, the packs' by the versions
|
|
238
|
+
* they were verified on (`Plugin.factsVerified`; a later plugin's range for a package wins).
|
|
239
|
+
*/
|
|
240
|
+
function gateOf(config) {
|
|
241
|
+
const verified = {};
|
|
242
|
+
for (const plugin of config.plugins)
|
|
243
|
+
Object.assign(verified, plugin.factsVerified ?? {});
|
|
244
|
+
return factsGate({
|
|
245
|
+
facts: config.facts,
|
|
246
|
+
versions: config.factVersions,
|
|
247
|
+
shipped: shippedFactsOf(config.plugins),
|
|
248
|
+
verified,
|
|
249
|
+
configDir: config.configDir,
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
/** What the cache key of a rule or analysis holds of the facts. */
|
|
253
|
+
function factsKey(config, gate, shipped) {
|
|
254
|
+
return { config: config.facts, shipped, platform: config.platform, versions: gate.key };
|
|
255
|
+
}
|
|
175
256
|
function nodeLocation(node) {
|
|
176
257
|
return { file: node.getSourceFile().fileName, start: node.getStart(), end: node.getEnd() };
|
|
177
258
|
}
|
|
178
259
|
function isStrings(value) {
|
|
179
260
|
return Array.isArray(value) && value.every((item) => typeof item === "string");
|
|
180
261
|
}
|
|
262
|
+
/** The analyses the rules read that the config's plugins publish, by id. */
|
|
263
|
+
function analysisRuns(config, rules, gate) {
|
|
264
|
+
const readers = new Map();
|
|
265
|
+
for (const entry of rules) {
|
|
266
|
+
if (entry.rule.kind !== "project")
|
|
267
|
+
continue;
|
|
268
|
+
for (const id of entry.rule.reads ?? []) {
|
|
269
|
+
const list = readers.get(id) ?? [];
|
|
270
|
+
list.push(entry.id);
|
|
271
|
+
readers.set(id, list);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
const shippedFacts = shippedFactsOf(config.plugins);
|
|
275
|
+
const runs = [];
|
|
276
|
+
for (const [id, readBy] of [...readers].sort(([a], [b]) => compareText(a, b))) {
|
|
277
|
+
const target = readTarget(config.plugins, id);
|
|
278
|
+
if (target.kind !== "found")
|
|
279
|
+
continue;
|
|
280
|
+
const facts = factsKey(config, gate, shippedFacts);
|
|
281
|
+
runs.push({
|
|
282
|
+
id,
|
|
283
|
+
analysis: target.analysis,
|
|
284
|
+
key: analysisKey({ id, analysis: target.analysis, facts }),
|
|
285
|
+
readers: [...readBy].sort(compareText),
|
|
286
|
+
gate,
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
return runs;
|
|
290
|
+
}
|
|
181
291
|
/** The rule's options with each shared list joined with the other rule's (`RuleInfo.sharedOptions`). */
|
|
182
292
|
function withSharedOptions(config, plugin, rule, options) {
|
|
183
293
|
const shared = Object.entries(rule.meta.sharedOptions ?? {});
|
|
@@ -193,7 +303,7 @@ function withSharedOptions(config, plugin, rule, options) {
|
|
|
193
303
|
return merged;
|
|
194
304
|
}
|
|
195
305
|
/** A rule with the settings it runs under, and the key its cached results are kept under. */
|
|
196
|
-
function entryOf(config, plugin, name, rule, severity, addons) {
|
|
306
|
+
function entryOf(config, plugin, name, rule, severity, addons, gate) {
|
|
197
307
|
const id = `${plugin}/${name}`;
|
|
198
308
|
const options = withSharedOptions(config, plugin, rule, config.ruleOptions[id] ?? defaultOptions(rule.meta.options));
|
|
199
309
|
const active = {
|
|
@@ -206,14 +316,16 @@ function entryOf(config, plugin, name, rule, severity, addons) {
|
|
|
206
316
|
options,
|
|
207
317
|
facts: config.facts,
|
|
208
318
|
shippedFacts: shippedFactsOf(config.plugins),
|
|
319
|
+
gate,
|
|
209
320
|
};
|
|
210
321
|
return {
|
|
211
322
|
...active,
|
|
212
|
-
key: ruleKey({ ...active, facts:
|
|
323
|
+
key: ruleKey({ ...active, facts: factsKey(config, gate, active.shippedFacts) }),
|
|
213
324
|
};
|
|
214
325
|
}
|
|
215
326
|
function ruleSets(config, selection) {
|
|
216
327
|
const rolledOut = rolloutSet(config, selection);
|
|
328
|
+
const gate = gateOf(config);
|
|
217
329
|
const anywhere = [];
|
|
218
330
|
const known = new Map();
|
|
219
331
|
for (const plugin of config.plugins) {
|
|
@@ -231,7 +343,7 @@ function ruleSets(config, selection) {
|
|
|
231
343
|
// A rule that only an override turns on has no config severity; project findings take
|
|
232
344
|
// their own from the file they are in, so this one is never shown.
|
|
233
345
|
const severity = base === "off" ? rule.meta.defaultSeverity : base;
|
|
234
|
-
anywhere.push(entryOf(config, plugin.name, name, codeOf(id, rule), severity, addons));
|
|
346
|
+
anywhere.push(entryOf(config, plugin.name, name, codeOf(id, rule), severity, addons, gate));
|
|
235
347
|
}
|
|
236
348
|
}
|
|
237
349
|
anywhere.sort((a, b) => compareText(a.id, b.id));
|
|
@@ -242,7 +354,9 @@ function ruleSets(config, selection) {
|
|
|
242
354
|
const settings = new Map();
|
|
243
355
|
return {
|
|
244
356
|
anywhere,
|
|
357
|
+
analyses: analysisRuns(config, anywhere, gate),
|
|
245
358
|
perFile,
|
|
359
|
+
gate,
|
|
246
360
|
forFile(file) {
|
|
247
361
|
if (!perFile)
|
|
248
362
|
return anywhere;
|
|
@@ -255,13 +369,17 @@ function ruleSets(config, selection) {
|
|
|
255
369
|
if (entry.rule.kind === "project")
|
|
256
370
|
return [entry];
|
|
257
371
|
const setting = ruleSettingWith(config, applied, entry.plugin, entry.name, entry.rule.meta);
|
|
258
|
-
if (setting === "off")
|
|
259
|
-
|
|
372
|
+
if (setting === "off") {
|
|
373
|
+
if (entry.rule.summarize === undefined)
|
|
374
|
+
return [];
|
|
375
|
+
const quiet = entryOf(config, entry.plugin, entry.name, entry.rule, entry.severity, [], gate);
|
|
376
|
+
return [{ ...quiet, key: `${quiet.key}:quiet`, quiet: true }];
|
|
377
|
+
}
|
|
260
378
|
const prefix = `${entry.plugin}/`;
|
|
261
379
|
const addons = addonsWith(config, applied)
|
|
262
380
|
.filter((one) => one.startsWith(prefix))
|
|
263
381
|
.map((one) => one.slice(prefix.length));
|
|
264
|
-
return [entryOf(config, entry.plugin, entry.name, entry.rule, setting, addons)];
|
|
382
|
+
return [entryOf(config, entry.plugin, entry.name, entry.rule, setting, addons, gate)];
|
|
265
383
|
});
|
|
266
384
|
variants.set(key, found);
|
|
267
385
|
}
|
|
@@ -348,15 +466,19 @@ function lower(a, b) {
|
|
|
348
466
|
}
|
|
349
467
|
/** The problem as the config shows it: at its kind's severity, or undefined when that kind is off. */
|
|
350
468
|
function problemFinding(entry, problem) {
|
|
469
|
+
const linked = problem.guarantees !== undefined && problem.guarantees.length > 0;
|
|
470
|
+
const against = problem.stated === true || problem.against === true || linked;
|
|
351
471
|
const setting = kindSetting(entry, problem.findingKind);
|
|
352
|
-
|
|
472
|
+
// A kind set to off hides the finding, unless it is against a stated guarantee: no setting
|
|
473
|
+
// makes a guarantee read proven, so it stays, as an info.
|
|
474
|
+
if (setting === "off" && !against)
|
|
353
475
|
return undefined;
|
|
354
476
|
// The config's severity for this kind wins; then the rule's own choice for this finding; then
|
|
355
477
|
// the rule's severity. A finding's own choice can only lower it, never raise it above the rule.
|
|
356
478
|
return {
|
|
357
479
|
kind: "problem",
|
|
358
480
|
ruleId: entry.id,
|
|
359
|
-
severity: setting ??
|
|
481
|
+
severity: (setting === "off" ? "info" : setting) ??
|
|
360
482
|
(problem.stated === true
|
|
361
483
|
? "error"
|
|
362
484
|
: problem.severity === undefined
|
|
@@ -369,18 +491,43 @@ function problemFinding(entry, problem) {
|
|
|
369
491
|
fixes: problem.fixes,
|
|
370
492
|
...(problem.findingKind === undefined ? {} : { findingKind: problem.findingKind }),
|
|
371
493
|
...(problem.about === undefined ? {} : { about: problem.about }),
|
|
494
|
+
...(against ? { against: true } : {}),
|
|
495
|
+
...(linked ? { guarantees: problem.guarantees } : {}),
|
|
372
496
|
};
|
|
373
497
|
}
|
|
374
|
-
|
|
375
|
-
|
|
498
|
+
/**
|
|
499
|
+
* The ids of the declarations a rule says a finding is against: a node is the declaration itself,
|
|
500
|
+
* a symbol is looked up. None when it says `true` (the finding is linked from where it lies, in
|
|
501
|
+
* the proof), says nothing, or names a symbol with no declaration.
|
|
502
|
+
*/
|
|
503
|
+
function declarationsAgainst(against, types) {
|
|
504
|
+
if (against === undefined || against === true)
|
|
505
|
+
return [];
|
|
506
|
+
const node = "kind" in against ? against : types.declarationOf(against)?.node;
|
|
507
|
+
return node === undefined ? [] : [declarationId(nodeLocation(node))];
|
|
508
|
+
}
|
|
509
|
+
/** The ids of the declarations a project rule names by where they are listed (`ProjectContext`). */
|
|
510
|
+
function declarationsAt(against) {
|
|
511
|
+
if (against === undefined || against === true)
|
|
512
|
+
return [];
|
|
513
|
+
return [...new Set(against.map(declarationId))];
|
|
514
|
+
}
|
|
515
|
+
function fileContext(entry, sourceFile, types, findings, ledger = [], marks = []) {
|
|
516
|
+
const { id, addons, options } = entry;
|
|
517
|
+
const { facts, shippedFacts, withheldFacts } = entry.gate.at(sourceFile.fileName);
|
|
376
518
|
return {
|
|
377
519
|
file: sourceFile.fileName,
|
|
520
|
+
ledger,
|
|
521
|
+
read(ref, outcome) {
|
|
522
|
+
marks.push({ ref: ref.id, trait: ref.trait, outcome });
|
|
523
|
+
},
|
|
378
524
|
sourceFile,
|
|
379
525
|
types,
|
|
380
526
|
addons,
|
|
381
527
|
options,
|
|
382
528
|
facts,
|
|
383
529
|
shippedFacts,
|
|
530
|
+
withheldFacts,
|
|
384
531
|
report(problem) {
|
|
385
532
|
const finding = problemFinding(entry, {
|
|
386
533
|
message: problem.message,
|
|
@@ -394,12 +541,15 @@ function fileContext(entry, sourceFile, types, findings) {
|
|
|
394
541
|
...(problem.findingKind === undefined ? {} : { findingKind: problem.findingKind }),
|
|
395
542
|
...(problem.severity === undefined ? {} : { severity: problem.severity }),
|
|
396
543
|
...(problem.stated === true ? { stated: true } : {}),
|
|
544
|
+
...(problem.against === true ? { against: true } : {}),
|
|
545
|
+
guarantees: declarationsAgainst(problem.against, types),
|
|
397
546
|
...(problem.about === undefined ? {} : { about: nodeLocation(problem.about) }),
|
|
398
547
|
});
|
|
399
548
|
if (finding !== undefined)
|
|
400
549
|
findings.push(finding);
|
|
401
550
|
},
|
|
402
|
-
unknown({ message, hint, node }) {
|
|
551
|
+
unknown({ message, hint, node, against, needs, unnamed }) {
|
|
552
|
+
const guarantees = declarationsAgainst(against, types);
|
|
403
553
|
findings.push({
|
|
404
554
|
kind: "unknown",
|
|
405
555
|
ruleId: id,
|
|
@@ -407,14 +557,29 @@ function fileContext(entry, sourceFile, types, findings) {
|
|
|
407
557
|
hint,
|
|
408
558
|
location: nodeLocation(node),
|
|
409
559
|
...listedFlag(entry),
|
|
560
|
+
...(guarantees.length > 0 ? { guarantees } : {}),
|
|
561
|
+
...(needs === undefined || needs.length === 0 ? {} : { needs }),
|
|
562
|
+
...(unnamed === undefined || unnamed.length === 0 ? {} : { unnamed }),
|
|
410
563
|
});
|
|
411
564
|
},
|
|
412
565
|
};
|
|
413
566
|
}
|
|
414
|
-
function projectContext(entry, findings) {
|
|
567
|
+
function projectContext(entry, findings, marks = [], analyses = {}, unstated = []) {
|
|
415
568
|
const { id, options } = entry;
|
|
416
569
|
return {
|
|
417
570
|
options,
|
|
571
|
+
analyses,
|
|
572
|
+
unstated({ location, needs, unnamed }) {
|
|
573
|
+
unstated.push({
|
|
574
|
+
ruleId: id,
|
|
575
|
+
location,
|
|
576
|
+
...(needs === undefined || needs.length === 0 ? {} : { needs }),
|
|
577
|
+
...(unnamed === undefined || unnamed.length === 0 ? {} : { unnamed }),
|
|
578
|
+
});
|
|
579
|
+
},
|
|
580
|
+
read(ref, outcome) {
|
|
581
|
+
marks.push({ ref: ref.id, trait: ref.trait, outcome });
|
|
582
|
+
},
|
|
418
583
|
report(problem) {
|
|
419
584
|
const finding = problemFinding(entry, {
|
|
420
585
|
message: problem.message,
|
|
@@ -424,12 +589,26 @@ function projectContext(entry, findings) {
|
|
|
424
589
|
fixes: problem.fixes ?? [],
|
|
425
590
|
...(problem.findingKind === undefined ? {} : { findingKind: problem.findingKind }),
|
|
426
591
|
...(problem.severity === undefined ? {} : { severity: problem.severity }),
|
|
592
|
+
...(problem.stated === true ? { stated: true } : {}),
|
|
593
|
+
...(problem.against === true ? { against: true } : {}),
|
|
594
|
+
guarantees: declarationsAt(problem.against),
|
|
427
595
|
});
|
|
428
596
|
if (finding !== undefined)
|
|
429
597
|
findings.push(finding);
|
|
430
598
|
},
|
|
431
|
-
unknown({ message, hint, location }) {
|
|
432
|
-
|
|
599
|
+
unknown({ message, hint, location, against, needs, unnamed }) {
|
|
600
|
+
const guarantees = declarationsAt(against);
|
|
601
|
+
findings.push({
|
|
602
|
+
kind: "unknown",
|
|
603
|
+
ruleId: id,
|
|
604
|
+
message,
|
|
605
|
+
hint,
|
|
606
|
+
location,
|
|
607
|
+
...listedFlag(entry),
|
|
608
|
+
...(guarantees.length > 0 ? { guarantees } : {}),
|
|
609
|
+
...(needs === undefined || needs.length === 0 ? {} : { needs }),
|
|
610
|
+
...(unnamed === undefined || unnamed.length === 0 ? {} : { unnamed }),
|
|
611
|
+
});
|
|
433
612
|
},
|
|
434
613
|
};
|
|
435
614
|
}
|
|
@@ -450,29 +629,55 @@ function failureFinding(rule, location, error) {
|
|
|
450
629
|
function summaryMap(sorted) {
|
|
451
630
|
return new Map(sorted.map(([file, summary]) => [file, summaryValue(summary)]));
|
|
452
631
|
}
|
|
632
|
+
/** A rule's marks in a fixed order (by reference, trait, then outcome), so the cache is stable. */
|
|
633
|
+
function sortedMarks(marks) {
|
|
634
|
+
return [...marks].sort((a, b) => compareText(a.ref, b.ref) ||
|
|
635
|
+
compareText(a.trait, b.trait) ||
|
|
636
|
+
compareText(JSON.stringify(a.outcome), JSON.stringify(b.outcome)));
|
|
637
|
+
}
|
|
638
|
+
/** The run's marks in a fixed order: by rule, then as `sortedMarks`. */
|
|
639
|
+
function sortedLedger(marks) {
|
|
640
|
+
return [...marks].sort((a, b) => compareText(a.ruleId, b.ruleId) ||
|
|
641
|
+
compareText(a.ref, b.ref) ||
|
|
642
|
+
compareText(a.trait, b.trait) ||
|
|
643
|
+
compareText(JSON.stringify(a.outcome), JSON.stringify(b.outcome)));
|
|
644
|
+
}
|
|
645
|
+
/** Whether a finding names the guarantees it is about (`Finding.guarantees`). */
|
|
646
|
+
function isLinked(finding) {
|
|
647
|
+
return finding.kind !== "failure" && (finding.guarantees?.length ?? 0) > 0;
|
|
648
|
+
}
|
|
453
649
|
/**
|
|
454
650
|
* A project rule's findings as the files they are in see the rule: dropped where an override turns
|
|
455
651
|
* the rule off, and at the severity that file has. The cache keeps the findings as the rule made
|
|
456
652
|
* them, so an override changes this step only.
|
|
457
653
|
*/
|
|
458
|
-
function atTheirFiles(sets, entry, found) {
|
|
654
|
+
function atTheirFiles(sets, entry, found, silenced) {
|
|
459
655
|
if (!sets.perFile)
|
|
460
656
|
return found;
|
|
461
657
|
return found.flatMap((finding) => {
|
|
462
658
|
if (finding.kind === "failure")
|
|
463
659
|
return [finding];
|
|
464
660
|
const setting = sets.settingAt(entry.id, finding.location.file);
|
|
465
|
-
if (setting === "off")
|
|
661
|
+
if (setting === "off") {
|
|
662
|
+
if (isLinked(finding))
|
|
663
|
+
silenced.push(finding);
|
|
466
664
|
return [];
|
|
665
|
+
}
|
|
467
666
|
if (finding.kind === "unknown")
|
|
468
667
|
return [finding];
|
|
469
668
|
// A severity the config gives this kind of finding holds in every file the rule is on in.
|
|
470
669
|
const own = kindSetting(entry, finding.findingKind);
|
|
471
670
|
if (own === "off")
|
|
472
|
-
return [];
|
|
671
|
+
return finding.against === true ? [{ ...finding, severity: "info" }] : [];
|
|
473
672
|
return [{ ...finding, severity: own ?? setting }];
|
|
474
673
|
});
|
|
475
674
|
}
|
|
675
|
+
/** A project rule's unstated places, without those in files the config turns the rule off in. */
|
|
676
|
+
function unstatedAtTheirFiles(sets, entry, found) {
|
|
677
|
+
if (!sets.perFile)
|
|
678
|
+
return found;
|
|
679
|
+
return found.filter((one) => sets.settingAt(entry.id, one.location.file) !== "off");
|
|
680
|
+
}
|
|
476
681
|
/**
|
|
477
682
|
* Where a project rule's failure is reported: the configured tsconfig when there is one, else the
|
|
478
683
|
* first project's (a glob names no single file).
|
|
@@ -488,17 +693,19 @@ function failureFile(config, cwd, units) {
|
|
|
488
693
|
* summary equal to one in `same` (by hash) is that object: several rules of a pack summarize the
|
|
489
694
|
* same facts of a file, and one copy of the text (and of its parsed value) serves them all.
|
|
490
695
|
*/
|
|
491
|
-
function runOnFile(entry, sourceFile, types, same) {
|
|
696
|
+
function runOnFile(entry, sourceFile, types, same, ledger) {
|
|
492
697
|
const findings = [];
|
|
493
|
-
const
|
|
698
|
+
const marks = [];
|
|
699
|
+
const ctx = fileContext(entry, sourceFile, types, findings, ledger, marks);
|
|
494
700
|
try {
|
|
495
701
|
const value = runFileSide(entry.rule, ctx);
|
|
702
|
+
const marked = marks.length === 0 ? {} : { marks: sortedMarks(marks) };
|
|
496
703
|
if (value === undefined)
|
|
497
|
-
return { result: { findings }, failed: false };
|
|
704
|
+
return { result: { findings, ...marked }, failed: false };
|
|
498
705
|
const made = summaryOf(value);
|
|
499
706
|
const summary = same.get(made.hash) ?? made;
|
|
500
707
|
same.set(summary.hash, summary);
|
|
501
|
-
return { result: { findings, summary }, failed: false };
|
|
708
|
+
return { result: { findings, summary, ...marked }, failed: false };
|
|
502
709
|
}
|
|
503
710
|
catch (error) {
|
|
504
711
|
const startOfFile = { file: sourceFile.fileName, start: 0, end: 0 };
|
|
@@ -506,6 +713,29 @@ function runOnFile(entry, sourceFile, types, same) {
|
|
|
506
713
|
return { result: { findings }, failed: true };
|
|
507
714
|
}
|
|
508
715
|
}
|
|
716
|
+
/**
|
|
717
|
+
* Runs an analysis's `summarize` on one file, as `runOnFile` a rule's: the error when it threw
|
|
718
|
+
* (such a result is not cached, and the analysis fails for this check).
|
|
719
|
+
*/
|
|
720
|
+
function runAnalysisOnFile(run, sourceFile, types, same) {
|
|
721
|
+
try {
|
|
722
|
+
const value = run.analysis.summarize({
|
|
723
|
+
file: sourceFile.fileName,
|
|
724
|
+
sourceFile,
|
|
725
|
+
types,
|
|
726
|
+
...run.gate.at(sourceFile.fileName),
|
|
727
|
+
});
|
|
728
|
+
if (value === undefined)
|
|
729
|
+
return { result: { findings: [] }, failed: false };
|
|
730
|
+
const made = summaryOf(value);
|
|
731
|
+
const summary = same.get(made.hash) ?? made;
|
|
732
|
+
same.set(summary.hash, summary);
|
|
733
|
+
return { result: { findings: [], summary }, failed: false };
|
|
734
|
+
}
|
|
735
|
+
catch (error) {
|
|
736
|
+
return { failed: true, error };
|
|
737
|
+
}
|
|
738
|
+
}
|
|
509
739
|
/**
|
|
510
740
|
* The first of the two phases of running the rules (then `runProjectPhase`): every active rule
|
|
511
741
|
* over the own files of `units`. With `rollout` on and the `configured` selection, this reads the
|
|
@@ -549,10 +779,20 @@ nextFiles, cache, ignores, timing) {
|
|
|
549
779
|
const sets = ruleSets(config, selection);
|
|
550
780
|
const rules = sets.anywhere;
|
|
551
781
|
const testFiles = config.replacesDefaultExclude
|
|
552
|
-
?
|
|
782
|
+
? defaultExcludes(config).map((pattern) => ({
|
|
783
|
+
pattern,
|
|
784
|
+
matches: picomatch(pattern, { dot: true }),
|
|
785
|
+
}))
|
|
553
786
|
: undefined;
|
|
554
787
|
const testsByPattern = new Map();
|
|
555
788
|
const findings = [];
|
|
789
|
+
/** The linked findings of a rule the config turned off where they lie: not shown, still not proven. */
|
|
790
|
+
const silenced = [];
|
|
791
|
+
const stated = [];
|
|
792
|
+
const proves = provesOf(rules.map((entry) => entry.rule.meta.proves));
|
|
793
|
+
const ledgerAt = ledgerKey(proves);
|
|
794
|
+
const ledgerRefs = [];
|
|
795
|
+
const ledgerMarks = [];
|
|
556
796
|
const summaries = new Map();
|
|
557
797
|
const directives = new Map();
|
|
558
798
|
let fileCount = 0;
|
|
@@ -562,6 +802,8 @@ nextFiles, cache, ignores, timing) {
|
|
|
562
802
|
summaries.set(entry.id, new Map());
|
|
563
803
|
}
|
|
564
804
|
}
|
|
805
|
+
const analysisSummaries = new Map(sets.analyses.map((run) => [run.id, new Map()]));
|
|
806
|
+
const analysisFailures = new Map();
|
|
565
807
|
for (const unit of units) {
|
|
566
808
|
fileCount += unit.files.length;
|
|
567
809
|
for (const file of unit.files) {
|
|
@@ -583,8 +825,13 @@ nextFiles, cache, ignores, timing) {
|
|
|
583
825
|
? before
|
|
584
826
|
: undefined;
|
|
585
827
|
const reusable = holding?.rules;
|
|
586
|
-
// Results of rules that did not run this time stay while the file's inputs are the same
|
|
828
|
+
// Results of rules that did not run this time stay while the file's inputs are the same,
|
|
829
|
+
// and while a recent run used their rule (`pruneUnused`).
|
|
587
830
|
const results = new Map(reusable ?? []);
|
|
831
|
+
if (cache !== undefined) {
|
|
832
|
+
useKey(cache, SYNTAX_RULE_ID);
|
|
833
|
+
useKey(cache, IMPORTS_RULE_ID);
|
|
834
|
+
}
|
|
588
835
|
let syntax = results.get(SYNTAX_RULE_ID);
|
|
589
836
|
if (syntax === undefined) {
|
|
590
837
|
syntax = { findings: syntaxFinding(unit, file, cwd) };
|
|
@@ -620,7 +867,33 @@ nextFiles, cache, ignores, timing) {
|
|
|
620
867
|
}
|
|
621
868
|
// One file's queries for all its rules (`ProjectUnit.typesFor`), made when one runs.
|
|
622
869
|
let fileTypes;
|
|
870
|
+
// The declarations that state a guarantee, for the guarantees no plugin lists.
|
|
871
|
+
const scanned = fileStated(results, () => {
|
|
872
|
+
const sourceFile = timing === undefined
|
|
873
|
+
? boundSourceFile(unit, file)
|
|
874
|
+
: timed(timing, "program", () => boundSourceFile(unit, file));
|
|
875
|
+
if (sourceFile === undefined)
|
|
876
|
+
return undefined;
|
|
877
|
+
fileTypes ??= unit.typesFor(file);
|
|
878
|
+
return { types: fileTypes, sourceFile };
|
|
879
|
+
});
|
|
880
|
+
if (scanned.stored && cache !== undefined)
|
|
881
|
+
cache.changed = true;
|
|
882
|
+
stated.push(...scanned.stated);
|
|
883
|
+
const readLedger = () => fileLedger(results, ledgerAt, () => {
|
|
884
|
+
const sourceFile = boundSourceFile(unit, file);
|
|
885
|
+
if (sourceFile === undefined)
|
|
886
|
+
return undefined;
|
|
887
|
+
fileTypes ??= unit.typesFor(file);
|
|
888
|
+
return { types: fileTypes, sourceFile };
|
|
889
|
+
}, proves);
|
|
890
|
+
const ledger = timing === undefined ? readLedger() : timed(timing, "ledger", readLedger);
|
|
891
|
+
if (ledger.stored && cache !== undefined)
|
|
892
|
+
cache.changed = true;
|
|
893
|
+
ledgerRefs.push(...ledger.refs);
|
|
623
894
|
for (const entry of sets.forFile(file)) {
|
|
895
|
+
if (cache !== undefined)
|
|
896
|
+
useKey(cache, entry.key);
|
|
624
897
|
let result = reusable?.get(entry.key);
|
|
625
898
|
if (result === undefined) {
|
|
626
899
|
const sourceFile = timing === undefined
|
|
@@ -631,8 +904,8 @@ nextFiles, cache, ignores, timing) {
|
|
|
631
904
|
fileTypes ??= unit.typesFor(file);
|
|
632
905
|
const types = fileTypes;
|
|
633
906
|
const ran = timing === undefined
|
|
634
|
-
? runOnFile(entry, sourceFile, types, sameSummaries)
|
|
635
|
-
: timing.fileSide(entry.id, entry.rule.kind, () => runOnFile(entry, sourceFile, timing.timedTypes(types), sameSummaries));
|
|
907
|
+
? runOnFile(entry, sourceFile, types, sameSummaries, ledger.refs)
|
|
908
|
+
: timing.fileSide(entry.id, entry.rule.kind, () => runOnFile(entry, sourceFile, timing.timedTypes(types), sameSummaries, ledger.refs));
|
|
636
909
|
result = ran.result;
|
|
637
910
|
if (cache !== undefined)
|
|
638
911
|
cache.changed = true;
|
|
@@ -647,10 +920,51 @@ nextFiles, cache, ignores, timing) {
|
|
|
647
920
|
else {
|
|
648
921
|
timing?.reused(entry.id, entry.rule.kind);
|
|
649
922
|
}
|
|
650
|
-
|
|
923
|
+
if (entry.quiet === true)
|
|
924
|
+
silenced.push(...result.findings.filter(isLinked));
|
|
925
|
+
else
|
|
926
|
+
findings.push(...result.findings);
|
|
927
|
+
// A rule off for this file still reads its references: the proof says "off" there.
|
|
928
|
+
if (result.marks !== undefined)
|
|
929
|
+
ledgerMarks.push(...withRule(entry.id, result.marks));
|
|
651
930
|
if (result.summary !== undefined)
|
|
652
931
|
summaries.get(entry.id)?.set(file, result.summary);
|
|
653
932
|
}
|
|
933
|
+
for (const run of sets.analyses) {
|
|
934
|
+
if (cache !== undefined)
|
|
935
|
+
useKey(cache, run.key);
|
|
936
|
+
let result = reusable?.get(run.key);
|
|
937
|
+
if (result === undefined) {
|
|
938
|
+
const sourceFile = timing === undefined
|
|
939
|
+
? boundSourceFile(unit, file)
|
|
940
|
+
: timed(timing, "program", () => boundSourceFile(unit, file));
|
|
941
|
+
if (sourceFile === undefined)
|
|
942
|
+
continue;
|
|
943
|
+
fileTypes ??= unit.typesFor(file);
|
|
944
|
+
const types = fileTypes;
|
|
945
|
+
const ran = timing === undefined
|
|
946
|
+
? runAnalysisOnFile(run, sourceFile, types, sameSummaries)
|
|
947
|
+
: timing.fileSide(run.id, "project", () => runAnalysisOnFile(run, sourceFile, timing.timedTypes(types), sameSummaries));
|
|
948
|
+
if (cache !== undefined)
|
|
949
|
+
cache.changed = true;
|
|
950
|
+
if (ran.failed) {
|
|
951
|
+
results.delete(run.key);
|
|
952
|
+
if (!analysisFailures.has(run.id)) {
|
|
953
|
+
analysisFailures.set(run.id, { file, error: ran.error });
|
|
954
|
+
}
|
|
955
|
+
yield { phase: "files", done, total, file, rule: run.id };
|
|
956
|
+
continue;
|
|
957
|
+
}
|
|
958
|
+
result = ran.result;
|
|
959
|
+
results.set(run.key, result);
|
|
960
|
+
yield { phase: "files", done, total, file, rule: run.id };
|
|
961
|
+
}
|
|
962
|
+
else {
|
|
963
|
+
timing?.reused(run.id, "project");
|
|
964
|
+
}
|
|
965
|
+
if (result.summary !== undefined)
|
|
966
|
+
analysisSummaries.get(run.id)?.set(file, result.summary);
|
|
967
|
+
}
|
|
654
968
|
if (fingerprint !== undefined) {
|
|
655
969
|
nextFiles.set(file, {
|
|
656
970
|
fingerprint,
|
|
@@ -676,6 +990,8 @@ nextFiles, cache, ignores, timing) {
|
|
|
676
990
|
sets,
|
|
677
991
|
findings,
|
|
678
992
|
summaries,
|
|
993
|
+
analysisSummaries,
|
|
994
|
+
analysisFailures,
|
|
679
995
|
directives,
|
|
680
996
|
fileCount,
|
|
681
997
|
testsByPattern: testFiles === undefined ? undefined : testsByPattern,
|
|
@@ -683,10 +999,21 @@ nextFiles, cache, ignores, timing) {
|
|
|
683
999
|
projects: units.length > 1
|
|
684
1000
|
? units.map((unit) => ({ tsconfig: unit.tsconfig, files: unit.files.length }))
|
|
685
1001
|
: undefined,
|
|
686
|
-
notes: notesOf(units, rules),
|
|
1002
|
+
notes: notesOf(units, rules, config.facts, sets.gate),
|
|
687
1003
|
looseNulls: looseNullFiles(units),
|
|
1004
|
+
silenced,
|
|
1005
|
+
stated,
|
|
1006
|
+
ledger: {
|
|
1007
|
+
traits: ledgerTraits(proves),
|
|
1008
|
+
refs: ledgerRefs,
|
|
1009
|
+
marks: ledgerMarks,
|
|
1010
|
+
...withTagRules(tagRulesOf(rules.map((entry) => ({ id: entry.id, proves: entry.rule.meta.proves })))),
|
|
1011
|
+
},
|
|
688
1012
|
};
|
|
689
1013
|
}
|
|
1014
|
+
function withTagRules(tagRules) {
|
|
1015
|
+
return tagRules === undefined ? {} : { tagRules };
|
|
1016
|
+
}
|
|
690
1017
|
/** The rules' project sides: each project rule's check over the summaries, and the result. */
|
|
691
1018
|
export function runProjectPhase(config, phase, started, keepSummaries, cache, capped = true, timing) {
|
|
692
1019
|
return drain(projectPhaseSteps(config, phase, started, keepSummaries, cache, capped, timing));
|
|
@@ -697,8 +1024,12 @@ export function runProjectPhase(config, phase, started, keepSummaries, cache, ca
|
|
|
697
1024
|
*/
|
|
698
1025
|
export function* projectPhaseSteps(config, phase, started, keepSummaries, cache, capped = true, timing) {
|
|
699
1026
|
const { sets, findings, summaries, directives, fileCount, testsByPattern, tsconfigLocation } = phase;
|
|
1027
|
+
const silenced = [...phase.silenced];
|
|
1028
|
+
const marks = [...phase.ledger.marks];
|
|
1029
|
+
const unstated = [];
|
|
700
1030
|
const rules = sets.anywhere;
|
|
701
1031
|
const total = rules.filter((entry) => entry.rule.kind === "project" && summaries.has(entry.id)).length;
|
|
1032
|
+
const analysisOf = solvedAnalyses(sets.analyses, phase.analysisSummaries, phase.analysisFailures, cache, timing);
|
|
702
1033
|
let done = 0;
|
|
703
1034
|
let previous;
|
|
704
1035
|
for (const entry of rules) {
|
|
@@ -722,35 +1053,60 @@ export function* projectPhaseSteps(config, phase, started, keepSummaries, cache,
|
|
|
722
1053
|
previous = entry.id;
|
|
723
1054
|
// In file order, so a rule cannot depend on the order the files were visited.
|
|
724
1055
|
const sorted = [...fileSummaries].sort(([a], [b]) => compareText(a, b));
|
|
725
|
-
const
|
|
1056
|
+
const read = readAnalyses(config, entry, analysisOf, tsconfigLocation);
|
|
1057
|
+
if (read.kind === "not-run") {
|
|
1058
|
+
keepSummaries?.set(entry.id, () => summaryMap(sorted));
|
|
1059
|
+
findings.push(...atTheirFiles(sets, entry, read.findings, silenced));
|
|
1060
|
+
continue;
|
|
1061
|
+
}
|
|
1062
|
+
const inputs = sha1([
|
|
1063
|
+
...sorted.map(([file, summary]) => `${file}\u0000${summary.hash}`),
|
|
1064
|
+
...read.fingerprints.map((print) => `\u0001${print}`),
|
|
1065
|
+
].join("\n"));
|
|
726
1066
|
const before = cache?.projects.get(entry.key);
|
|
727
1067
|
if (before?.inputs === inputs) {
|
|
728
|
-
findings.push(...atTheirFiles(sets, entry, before.findings));
|
|
1068
|
+
findings.push(...atTheirFiles(sets, entry, before.findings, silenced));
|
|
1069
|
+
unstated.push(...unstatedAtTheirFiles(sets, entry, before.unstated ?? []));
|
|
1070
|
+
marks.push(...withRule(entry.id, before.marks ?? []));
|
|
729
1071
|
// Built only if a hover asks: a CLI run whose summaries are unchanged never parses them.
|
|
730
1072
|
keepSummaries?.set(entry.id, () => (before.summaries ??= summaryMap(sorted)));
|
|
731
1073
|
continue;
|
|
732
1074
|
}
|
|
733
1075
|
const own = [];
|
|
1076
|
+
const settled = [];
|
|
1077
|
+
const ownUnstated = [];
|
|
734
1078
|
const rule = entry.rule;
|
|
735
1079
|
const runCheck = () => {
|
|
736
1080
|
const asJson = summaryMap(sorted);
|
|
737
1081
|
keepSummaries?.set(entry.id, () => asJson);
|
|
738
|
-
rule.check(asJson, projectContext(entry, own));
|
|
1082
|
+
rule.check(asJson, projectContext(entry, own, settled, read.values(), ownUnstated));
|
|
739
1083
|
return asJson;
|
|
740
1084
|
};
|
|
741
1085
|
try {
|
|
742
1086
|
const asJson = timing === undefined ? runCheck() : timing.projectSide(entry.id, runCheck);
|
|
1087
|
+
const settledMarks = sortedMarks(settled);
|
|
1088
|
+
marks.push(...withRule(entry.id, settledMarks));
|
|
743
1089
|
if (cache !== undefined) {
|
|
744
|
-
cache.projects.set(entry.key, {
|
|
1090
|
+
cache.projects.set(entry.key, {
|
|
1091
|
+
inputs,
|
|
1092
|
+
findings: own,
|
|
1093
|
+
...(ownUnstated.length === 0 ? {} : { unstated: ownUnstated }),
|
|
1094
|
+
...(settledMarks.length === 0 ? {} : { marks: settledMarks }),
|
|
1095
|
+
summaries: asJson,
|
|
1096
|
+
});
|
|
745
1097
|
cache.changed = true;
|
|
746
1098
|
}
|
|
1099
|
+
unstated.push(...unstatedAtTheirFiles(sets, entry, ownUnstated));
|
|
747
1100
|
}
|
|
748
1101
|
catch (error) {
|
|
749
1102
|
own.push(failureFinding(entry, tsconfigLocation, error));
|
|
750
1103
|
cache?.projects.delete(entry.key);
|
|
751
1104
|
}
|
|
752
|
-
findings.push(...atTheirFiles(sets, entry, own));
|
|
1105
|
+
findings.push(...atTheirFiles(sets, entry, own, silenced));
|
|
753
1106
|
}
|
|
1107
|
+
unstated.sort((a, b) => compareText(a.location.file, b.location.file) ||
|
|
1108
|
+
a.location.start - b.location.start ||
|
|
1109
|
+
compareText(a.ruleId, b.ruleId));
|
|
754
1110
|
const covered = applyIgnores(withLooseNullFixes(oneCauseOneMessage(findings, rules), rules, phase.looseNulls), directives, ignoreScope(config, rules));
|
|
755
1111
|
covered.findings.sort(compareFindings);
|
|
756
1112
|
const { shown, hidden } = capped
|
|
@@ -760,7 +1116,15 @@ export function* projectPhaseSteps(config, phase, started, keepSummaries, cache,
|
|
|
760
1116
|
findings: shown,
|
|
761
1117
|
hidden,
|
|
762
1118
|
ignored: covered.ignored,
|
|
1119
|
+
...(silenced.length === 0 ? {} : { silenced }),
|
|
1120
|
+
ledger: {
|
|
1121
|
+
traits: phase.ledger.traits,
|
|
1122
|
+
refs: phase.ledger.refs,
|
|
1123
|
+
marks: sortedLedger(marks),
|
|
1124
|
+
...withTagRules(phase.ledger.tagRules),
|
|
1125
|
+
},
|
|
763
1126
|
...(phase.notes === undefined ? {} : { notes: phase.notes }),
|
|
1127
|
+
...(unstated.length === 0 ? {} : { unstated }),
|
|
764
1128
|
stats: {
|
|
765
1129
|
files: fileCount,
|
|
766
1130
|
durationMs: Math.round(performance.now() - started),
|
|
@@ -768,7 +1132,7 @@ export function* projectPhaseSteps(config, phase, started, keepSummaries, cache,
|
|
|
768
1132
|
? {}
|
|
769
1133
|
: {
|
|
770
1134
|
testFiles: [...testsByPattern.values()].reduce((sum, count) => sum + count, 0),
|
|
771
|
-
testFilesByPattern: Object.fromEntries(
|
|
1135
|
+
testFilesByPattern: Object.fromEntries(defaultExcludes(config).flatMap((pattern) => {
|
|
772
1136
|
const count = testsByPattern.get(pattern);
|
|
773
1137
|
return count === undefined ? [] : [[pattern, count]];
|
|
774
1138
|
})),
|
|
@@ -777,6 +1141,102 @@ export function* projectPhaseSteps(config, phase, started, keepSummaries, cache,
|
|
|
777
1141
|
},
|
|
778
1142
|
};
|
|
779
1143
|
}
|
|
1144
|
+
/**
|
|
1145
|
+
* Each analysis of the run, solved at most once and only when a rule asks: an analysis whose
|
|
1146
|
+
* summaries are as the cache last saw them keeps its fingerprint, and is solved again only when a
|
|
1147
|
+
* rule that reads it must run.
|
|
1148
|
+
*/
|
|
1149
|
+
function solvedAnalyses(runs, summaries, failures, cache, timing) {
|
|
1150
|
+
const done = new Map();
|
|
1151
|
+
const byId = new Map(runs.map((run) => [run.id, run]));
|
|
1152
|
+
return (id) => {
|
|
1153
|
+
const known = done.get(id);
|
|
1154
|
+
if (known !== undefined)
|
|
1155
|
+
return known;
|
|
1156
|
+
const run = byId.get(id);
|
|
1157
|
+
if (run === undefined)
|
|
1158
|
+
return undefined;
|
|
1159
|
+
// A file it could not summarize: solved without that file, it would be wrong, not partial.
|
|
1160
|
+
const failed = failures.get(id);
|
|
1161
|
+
if (failed !== undefined) {
|
|
1162
|
+
const solved = { kind: "failed", error: failed.error, file: failed.file };
|
|
1163
|
+
done.set(id, solved);
|
|
1164
|
+
return solved;
|
|
1165
|
+
}
|
|
1166
|
+
const sorted = [...(summaries.get(id) ?? [])].sort(([a], [b]) => compareText(a, b));
|
|
1167
|
+
const inputs = sha1(sorted.map(([file, summary]) => `${file}\u0000${summary.hash}`).join("\n"));
|
|
1168
|
+
const solve = () => {
|
|
1169
|
+
const solveNow = () => deepFreeze(run.analysis.solve(summaryMap(sorted)));
|
|
1170
|
+
return timing === undefined ? solveNow() : timing.projectSide(id, solveNow);
|
|
1171
|
+
};
|
|
1172
|
+
let solved;
|
|
1173
|
+
const before = cache?.analyses.get(run.key);
|
|
1174
|
+
try {
|
|
1175
|
+
if (before?.inputs === inputs) {
|
|
1176
|
+
const entry = before;
|
|
1177
|
+
solved = {
|
|
1178
|
+
kind: "solved",
|
|
1179
|
+
fingerprint: entry.fingerprint,
|
|
1180
|
+
value: () => (entry.value ??= solve()),
|
|
1181
|
+
};
|
|
1182
|
+
}
|
|
1183
|
+
else {
|
|
1184
|
+
const value = solve();
|
|
1185
|
+
const fingerprint = sha1(JSON.stringify(value));
|
|
1186
|
+
cache?.analyses.set(run.key, { inputs, fingerprint, value });
|
|
1187
|
+
if (cache !== undefined)
|
|
1188
|
+
cache.changed = true;
|
|
1189
|
+
solved = { kind: "solved", fingerprint, value: () => value };
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
catch (error) {
|
|
1193
|
+
cache?.analyses.delete(run.key);
|
|
1194
|
+
solved = { kind: "failed", error };
|
|
1195
|
+
}
|
|
1196
|
+
done.set(id, solved);
|
|
1197
|
+
return solved;
|
|
1198
|
+
};
|
|
1199
|
+
}
|
|
1200
|
+
/**
|
|
1201
|
+
* What a project rule reads (`ProjectRule.reads`): the fingerprints of its analyses for its cache
|
|
1202
|
+
* inputs and their values for its check, or the findings it reports instead of running: one "not
|
|
1203
|
+
* checked" finding for each analysis the config's plugins do not publish (SW4), or a failure.
|
|
1204
|
+
*/
|
|
1205
|
+
function readAnalyses(config, entry, analysisOf, location) {
|
|
1206
|
+
const reads = entry.rule.kind === "project" ? (entry.rule.reads ?? []) : [];
|
|
1207
|
+
const missing = [];
|
|
1208
|
+
const solved = [];
|
|
1209
|
+
for (const id of reads) {
|
|
1210
|
+
const found = analysisOf(id);
|
|
1211
|
+
if (found === undefined) {
|
|
1212
|
+
const target = readTarget(config.plugins, id);
|
|
1213
|
+
if (target.kind === "found")
|
|
1214
|
+
continue;
|
|
1215
|
+
missing.push({
|
|
1216
|
+
kind: "unknown",
|
|
1217
|
+
ruleId: entry.id,
|
|
1218
|
+
...missingAnalysis(entry.id, id, target),
|
|
1219
|
+
location,
|
|
1220
|
+
...listedFlag(entry),
|
|
1221
|
+
});
|
|
1222
|
+
}
|
|
1223
|
+
else if (found.kind === "failed") {
|
|
1224
|
+
const at = found.file === undefined ? location : { file: found.file, start: 0, end: 0 };
|
|
1225
|
+
const failure = failureFinding(entry, at, found.error);
|
|
1226
|
+
missing.push({ ...failure, message: `${failure.message} (in analysis ${id})` });
|
|
1227
|
+
}
|
|
1228
|
+
else {
|
|
1229
|
+
solved.push({ id, fingerprint: found.fingerprint, value: found.value });
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
if (missing.length > 0)
|
|
1233
|
+
return { kind: "not-run", findings: missing };
|
|
1234
|
+
return {
|
|
1235
|
+
kind: "run",
|
|
1236
|
+
fingerprints: solved.map((one) => `${one.id}\u0000${one.fingerprint}`),
|
|
1237
|
+
values: () => Object.fromEntries(solved.map((one) => [one.id, one.value()])),
|
|
1238
|
+
};
|
|
1239
|
+
}
|
|
780
1240
|
/**
|
|
781
1241
|
* One cause, one message (`RuleMeta.yieldsTo`): a finding is left out when a rule it yields to
|
|
782
1242
|
* reports a problem where the finding's `about` is. `about` itself is dropped from every finding.
|
|
@@ -844,6 +1304,12 @@ function limitPerRuleAndFile(sorted) {
|
|
|
844
1304
|
.map((finding, index) => ({ finding, index }))
|
|
845
1305
|
.sort((a, b) => capRank(a.finding) - capRank(b.finding) || a.index - b.index);
|
|
846
1306
|
for (const { finding } of byRank) {
|
|
1307
|
+
// A finding that names a guarantee it is against is never hidden: it is what keeps the
|
|
1308
|
+
// guarantee from reading proven, and the list must show why.
|
|
1309
|
+
if (isLinked(finding)) {
|
|
1310
|
+
kept.add(finding);
|
|
1311
|
+
continue;
|
|
1312
|
+
}
|
|
847
1313
|
const key = JSON.stringify([finding.location.file, finding.ruleId]);
|
|
848
1314
|
const entry = seen.get(key) ?? {
|
|
849
1315
|
file: finding.location.file,
|
|
@@ -882,7 +1348,7 @@ function secondPass(units, sets, timing) {
|
|
|
882
1348
|
const types = timing.timedTypes(unit.typesFor(file));
|
|
883
1349
|
for (const entry of sets.forFile(file)) {
|
|
884
1350
|
timing.warmSide(entry.id, entry.rule.kind, () => {
|
|
885
|
-
runOnFile(entry, sourceFile, types, same);
|
|
1351
|
+
runOnFile(entry, sourceFile, types, same, []);
|
|
886
1352
|
});
|
|
887
1353
|
}
|
|
888
1354
|
}
|
|
@@ -957,6 +1423,15 @@ function runFileSide(rule, ctx) {
|
|
|
957
1423
|
}
|
|
958
1424
|
}
|
|
959
1425
|
/** Ids of the rules that `selection` runs somewhere (not off everywhere; the rollout applied for `configured`). */
|
|
1426
|
+
/**
|
|
1427
|
+
* Whether the config turns a rule off for a file (the rule off, or an `overrides` entry that
|
|
1428
|
+
* does): `stateward guarantees` reads it for the places a guarantee covers, where the rule never
|
|
1429
|
+
* looked. Built once; every rule counts, whatever the rollout.
|
|
1430
|
+
*/
|
|
1431
|
+
export function ruleOffAtFn(config) {
|
|
1432
|
+
const sets = ruleSets(config, { kind: "all" });
|
|
1433
|
+
return (ruleId, file) => sets.settingAt(ruleId, file) === "off";
|
|
1434
|
+
}
|
|
960
1435
|
export function activeRuleIds(config, selection) {
|
|
961
1436
|
return new Set(ruleSets(config, selection).anywhere.map((entry) => entry.id));
|
|
962
1437
|
}
|
|
@@ -1039,7 +1514,7 @@ export function runFileRules(config, cwd, units, files, started, capped = true,
|
|
|
1039
1514
|
const startOfFile = { file, start: 0, end: 0 };
|
|
1040
1515
|
let types;
|
|
1041
1516
|
for (const entry of sets.forFile(file)) {
|
|
1042
|
-
if (entry.rule.kind !== "file")
|
|
1517
|
+
if (entry.rule.kind !== "file" || entry.quiet === true)
|
|
1043
1518
|
continue;
|
|
1044
1519
|
const result = results.get(entry.key);
|
|
1045
1520
|
if (result !== undefined) {
|