@cplieger/deadset-ts 3.12.0 → 3.13.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.
Files changed (63) hide show
  1. package/README.md +2 -2
  2. package/dist/src/analysis.js +100 -27
  3. package/dist/src/components.js +4 -2
  4. package/dist/src/configured-declarations.js +36 -0
  5. package/dist/src/conformance-record.js +2 -2
  6. package/dist/src/edges.js +4 -1
  7. package/dist/src/findings/completion.js +37 -8
  8. package/dist/src/findings/emitters.js +5 -5
  9. package/dist/src/findings/intra-function.js +91 -2
  10. package/dist/src/findings/self-check.js +30 -7
  11. package/dist/src/findings/unused-declarations.js +15 -3
  12. package/dist/src/findings-pass.js +18 -11
  13. package/dist/src/graph.js +7 -7
  14. package/dist/src/intra-function-parts.js +643 -0
  15. package/dist/src/kinds.js +337 -35
  16. package/dist/src/reflective-lookup.js +35 -2
  17. package/dist/src/report.js +11 -2
  18. package/dist/src/reporters/sarif.js +20 -15
  19. package/dist/src/reporters/template.js +64 -5
  20. package/dist/src/roots.js +13 -8
  21. package/dist/src/serialization-contract.js +41 -22
  22. package/dist/src/signatures.js +32 -0
  23. package/dist/src/suppress-file.js +27 -6
  24. package/dist/src/suppress-inline.js +8 -1
  25. package/dist/src/suppress.js +27 -0
  26. package/dist/src/value-reach.js +33 -9
  27. package/dist/src/verbs/analyze.js +19 -11
  28. package/dist/src/verbs/describe.js +12 -8
  29. package/dist/src/version.js +1 -1
  30. package/jsr.json +1 -1
  31. package/package.json +1 -1
  32. package/src/analysis.ts +167 -48
  33. package/src/components.ts +4 -2
  34. package/src/configured-declarations.ts +57 -1
  35. package/src/conformance-record.ts +2 -2
  36. package/src/edges.ts +4 -1
  37. package/src/finding.ts +5 -1
  38. package/src/findings/completion.ts +46 -10
  39. package/src/findings/emitter.ts +3 -0
  40. package/src/findings/emitters.ts +9 -5
  41. package/src/findings/intra-function.ts +106 -3
  42. package/src/findings/self-check.ts +48 -7
  43. package/src/findings/unused-declarations.ts +18 -4
  44. package/src/findings-pass.ts +26 -11
  45. package/src/graph.ts +7 -7
  46. package/src/intra-function-parts.ts +871 -0
  47. package/src/kinds.ts +355 -41
  48. package/src/reflective-lookup.ts +42 -2
  49. package/src/report.ts +18 -2
  50. package/src/reporters/sarif.ts +24 -16
  51. package/src/reporters/template.ts +69 -6
  52. package/src/roots.ts +14 -9
  53. package/src/serialization-contract.ts +47 -30
  54. package/src/signatures.ts +55 -0
  55. package/src/suppress-file.ts +34 -6
  56. package/src/suppress-inline.ts +8 -1
  57. package/src/suppress.ts +31 -0
  58. package/src/value-reach.ts +53 -12
  59. package/src/verbs/analyze.ts +26 -11
  60. package/src/verbs/describe.ts +13 -9
  61. package/src/version.ts +1 -1
  62. package/dist/src/reporters/rules.js +0 -178
  63. package/src/reporters/rules.ts +0 -195
