@cplieger/deadset-ts 7.2.0-dev.4 → 8.0.0-dev.2
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/analysis.js +108 -10
- package/dist/src/augmentations.js +62 -18
- package/dist/src/automatic-types.js +189 -0
- package/dist/src/base-url.js +18 -0
- package/dist/src/components.js +7 -6
- package/dist/src/config.js +1 -0
- package/dist/src/configuration-files.js +50 -12
- package/dist/src/conformance-record.js +2 -2
- package/dist/src/convention-rows.js +98 -0
- package/dist/src/conventions.js +101 -5
- package/dist/src/decorator.js +21 -18
- package/dist/src/dependencies.js +183 -28
- package/dist/src/discover.js +132 -11
- package/dist/src/entry-point-gaps.js +7 -10
- package/dist/src/entry-points.js +112 -11
- package/dist/src/findings/completion.js +172 -40
- package/dist/src/findings/dependencies-and-module-machinery.js +71 -25
- package/dist/src/findings/emitters.js +1 -1
- package/dist/src/findings/intra-function.js +44 -13
- package/dist/src/findings/non-code-artifacts.js +66 -33
- package/dist/src/findings/unused-declarations.js +30 -5
- package/dist/src/findings/visibility-narrowing.js +29 -5
- package/dist/src/generated-file.js +11 -0
- package/dist/src/git-ignore.js +86 -0
- package/dist/src/graph.js +4 -1
- package/dist/src/import-bindings.js +97 -0
- package/dist/src/indexed-access.js +130 -28
- package/dist/src/interface-satisfaction.js +30 -12
- package/dist/src/intra-function-parts.js +297 -45
- package/dist/src/inventory.js +52 -8
- package/dist/src/kinds.js +13 -13
- package/dist/src/matrix.js +57 -10
- package/dist/src/mdx-entries.js +197 -0
- package/dist/src/module-declarations.js +9 -13
- package/dist/src/overrides.js +41 -10
- package/dist/src/print.js +1 -0
- package/dist/src/ref.js +10 -0
- package/dist/src/references.js +38 -4
- package/dist/src/report.js +4 -2
- package/dist/src/resolve.js +2 -0
- package/dist/src/roots.js +110 -38
- package/dist/src/schema.js +1 -0
- package/dist/src/serialization-contract.js +54 -8
- package/dist/src/session.js +7 -0
- package/dist/src/source-files.js +39 -14
- package/dist/src/suppress-file.js +10 -2
- package/dist/src/suppress-inline.js +18 -2
- package/dist/src/suppress.js +8 -5
- package/dist/src/sweep.js +27 -10
- package/dist/src/symbol-keys.js +103 -2
- package/dist/src/test-support.js +119 -18
- package/dist/src/type-errors.js +34 -7
- package/dist/src/type-parameter-reads.js +172 -0
- package/dist/src/verbs/analyze.js +16 -0
- package/dist/src/verbs/explain.js +4 -2
- package/dist/src/version.js +1 -1
- package/dist/src/workflow-steps.js +119 -22
- package/dist/src/workspace-programs.js +7 -3
- package/dist/src/workspace-resolution.js +53 -10
- package/jsr.json +1 -1
- package/package.json +2 -2
- package/src/analysis.ts +146 -11
- package/src/augmentations.ts +76 -22
- package/src/automatic-types.ts +246 -0
- package/src/base-url.ts +24 -0
- package/src/components.ts +7 -6
- package/src/config.ts +3 -0
- package/src/configuration-files.ts +66 -12
- package/src/conformance-record.ts +2 -2
- package/src/convention-rows.ts +128 -0
- package/src/conventions.ts +121 -7
- package/src/decorator.ts +28 -18
- package/src/dependencies.ts +247 -41
- package/src/discover.ts +156 -13
- package/src/entry-point-gaps.ts +8 -11
- package/src/entry-points.ts +133 -11
- package/src/finding.ts +15 -0
- package/src/findings/completion.ts +222 -46
- package/src/findings/dependencies-and-module-machinery.ts +90 -28
- package/src/findings/emitters.ts +1 -1
- package/src/findings/intra-function.ts +56 -14
- package/src/findings/non-code-artifacts.ts +81 -41
- package/src/findings/unused-declarations.ts +36 -5
- package/src/findings/visibility-narrowing.ts +40 -5
- package/src/generated-file.ts +16 -0
- package/src/git-ignore.ts +98 -0
- package/src/graph.ts +6 -0
- package/src/host.ts +5 -9
- package/src/import-bindings.ts +128 -0
- package/src/indexed-access.ts +152 -30
- package/src/interface-satisfaction.ts +33 -13
- package/src/intra-function-parts.ts +394 -59
- package/src/inventory.ts +71 -7
- package/src/kinds.ts +13 -13
- package/src/matrix.ts +104 -15
- package/src/mdx-entries.ts +241 -0
- package/src/module-declarations.ts +11 -13
- package/src/overrides.ts +51 -12
- package/src/print.ts +1 -0
- package/src/ref.ts +12 -0
- package/src/references.ts +48 -3
- package/src/report.ts +16 -3
- package/src/resolve.ts +3 -0
- package/src/roots.ts +163 -45
- package/src/schema.ts +1 -0
- package/src/serialization-contract.ts +55 -4
- package/src/session.ts +7 -0
- package/src/source-files.ts +66 -16
- package/src/suppress-file.ts +12 -1
- package/src/suppress-inline.ts +18 -1
- package/src/suppress.ts +10 -5
- package/src/sweep.ts +32 -11
- package/src/symbol-keys.ts +129 -2
- package/src/test-support.ts +155 -18
- package/src/type-errors.ts +38 -6
- package/src/type-parameter-reads.ts +227 -0
- package/src/verbs/analyze.ts +22 -0
- package/src/verbs/explain.ts +5 -2
- package/src/version.ts +1 -1
- package/src/workflow-steps.ts +127 -22
- package/src/workspace-programs.ts +7 -3
- package/src/workspace-resolution.ts +62 -10
package/dist/src/kinds.js
CHANGED
|
@@ -20,7 +20,7 @@ const ROWS = [
|
|
|
20
20
|
code: "DS1002",
|
|
21
21
|
name: "unused-unexported",
|
|
22
22
|
languages: ["go", "ts"],
|
|
23
|
-
rule: "An unexported symbol with no reference in the target. A symbol referenced only from its own declaration site counts as unreferenced.",
|
|
23
|
+
rule: "An unexported symbol with no reference in the target. A symbol referenced only from its own declaration site counts as unreferenced. In TypeScript a name an import declaration binds, or an `import x = require()` declaration that is not exported, is such a symbol of its file, reported at the binding when nothing in the file reads it: a use in a type position, in a local export or in a type, a link or a `@see` tag of a doc comment reads it, and so does JSX the compiler turns into calls of a factory it names. A binding of a declaration file or of a component file is not judged, nor one of a generated file while generated files are excluded. In Go a constant or a type a function body declares, a function literal's body included, that nothing in that body names outside its own specification is reported under this code, under the reference of the enclosing declaration, as `grammar/symbol-ref.md` states for a declaration inside a function body, at the local declaration's own position, with `symbol.kind` `constant` or `type` and the liveness relation `reference-counting`.",
|
|
24
24
|
defaultSeverity: "deny",
|
|
25
25
|
maxClass: "certain",
|
|
26
26
|
fixability: "deletable",
|
|
@@ -43,7 +43,7 @@ const ROWS = [
|
|
|
43
43
|
code: "DS1004",
|
|
44
44
|
name: "test-only-use",
|
|
45
45
|
languages: ["go", "ts"],
|
|
46
|
-
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. A reference from test-support code, a package or file that only tests reach, is a test reference. A declaration of test-support code
|
|
46
|
+
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. A reference from test-support code, a package or file that only tests reach and that carries test evidence of its own language, is a test reference. A declaration of test-support code is test code and is no subject of this code, as grammar/analysis.md states. An interface method whose only calls and selections through the interface are in test code, and that DS1203's precondition does not exempt, is reported under this code. The methods implementing it are not reported with it, because the test reaches them through it. A candidate found dead under reachability, every production reference to which is made by a declaration itself dead, is reported under this code as well where test code that is no test of dead code, and that the run counting test references reaches, references it, because that test keeps it, and the finding's message names both kinds of reference.",
|
|
47
47
|
defaultSeverity: "deny",
|
|
48
48
|
maxClass: "certain",
|
|
49
49
|
fixability: "deletable",
|
|
@@ -54,7 +54,7 @@ const ROWS = [
|
|
|
54
54
|
code: "DS1005",
|
|
55
55
|
name: "test-of-dead-code",
|
|
56
56
|
languages: ["go", "ts"],
|
|
57
|
-
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.",
|
|
57
|
+
rule: "A test symbol whose set of referenced target symbols is non-empty and every member of that set is reported dead. In TypeScript an ambient declaration, one a declaration file holds or one a `declare` modifier carries or a declaration carrying one holds, describes code the target does not implement, so it is no target symbol of that set. 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.",
|
|
58
58
|
defaultSeverity: "deny",
|
|
59
59
|
maxClass: "certain",
|
|
60
60
|
fixability: "deletable",
|
|
@@ -110,7 +110,7 @@ const ROWS = [
|
|
|
110
110
|
name: "redundant-export-keyword",
|
|
111
111
|
languages: ["ts"],
|
|
112
112
|
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.",
|
|
113
|
-
precondition:
|
|
113
|
+
precondition: 'Closed world only. Reported in a file that is not an entry file, a file only a configuration string or a script token names being none, because each runs the file and reads no name it exports, and a test file being one only for the exports its test runner calls, as grammar/analysis.md "Test code" states, and a file a Markdown or MDX document imports one only for the exports the import reads, as grammar/analysis.md "Markdown and MDX documents" states, 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.',
|
|
114
114
|
defaultSeverity: "warn",
|
|
115
115
|
maxClass: "certain",
|
|
116
116
|
fixability: "narrowable",
|
|
@@ -131,8 +131,8 @@ const ROWS = [
|
|
|
131
131
|
code: "DS1203",
|
|
132
132
|
name: "uncalled-interface-method",
|
|
133
133
|
languages: ["go", "ts"],
|
|
134
|
-
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. Each method that implements it and that nothing else keeps is reported under the code its own references select. Such a method counts as referenced by the interface method alone, so it belongs to this finding's dead component, whose root member is the interface method.",
|
|
135
|
-
precondition: "In Go, every method of an interface
|
|
134
|
+
rule: "An interface method that no call site invokes or selects through the interface, whatever the number of implementations. A call or selection in test code is no call for this rule, and an interface method only test code calls is DS1004's. The finding names the concrete implementations and their positions. Each method that implements it and that nothing else keeps is reported under the code its own references select. Such a method counts as referenced by the interface method alone, so it belongs to this finding's dead component, whose root member is the interface method.",
|
|
135
|
+
precondition: "In Go, every method of an exported interface whose method set holds an unexported method is exempt, a method of an interface it embeds included. An unexported interface restricts no implementor outside its package, so a method only it holds is judged. That is the sum-type shape, whose method set exists to restrict the implementors, and a TypeScript interface cannot take it because it declares no member less visible than itself. In both languages, every marker method is exempt, an interface method whose every implementation carries an empty body.",
|
|
136
136
|
defaultSeverity: "warn",
|
|
137
137
|
maxClass: "certain",
|
|
138
138
|
fixability: "manual",
|
|
@@ -143,7 +143,7 @@ const ROWS = [
|
|
|
143
143
|
name: "unused-satisfaction-assertion",
|
|
144
144
|
languages: ["go"],
|
|
145
145
|
rule: "A compile-time satisfaction assertion whose interface no symbol uses as a type.",
|
|
146
|
-
precondition: "In a library, an assertion whose interface
|
|
146
|
+
precondition: "In a library, an assertion whose interface and whose concrete type are both published API, each an exported declaration of a package outside programs can import, is not reported: it states to every importer a promise of the published API. An assertion whose interface alone is published API has the reachability class possible, whatever consumers the run declares and loads. The assertion checks a promise the published API makes, that the type satisfies the published interface, and that promise is made to every program that imports the package, not only to the consumers the run declares. A loaded consumer that names the interface as a type uses it, and the assertion is not reported.",
|
|
147
147
|
defaultSeverity: "deny",
|
|
148
148
|
maxClass: "certain",
|
|
149
149
|
fixability: "deletable",
|
|
@@ -153,7 +153,7 @@ const ROWS = [
|
|
|
153
153
|
code: "DS1301",
|
|
154
154
|
name: "write-only-symbol",
|
|
155
155
|
languages: ["go", "ts"],
|
|
156
|
-
rule: "A package-level or module-level variable, struct field, class member, type member or collection that production code writes and never reads. In production mode a read from a test file counts as no read. A write from a loaded consumer's code counts as a read, because the deletion the finding names would break a consumer the target does not own. A write in a consumer's test file counts as a read in the run that counts test references. It counts in a production sweep only where the configuration counts consumer tests as production. 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 Go a type argument the program instantiates a type parameter with, where the parameter's constraint is `comparable` or embeds it, is compared as an operand of `==` of that type is, recorded at the instantiation, so the struct values `slices.Equal`, `slices.Index` or `maps.Equal` compares have every field read. `reflect.DeepEqual` is not a comparison under this rule. In Go, a conversion the compiler accepts between two struct types, or between two pointer types that are not named types and whose base types are struct types, reads every field of the two struct types where their struct type literals are distinct, recorded at the conversion, because the conversion is legal only while their fields are identical, ignoring tags, and so no field of either can be deleted alone. It reads in the same way every field of each pair of distinct struct type literals the identity of the two types compares in turn: through each field's type, and from there through the element, key, base, parameter and result types of the type literals it reaches, through the method signatures of an interface type literal, and through the type arguments of an instantiated generic type. A field reached there has no reference of its own, as grammar/symbol-ref.md states, so it is never a subject and those reads hold no finding back. It stops at a defined type, whose fields the conversion does not read, because a defined type is identical to itself whatever fields it declares. A pair whose two sides are one struct type literal, the two struct types themselves included, as where one type is declared from the other or the conversion is to the operand's own type, reads nothing, because a field deleted from that literal leaves both sides identical. Where the operand's type or the conversion's type is a type parameter, the struct type its constraint's core type is takes that side's place, and a type parameter operand reads in the same way the fields of each struct type argument an instantiation the program holds gives it, an instantiation made through another generic declaration's own type parameters included. A conversion to any other type, an interface type among them, reads no field under this rule. In TypeScript a comparison of two object references reads no member, because `===` compares identity and never a member. A TypeScript parameter property, a constructor parameter that carries a modifier, declares a member of its class that the constructor writes with its argument, so the member is judged under this rule, and under every rule that reads a class member, as a member the class body declares is. In TypeScript a property of an object literal writes the member of the same name that the literal's contextual type declares, whether or not the compiler checks the literal for excess properties. Where that contextual type is a union or an intersection, the property writes the member of that name on each constituent that declares one. So a literal that a declaration annotates, a function returns, a call passes or a `satisfies` expression checks writes the members of the type it is given. An object literal handed to a callee the target does not implement has its members read, as grammar/analysis.md states. A store through the value a field or a member holds reads that field or member rather than writing it, because the store lands in storage every other holder of the value reads. In Go that store is an assignment, an increment, a compound assignment or a `delete` whose target is reached through a struct field holding a map, a slice or a pointer. Examples are `s.f[k] = v`, `s.f.x = v` and `delete(s.f, k)`. The same store through a field holding an array or a struct is a store into the field itself. TypeScript holds every object by reference, so an element or property store through a member's value reads the member. The finding names each write position, so the deletion set is visible. Deleting the subject and its writes also deletes every declaration whose only uses they hold. Such a declaration is a type parameter of the subject's declaring type that the subject's type alone names, an import binding the writes alone use, or a declaration whose every use is in the type annotation of the subject or of another subject this rule reports, or in the writes those findings name. The finding's message names each such declaration, and no finding is reported about the declaration itself.",
|
|
156
|
+
rule: "A package-level or module-level variable, struct field, class member, type member or collection that production code writes and never reads. In production mode a read from a test file counts as no read. A write from a loaded consumer's code counts as a read, because the deletion the finding names would break a consumer the target does not own. A write in a consumer's test file counts as a read in the run that counts test references. It counts in a production sweep only where the configuration counts consumer tests as production. In Go a read counts only from a declaration that is live under the finding's liveness relation, which is reference counting: a read from a declaration nothing references, whose own finding has the reachability class `certain`, is no read, so a declaration that only such declarations read is reported where a declaration something references writes it. 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 Go a type argument the program instantiates a type parameter with, where the parameter's constraint is `comparable` or embeds it, is compared as an operand of `==` of that type is, recorded at the instantiation, so the struct values `slices.Equal`, `slices.Index` or `maps.Equal` compares have every field read. `reflect.DeepEqual` is not a comparison under this rule. In Go, a conversion the compiler accepts between two struct types, or between two pointer types that are not named types and whose base types are struct types, reads every field of the two struct types where their struct type literals are distinct, recorded at the conversion, because the conversion is legal only while their fields are identical, ignoring tags, and so no field of either can be deleted alone. It reads in the same way every field of each pair of distinct struct type literals the identity of the two types compares in turn: through each field's type, and from there through the element, key, base, parameter and result types of the type literals it reaches, through the method signatures of an interface type literal, and through the type arguments of an instantiated generic type. A field reached there has no reference of its own, as grammar/symbol-ref.md states, so it is never a subject and those reads hold no finding back. It stops at a defined type, whose fields the conversion does not read, because a defined type is identical to itself whatever fields it declares. A pair whose two sides are one struct type literal, the two struct types themselves included, as where one type is declared from the other or the conversion is to the operand's own type, reads nothing, because a field deleted from that literal leaves both sides identical. Where the operand's type or the conversion's type is a type parameter, the struct type its constraint's core type is takes that side's place, and a type parameter operand reads in the same way the fields of each struct type argument an instantiation the program holds gives it, an instantiation made through another generic declaration's own type parameters included. A conversion to any other type, an interface type among them, reads no field under this rule. In TypeScript a comparison of two object references reads no member, because `===` compares identity and never a member. A TypeScript parameter property, a constructor parameter that carries a modifier, declares a member of its class that the constructor writes with its argument, so the member is judged under this rule, and under every rule that reads a class member, as a member the class body declares is. In TypeScript a property of an object literal writes the member of the same name that the literal's contextual type declares, whether or not the compiler checks the literal for excess properties. Where that contextual type is a union or an intersection, the property writes the member of that name on each constituent that declares one. So a literal that a declaration annotates, a function returns, a call passes or a `satisfies` expression checks writes the members of the type it is given. An object literal handed to a callee the target does not implement has its members read, as grammar/analysis.md states. A store through the value a field or a member holds reads that field or member rather than writing it, because the store lands in storage every other holder of the value reads. In Go that store is an assignment, an increment, a compound assignment or a `delete` whose target is reached through a struct field holding a map, a slice or a pointer. Examples are `s.f[k] = v`, `s.f.x = v` and `delete(s.f, k)`. The same store through a field holding an array or a struct is a store into the field itself. TypeScript holds every object by reference, so an element or property store through a member's value reads the member. The finding names each write position, so the deletion set is visible. Deleting the subject and its writes also deletes every declaration whose only uses they hold. Such a declaration is a type parameter of the subject's declaring type that the subject's type alone names, an import binding the writes alone use, or a declaration whose every use is in the type annotation of the subject or of another subject this rule reports, or in the writes those findings name. The finding's message names each such declaration, and no finding is reported about the declaration itself.",
|
|
157
157
|
defaultSeverity: "deny",
|
|
158
158
|
maxClass: "certain",
|
|
159
159
|
fixability: "deletable",
|
|
@@ -196,7 +196,7 @@ const ROWS = [
|
|
|
196
196
|
code: "DS1502",
|
|
197
197
|
name: "file-never-imported",
|
|
198
198
|
languages: ["go", "ts"],
|
|
199
|
-
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.",
|
|
199
|
+
rule: "A source file that no import from live code reaches, that no root names, and in which no declared cross-language edge names a declaration: an import counts where it is written in a file a root, a live declaration or such an import keeps, or in a live declaration, so a file only dead code imports is reported, under reachability. 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.",
|
|
200
200
|
defaultSeverity: "deny",
|
|
201
201
|
maxClass: "certain",
|
|
202
202
|
fixability: "deletable",
|
|
@@ -206,8 +206,8 @@ const ROWS = [
|
|
|
206
206
|
code: "DS1601",
|
|
207
207
|
name: "unused-dependency",
|
|
208
208
|
languages: ["go", "ts"],
|
|
209
|
-
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.",
|
|
210
|
-
precondition: "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 a call of `import.meta.resolve` or of `require.resolve` in them, whatever `require` names, whose first argument is a string literal or a template literal with no substitution needs each dependency an import of that specifier needs. Four more dependencies are needed: one whose command a script entry
|
|
209
|
+
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. On the TypeScript side, a needed dependency whose every use is written inside declarations that are members of the run's dead components, or at the top level of a file reported under DS1502, that no command runs and that no needed dependency used otherwise names as a peer, is reported as well, dead only through that code: at the reachability class possible where one of those declarations belongs to a library's published API, and found under reachability alone where one of those declarations or files is, so at probable unless ts.roots_complete is true. A use the configuration makes, a use an unanswered specifier may make and an import none of whose bindings is used are uses by live code.",
|
|
210
|
+
precondition: "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 a call of `import.meta.resolve` or of `require.resolve` in them, whatever `require` names, whose first argument is a string literal or a template literal with no substitution needs each dependency an import of that specifier needs. A `@types/<name>` package in a type root of a compiler configuration that lists no `types`, a `node_modules/@types` directory at or above the configuration's directory or a `typeRoots` entry naming one, is needed by a use, in a file of that configuration, of a global name or an ambient module that one of the package's declaration files declares, which resolves to no declaration of the program: a compiler before version 6 includes every package of the type roots where `types` is not listed, and version 6 and later include none, so the program the analysis builds holds none of those declarations. A package's declaration files are the file its `types` or `typings` names, else its `index.d.ts`, and each file a `/// <reference path>` of one of them reaches inside the package. A global is a top-level declaration of such a file that is no module, or a declaration of a `declare global` block of one that is, and an ambient module is a `declare module` with a string name of a file that is no module. A name that names a member, a property or a label is no use of a global. Four more dependencies are needed: one whose command a script entry, a workflow step or a git hook runs, one that a string of a configuration file names, and one that a string names under a manifest key or a package key of an applied convention row, each as grammar/analysis.md states, and one that a needed dependency names as a peer, as stated below. A command no script entry, workflow step or git hook runs needs nothing. A declared dependency that the installed manifest of a needed declared dependency names in its peerDependencies is needed, and so on until no further dependency joins. A peer dependency is a package the needed dependency expects beside it at a version its manifest states, whether or not it imports the package, and the project's declaration is what keeps that package present at a version the project chooses, so removing the declaration can break the needed dependency where nothing the analysis reads imports the peer. A peer that peerDependenciesMeta marks optional is needed in the same way, because the needed dependency's manifest still names it as a package it works with, and a package manager may leave an optional peer out where the project does not declare it, so the project's declaration is what keeps it present for the needed dependency. A declared dependency that only dependencies nothing needs name as a peer is needed by nothing. A dependency of a manifest whose directory holds source only in configurations the run lists in configurations_not_built is reported at the reachability class possible, because the source that may import it was not analyzed. An installed manifest is the package's manifest in the nearest node_modules directory at or above the directory of the manifest that declares the dependency, and a dependency with none is decided by the import closure alone. On the TypeScript side, the dependencies judged are those of every manifest grammar/analysis.md says the analysis reads, a nested package's among them, each read against its own directory: a dependency is needed by a use written in a file at or below the directory of the manifest that declares it where no manifest between them declares a dependency of the same name, so a use below a nested manifest that declares the same dependency needs that nested manifest's declaration only, by a use no one file holds, and as a peer of a needed dependency of the same manifest or of a manifest below it. A dependency a nested package's manifest declares whose installed manifest the analysis cannot find is not judged, because no run requires a nested package to be installed and its commands and peers cannot be read, while a workspace member's and the target's own are judged as above.",
|
|
211
211
|
defaultSeverity: "deny",
|
|
212
212
|
maxClass: "certain",
|
|
213
213
|
fixability: "manual",
|
|
@@ -289,7 +289,7 @@ const ROWS = [
|
|
|
289
289
|
name: "unused-parameter",
|
|
290
290
|
languages: ["go", "ts"],
|
|
291
291
|
rule: "A parameter with no reference inside its function body, on a function whose signature is free to change.",
|
|
292
|
-
precondition: "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 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. 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 when its body reads no parameter after it, and an unread parameter before the last read one is
|
|
292
|
+
precondition: "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. Such a parameter is not reported when it is an object binding pattern, because the pattern reads each property it names from the argument and the code that hands the argument may act on that read. No name such a pattern binds is reported either. 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.",
|
|
293
293
|
defaultSeverity: "warn",
|
|
294
294
|
maxClass: "certain",
|
|
295
295
|
fixability: "manual",
|
|
@@ -336,7 +336,7 @@ const ROWS = [
|
|
|
336
336
|
name: "dead-store",
|
|
337
337
|
languages: ["go", "ts"],
|
|
338
338
|
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.",
|
|
339
|
-
precondition: "In TypeScript the binding of a catch clause is a local variable the clause writes when it catches, so a binding that is a name and that the clause's block never reads is a dead store, positioned at the binding: the clause written with no binding behaves the same.",
|
|
339
|
+
precondition: "In TypeScript the binding of a catch clause is a local variable the clause writes when it catches, so a binding that is a name and that the clause's block never reads is a dead store, positioned at the binding: the clause written with no binding behaves the same. A TypeScript local is a name a `let` or `const` declaration of a block binds, or a `var` declaration of a block of a function, a name an object or array binding pattern of one binds at any depth included, except a name with a default, whose removal skips the default's evaluation, and a name beside a rest element of its object pattern, whose removal changes what the rest holds. A `var` of a block nested in its function's body is judged in that block, its last write kept because the function scope reads on past the block's end, and is no subject where a nested function of its function names it. A local a nested function reads is no subject, because the function may read it at any time, and every write to a local nothing reads is dead, one a nested function makes included, each positioned at the name it writes. The variable a `let` or `const` declaration of a `for…of` or `for…in` statement binds is written at each iteration, so one the loop body never reads is a dead store positioned at the binding, except a name that starts with an underscore, because a loop must bind a name and that spelling declares it unread. In Go a function literal a package-level variable's initializer holds is a function body of its own, and a finding about one of its stores carries the reference of the variable the literal initializes, which for a blank variable is its package's, as `grammar/symbol-ref.md` states for a blank-identifier declaration. In Go a range statement stores its key and its value at the start of every iteration, and an empty range stores neither. In Go a function literal reads each variable it names where it is written, and a store that a literal naming its variable may precede on some path of the control-flow graph, the literal of an earlier iteration of a loop included, is not dead, because a call of the literal the graph does not order may read it. A store no such literal precedes is judged as any other. A literal that is the callee of the call it is written in, outside a `go` or `defer` statement, runs there, so it reads its variables at that call and precedes no later store.",
|
|
340
340
|
defaultSeverity: "deny",
|
|
341
341
|
maxClass: "certain",
|
|
342
342
|
fixability: "deletable",
|
package/dist/src/matrix.js
CHANGED
|
@@ -70,11 +70,13 @@ export function matrixOf(per) {
|
|
|
70
70
|
}
|
|
71
71
|
});
|
|
72
72
|
symbols.sort((a, b) => byPosition(a.position, b.position));
|
|
73
|
+
const testUsed = new Set(per.flatMap((one) => one.testUsedFiles ?? []));
|
|
73
74
|
return {
|
|
74
75
|
configurations: per.map((one) => one.configuration),
|
|
75
|
-
graphs: per.map((one) => graphOf(one.symbols, one.references, one.roots, one.testFiles, one.supportFiles)),
|
|
76
|
-
union: graphOf(symbols, references, per.flatMap((one) => one.roots), [...new Set(per.flatMap((one) => one.testFiles))], [...new Set(per.flatMap((one) => one.supportFiles ?? []))]),
|
|
76
|
+
graphs: per.map((one) => graphOf(one.symbols, one.references, one.roots, one.testFiles, one.supportFiles, one.ambient)),
|
|
77
|
+
union: graphOf(symbols, references, per.flatMap((one) => one.roots), [...new Set(per.flatMap((one) => one.testFiles))], [...new Set(per.flatMap((one) => one.supportFiles ?? []))], new Set(per.flatMap((one) => [...(one.ambient ?? [])]))),
|
|
77
78
|
heldIn: symbols.map((symbol) => holders.get(symbol.id) ?? []),
|
|
79
|
+
testUsed: symbols.map((symbol) => testUsed.has(symbol.position.path)),
|
|
78
80
|
dependents,
|
|
79
81
|
};
|
|
80
82
|
}
|
|
@@ -100,10 +102,7 @@ export function sweepMatrix(matrix, input) {
|
|
|
100
102
|
new Map((per[index]?.candidates ?? []).map((candidate) => [candidate.id, candidate])),
|
|
101
103
|
]));
|
|
102
104
|
const union = matrix.union;
|
|
103
|
-
const dead = union.symbols.map(() => false);
|
|
104
|
-
const testOfDeadCode = union.symbols.map(() => false);
|
|
105
105
|
const heldBy = union.symbols.map(() => undefined);
|
|
106
|
-
const unreferencedTest = union.symbols.map(() => false);
|
|
107
106
|
const testReached = reachedWithTheTests(union, [
|
|
108
107
|
...input.marked,
|
|
109
108
|
...(input.exempt ?? []).map((record) => record.id),
|
|
@@ -121,8 +120,12 @@ export function sweepMatrix(matrix, input) {
|
|
|
121
120
|
// every configuration that holds it.
|
|
122
121
|
const subjectsDead = (at) => (union.out[at] ?? []).every((edge) => union.test[edge.to] === true ||
|
|
123
122
|
union.support[edge.to] === true ||
|
|
123
|
+
union.ambient[edge.to] === true ||
|
|
124
124
|
union.subject[edge.to] !== true ||
|
|
125
125
|
judged[edge.to] !== undefined);
|
|
126
|
+
const admittedAt = (at) => judged[at]?.every((candidate) => candidate.testOfDeadCode) === true && subjectsDead(at);
|
|
127
|
+
const kept = keptByTests(union, testReached, admittedAt);
|
|
128
|
+
const testUsed = testUsedReach(union, union.symbols.map((_symbol, at) => matrix.testUsed[at] === true && testReached[at] === true), judged.map((one) => one !== undefined));
|
|
126
129
|
const candidates = [];
|
|
127
130
|
union.symbols.forEach((symbol, at) => {
|
|
128
131
|
const all = judged[at];
|
|
@@ -130,15 +133,12 @@ export function sweepMatrix(matrix, input) {
|
|
|
130
133
|
return;
|
|
131
134
|
}
|
|
132
135
|
const held = matrix.heldIn[at] ?? [];
|
|
133
|
-
const admitted =
|
|
136
|
+
const admitted = admittedAt(at);
|
|
134
137
|
const testRefs = union.made[at]?.test ?? 0;
|
|
135
138
|
const heldByTests = heldBy[union.parent[at] ?? OUTSIDE] ??
|
|
136
139
|
(union.support[at] === true && testRefs > 0 && !admitted ? symbol.id : undefined);
|
|
137
140
|
const unreferenced = union.test[at] === true && !admitted && testReached[at] !== true;
|
|
138
|
-
dead[at] = true;
|
|
139
|
-
testOfDeadCode[at] = admitted;
|
|
140
141
|
heldBy[at] = heldByTests;
|
|
141
|
-
unreferencedTest[at] = unreferenced;
|
|
142
142
|
const productionRefs = union.made[at]?.production ?? 0;
|
|
143
143
|
const counted = all.every((candidate) => candidate.relation === "reference-counting");
|
|
144
144
|
candidates.push({
|
|
@@ -153,15 +153,62 @@ export function sweepMatrix(matrix, input) {
|
|
|
153
153
|
configurations: held,
|
|
154
154
|
heldByTests,
|
|
155
155
|
unreferencedTest: unreferenced,
|
|
156
|
+
testUsed: testUsed[at] === true,
|
|
157
|
+
keptByTests: kept[at] === true,
|
|
156
158
|
});
|
|
157
159
|
});
|
|
158
160
|
const liveUnder = liveAnywhere(union.symbols, per);
|
|
159
161
|
return {
|
|
160
162
|
liveUnder,
|
|
161
163
|
candidates,
|
|
162
|
-
components:
|
|
164
|
+
components: deadComponents(matrix, { liveUnder, candidates }, new Set()),
|
|
163
165
|
};
|
|
164
166
|
}
|
|
167
|
+
/** Per declaration of the union, whether one of `seeds` is it or reaches it through `dead` declarations. */
|
|
168
|
+
function testUsedReach(union, seeds, dead) {
|
|
169
|
+
// A file is no candidate, and its top level is what reaches what it alone calls.
|
|
170
|
+
const reached = seeds.map((seed, at) => seed && dead[at] === true);
|
|
171
|
+
const queue = seeds.flatMap((one, at) => (one ? [at] : []));
|
|
172
|
+
for (let at = queue.pop(); at !== undefined; at = queue.pop()) {
|
|
173
|
+
for (const edge of union.out[at] ?? []) {
|
|
174
|
+
if (dead[edge.to] === true && reached[edge.to] !== true) {
|
|
175
|
+
reached[edge.to] = true;
|
|
176
|
+
queue.push(edge.to);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return reached;
|
|
181
|
+
}
|
|
182
|
+
/** Per declaration of the union, whether test code `reached` holds and `admitted` rejects references it. */
|
|
183
|
+
function keptByTests(union, reached, admitted) {
|
|
184
|
+
const kept = union.symbols.map(() => false);
|
|
185
|
+
union.out.forEach((edges, from) => {
|
|
186
|
+
const testCode = union.test[from] === true || union.support[from] === true;
|
|
187
|
+
if (!testCode || reached[from] !== true || admitted(from)) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
for (const edge of edges) {
|
|
191
|
+
if (edge.test) {
|
|
192
|
+
kept[edge.to] = true;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
return kept;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* The dead components of one sweep over the union, with the file declarations at `files`
|
|
200
|
+
* dead as well: a file that is deleted whole takes the declarations it holds and every
|
|
201
|
+
* dead declaration only its top level references with it.
|
|
202
|
+
*/
|
|
203
|
+
export function deadComponents(matrix, result, files) {
|
|
204
|
+
const union = matrix.union;
|
|
205
|
+
const byId = new Map(result.candidates.map((candidate) => [candidate.id, candidate]));
|
|
206
|
+
const candidateAt = (at) => byId.get(union.symbols[at]?.id ?? "");
|
|
207
|
+
return componentsOf(union, union.symbols.map((_symbol, at) => {
|
|
208
|
+
const candidate = candidateAt(at);
|
|
209
|
+
return files.has(at) || (candidate !== undefined && candidate.heldByTests === undefined);
|
|
210
|
+
}), union.symbols.map((_symbol, at) => candidateAt(at)?.testOfDeadCode === true), union.symbols.map((_symbol, at) => candidateAt(at)?.unreferencedTest === true), positionsOf(union, matrix.dependents, result.liveUnder));
|
|
211
|
+
}
|
|
165
212
|
/**
|
|
166
213
|
* The file declarations at `paths`, below the target root, that one sweep holds live
|
|
167
214
|
* under both relations, the rule a judged declaration is live by.
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The files the import declarations of the target's Markdown and MDX documents load. A
|
|
3
|
+
* document is read as text: a line outside a fenced code block that starts with `import`
|
|
4
|
+
* is an import declaration, which an MDX compiler hoists into the module it builds.
|
|
5
|
+
*/
|
|
6
|
+
import { resolveRelativeSpecifier } from "./configuration-files.js";
|
|
7
|
+
import { dirnamePath, joinPath, resolvePath } from "./paths.js";
|
|
8
|
+
/** The directories no document is read below. */
|
|
9
|
+
const SKIPPED = new Set(["node_modules", ".git"]);
|
|
10
|
+
/** The extensions of a document whose imports an MDX compiler reads. */
|
|
11
|
+
const DOCUMENT = /\.mdx?$/u;
|
|
12
|
+
/** A fence line, its marker run and what follows it captured. */
|
|
13
|
+
const FENCE = /^ {0,3}(`{3,}|~{3,})(.*)$/u;
|
|
14
|
+
/** A string literal in either quote, its escapes included. */
|
|
15
|
+
const STRING = String.raw `"(?:[^"\\\n]|\\.)*"|'(?:[^'\\\n]|\\.)*'`;
|
|
16
|
+
/** An import declaration at the start of a line, its clause and its specifier captured. */
|
|
17
|
+
const IMPORT_LINE = new RegExp(String.raw `^import\s+(?:((?:[^"'\n]|${STRING})*?)\s+from\s*)?["']([^"'\n]+)["']`, "u");
|
|
18
|
+
/** The braces of an import clause, what they hold captured. */
|
|
19
|
+
const BRACES = new RegExp(String.raw `\{((?:[^}"']|${STRING})*)\}`, "u");
|
|
20
|
+
/** One comma-separated part of a clause's braces. */
|
|
21
|
+
const PART = new RegExp(String.raw `(?:[^,"']|${STRING})+`, "gu");
|
|
22
|
+
/** A named import of a clause's braces: the exported name and an optional local alias. */
|
|
23
|
+
const NAMED_IMPORT = new RegExp(String.raw `^([\w$]+|${STRING})(?:\s+as\s+[\w$]+)?$`, "u");
|
|
24
|
+
/** The single-character escapes of a string literal and the character each stands for. */
|
|
25
|
+
const SINGLE_ESCAPES = new Map([
|
|
26
|
+
["b", "\b"],
|
|
27
|
+
["f", "\f"],
|
|
28
|
+
["n", "\n"],
|
|
29
|
+
["r", "\r"],
|
|
30
|
+
["t", "\t"],
|
|
31
|
+
["v", "\v"],
|
|
32
|
+
["0", "\0"],
|
|
33
|
+
["'", "'"],
|
|
34
|
+
['"', '"'],
|
|
35
|
+
["\\", "\\"],
|
|
36
|
+
]);
|
|
37
|
+
/**
|
|
38
|
+
* One escape of a string literal: two hexadecimal digits, a code unit, a code point, or one
|
|
39
|
+
* character and the digit after it.
|
|
40
|
+
*/
|
|
41
|
+
const ESCAPE = /\\(?:x([\da-fA-F]{2})|u([\da-fA-F]{4})|u\{([\da-fA-F]+)\}|(.)(\d?))/gu;
|
|
42
|
+
/** What one escape stands for, or undefined for one a module cannot hold. */
|
|
43
|
+
function unescaped([, hex, unit, point, single, digit]) {
|
|
44
|
+
if (single === undefined) {
|
|
45
|
+
const code = Number.parseInt(hex ?? unit ?? point ?? "", 16);
|
|
46
|
+
return code <= 0x10ffff ? String.fromCodePoint(code) : undefined;
|
|
47
|
+
}
|
|
48
|
+
return /[1-9xu]/u.test(single) || (single === "0" && digit !== "")
|
|
49
|
+
? undefined
|
|
50
|
+
: `${SINGLE_ESCAPES.get(single) ?? single}${digit ?? ""}`;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The value of a quoted export name, its escapes decoded, or undefined for an escape this
|
|
54
|
+
* reading does not decode. A module is strict code, so no legacy octal escape is valid.
|
|
55
|
+
*/
|
|
56
|
+
function quotedName(literal) {
|
|
57
|
+
const body = literal.slice(1, -1);
|
|
58
|
+
let value = "";
|
|
59
|
+
let from = 0;
|
|
60
|
+
for (const escape of body.matchAll(ESCAPE)) {
|
|
61
|
+
const decoded = unescaped(escape);
|
|
62
|
+
if (decoded === undefined) {
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
value += body.slice(from, escape.index) + decoded;
|
|
66
|
+
from = escape.index + escape[0].length;
|
|
67
|
+
}
|
|
68
|
+
return value + body.slice(from);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The export names one import clause reads: `default` for a default binding and each name
|
|
72
|
+
* its braces list, or undefined for a namespace import, which reads every export, and for
|
|
73
|
+
* a clause this reading does not parse, which may read any.
|
|
74
|
+
*/
|
|
75
|
+
function clauseNames(clause) {
|
|
76
|
+
const braces = BRACES.exec(clause);
|
|
77
|
+
const head = (braces === null ? clause : clause.slice(0, braces.index))
|
|
78
|
+
.replace(/,\s*$/u, "")
|
|
79
|
+
.trim();
|
|
80
|
+
if (head.includes("*")) {
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
const names = head === "" ? [] : ["default"];
|
|
84
|
+
if (head !== "" && !/^[\w$]+$/u.test(head)) {
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
for (const part of (braces?.[1]?.match(PART) ?? []).map((one) => one.trim())) {
|
|
88
|
+
const named = NAMED_IMPORT.exec(part);
|
|
89
|
+
if (part === "") {
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
if (named?.[1] === undefined) {
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
const name = /^["']/u.test(named[1]) ? quotedName(named[1]) : named[1];
|
|
96
|
+
if (name === undefined) {
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
99
|
+
names.push(name);
|
|
100
|
+
}
|
|
101
|
+
return names;
|
|
102
|
+
}
|
|
103
|
+
/** Every document below `dir`, outside every skipped directory, by absolute path. */
|
|
104
|
+
function documents(host, dir) {
|
|
105
|
+
let entries;
|
|
106
|
+
try {
|
|
107
|
+
entries = host.readDirectory(dir);
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
return [];
|
|
111
|
+
}
|
|
112
|
+
const found = [];
|
|
113
|
+
for (const entry of entries) {
|
|
114
|
+
const path = joinPath(dir, entry.name);
|
|
115
|
+
if (entry.directory) {
|
|
116
|
+
if (!SKIPPED.has(entry.name)) {
|
|
117
|
+
found.push(...documents(host, path));
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
else if (DOCUMENT.test(entry.name)) {
|
|
121
|
+
found.push(path);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return found.sort();
|
|
125
|
+
}
|
|
126
|
+
/** The relative specifiers one document's import lines name, its fenced code blocks skipped. */
|
|
127
|
+
function importedBy(text) {
|
|
128
|
+
const found = [];
|
|
129
|
+
let open;
|
|
130
|
+
for (const line of text.split(/\r?\n/u)) {
|
|
131
|
+
const fence = FENCE.exec(line);
|
|
132
|
+
const marker = fence?.[1];
|
|
133
|
+
if (marker !== undefined && open === undefined) {
|
|
134
|
+
open = marker;
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
// https://spec.commonmark.org/0.31.2/#fenced-code-blocks: only a run of the opening
|
|
138
|
+
// character, at least as long and followed by nothing, closes a fence.
|
|
139
|
+
if (marker !== undefined &&
|
|
140
|
+
open !== undefined &&
|
|
141
|
+
marker.startsWith(open.slice(0, 1)) &&
|
|
142
|
+
marker.length >= open.length &&
|
|
143
|
+
fence?.[2]?.trim() === "") {
|
|
144
|
+
open = undefined;
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
const matched = open === undefined ? IMPORT_LINE.exec(line) : null;
|
|
148
|
+
const specifier = matched?.[2];
|
|
149
|
+
if (specifier?.startsWith("./") === true || specifier?.startsWith("../") === true) {
|
|
150
|
+
found.push({ specifier, names: clauseNames(matched?.[1] ?? "") });
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return found;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* The documents each host's target roots hold, which every project of a run reads alike,
|
|
157
|
+
* kept for the host's life as {@link Host} allows.
|
|
158
|
+
*/
|
|
159
|
+
const documentsOf = new WeakMap();
|
|
160
|
+
/** Every readable document below `root` and the import lines it writes, read once per host. */
|
|
161
|
+
function documentImports(host, root) {
|
|
162
|
+
const byRoot = documentsOf.get(host) ?? new Map();
|
|
163
|
+
documentsOf.set(host, byRoot);
|
|
164
|
+
const known = byRoot.get(root);
|
|
165
|
+
if (known !== undefined) {
|
|
166
|
+
return known;
|
|
167
|
+
}
|
|
168
|
+
const found = documents(host, root).flatMap((path) => {
|
|
169
|
+
try {
|
|
170
|
+
return [{ path, imports: importedBy(host.readFile(path)) }];
|
|
171
|
+
}
|
|
172
|
+
catch {
|
|
173
|
+
return [];
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
byRoot.set(root, found);
|
|
177
|
+
return found;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Every own file one document below the target root imports by a relative specifier,
|
|
181
|
+
* read against the document's directory, on disk or through the emit mapping.
|
|
182
|
+
*/
|
|
183
|
+
export function documentEntries(host, targetRoot, files) {
|
|
184
|
+
const root = resolvePath(host.workingDirectory(), targetRoot);
|
|
185
|
+
const found = [];
|
|
186
|
+
for (const { path, imports } of documentImports(host, root)) {
|
|
187
|
+
const dir = dirnamePath(path);
|
|
188
|
+
for (const { specifier, names } of imports) {
|
|
189
|
+
const reached = resolveRelativeSpecifier(host, dir, specifier);
|
|
190
|
+
const held = reached === undefined ? undefined : files.byName.get(reached);
|
|
191
|
+
for (const file of held === undefined ? files.named(resolvePath(dir, specifier)) : [held]) {
|
|
192
|
+
found.push({ file, source: specifier, names });
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return found;
|
|
197
|
+
}
|
|
@@ -103,7 +103,7 @@ function namedBy(held) {
|
|
|
103
103
|
`${scope}#${aliasFragment(one, name)}`,
|
|
104
104
|
]));
|
|
105
105
|
const members = (children.get(id) ?? []).filter((child) => wanted.has(child.ref));
|
|
106
|
-
return [{ id, members: members.map((child) => child.id) }];
|
|
106
|
+
return [{ id, members: members.map((child) => child.id), wildcard: name.includes("*") }];
|
|
107
107
|
});
|
|
108
108
|
}
|
|
109
109
|
/**
|
|
@@ -149,26 +149,22 @@ export function moduleDeclarationReferences(project, held, root, testFiles) {
|
|
|
149
149
|
imports.forEach((one, index) => {
|
|
150
150
|
const resolved = moduleOf(declared.length + index);
|
|
151
151
|
const position = renderPosition(one.file, root, one.specifier.getStart());
|
|
152
|
-
const read = (to, resolution) => {
|
|
153
|
-
found.push({
|
|
154
|
-
from: one.from,
|
|
155
|
-
to,
|
|
156
|
-
position,
|
|
157
|
-
use: "read",
|
|
158
|
-
resolution,
|
|
159
|
-
test: testFiles.has(position.path),
|
|
160
|
-
});
|
|
152
|
+
const read = (to, resolution, test) => {
|
|
153
|
+
found.push({ from: one.from, to, position, use: "read", resolution, test });
|
|
161
154
|
};
|
|
155
|
+
const test = testFiles.has(position.path);
|
|
162
156
|
const same = new Set(declared
|
|
163
157
|
.filter((_, at) => resolved !== undefined && resolved === moduleOf(at))
|
|
164
158
|
.map((declaration) => declaration.id));
|
|
165
159
|
for (const id of same) {
|
|
166
|
-
read(id, "batch");
|
|
160
|
+
read(id, "batch", test);
|
|
167
161
|
}
|
|
168
162
|
for (const declaration of named(one.specifier.text, one.names)) {
|
|
169
|
-
|
|
163
|
+
// A wildcard declaration is how the compiler types the file a matching specifier
|
|
164
|
+
// names, so the import uses it whoever writes it, a test included.
|
|
165
|
+
if (declaration.wildcard || !same.has(declaration.id)) {
|
|
170
166
|
for (const to of [declaration.id, ...declaration.members]) {
|
|
171
|
-
read(to, "syntax");
|
|
167
|
+
read(to, "syntax", test && !declaration.wildcard);
|
|
172
168
|
}
|
|
173
169
|
}
|
|
174
170
|
}
|
package/dist/src/overrides.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The overrides of the target's class members. A call through the base class
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* through that class, so its own class references it.
|
|
2
|
+
* The overrides of the target's class members. A call through the base class runs the
|
|
3
|
+
* override of whichever subclass the value is, so the base member references every
|
|
4
|
+
* override. A member, static or not, overriding one of a class declared outside the target
|
|
5
|
+
* at any depth of its `extends` chain, a library's interface-and-variable class such as
|
|
6
|
+
* `Error` included, is used by outside code holding the value, so its own class references it.
|
|
8
7
|
*/
|
|
9
8
|
import { isClassDeclaration, isClassExpression, isExpressionWithTypeArguments, isPropertyAccessExpression, isQualifiedName, SyntaxKind, } from "@typescript/native/ast";
|
|
10
9
|
import { memberComponent } from "./class-members.js";
|
|
@@ -85,10 +84,12 @@ export function overrideReferences(project, held, chains, testFiles) {
|
|
|
85
84
|
const declared = (symbol.flags & SymbolFlags.Alias) === 0 ? symbol : project.queries.aliased(symbol);
|
|
86
85
|
if (inTarget.length === 0 &&
|
|
87
86
|
declared !== UNANSWERED &&
|
|
88
|
-
(declared.flags & SymbolFlags.Class) !== 0 &&
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
87
|
+
(((declared.flags & SymbolFlags.Class) !== 0 &&
|
|
88
|
+
// The target's augmentation of an outside class merges an interface into it,
|
|
89
|
+
// so only a class declaration says where the class is.
|
|
90
|
+
declared.declarations.some((handle) => CLASS_DECLARATIONS.has(handle.kind) && !own.has(handle.path))) ||
|
|
91
|
+
((declared.flags & SymbolFlags.Interface) !== 0 &&
|
|
92
|
+
declared.declarations.some((handle) => handle.kind === SyntaxKind.VariableDeclaration && !own.has(handle.path))))) {
|
|
92
93
|
outsideBases.set(id, declared);
|
|
93
94
|
}
|
|
94
95
|
}
|
|
@@ -145,11 +146,13 @@ export function overrideReferences(project, held, chains, testFiles) {
|
|
|
145
146
|
*/
|
|
146
147
|
function outsideMemberNames(project, bases, outsideBases) {
|
|
147
148
|
const direct = new Map();
|
|
149
|
+
const error = errorType(project);
|
|
148
150
|
for (const [classId, base] of outsideBases) {
|
|
149
151
|
const instance = project.queries.declaredTypeOf(base);
|
|
150
152
|
const statics = project.queries.typeOfSymbol(base);
|
|
151
153
|
const components = [
|
|
152
154
|
...namesOf(project, instance === UNANSWERED ? undefined : instance).map(nameComponent),
|
|
155
|
+
...(instance !== UNANSWERED && reaches(project, instance, error) ? ["toString"] : []),
|
|
153
156
|
...namesOf(project, statics === UNANSWERED ? undefined : statics).map((name) => `${nameComponent(name)}:static`),
|
|
154
157
|
];
|
|
155
158
|
if (components.length > 0) {
|
|
@@ -175,6 +178,34 @@ function outsideMemberNames(project, bases, outsideBases) {
|
|
|
175
178
|
}
|
|
176
179
|
return names;
|
|
177
180
|
}
|
|
181
|
+
/** The global `Error` instance type's identifier, where the program's library declares one. */
|
|
182
|
+
function errorType(project) {
|
|
183
|
+
const symbol = project.queries.resolveName("Error", SymbolFlags.Type, undefined, false);
|
|
184
|
+
if (symbol === UNANSWERED || symbol === undefined) {
|
|
185
|
+
return undefined;
|
|
186
|
+
}
|
|
187
|
+
const type = project.queries.declaredTypeOf(symbol);
|
|
188
|
+
return type === UNANSWERED ? undefined : type.id;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Whether one type is the `Error` instance type or extends it at any depth: the runtime
|
|
192
|
+
* prints an error through its `toString`, a member the library's `Error` interface omits.
|
|
193
|
+
*/
|
|
194
|
+
function reaches(project, type, target) {
|
|
195
|
+
const seen = new Set();
|
|
196
|
+
const pending = [type];
|
|
197
|
+
for (let next = pending.pop(); next !== undefined; next = pending.pop()) {
|
|
198
|
+
if (next.id === target) {
|
|
199
|
+
return true;
|
|
200
|
+
}
|
|
201
|
+
if (!seen.has(next.id)) {
|
|
202
|
+
seen.add(next.id);
|
|
203
|
+
const bases = project.queries.baseTypes(next);
|
|
204
|
+
pending.push(...(bases === UNANSWERED ? [] : bases));
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
178
209
|
/** The names of a type's properties; none where the type or its properties are unanswered. */
|
|
179
210
|
function namesOf(project, type) {
|
|
180
211
|
const properties = type === undefined ? UNANSWERED : project.queries.propertiesOf(type);
|
package/dist/src/print.js
CHANGED
|
@@ -73,6 +73,7 @@ export function printConfig(config, provenance) {
|
|
|
73
73
|
members: entry.members,
|
|
74
74
|
})),
|
|
75
75
|
serializers: config.ts.serializers.map(declarationOf),
|
|
76
|
+
roots_complete: config.ts.rootsComplete,
|
|
76
77
|
},
|
|
77
78
|
provenance: Object.fromEntries([...provenance]
|
|
78
79
|
.sort(([a], [b]) => (a < b ? -1 : 1))
|