@cplieger/deadset-ts 8.0.0-dev.20 → 8.0.0-dev.22
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/src/alias-chain.js +33 -2
- package/dist/src/analysis.js +18 -77
- package/dist/src/conformance-record.js +2 -2
- package/dist/src/contract/contract.generated.js +5 -4
- package/dist/src/dependencies.js +1 -1
- package/dist/src/exemptions/argument-places.js +131 -0
- package/dist/src/{calls.js → exemptions/calls.js} +126 -179
- package/dist/src/{exempt-classes.js → exemptions/classes.js} +1 -1
- package/dist/src/{decorator.js → exemptions/decorator.js} +19 -30
- package/dist/src/exemptions/detectors.js +48 -0
- package/dist/src/{enum-group.js → exemptions/enum-group.js} +7 -7
- package/dist/src/{erased-stores.js → exemptions/erased-stores.js} +4 -6
- package/dist/src/{framework-lifecycle.js → exemptions/framework-lifecycle.js} +31 -36
- package/dist/src/{generated-file.js → exemptions/generated-file.js} +4 -4
- package/dist/src/{injection-container.js → exemptions/injection-container.js} +19 -25
- package/dist/src/exemptions/installed-globals.js +173 -0
- package/dist/src/{interface-satisfaction.js → exemptions/interface-satisfaction.js} +52 -121
- package/dist/src/exemptions/lifecycle.js +150 -0
- package/dist/src/{reflective-lookup.js → exemptions/reflective-lookup.js} +3 -3
- package/dist/src/{serialization-contract.js → exemptions/serialization-contract.js} +415 -329
- package/dist/src/exemptions/sites.js +182 -0
- package/dist/src/{template-field.js → exemptions/template-field.js} +7 -7
- package/dist/src/{value-reach.js → exemptions/value-reach.js} +14 -7
- package/dist/src/findings/intra-function.js +50 -37
- package/dist/src/index/sites.js +1 -1
- package/dist/src/index/values.js +124 -0
- package/dist/src/intra-function-parts.js +1149 -222
- package/dist/src/liveness/sweep.js +2 -2
- package/dist/src/query.js +48 -0
- package/dist/src/roots/configured-declarations.js +1 -1
- package/dist/src/verbs/print-retained.js +23 -1
- package/jsr.json +1 -1
- package/package.json +2 -2
- package/src/alias-chain.ts +38 -2
- package/src/analysis.ts +19 -100
- package/src/bindings.ts +1 -1
- package/src/conformance-record.ts +2 -2
- package/src/contract/contract.generated.ts +5 -4
- package/src/dependencies.ts +1 -1
- package/src/exemptions/argument-places.ts +198 -0
- package/src/{calls.ts → exemptions/calls.ts} +190 -224
- package/src/{exempt-classes.ts → exemptions/classes.ts} +1 -1
- package/src/exemptions/decorator.ts +56 -0
- package/src/exemptions/detectors.ts +75 -0
- package/src/{enum-group.ts → exemptions/enum-group.ts} +9 -9
- package/src/{erased-stores.ts → exemptions/erased-stores.ts} +5 -8
- package/src/{framework-lifecycle.ts → exemptions/framework-lifecycle.ts} +39 -48
- package/src/{generated-file.ts → exemptions/generated-file.ts} +6 -6
- package/src/{injection-container.ts → exemptions/injection-container.ts} +28 -33
- package/src/exemptions/installed-globals.ts +255 -0
- package/src/{interface-satisfaction.ts → exemptions/interface-satisfaction.ts} +69 -160
- package/src/exemptions/lifecycle.ts +286 -0
- package/src/{reflective-lookup.ts → exemptions/reflective-lookup.ts} +5 -5
- package/src/{serialization-contract.ts → exemptions/serialization-contract.ts} +563 -429
- package/src/exemptions/sites.ts +293 -0
- package/src/{template-field.ts → exemptions/template-field.ts} +11 -11
- package/src/{value-reach.ts → exemptions/value-reach.ts} +16 -8
- package/src/facts.ts +1 -1
- package/src/findings/intra-function.ts +59 -37
- package/src/index/sites.ts +1 -1
- package/src/index/values.ts +170 -0
- package/src/intra-function-parts.ts +1435 -247
- package/src/liveness/sweep.ts +2 -2
- package/src/query.ts +109 -10
- package/src/roots/configured-declarations.ts +1 -2
- package/src/stores.ts +1 -1
- package/src/verbs/print-retained.ts +29 -1
- package/dist/src/exempt.js +0 -164
- package/dist/src/value-flow.js +0 -74
- package/src/decorator.ts +0 -78
- package/src/exempt.ts +0 -295
- package/src/value-flow.ts +0 -104
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* first: a caller, an exemption or a live component file's markup, a suppression mark, and an
|
|
7
7
|
* unanswered checker question; each Contract rule "live only through" one is a view up to it.
|
|
8
8
|
*/
|
|
9
|
-
import { exemptionsOf
|
|
9
|
+
import { exemptionsOf } from "../exemptions/lifecycle.js";
|
|
10
10
|
import { edgeWithheldBy } from "../tests/file-class.js";
|
|
11
11
|
import { componentsOf } from "./components.js";
|
|
12
12
|
import { namesACaller, OUTSIDE } from "./graph.js";
|
|
@@ -367,7 +367,7 @@ function seedsOf(graph, policy) {
|
|
|
367
367
|
if (record.whileLive !== undefined) {
|
|
368
368
|
gate(record.whileLive, seed);
|
|
369
369
|
}
|
|
370
|
-
else if (
|
|
370
|
+
else if (record.unanswered === true) {
|
|
371
371
|
unanswered.push(seed);
|
|
372
372
|
}
|
|
373
373
|
else {
|
package/dist/src/query.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* form where it has one and otherwise as one batch, one round trip per capped run.
|
|
8
8
|
*/
|
|
9
9
|
import { isIdentifier } from "@typescript/native/ast";
|
|
10
|
+
import { IndexKind, } from "@typescript/native/sync";
|
|
10
11
|
/**
|
|
11
12
|
* The greatest number of locations one batched request asks about. A batch is
|
|
12
13
|
* answered by an array of its own length, so an uncapped batch over a large file
|
|
@@ -118,6 +119,41 @@ function partQuestion(type) {
|
|
|
118
119
|
}
|
|
119
120
|
return undefined;
|
|
120
121
|
}
|
|
122
|
+
/** How deep {@link mappedParameters} reads, as a recursive mapped type makes a new one at each level. */
|
|
123
|
+
const MAPPED_DEPTH = 4;
|
|
124
|
+
/** The type parameters a mapped type is over, as {@link Queries.mappedParametersOf} names them. */
|
|
125
|
+
function mappedParameters(checker, mapped) {
|
|
126
|
+
const own = new Set();
|
|
127
|
+
const found = new Map();
|
|
128
|
+
const seen = new Set();
|
|
129
|
+
const visit = (type, depth) => {
|
|
130
|
+
if (depth > MAPPED_DEPTH || seen.has(type.id)) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
seen.add(type.id);
|
|
134
|
+
if (type.isMappedType()) {
|
|
135
|
+
own.add(type.getTypeParameter().id);
|
|
136
|
+
}
|
|
137
|
+
if (type.isTypeParameter() && !type.isThisType) {
|
|
138
|
+
found.set(type.id, type);
|
|
139
|
+
}
|
|
140
|
+
const aliased = type
|
|
141
|
+
.aliasTypeArguments;
|
|
142
|
+
const inner = [
|
|
143
|
+
...(type.isUnionType() || type.isIntersectionType() ? type.getTypes() : []),
|
|
144
|
+
...(type.isTypeReference() ? checker.getTypeArguments(type) : []),
|
|
145
|
+
...(aliased === undefined || aliased.length === 0 ? [] : type.getAliasTypeArguments()),
|
|
146
|
+
...(partQuestion(type)?.() ?? []),
|
|
147
|
+
];
|
|
148
|
+
for (const part of inner) {
|
|
149
|
+
if (part !== undefined) {
|
|
150
|
+
visit(part, depth + 1);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
visit(mapped, 0);
|
|
155
|
+
return [...found.values()].filter((parameter) => !own.has(parameter.id));
|
|
156
|
+
}
|
|
121
157
|
/**
|
|
122
158
|
* The guarded questions over one project's checker. `configFile` names the project
|
|
123
159
|
* in the log, `batch` sends many questions in one round trip, `log` is the run's,
|
|
@@ -244,6 +280,7 @@ export function queriesOf(checker, configFile, batch, log, ask = ASK_DIRECTLY) {
|
|
|
244
280
|
constraintOf: (type) => type.isTypeParameter()
|
|
245
281
|
? one("getConstraint", () => typeLocation(type), () => type.getConstraint())
|
|
246
282
|
: undefined,
|
|
283
|
+
baseConstraintOf: (type) => one("getBaseConstraintOfType", () => typeLocation(type), () => checker.getBaseConstraintOfType(type)),
|
|
247
284
|
indexedAccessOf: (type) => type.isIndexedAccessType()
|
|
248
285
|
? one("getObjectType", () => typeLocation(type), () => ({ object: type.getObjectType(), index: type.getIndexType() }))
|
|
249
286
|
: undefined,
|
|
@@ -272,6 +309,17 @@ export function queriesOf(checker, configFile, batch, log, ask = ASK_DIRECTLY) {
|
|
|
272
309
|
? undefined
|
|
273
310
|
: one("getTarget", () => `signature ${String(signature.id)}`, () => signature.getTarget()),
|
|
274
311
|
typeAtPosition: (signature, index) => one("getTypeParameterAtPosition", () => `signature ${String(signature.id)} position ${String(index)}`, () => signature.getTypeParameterAtPosition(index)),
|
|
312
|
+
restTypeOf: (signature) => signature.hasRestParameter
|
|
313
|
+
? one("getTypeOfSymbol", () => `signature ${String(signature.id)} rest parameter`, () => {
|
|
314
|
+
const rest = signature.getParameters().at(-1);
|
|
315
|
+
return rest === undefined ? undefined : checker.getTypeOfSymbol(rest);
|
|
316
|
+
})
|
|
317
|
+
: undefined,
|
|
318
|
+
numberIndexOf: (type) => one("getIndexTypeOfType", () => typeLocation(type), () => checker.getIndexTypeOfType(type, IndexKind.Number)),
|
|
319
|
+
mappedParametersOf: (type) => type.isMappedType()
|
|
320
|
+
? one("getConstraintType", () => typeLocation(type), () => mappedParameters(checker, type))
|
|
321
|
+
: [],
|
|
322
|
+
propertyTypeOf: (type, name) => one("getTypeOfPropertyOfType", () => `${typeLocation(type)} property ${name}`, () => checker.getTypeOfPropertyOfType(type, name)),
|
|
275
323
|
signatureOf: (declaration) => one("getSignatureFromDeclaration", () => nodeLocation(declaration), () => checker.getSignatureFromDeclaration(declaration)),
|
|
276
324
|
returnTypeOf: (signature) => one("getReturnTypeOfSignature", () => `signature ${String(signature.id)}`, () => checker.getReturnTypeOfSignature(signature)),
|
|
277
325
|
typeToString: (type) => one("typeToString", () => typeLocation(type), () => checker.typeToString(type)),
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { isCallExpression, isExportDeclaration, isExternalModuleReference, isImportDeclaration, isImportEqualsDeclaration, isNoSubstitutionTemplateLiteral, isStringLiteral, SyntaxKind, } from "@typescript/native/ast";
|
|
8
8
|
import { SymbolFlags } from "@typescript/native/sync";
|
|
9
|
-
import { resolvedTargets } from "../
|
|
9
|
+
import { resolvedTargets } from "../alias-chain.js";
|
|
10
10
|
import { declaredComponent } from "../inventory.js";
|
|
11
11
|
import { must, Unanswerable } from "../query.js";
|
|
12
12
|
import { nameComponent } from "../ref.js";
|
|
@@ -1,11 +1,33 @@
|
|
|
1
1
|
import { EXIT_CLEAN } from "../contract/contract.generated.js";
|
|
2
2
|
import { productionMode, runSweep } from "../analysis.js";
|
|
3
|
-
import { retainedLines } from "../exempt.js";
|
|
4
3
|
import { partialNotes } from "../partial.js";
|
|
4
|
+
import { positionKey } from "../position.js";
|
|
5
5
|
import { resolvePath } from "../paths.js";
|
|
6
6
|
import { resolve } from "../resolve.js";
|
|
7
7
|
import {} from "./verb.js";
|
|
8
8
|
import { diagnose } from "../product.js";
|
|
9
|
+
/**
|
|
10
|
+
* One line per held-back declaration, in site order: its reference and position, then
|
|
11
|
+
* each record's class, site and detail, all separated by tabs.
|
|
12
|
+
*/
|
|
13
|
+
function retainedLines(symbols, retained) {
|
|
14
|
+
const held = new Map();
|
|
15
|
+
for (const record of retained) {
|
|
16
|
+
held.set(record.id, [...(held.get(record.id) ?? []), record]);
|
|
17
|
+
}
|
|
18
|
+
return symbols.flatMap((symbol) => {
|
|
19
|
+
const records = held.get(symbol.id);
|
|
20
|
+
if (records === undefined) {
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
const fields = records.flatMap((record) => [
|
|
24
|
+
record.class,
|
|
25
|
+
positionKey(record.site),
|
|
26
|
+
record.detail,
|
|
27
|
+
]);
|
|
28
|
+
return [[symbol.ref, positionKey(symbol.position), ...fields].join("\t")];
|
|
29
|
+
});
|
|
30
|
+
}
|
|
9
31
|
/**
|
|
10
32
|
* Writes every declaration an exemption held back in the production sweep a report is
|
|
11
33
|
* built from, one per line, and nothing where no exemption held one back. One fact
|
package/jsr.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cplieger/deadset-ts",
|
|
3
|
-
"version": "8.0.0-dev.
|
|
3
|
+
"version": "8.0.0-dev.22",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"description": "Deterministic dead-code analysis for TypeScript, class and type members included",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"lint:fix": "eslint . --fix && prettier --write ."
|
|
33
33
|
},
|
|
34
34
|
"cplieger": {
|
|
35
|
-
"vitestShards":
|
|
35
|
+
"vitestShards": 3
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@typescript/native": "npm:typescript@7.1.0-dev.20261103.1"
|
package/src/alias-chain.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Where an import or export chain leads in one project: from one symbol to each
|
|
3
3
|
* declaration of the target it is, and along the chain of aliases it heads to each
|
|
4
|
-
* declaration every link of that chain is.
|
|
4
|
+
* declaration every link of that chain is, and what a name resolves to through them.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import {
|
|
@@ -12,10 +12,11 @@ import {
|
|
|
12
12
|
isImportSpecifier,
|
|
13
13
|
isNamespaceExport,
|
|
14
14
|
isNamespaceImport,
|
|
15
|
+
type Node,
|
|
15
16
|
} from "@typescript/native/ast";
|
|
16
17
|
import { SymbolFlags, type Symbol as TSSymbol } from "@typescript/native/sync";
|
|
17
18
|
import { isParameterProperty, nodeKey, type Inventory } from "./inventory.ts";
|
|
18
|
-
import { UNANSWERED, type Answer } from "./query.ts";
|
|
19
|
+
import { must, UNANSWERED, type Answer } from "./query.ts";
|
|
19
20
|
import type { ProjectView } from "./session.ts";
|
|
20
21
|
|
|
21
22
|
/** One declaration a chain reaches, and whether a step along an alias reached it. */
|
|
@@ -195,3 +196,38 @@ export function aliasChains<Brand>(project: ProjectView<Brand>, held: Inventory)
|
|
|
195
196
|
nextDeclared,
|
|
196
197
|
};
|
|
197
198
|
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* What each of a batch of nodes resolves to, every alias followed to the declaration
|
|
202
|
+
* it stands for. A node the checker resolves to nothing, and an alias that resolves
|
|
203
|
+
* to nothing, are absent from the answer. Each alias is followed once. A question the
|
|
204
|
+
* checker does not answer stops the pass, as {@link must} stops.
|
|
205
|
+
*/
|
|
206
|
+
export function resolvedTargets<Brand>(
|
|
207
|
+
project: ProjectView<Brand>,
|
|
208
|
+
nodes: readonly Node[],
|
|
209
|
+
): ReadonlyMap<Node, TSSymbol> {
|
|
210
|
+
const followed = new Map<number, TSSymbol | undefined>();
|
|
211
|
+
const targets = new Map<Node, TSSymbol>();
|
|
212
|
+
project
|
|
213
|
+
.symbolsAt(nodes.map((node) => project.handle(node)))
|
|
214
|
+
.map(must)
|
|
215
|
+
.forEach((symbol, index) => {
|
|
216
|
+
const node = nodes[index];
|
|
217
|
+
if (symbol === undefined || node === undefined) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
let target: TSSymbol | undefined = symbol;
|
|
221
|
+
if ((symbol.flags & SymbolFlags.Alias) !== 0) {
|
|
222
|
+
if (!followed.has(symbol.id)) {
|
|
223
|
+
const aliased = must(project.queries.aliased(symbol));
|
|
224
|
+
followed.set(symbol.id, aliased.declarations.length === 0 ? undefined : aliased);
|
|
225
|
+
}
|
|
226
|
+
target = followed.get(symbol.id);
|
|
227
|
+
}
|
|
228
|
+
if (target !== undefined) {
|
|
229
|
+
targets.set(node, target);
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
return targets;
|
|
233
|
+
}
|
package/src/analysis.ts
CHANGED
|
@@ -15,7 +15,6 @@ import {
|
|
|
15
15
|
configuredRef,
|
|
16
16
|
declarationsNamed,
|
|
17
17
|
} from "./roots/configured-declarations.ts";
|
|
18
|
-
import { decorator } from "./decorator.ts";
|
|
19
18
|
import { configurationNeeds, dependenciesOf, projectNeeds } from "./dependencies.ts";
|
|
20
19
|
import { carriersOf, NO_CARRIERS, type Carriers } from "./exposure.ts";
|
|
21
20
|
import { deprecatedDeclarations, type Deprecation } from "./deprecation.ts";
|
|
@@ -26,32 +25,19 @@ import type { AppliedConvention } from "./entries/conventions.ts";
|
|
|
26
25
|
import { readSources, type SourceFacts } from "./entries/sources.ts";
|
|
27
26
|
import { readWorkflows, type Workflows } from "./entries/workflow-steps.ts";
|
|
28
27
|
import { readEdgeSides } from "./edges.ts";
|
|
29
|
-
import { enumGroup } from "./enum-group.ts";
|
|
30
28
|
import { bindingsOf, distinctBindings, type BindingRecord } from "./bindings.ts";
|
|
31
|
-
import {
|
|
29
|
+
import { generatedFilesOf, type GeneratedFact } from "./exemptions/generated-file.ts";
|
|
32
30
|
import { inOperandNames } from "./findings/in-operands.ts";
|
|
33
31
|
import { sourceFilesOf } from "./source-files.ts";
|
|
34
|
-
import {
|
|
35
|
-
|
|
36
|
-
heldRecords,
|
|
37
|
-
disabledClasses,
|
|
38
|
-
exemptionsOf,
|
|
39
|
-
isUnansweredRecord,
|
|
40
|
-
writtenRecords,
|
|
41
|
-
type Detector,
|
|
42
|
-
type Detectors,
|
|
43
|
-
} from "./exempt.ts";
|
|
44
|
-
import type { TSExemptionClass } from "./exempt-classes.ts";
|
|
32
|
+
import { DETECTORS, detection } from "./exemptions/detectors.ts";
|
|
33
|
+
import { exemptionsOf, settle, type Detectors, type Exemption } from "./exemptions/lifecycle.ts";
|
|
45
34
|
import { heldByInclusion, sourcePaths, sourceTree } from "./file-facts.ts";
|
|
46
35
|
import type { Finding } from "./finding.ts";
|
|
47
36
|
import { findingsPass, recordedFindings, rowKey, type PassResult } from "./findings-pass.ts";
|
|
48
37
|
import type { EmitterInput } from "./findings/emitter.ts";
|
|
49
38
|
import { unmatchedRootFindings, type SelfCheckFacts } from "./findings/self-check.ts";
|
|
50
|
-
import { frameworkLifecycle } from "./framework-lifecycle.ts";
|
|
51
39
|
import type { Host } from "./host.ts";
|
|
52
40
|
import { implementations, mergeImplementations } from "./findings/implementations.ts";
|
|
53
|
-
import { injectionContainer } from "./injection-container.ts";
|
|
54
|
-
import { interfaceSatisfaction, settledSatisfaction } from "./interface-satisfaction.ts";
|
|
55
41
|
import { intraFunctionFacts, projectParts, type ProjectParts } from "./intra-function-parts.ts";
|
|
56
42
|
import { type Inventory, type InventorySymbol } from "./inventory.ts";
|
|
57
43
|
import { inventory } from "./inventory/enumerate.ts";
|
|
@@ -69,7 +55,6 @@ import type { UnansweredQuestion } from "./query.ts";
|
|
|
69
55
|
import { byPosition, isComponentFile, type Position } from "./position.ts";
|
|
70
56
|
import type { TypeErrorSkip, UnansweredCount } from "./report.ts";
|
|
71
57
|
import { skippedUnits, type SkippedUnit } from "./type-errors.ts";
|
|
72
|
-
import { reflectiveLookup } from "./reflective-lookup.ts";
|
|
73
58
|
import { references, type Reference } from "./references.ts";
|
|
74
59
|
import {
|
|
75
60
|
rootSet,
|
|
@@ -79,7 +64,7 @@ import {
|
|
|
79
64
|
type HeldScripts,
|
|
80
65
|
} from "./roots/root-set.ts";
|
|
81
66
|
import type { Scope } from "./scope.ts";
|
|
82
|
-
import { decodedMembers,
|
|
67
|
+
import { decodedMembers, type Decoded } from "./exemptions/serialization-contract.ts";
|
|
83
68
|
import { outsideTestReferences, testFilesAt, type OutsideTest } from "./tests/outside.ts";
|
|
84
69
|
import type { UnseenLoad } from "./roots/unseen-loads.ts";
|
|
85
70
|
import type { UnresolvedSpecifier } from "./load/specifiers.ts";
|
|
@@ -100,9 +85,7 @@ import { isPartKind, type SuppressionRecord, type Suppressions, type Verdict } f
|
|
|
100
85
|
import { bindRows, readBaseline, readIgnoreFile, type Recorded } from "./suppress-file.ts";
|
|
101
86
|
import { inlineDirectives, inlineSuppressions, type InlineDirective } from "./suppress-inline.ts";
|
|
102
87
|
import { sweep, type Sweep, type SweepPolicy } from "./liveness/sweep.ts";
|
|
103
|
-
import type { Exemption } from "./exempt.ts";
|
|
104
88
|
import type { Mode } from "./tests/file-class.ts";
|
|
105
|
-
import { readTemplates, templateField } from "./template-field.ts";
|
|
106
89
|
import { bytewise } from "./text/compare.ts";
|
|
107
90
|
import { holdsManifest, manifestAt } from "./fs/manifest.ts";
|
|
108
91
|
import { runDirectories } from "./entries/run-directories.ts";
|
|
@@ -444,19 +427,6 @@ interface ComponentWarning {
|
|
|
444
427
|
readonly reason: string;
|
|
445
428
|
}
|
|
446
429
|
|
|
447
|
-
/** The exemption classes this analyzer detects, each by its detector; any other retains nothing. */
|
|
448
|
-
export const DETECTORS: Detectors = new Map<TSExemptionClass, Detector>([
|
|
449
|
-
["interface-satisfaction", interfaceSatisfaction],
|
|
450
|
-
["enum-group", enumGroup],
|
|
451
|
-
["generated-file", generatedFile],
|
|
452
|
-
["template-field", templateField],
|
|
453
|
-
["reflective-lookup", reflectiveLookup],
|
|
454
|
-
["decorator", decorator],
|
|
455
|
-
["injection-container", injectionContainer],
|
|
456
|
-
["framework-lifecycle", frameworkLifecycle],
|
|
457
|
-
["serialization-contract", serializationContract],
|
|
458
|
-
]);
|
|
459
|
-
|
|
460
430
|
/** What the sweep of one run reads of each project, beside what a caller's stage adds. */
|
|
461
431
|
interface SweptProject<Extra> {
|
|
462
432
|
readonly configFile: string;
|
|
@@ -599,11 +569,8 @@ function readRun<Extra>(
|
|
|
599
569
|
) => Extra,
|
|
600
570
|
): ReadRun<Extra> {
|
|
601
571
|
const targetRoot = scope.target.path;
|
|
602
|
-
const disabled = disabledClasses(config);
|
|
603
|
-
const templates = disabled.has("template-field")
|
|
604
|
-
? { delimiters: config.analysis.template_delimiters, files: [] }
|
|
605
|
-
: readTemplates(host, targetRoot, config.analysis);
|
|
606
572
|
const consumers = scope.consumers.map((consumer) => consumer.path);
|
|
573
|
+
const detect = detection(host, targetRoot, config, consumers, detectors);
|
|
607
574
|
const directories = runDirectories(host, targetRoot, (fileName, text) =>
|
|
608
575
|
engine.parseSourceFile(fileName, text),
|
|
609
576
|
);
|
|
@@ -616,21 +583,7 @@ function readRun<Extra>(
|
|
|
616
583
|
formedForNode: projectRead.formedForNode,
|
|
617
584
|
});
|
|
618
585
|
const testFiles = testFilePaths(project, targetRoot, testFile);
|
|
619
|
-
const evidence =
|
|
620
|
-
{
|
|
621
|
-
project,
|
|
622
|
-
held: projectRead.held,
|
|
623
|
-
targetRoot,
|
|
624
|
-
templates,
|
|
625
|
-
ts: config.ts,
|
|
626
|
-
consumers,
|
|
627
|
-
...(config.analysis.generated_files === "include"
|
|
628
|
-
? {}
|
|
629
|
-
: { generated: projectRead.generated }),
|
|
630
|
-
},
|
|
631
|
-
detectors,
|
|
632
|
-
disabled,
|
|
633
|
-
);
|
|
586
|
+
const evidence = detect({ project, held: projectRead.held, generated: projectRead.generated });
|
|
634
587
|
const components = project.ownSourceFiles().filter(isComponentFile);
|
|
635
588
|
const injected = project.program
|
|
636
589
|
.getSourceFileNames()
|
|
@@ -724,30 +677,29 @@ function readRun<Extra>(
|
|
|
724
677
|
...one.decoded.copied,
|
|
725
678
|
]),
|
|
726
679
|
]);
|
|
727
|
-
const
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
evidence: evidence[index] ?? [],
|
|
680
|
+
const settled = settle(
|
|
681
|
+
withOutside.map((one) => ({
|
|
682
|
+
records: one.evidence,
|
|
731
683
|
held: one.projectRead.held,
|
|
684
|
+
testFiles: new Set([...one.testFiles, ...support]),
|
|
732
685
|
})),
|
|
733
|
-
|
|
686
|
+
{
|
|
687
|
+
references: [...withOutside.flatMap((one) => one.references), ...read.result.references],
|
|
688
|
+
written,
|
|
689
|
+
mode,
|
|
690
|
+
},
|
|
734
691
|
);
|
|
735
692
|
const answers = withOutside.map((one, index): SweptProject<Extra> => {
|
|
736
693
|
const { projectRead } = one;
|
|
737
|
-
const
|
|
738
|
-
const
|
|
739
|
-
mode,
|
|
740
|
-
testFiles: new Set([...one.testFiles, ...support]),
|
|
741
|
-
});
|
|
742
|
-
const exempt = detected.records;
|
|
743
|
-
const made = [...one.references, ...(satisfied?.references ?? [])];
|
|
694
|
+
const exempt = settled[index]?.records ?? [];
|
|
695
|
+
const made = [...one.references, ...(settled[index]?.references ?? [])];
|
|
744
696
|
const held = new Set(projectRead.held.symbols.map((symbol) => symbol.position.path));
|
|
745
697
|
const supportFiles = [...support].filter((path) => held.has(path)).sort(bytewise);
|
|
746
698
|
const testUsedFiles = [...testUsed].filter((path) => held.has(path)).sort(bytewise);
|
|
747
699
|
const configured: Configured = {
|
|
748
700
|
configuration: projectRead.configuration,
|
|
749
701
|
symbols: projectRead.held.symbols,
|
|
750
|
-
references:
|
|
702
|
+
references: made,
|
|
751
703
|
roots: projectRead.rooted.liveUnderReachability,
|
|
752
704
|
testFiles: [...one.testFiles, ...supportFiles],
|
|
753
705
|
...(supportFiles.length === 0 ? {} : { supportFiles }),
|
|
@@ -769,7 +721,7 @@ function readRun<Extra>(
|
|
|
769
721
|
...projectRead.rooted.unanswered,
|
|
770
722
|
...made.filter((reference) => reference.guessed === true).map((reference) => reference.to),
|
|
771
723
|
...one.held,
|
|
772
|
-
...exempt.filter(
|
|
724
|
+
...exempt.filter((record) => record.unanswered === true).map((record) => record.id),
|
|
773
725
|
...one.decoded.unanswered,
|
|
774
726
|
],
|
|
775
727
|
filledOutside: one.decoded.filled,
|
|
@@ -822,39 +774,6 @@ function readRun<Extra>(
|
|
|
822
774
|
};
|
|
823
775
|
}
|
|
824
776
|
|
|
825
|
-
/**
|
|
826
|
-
* The test references exemption evidence written in a test file makes: each is a read of
|
|
827
|
-
* the declaration it would retain, made by the test file at the evidence's site.
|
|
828
|
-
*/
|
|
829
|
-
function evidenceReferences(
|
|
830
|
-
symbols: readonly InventorySymbol[],
|
|
831
|
-
inTestFiles: readonly Exemption[],
|
|
832
|
-
): readonly Reference[] {
|
|
833
|
-
if (inTestFiles.length === 0) {
|
|
834
|
-
return [];
|
|
835
|
-
}
|
|
836
|
-
const files = new Map(
|
|
837
|
-
symbols
|
|
838
|
-
.filter((symbol) => symbol.kind === "file")
|
|
839
|
-
.map((symbol) => [symbol.position.path, symbol.id]),
|
|
840
|
-
);
|
|
841
|
-
return inTestFiles.flatMap((record) => {
|
|
842
|
-
const from = files.get(record.site.path);
|
|
843
|
-
return from === undefined
|
|
844
|
-
? []
|
|
845
|
-
: [
|
|
846
|
-
{
|
|
847
|
-
from,
|
|
848
|
-
to: record.id,
|
|
849
|
-
position: record.site,
|
|
850
|
-
use: "read",
|
|
851
|
-
resolution: "syntax",
|
|
852
|
-
test: true,
|
|
853
|
-
},
|
|
854
|
-
];
|
|
855
|
-
});
|
|
856
|
-
}
|
|
857
|
-
|
|
858
777
|
/**
|
|
859
778
|
* The declarations a write the mode counts stores into, a write a test-support file
|
|
860
779
|
* makes being a test's.
|
package/src/bindings.ts
CHANGED
|
@@ -29,7 +29,7 @@ import {
|
|
|
29
29
|
type SourceFile,
|
|
30
30
|
} from "@typescript/native/ast";
|
|
31
31
|
import { GENERATORS } from "./contract/contract.generated.ts";
|
|
32
|
-
import type { GeneratedFact } from "./generated-file.ts";
|
|
32
|
+
import type { GeneratedFact } from "./exemptions/generated-file.ts";
|
|
33
33
|
import { componentOf, nameNodeOf } from "./inventory.ts";
|
|
34
34
|
import { nameComponent, spell } from "./ref.ts";
|
|
35
35
|
import { bytewise } from "./text/compare.ts";
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// Regenerate it with `UPDATE_GOLDEN=1 npx vitest --run src/conformance.corpus.test.ts`.
|
|
3
3
|
export const RECORD = {
|
|
4
4
|
conformance: {
|
|
5
|
-
corpusVersion: "6.
|
|
5
|
+
corpusVersion: "6.1.0",
|
|
6
6
|
result: "pass",
|
|
7
|
-
digest: "sha256:
|
|
7
|
+
digest: "sha256:fcfdf88a7d45e1ac96545ef10c8427462260f4e81641d4d808b80086256bb6b7",
|
|
8
8
|
},
|
|
9
9
|
gaps: [],
|
|
10
10
|
} as const;
|
|
@@ -4,7 +4,7 @@ export const CONTRACT_VERSION = "8.0.0";
|
|
|
4
4
|
export const SCHEMA_VERSIONS = ["9.0.0"] as const;
|
|
5
5
|
export const SCHEMA_VERSION = "9.0.0";
|
|
6
6
|
export const FACTS_VERSION = "1.0.0";
|
|
7
|
-
export const CORPUS_VERSION = "6.
|
|
7
|
+
export const CORPUS_VERSION = "6.1.0";
|
|
8
8
|
export const CODE_PREFIX = "DS";
|
|
9
9
|
export const FAMILY_KEY_LENGTH = 4;
|
|
10
10
|
|
|
@@ -313,7 +313,7 @@ export const KIND_ROWS = [
|
|
|
313
313
|
holdsLive: false,
|
|
314
314
|
rule: "A parameter with no reference inside its function body, on a function whose signature is free to change.",
|
|
315
315
|
precondition:
|
|
316
|
-
"The signature must be free, defined as follows: the function is not a method retained by interface satisfaction, is not a method whose name and signature are those of a method of an exported interface type declared by a package outside the target that the import closure holds, is not used as a value, is not a go:linkname or cgo target, is not a go-fuzz entry point, is not a function the Go test driver runs (a test, benchmark or fuzz test of a test file, or TestMain), and is not a stub whose body is empty or only panics. A function literal or function expression that initializes a variable the program only calls, never passing, storing, returning or assigning it, is called by name and is not used as a value. In Go a function literal that is the callee of the call it is written in, the call of a `go` or a `defer` statement included, is not used as a value, wherever the literal is written. A parameter its body never names is dead whatever the callers, so a published declaration of a library is reported too, with the fixability the vocabulary gives the kind: the signature change is a breaking change. In TypeScript a caller may pass a function used as a value more arguments than it declares parameters, so in such a function whose signature is free but for that use, a parameter its body never reads is reported for deletion when its body reads no parameter after it, and an unread parameter before the last read one is reported for a rename to its name with a leading underscore, which keeps every argument in place and which the compilers' unused-parameter rules read as declared unread, unless its name already starts with one. A parameter of a TypeScript function expression or arrow function that the compiler gives a contextual type, and that carries a type annotation, is not reported for deletion where the inference of the call holding the function may read the annotation, being where the callee is generic and its parameter type at the function's place names a type parameter at the parameter's place, or where the function is written inside an object literal such a call is passed, and it is reported for deletion at `probable` where it carries an annotation no such inference reads, because nothing in the program shows that an outside reader ignores it. A name an object binding pattern of a parameter of such a function binds, annotated or not, that the body never reads is reported for deletion at `probable`, because the pattern reads the property it names from the argument and the code that hands the argument may act on that read, which nothing in the program shows. Any other TypeScript parameter that is a binding pattern is judged by the names it binds: each name the body never reads is reported wherever the pattern stands, because removing it from the pattern moves no argument, except a name beside a rest element of the same object pattern, whose removal changes what that element holds, and the pattern counts as a read parameter when the body reads any name it binds. A rest parameter is judged as the last parameter. A TypeScript `this` parameter declares the type of `this` and receives no argument, so it is never reported. A TypeScript constructor is used as a value where its class is used as a value other than as the callee of a `new` expression or the class an `extends` clause names, and its signature is not free where its class carries a decorator or a parameter of the constructor carries one, because the code that decorator or a container runs may construct the class. A parameter property is read by the write to its member the constructor makes, so it is never reported under this kind, and its member is judged under DS1301. A TypeScript name a parameter binds, whole or through a binding pattern, that starts with an underscore is never reported, because a leading underscore is the spelling unused-parameter rules read as declared unread, and no other name exempts a parameter. A Go parameter named by the blank identifier declares no name a body could read and is never reported.",
|
|
316
|
+
"The signature must be free, defined as follows: the function is not a method retained by interface satisfaction, is not a method whose name and signature are those of a method of an exported interface type declared by a package outside the target that the import closure holds, is not used as a value, is not a go:linkname or cgo target, is not a go-fuzz entry point, is not a function the Go test driver runs (a test, benchmark or fuzz test of a test file, or TestMain), and is not a stub whose body is empty or only panics. A function literal or function expression that initializes a variable the program only calls, never passing, storing, returning or assigning it, is called by name and is not used as a value. In Go a function literal that is the callee of the call it is written in, the call of a `go` or a `defer` statement included, is not used as a value, wherever the literal is written. A parameter its body never names is dead whatever the callers, so a published declaration of a library is reported too, with the fixability the vocabulary gives the kind: the signature change is a breaking change. In TypeScript a caller may pass a function used as a value more arguments than it declares parameters, so in such a function whose signature is free but for that use, a parameter its body never reads is reported for deletion when its body reads no parameter after it, and an unread parameter before the last read one is reported for a rename to its name with a leading underscore, which keeps every argument in place and which the compilers' unused-parameter rules read as declared unread, unless its name already starts with one. A function's `length` counts each parameter before the first one with a default or a rest, and code holding the function may read it, so in TypeScript an unread parameter that `length` counts is reported at `probable` where the function is used as a value or is a root, which a library's published API is and which code outside the program calls, and a function whose `length` the program reads through its own name reports no parameter. A parameter of a TypeScript function expression or arrow function that the compiler gives a contextual type, and that carries a type annotation, is not reported for deletion where the inference of the call holding the function may read the annotation, being where the callee is generic and its parameter type at the function's place names a type parameter at the parameter's place, or where the function is written inside an object literal such a call is passed, and it is reported for deletion at `probable` where it carries an annotation no such inference reads, because nothing in the program shows that an outside reader ignores it. A name an object binding pattern of a parameter of such a function binds, annotated or not, that the body never reads is reported for deletion at `probable`, because the pattern reads the property it names from the argument and the code that hands the argument may act on that read, which nothing in the program shows. Any other TypeScript parameter that is a binding pattern is judged by the names it binds: each name the body never reads is reported wherever the pattern stands, because removing it from the pattern moves no argument, except a name beside a rest element of the same object pattern, whose removal changes what that element holds, and the pattern counts as a read parameter when the body reads any name it binds. A rest parameter is judged as the last parameter. A TypeScript `this` parameter declares the type of `this` and receives no argument, so it is never reported. A TypeScript constructor is used as a value where its class is used as a value other than as the callee of a `new` expression or the class an `extends` clause names, and its signature is not free where its class carries a decorator or a parameter of the constructor carries one, because the code that decorator or a container runs may construct the class. A parameter property is read by the write to its member the constructor makes, so it is never reported under this kind, and its member is judged under DS1301. A TypeScript name a parameter binds, whole or through a binding pattern, that starts with an underscore is never reported, because a leading underscore is the spelling unused-parameter rules read as declared unread, and no other name exempts a parameter. A Go parameter named by the blank identifier declares no name a body could read and is never reported.",
|
|
317
317
|
details: { overlap: "required" },
|
|
318
318
|
defaultEnabled: true,
|
|
319
319
|
defaultSeverity: "warn",
|
|
@@ -421,7 +421,7 @@ export const KIND_ROWS = [
|
|
|
421
421
|
languages: ["go", "ts"],
|
|
422
422
|
subject: "declaration",
|
|
423
423
|
holdsLive: true,
|
|
424
|
-
rule: "An exported symbol whose every reference is inside the symbol's own package or module, reported as a candidate for unexporting. The subject is a package-level declaration or a method.
|
|
424
|
+
rule: "An exported symbol whose every reference is inside the symbol's own package or module, reported as a candidate for unexporting. The subject is a package-level declaration or a method. Four subjects are excluded. An interface method is excluded because its exportedness is the contract of the interface that declares it. A struct field is excluded because an encoder reads it by name. A method that satisfies an interface some symbol uses as a type is excluded because it cannot be unexported without its type ceasing to satisfy that interface, and so is a method whose name and signature are those of a method of an exported interface type declared by a package outside the target that the import closure holds, because that interface fixes them whether or not the program converts the method's type to it. A Go function a driver finds by its exported name is excluded, whatever else refers to it, because unexporting it stops the driver from running it: a test, a benchmark, a fuzz test or an example of a test file, TestMain, a test method a suite runner calls, and a go-fuzz entry point. The finding names the narrower visibility the references support. A declared cross-language edge counts as an out-of-package reference. Where the edge's other side is unknown to the analyzer, the finding is emitted pending. A reference from a Go external test package, a test file whose package clause names its directory's package with the suffix _test, is a reference from outside the package, because that test builds as another package and needs the export.",
|
|
425
425
|
precondition:
|
|
426
426
|
"Closed world only. A Go main package, and an internal/ directory tree for importers outside its parent, are closed worlds whatever the configuration declares, because no other program can import them, so this finding is reported there always. A published package is a closed world only when the configuration declares the consumer set complete and every declared consumer loads. A library with no consumer loaded and no complete consumer set declared gets this finding on its internal/ tree and its main packages and never on its published API. A symbol the rule of DS1301 holds for is not reported under this code, whatever severity the configuration gives DS1301, because the write-only finding names the defect to fix first. A type is not reported when a reference from outside the package reaches its values through its own package's exported declarations: a reference to an exported function or method whose parameters or results name the type, to an exported variable or constant whose type names it, to an exported field or property whose type names it, an embedded field included, or to an exported member of the type itself, a field promoted through an embedding included. A type a reference from outside the package names, or whose values such a reference reaches, passes the reach on to each type its definition names other than through an unexported member, whether it is exported or not, so an unexported type an exported function returns passes it to the types its exported fields name. A type names another through every composite that spells it: a pointer, an array, a slice, a map key or value, a channel, a function signature and a type argument. The referencing code holds values of the type, so unexporting it would leave an exported declaration naming a type its users cannot name. A package-level declaration whose name a string literal spells carries the class grammar/analysis/confidence.md gives it.",
|
|
427
427
|
details: { narrower_visibility: "required", name_literal: "optional" },
|
|
@@ -437,7 +437,7 @@ export const KIND_ROWS = [
|
|
|
437
437
|
languages: ["go"],
|
|
438
438
|
subject: "declaration",
|
|
439
439
|
holdsLive: true,
|
|
440
|
-
rule: "An exported symbol of a non-internal package whose every reference is inside the target module, reported as a candidate for relocation behind an internal boundary. The subject is a package-level declaration or a method.
|
|
440
|
+
rule: "An exported symbol of a non-internal package whose every reference is inside the target module, reported as a candidate for relocation behind an internal boundary. The subject is a package-level declaration or a method. Four subjects are excluded. An interface method is excluded because its exportedness is the contract of the interface that declares it. A struct field is excluded because an encoder reads it by name. A method that satisfies an interface some symbol uses as a type is excluded because it cannot be unexported without its type ceasing to satisfy that interface, and so is a method whose name and signature are those of a method of an exported interface type declared by a package outside the target that the import closure holds, because that interface fixes them whether or not the program converts the method's type to it. A Go function a driver finds by its exported name is excluded, whatever else refers to it, because unexporting it stops the driver from running it: a test, a benchmark, a fuzz test or an example of a test file, TestMain, a test method a suite runner calls, and a go-fuzz entry point. The finding names the narrower visibility the references support. A declared cross-language edge counts as an out-of-package reference. Where the edge's other side is unknown to the analyzer, the finding is emitted pending. A reference from a Go external test package, a test file whose package clause names its directory's package with the suffix _test, is a reference from outside the package, because that test builds as another package and needs the export.",
|
|
441
441
|
precondition:
|
|
442
442
|
"Closed world only. Reported always for a main package and an internal/ directory tree, and for a published package only when the configuration declares the consumer set complete and every declared consumer loads. A library with no consumer loaded and no complete consumer set declared gets this finding on its internal/ tree and its main packages and never on its published API. A symbol the rule of DS1301 holds for is not reported under this code, whatever severity the configuration gives DS1301, because the write-only finding names the defect to fix first. A type is not reported when a reference from outside the target module reaches its values through its own package's exported declarations, as DS1501 defines that reach, because the referencing code holds values of the type, and moving it behind an internal boundary would leave an exported declaration naming a type its users cannot name.",
|
|
443
443
|
details: { narrower_visibility: "required", name_literal: "optional" },
|
|
@@ -1444,6 +1444,7 @@ export const FAILURE_CLASSES = {
|
|
|
1444
1444
|
"unwritten-output": "run",
|
|
1445
1445
|
"unreportable-path": "run",
|
|
1446
1446
|
"memory-exhausted": "run",
|
|
1447
|
+
"missing-toolchain": "run",
|
|
1447
1448
|
"missing-analyzer": "run",
|
|
1448
1449
|
"unadmitted-analyzer": "run",
|
|
1449
1450
|
"unresolved-edge": "run",
|
package/src/dependencies.ts
CHANGED
|
@@ -202,7 +202,7 @@ export function packageOfSpecifier(specifier: string): string | undefined {
|
|
|
202
202
|
}
|
|
203
203
|
|
|
204
204
|
/** The package an installed file belongs to, read below the last dependency directory of its path. */
|
|
205
|
-
function packageOfPath(path: string): string | undefined {
|
|
205
|
+
export function packageOfPath(path: string): string | undefined {
|
|
206
206
|
const at = path.lastIndexOf(MODULES_SEGMENT);
|
|
207
207
|
return at < 0 ? undefined : packageOfSpecifier(path.slice(at + MODULES_SEGMENT.length));
|
|
208
208
|
}
|