package/src/kinds.ts CHANGED
@@ -8,6 +8,12 @@ export interface KindRow {
8
8
  readonly code: string;
9
9
  /** The kind's name, which a finding carries as its `kind`. */
10
10
  readonly name: string;
11
+ /** The languages whose analyzers report the kind. */
12
+ readonly languages: readonly ("go" | "ts")[];
13
+ /** The kind's rule, whole, which a SARIF rule describes the kind with. */
14
+ readonly rule: string;
15
+ /** The condition the kind reports under, where it declares one. */
16
+ readonly precondition?: string;
11
17
  /** The severity a finding carries where no severity key names its code or its family. */
12
18
  readonly defaultSeverity: Severity;
13
19
  /** The highest confidence a finding of the kind carries. */
@@ -18,6 +24,8 @@ export interface KindRow {
18
24
  * naming the code, or a family prefix whose range holds it, is an unimplemented key.
19
25
  */
20
26
  readonly fixed: boolean;
27
+ /** The external rules that report the same kind in TypeScript, where the row names them. */
28
+ readonly overlap?: readonly string[];
21
29
  }
22
30
 
23
31
  /**
@@ -27,49 +35,355 @@ export interface KindRow {
27
35
  * Contract release the analyzer is written against.
28
36
  */
29
37
  const ROWS: readonly KindRow[] = [
30
- row("DS1001", "unused-exported", "deny", "deletable"),
31
- row("DS1002", "unused-unexported", "deny", "deletable"),
32
- row("DS1003", "unused-member", "deny", "deletable"),
33
- row("DS1004", "test-only-use", "deny", "deletable"),
34
- row("DS1005", "test-of-dead-code", "deny", "deletable"),
35
- row("DS1006", "deprecated-unused", "deny", "deletable"),
36
- row("DS1101", "unnecessary-export", "warn", "narrowable"),
37
- row("DS1102", "unnecessary-exposure", "warn", "narrowable"),
38
- row("DS1103", "unreachable-export", "deny", "deletable"),
39
- row("DS1104", "redundant-export-keyword", "warn", "narrowable"),
40
- row("DS1201", "unused-interface", "deny", "deletable"),
41
- row("DS1203", "uncalled-interface-method", "warn", "manual"),
42
- row("DS1204", "unused-satisfaction-assertion", "deny", "deletable"),
43
- row("DS1301", "write-only-symbol", "deny", "deletable"),
44
- row("DS1302", "unused-enum-member", "deny", "deletable"),
45
- row("DS1303", "unused-type-parameter", "deny", "deletable"),
46
- row("DS1501", "file-never-built", "deny", "deletable"),
47
- row("DS1502", "file-never-imported", "deny", "deletable"),
48
- row("DS1601", "unused-dependency", "deny", "manual"),
49
- row("DS1605", "unused-module-directive", "warn", "deletable"),
50
- row("DS1701", "suppression-without-reason", "deny", "none"),
51
- row("DS1702", "unscoped-ignore-entry", "deny", "none"),
52
- { ...row("DS1703", "stale-suppression", "deny", "none"), fixed: true },
53
- { ...row("DS1704", "unmatched-root", "deny", "none"), fixed: true },
54
- row("DS1705", "stale-cross-language-edge", "deny", "none"),
55
- row("DS1801", "unused-parameter", "warn", "manual"),
56
- row("DS1802", "unused-receiver", "warn", "deletable"),
57
- row("DS1803", "unused-result", "warn", "manual"),
58
- row("DS1805", "unreachable-statement", "deny", "deletable"),
59
- row("DS1807", "dead-store", "deny", "deletable"),
60
- row("DS1809", "unreachable-case", "deny", "deletable"),
38
+ {
39
+ code: "DS1001",
40
+ name: "unused-exported",
41
+ languages: ["go", "ts"],
42
+ rule: "An exported symbol with no reference in the target and no reference from any loaded consumer. A symbol referenced only from its own declaration site counts as unreferenced.",
43
+ defaultSeverity: "deny",
44
+ maxClass: "certain",
45
+ fixability: "deletable",
46
+ fixed: false,
47
+ },
48
+ {
49
+ code: "DS1002",
50
+ name: "unused-unexported",
51
+ languages: ["go", "ts"],
52
+ rule: "An unexported symbol with no reference in the target. A symbol referenced only from its own declaration site counts as unreferenced.",
53
+ defaultSeverity: "deny",
54
+ maxClass: "certain",
55
+ fixability: "deletable",
56
+ fixed: false,
57
+ },
58
+ {
59
+ code: "DS1003",
60
+ name: "unused-member",
61
+ languages: ["go", "ts"],
62
+ rule: "A struct field, class member or type member with no reference, a private member included. A member referenced only from its own declaration site counts as unreferenced.",
63
+ defaultSeverity: "deny",
64
+ maxClass: "certain",
65
+ fixability: "deletable",
66
+ fixed: false,
67
+ },
68
+ {
69
+ code: "DS1004",
70
+ name: "test-only-use",
71
+ languages: ["go", "ts"],
72
+ rule: "A symbol with zero production references and at least one test reference: an unused-exported, unused-unexported or unused-member candidate whose test reference count is not zero, reported once under this code. A reference from a consumer's test files is a test reference unless the configuration counts consumer tests as production.",
73
+ defaultSeverity: "deny",
74
+ maxClass: "certain",
75
+ fixability: "deletable",
76
+ fixed: false,
77
+ },
78
+ {
79
+ code: "DS1005",
80
+ name: "test-of-dead-code",
81
+ languages: ["go", "ts"],
82
+ rule: "A test symbol whose set of referenced target symbols is non-empty and every member of that set is reported dead. A test that references at least one live target symbol is never reported, no notion of a test's subject and no name matching enters the rule, and the message states the rule. The test joins the dead component of the symbols it references, and it and each of them count as referencing each other, so the test is a member of their cycle and never a dead symbol outside it.",
83
+ defaultSeverity: "deny",
84
+ maxClass: "certain",
85
+ fixability: "deletable",
86
+ fixed: false,
87
+ },
88
+ {
89
+ code: "DS1006",
90
+ name: "deprecated-unused",
91
+ languages: ["go", "ts"],
92
+ rule: "A symbol carrying a deprecation marker and no production reference: an unused-exported, unused-unexported or unused-member candidate whose symbol is deprecated, reported once under this code. Go identifies the marker by the convention the standard tools recognize, TypeScript by the documentation tag its tools recognize.",
93
+ defaultSeverity: "deny",
94
+ maxClass: "certain",
95
+ fixability: "deletable",
96
+ fixed: false,
97
+ },
98
+ {
99
+ code: "DS1101",
100
+ name: "unnecessary-export",
101
+ languages: ["go", "ts"],
102
+ 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, and three subjects are excluded: an interface method, whose exportedness is the contract of the interface that declares it; a struct field, which an encoder reads by name; and a method that satisfies an interface some symbol uses as a type, which cannot be unexported without its type ceasing to satisfy that interface. 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.",
103
+ precondition:
104
+ "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.",
105
+ defaultSeverity: "warn",
106
+ maxClass: "certain",
107
+ fixability: "narrowable",
108
+ fixed: false,
109
+ },
110
+ {
111
+ code: "DS1102",
112
+ name: "unnecessary-exposure",
113
+ languages: ["go"],
114
+ 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, and three subjects are excluded: an interface method, whose exportedness is the contract of the interface that declares it; a struct field, which an encoder reads by name; and a method that satisfies an interface some symbol uses as a type, which cannot be unexported without its type ceasing to satisfy that interface. 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.",
115
+ precondition:
116
+ "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.",
117
+ defaultSeverity: "warn",
118
+ maxClass: "certain",
119
+ fixability: "narrowable",
120
+ fixed: false,
121
+ },
122
+ {
123
+ code: "DS1103",
124
+ name: "unreachable-export",
125
+ languages: ["go", "ts"],
126
+ rule: "An unused exported symbol in a package or file no external code can import: an unused-exported candidate whose enclosing package or file is unimportable from outside, reported once under this code at the certain class, because unimportability is a property of the package graph rather than of the consumer set.",
127
+ defaultSeverity: "deny",
128
+ maxClass: "certain",
129
+ fixability: "deletable",
130
+ fixed: false,
131
+ },
132
+ {
133
+ code: "DS1104",
134
+ name: "redundant-export-keyword",
135
+ languages: ["ts"],
136
+ rule: "An exported declaration used only inside its own file, reported as a candidate for removing the export keyword. The finding names the narrower visibility the references support.",
137
+ precondition:
138
+ "Closed world only. Reported in a file that is not an entry file and that either belongs to a project whose consumer set the configuration declares complete or is reached by no manifest export. A declared cross-language edge counts as a reference from outside the file; where the edge's other side is unknown to the analyzer the finding is emitted pending. 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.",
139
+ defaultSeverity: "warn",
140
+ maxClass: "certain",
141
+ fixability: "narrowable",
142
+ fixed: false,
143
+ },
144
+ {
145
+ code: "DS1201",
146
+ name: "unused-interface",
147
+ languages: ["go", "ts"],
148
+ rule: "An interface no symbol uses as a type, counting uses from every loaded module. The finding names the concrete implementations and their positions, and the interface's members join its dead component rather than being reported as independent unused declarations.",
149
+ defaultSeverity: "deny",
150
+ maxClass: "certain",
151
+ fixability: "deletable",
152
+ fixed: false,
153
+ },
154
+ {
155
+ code: "DS1203",
156
+ name: "uncalled-interface-method",
157
+ languages: ["go", "ts"],
158
+ rule: "An interface method that no call site invokes or selects through the interface, whatever the number of implementations. The finding names the concrete implementations and their positions.",
159
+ precondition:
160
+ "Exempt: in Go, every method of an interface that declares an unexported method, the sum-type shape whose method set exists to restrict the implementors, a shape a TypeScript interface cannot take because it declares no member less visible than itself; and, in both languages, every marker method, an interface method whose every implementation carries an empty body.",
161
+ defaultSeverity: "warn",
162
+ maxClass: "certain",
163
+ fixability: "manual",
164
+ fixed: false,
165
+ },
166
+ {
167
+ code: "DS1204",
168
+ name: "unused-satisfaction-assertion",
169
+ languages: ["go"],
170
+ rule: "A compile-time satisfaction assertion whose interface no symbol uses as a type.",
171
+ defaultSeverity: "deny",
172
+ maxClass: "certain",
173
+ fixability: "deletable",
174
+ fixed: false,
175
+ },
176
+ {
177
+ code: "DS1301",
178
+ name: "write-only-symbol",
179
+ languages: ["go", "ts"],
180
+ rule: "A package-level or module-level variable, struct field, class member or collection that production code writes and never reads. In production mode a read from a test file counts as no read. A comparison of struct values reads every field of the type: in Go, a value of a struct type used as an operand of `==` or `!=`, as a map key, or as a `switch` tag or `case` expression is a read of every field of that type, transitively through the fields of every struct type it holds, recorded at the comparison, because equality reads every field and a field that decides equality carries information. In TypeScript a comparison of two object references reads no member, because `===` compares identity and never a member. The finding names each write position, so the deletion set is visible.",
181
+ defaultSeverity: "deny",
182
+ maxClass: "certain",
183
+ fixability: "deletable",
184
+ fixed: false,
185
+ },
186
+ {
187
+ code: "DS1302",
188
+ name: "unused-enum-member",
189
+ languages: ["go", "ts"],
190
+ rule: "An enumerated member that no symbol names, at the reachability class derived for the member and with no confidence ceiling below it. Every member of a type that carries a string, text or binary conversion method, or that a conversion from an integer or a wire value produces, is retained by the enum-group exemption first, so a member reached only by value is never a candidate.",
191
+ defaultSeverity: "deny",
192
+ maxClass: "certain",
193
+ fixability: "deletable",
194
+ fixed: false,
195
+ },
196
+ {
197
+ code: "DS1303",
198
+ name: "unused-type-parameter",
199
+ languages: ["go", "ts"],
200
+ rule: "A type parameter of a function or method that no part of the declaration's signature and no part of the declaration's body names, at the certain class. The deletion is local to the declaration and the explicit instantiations the reference set already lists. A type parameter of a function or method that is itself dead falls with it and is reported under no code of its own.",
201
+ precondition:
202
+ "Function and method type parameters only. A type parameter of a type declaration is never reported, because a phantom type parameter such as `type ID[T any] int` makes two instantiations distinct types while naming the parameter nowhere, so deleting it changes the program. A method signature an interface or an object type declares belongs to that type declaration, so its type parameters are never reported either.",
203
+ defaultSeverity: "deny",
204
+ maxClass: "certain",
205
+ fixability: "deletable",
206
+ fixed: false,
207
+ },
208
+ {
209
+ code: "DS1501",
210
+ name: "file-never-built",
211
+ languages: ["go", "ts"],
212
+ rule: "A source file no configuration in the build matrix builds. On the Go side the finding names the build constraint that excluded the file. A file whose build constraint is the ignore tag is never reported: the toolchain applies no build constraint to a file named on its own command line, so that tag is the toolchain's convention for a file built by hand. A file any other custom tag excludes is reported under a matrix the configuration declares complete, because completeness is the maintainer's assertion that the listed configurations are every one the target builds, and a configuration the maintainer builds by hand belongs in that list.",
213
+ precondition:
214
+ 'Reported only when the configuration declares the build matrix complete, and never for a file the toolchain ignored solely because it imports "C" under a build with cgo disabled; such a file is recorded as excluded by cgo rather than as never built.',
215
+ defaultSeverity: "deny",
216
+ maxClass: "certain",
217
+ fixability: "deletable",
218
+ fixed: false,
219
+ },
220
+ {
221
+ code: "DS1502",
222
+ name: "file-never-imported",
223
+ languages: ["go", "ts"],
224
+ rule: "A source file that no import reaches, that no root names, and in which no declared cross-language edge names a declaration. An import written in a loaded consumer reaches a file of the target as an import written in the target does. An edge's side names a declaration as a root names one, so a file holding a declaration an edge names is evaluated with the edge rather than reported: whether that declaration is dead is the edge evaluation's to say, and the merge resolves it against the paired side.",
225
+ defaultSeverity: "deny",
226
+ maxClass: "certain",
227
+ fixability: "deletable",
228
+ fixed: false,
229
+ },
230
+ {
231
+ code: "DS1601",
232
+ name: "unused-dependency",
233
+ languages: ["go", "ts"],
234
+ rule: "A directly declared dependency that no import in the target needs. On the Go side, a direct require whose module provides no package any target package or test variant imports. On the TypeScript side, a manifest dependency, development dependency or peer dependency the project's import closure does not need. A deletion finding whose fix would remove the last use of a dependency names that dependency.",
235
+ precondition:
236
+ "On the Go side the rule is the semantics of `go mod tidy -diff` exactly: a requirement marked indirect is never reported, because it exists to pin a transitive version and removing it changes the build list. On the TypeScript side the import closure is the files of the run's projects, and three more dependencies are needed: one whose installed manifest declares a command, because a command is run by name rather than imported; one that the installed manifest of a needed dependency declares as a peer and does not mark optional; and, to a fixpoint, the required peers of every dependency so held. An installed manifest is the package's manifest in the nearest node_modules directory at or above the target, and a dependency with none is decided by the import closure alone.",
237
+ defaultSeverity: "deny",
238
+ maxClass: "certain",
239
+ fixability: "manual",
240
+ fixed: false,
241
+ },
242
+ {
243
+ code: "DS1605",
244
+ name: "unused-module-directive",
245
+ languages: ["go"],
246
+ rule: "A replace directive whose target module is absent from the build list, the one case in which the directive is exactly a no-op.",
247
+ precondition:
248
+ "Only a replace whose target is absent from the build list. No other module-file directive is reported: not an exclude directive, because not selected is a counterfactual about a resolution that did not happen; not a workspace use entry and not a tool directive, because each is an external entry point whose invocation lives outside anything the analysis reads.",
249
+ defaultSeverity: "warn",
250
+ maxClass: "certain",
251
+ fixability: "deletable",
252
+ fixed: false,
253
+ },
254
+ {
255
+ code: "DS1701",
256
+ name: "suppression-without-reason",
257
+ languages: ["go", "ts"],
258
+ rule: "A suppression that carries no reason, in any of the three documents: an inline directive, an ignore-file entry or a baseline row. For the ignore file and the baseline, an entry or a row whose reason field is absent, empty or whitespace only is refused and reported rather than matched.",
259
+ defaultSeverity: "deny",
260
+ maxClass: "certain",
261
+ fixability: "none",
262
+ fixed: false,
263
+ },
264
+ {
265
+ code: "DS1702",
266
+ name: "unscoped-ignore-entry",
267
+ languages: ["go", "ts"],
268
+ rule: "An ignore-file entry or a baseline row that names a symbol and no file path. The entry is reported rather than matched, so a bare name cannot mask a match anywhere else in the project; the inline directive is scoped by its position and cannot be unscoped.",
269
+ defaultSeverity: "deny",
270
+ maxClass: "certain",
271
+ fixability: "none",
272
+ fixed: false,
273
+ },
274
+ {
275
+ code: "DS1703",
276
+ name: "stale-suppression",
277
+ languages: ["go", "ts"],
278
+ rule: "A suppression that matches no current finding, at either mechanism and in the baseline alike. The run exits with the findings code when at least one is reported. The kind is fixed on at deny: no flag, no severity setting and no per-mechanism exception reduces it below a finding, and a configuration naming this code under a severity key is an unimplemented key.",
279
+ defaultSeverity: "deny",
280
+ maxClass: "certain",
281
+ fixability: "none",
282
+ fixed: true,
283
+ },
284
+ {
285
+ code: "DS1704",
286
+ name: "unmatched-root",
287
+ languages: ["go", "ts"],
288
+ rule: "A configured root that matches no symbol, or a configured root pattern that matches no symbol. A root set nobody checks silently changes every result, so a stale one is a finding. The kind is fixed on at deny: no flag, no severity setting and no exception reduces it below a finding, and a configuration naming this code under a severity key is an unimplemented key.",
289
+ defaultSeverity: "deny",
290
+ maxClass: "certain",
291
+ fixability: "none",
292
+ fixed: true,
293
+ },
294
+ {
295
+ code: "DS1705",
296
+ name: "stale-cross-language-edge",
297
+ languages: ["go", "ts"],
298
+ rule: "A declared cross-language edge with a side that at least one analyzer evaluated and every evaluation of that side reports absent, so no analyzer that ran enumerates that side's symbol. Emitted by the merge, once per edge, never by an analyzer, so a stale edge is visible rather than silently inert. A dead side paired with an absent side drops its pending finding, and the edge is the reported defect: a misspelled reference must not turn a live pairing into a deletion.",
299
+ defaultSeverity: "deny",
300
+ maxClass: "certain",
301
+ fixability: "none",
302
+ fixed: false,
303
+ },
304
+ {
305
+ code: "DS1706",
306
+ name: "unmatched-configured-declaration",
307
+ languages: ["ts"],
308
+ rule: "An entry of a configuration key that names a declaration, being an entry of ts.injection_registrations, of the components or the bases of an entry of ts.lifecycle_contracts, or of ts.serializers, that names no declaration in any project of the run, by the resolution the ts section of contract/config.schema.json states for its shape. An entry that names a declaration no call reaches matches. An exemption whose configured declarations nobody checks silently retains nothing, so a stale entry is a finding. The kind is fixed on at deny: no flag, no severity setting and no exception reduces it below a finding, and a configuration naming this code under a severity key is an unimplemented key.",
309
+ defaultSeverity: "deny",
310
+ maxClass: "certain",
311
+ fixability: "none",
312
+ fixed: true,
313
+ },
314
+ {
315
+ code: "DS1801",
316
+ name: "unused-parameter",
317
+ languages: ["go", "ts"],
318
+ rule: "A parameter with no reference inside its function body, on a function whose signature is free to change.",
319
+ precondition:
320
+ "The signature must be free, defined as follows: the function is not a method retained by interface satisfaction, is not used as a value, is not a go:linkname or cgo target, and is not a stub whose body is empty or only panics. 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.",
321
+ defaultSeverity: "warn",
322
+ maxClass: "certain",
323
+ fixability: "manual",
324
+ fixed: false,
325
+ overlap: ["tsc --noUnusedParameters", "@typescript-eslint/no-unused-vars"],
326
+ },
327
+ {
328
+ code: "DS1802",
329
+ name: "unused-receiver",
330
+ languages: ["go"],
331
+ rule: "A named method receiver with no reference inside the method body, on a method whose signature is free to change. Go permits a method with no receiver name, so the fix deletes an identifier and changes no signature.",
332
+ precondition: "The same free-signature rule as unused-parameter, applied to the receiver.",
333
+ defaultSeverity: "warn",
334
+ maxClass: "certain",
335
+ fixability: "deletable",
336
+ fixed: false,
337
+ overlap: ["not applicable"],
338
+ },
339
+ {
340
+ code: "DS1803",
341
+ name: "unused-result",
342
+ languages: ["go", "ts"],
343
+ rule: "A result value that no call site of the function uses, on a function whose signature is free to change.",
344
+ precondition:
345
+ "The same free-signature rule as unused-parameter, plus a closed-world condition: every call site of the function must be in the loaded graph, because an unknown caller may consume the result, so the kind reports only for a function whose callers are all visible.",
346
+ defaultSeverity: "warn",
347
+ maxClass: "certain",
348
+ fixability: "manual",
349
+ fixed: false,
350
+ overlap: ["none known"],
351
+ },
352
+ {
353
+ code: "DS1805",
354
+ name: "unreachable-statement",
355
+ languages: ["go", "ts"],
356
+ rule: "A statement that control flow cannot reach, at the precision the language's compiler applies to the same construct.",
357
+ defaultSeverity: "deny",
358
+ maxClass: "certain",
359
+ fixability: "deletable",
360
+ fixed: false,
361
+ overlap: ["tsc allowUnreachableCode", "eslint no-unreachable"],
362
+ },
363
+ {
364
+ code: "DS1807",
365
+ name: "dead-store",
366
+ languages: ["go", "ts"],
367
+ rule: "A write to a local variable with no read before the next write to it or the end of its scope, computed on the same read-and-write classification the write-only-symbol kind uses. The finding names the write position.",
368
+ defaultSeverity: "deny",
369
+ maxClass: "certain",
370
+ fixability: "deletable",
371
+ fixed: false,
372
+ overlap: ["eslint no-useless-assignment"],
373
+ },
374
+ {
375
+ code: "DS1809",
376
+ name: "unreachable-case",
377
+ languages: ["go", "ts"],
378
+ rule: "A switch case whose type or value an earlier case in the same switch already covers.",
379
+ defaultSeverity: "deny",
380
+ maxClass: "certain",
381
+ fixability: "deletable",
382
+ fixed: false,
383
+ overlap: ["none known"],
384
+ },
61
385
  ];
62
386
 
63
- /** A row at the `certain` ceiling whose severity a configuration may set. */
64
- function row(
65
- code: string,
66
- name: string,
67
- defaultSeverity: Severity,
68
- fixability: Fixability,
69
- ): KindRow {
70
- return { code, name, defaultSeverity, maxClass: "certain", fixability, fixed: false };
71
- }
72
-
73
387
  /** Every live row of the issue-kind vocabulary, by its code, in ascending code order. */
74
388
  export const KINDS: ReadonlyMap<string, KindRow> = new Map(ROWS.map((one) => [one.code, one]));
75
389
 
@@ -8,7 +8,9 @@
8
8
  * string reaches every member of that name on any type, static members included,
9
9
  * and every record names the string's own position. A key that is not literal text
10
10
  * holds nothing back: a computed name is the case no exact rule serves. `Reflect` is
11
- * the global one only: a local declaration of that name is a different object.
11
+ * the global one only: a local declaration of that name is a different object. An
12
+ * element access through a receiver whose type declares a string index signature, and is
13
+ * not `any`, reads that signature and holds nothing back.
12
14
  */
13
15
 
14
16
  import {
@@ -21,9 +23,12 @@ import {
21
23
  type Node,
22
24
  type SourceFile,
23
25
  } from "@typescript/native/unstable/ast";
26
+ import { TypeFlags, type Type } from "@typescript/native/unstable/sync";
27
+ import { typesAt } from "./class-members.ts";
24
28
  import type { DetectorInput, Evidence } from "./exempt.ts";
25
29
  import { memberNames } from "./member-names.ts";
26
30
  import { renderPosition } from "./position.ts";
31
+ import type { ProjectView } from "./session.ts";
27
32
 
28
33
  /** The `Reflect` methods whose second argument is a property key. */
29
34
  const REFLECT_KEYED: ReadonlySet<string> = new Set(["get", "set", "has"]);
@@ -35,6 +40,8 @@ interface Lookup {
35
40
  readonly callee: string;
36
41
  /** The `Reflect` the call names, where the lookup is a `Reflect` call. */
37
42
  readonly reflect: Node | undefined;
43
+ /** The expression an element access reads from, where the lookup is one. */
44
+ readonly receiver: Node | undefined;
38
45
  }
39
46
 
40
47
  /** The text one key denotes, where it is literal text. */
@@ -57,6 +64,7 @@ function lookupsOf(file: SourceFile): readonly Lookup[] {
57
64
  name,
58
65
  callee: `[${JSON.stringify(name)}]`,
59
66
  reflect: undefined,
67
+ receiver: node.expression,
60
68
  });
61
69
  }
62
70
  } else if (isCallExpression(node) && isPropertyAccessExpression(node.expression)) {
@@ -72,7 +80,13 @@ function lookupsOf(file: SourceFile): readonly Lookup[] {
72
80
  key !== undefined &&
73
81
  name !== undefined
74
82
  ) {
75
- found.push({ key, name, callee: `Reflect.${method.text}`, reflect: target });
83
+ found.push({
84
+ key,
85
+ name,
86
+ callee: `Reflect.${method.text}`,
87
+ reflect: target,
88
+ receiver: undefined,
89
+ });
76
90
  }
77
91
  }
78
92
  node.forEachChild(visit);
@@ -81,6 +95,16 @@ function lookupsOf(file: SourceFile): readonly Lookup[] {
81
95
  return found;
82
96
  }
83
97
 
98
+ /** Whether a receiver's type is not `any` and declares a string index signature. */
99
+ function readsAMapping<Brand>(project: ProjectView<Brand>, type: Type): boolean {
100
+ if ((type.flags & TypeFlags.Any) !== 0) {
101
+ return false;
102
+ }
103
+ return project.checker
104
+ .getIndexInfosOfType(type)
105
+ .some((info) => (info.keyType.flags & TypeFlags.String) !== 0);
106
+ }
107
+
84
108
  /**
85
109
  * The reflective-lookup detector: every member whose name a literal key of a lookup
86
110
  * spells, recorded at the key.
@@ -112,12 +136,28 @@ export function reflectiveLookup<Brand>(input: DetectorInput<Brand>): readonly E
112
136
  });
113
137
  }
114
138
 
139
+ // An element access through a receiver that maps every string key to one value type
140
+ // reads that mapping rather than a member, asked in one batch.
141
+ const receivers = lookups.flatMap((lookup) =>
142
+ lookup.receiver === undefined ? [] : [lookup.receiver],
143
+ );
144
+ const mapped = new Set<Node>();
145
+ typesAt(project, receivers).forEach((type, index) => {
146
+ const receiver = receivers[index];
147
+ if (receiver !== undefined && type !== undefined && readsAMapping(project, type)) {
148
+ mapped.add(receiver);
149
+ }
150
+ });
151
+
115
152
  const members = memberNames(files, held);
116
153
  const found: Evidence[] = [];
117
154
  for (const lookup of lookups) {
118
155
  if (lookup.reflect !== undefined && !global.has(lookup.reflect)) {
119
156
  continue;
120
157
  }
158
+ if (lookup.receiver !== undefined && mapped.has(lookup.receiver)) {
159
+ continue;
160
+ }
121
161
  const site = renderPosition(lookup.key.getSourceFile(), targetRoot, lookup.key.getStart());
122
162
  for (const member of members.get(lookup.name) ?? []) {
123
163
  found.push({ id: member.id, detail: `looked up by ${lookup.callee}`, site });
package/src/report.ts CHANGED
@@ -18,7 +18,13 @@ import type { StaleSuppression } from "./findings/self-check.ts";
18
18
  import type { TestFileRule } from "./references.ts";
19
19
 
20
20
  /** The version of the report schema this analyzer writes a report to. */
21
- export const SCHEMA_VERSION = "6.0.0";
21
+ const SCHEMA_VERSION = "6.1.0";
22
+
23
+ /**
24
+ * Every report schema version this analyzer reads: the schema versions the Contract it
25
+ * implements admits, each an instance of the one it writes.
26
+ */
27
+ export const SCHEMA_VERSIONS_ACCEPTED: readonly string[] = ["6.0.0", SCHEMA_VERSION];
22
28
 
23
29
  /** The name this analyzer writes every document under and mints every identifier with. */
24
30
  export const ANALYZER_NAME = "deadset-ts";
@@ -49,6 +55,7 @@ export interface WireDetails {
49
55
  readonly path?: string;
50
56
  readonly reason?: string;
51
57
  };
58
+ readonly overlap?: readonly string[];
52
59
  }
53
60
 
54
61
  /** One finding as the finding schema spells it. */
@@ -73,6 +80,11 @@ export interface WireFinding {
73
80
  readonly root: boolean;
74
81
  readonly symbol_count: number;
75
82
  readonly deletable_lines: number;
83
+ readonly members?: readonly {
84
+ readonly ref: string;
85
+ readonly name: string;
86
+ readonly position: WirePosition;
87
+ }[];
76
88
  };
77
89
  readonly retained_by: readonly string[];
78
90
  readonly configurations: readonly string[];
@@ -247,6 +259,7 @@ function wireDetails(details: FindingDetails): WireDetails {
247
259
  ...(entry.reason === undefined ? {} : { reason: entry.reason }),
248
260
  },
249
261
  }),
262
+ ...(details.overlap === undefined ? {} : { overlap: details.overlap }),
250
263
  };
251
264
  }
252
265
 
@@ -275,6 +288,9 @@ export function wireFinding(finding: CompletedFinding): WireFinding {
275
288
  root: finding.component.root,
276
289
  symbol_count: finding.component.symbolCount,
277
290
  deletable_lines: finding.component.deletableLines,
291
+ ...(finding.component.members === undefined
292
+ ? {}
293
+ : { members: finding.component.members.map(wireSymbol) }),
278
294
  },
279
295
  retained_by: finding.retainedBy,
280
296
  configurations: finding.configurations,
@@ -409,7 +425,7 @@ export function buildReport(input: ReportInput): Report {
409
425
  name: ANALYZER_NAME,
410
426
  version: input.version,
411
427
  languages: [LANGUAGE],
412
- schema_versions_accepted: [SCHEMA_VERSION],
428
+ schema_versions_accepted: SCHEMA_VERSIONS_ACCEPTED,
413
429
  conformance: {
414
430
  corpus_version: input.conformance.corpusVersion,
415
431
  result: input.conformance.result,