@cplieger/deadset-ts 8.0.0-dev.2 → 8.0.0-dev.4
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/README.md +1 -1
- package/dist/src/analysis.js +61 -10
- package/dist/src/augmentations.js +63 -1
- package/dist/src/build-scripts.js +437 -0
- package/dist/src/conformance-record.js +1 -1
- package/dist/src/contextual-uses.js +56 -9
- package/dist/src/convention-rows.js +39 -2
- package/dist/src/conventions.js +15 -0
- package/dist/src/dependencies.js +98 -1
- package/dist/src/discover.js +14 -82
- package/dist/src/entry-points.js +9 -18
- package/dist/src/exempt.js +8 -0
- package/dist/src/findings/completion.js +66 -28
- package/dist/src/findings/intra-function.js +4 -2
- package/dist/src/findings/reads-and-writes.js +7 -6
- package/dist/src/findings/unused-declarations.js +4 -1
- package/dist/src/graph.js +5 -3
- package/dist/src/intra-function-parts.js +45 -17
- package/dist/src/kinds.js +8 -8
- package/dist/src/manifest.js +18 -0
- package/dist/src/matrix.js +38 -4
- package/dist/src/query.js +1 -0
- package/dist/src/report.js +23 -4
- package/dist/src/reporters/annotations.js +15 -8
- package/dist/src/reporters/sarif.js +12 -8
- package/dist/src/roots.js +197 -42
- package/dist/src/serialization-contract.js +590 -12
- package/dist/src/sweep.js +7 -9
- package/dist/src/test-globals.js +234 -0
- package/dist/src/type-errors.js +11 -3
- package/dist/src/unseen-loads.js +107 -0
- package/dist/src/verbs/analyze.js +24 -3
- package/dist/src/workflow-steps.js +32 -15
- package/dist/src/yaml-document.js +355 -0
- package/jsr.json +1 -1
- package/package.json +2 -2
- package/src/analysis.ts +109 -12
- package/src/augmentations.ts +77 -2
- package/src/build-scripts.ts +564 -0
- package/src/conformance-record.ts +1 -1
- package/src/contextual-uses.ts +64 -12
- package/src/convention-rows.ts +47 -2
- package/src/conventions.ts +16 -0
- package/src/dependencies.ts +110 -1
- package/src/discover.ts +14 -94
- package/src/entry-points.ts +10 -25
- package/src/exempt.ts +16 -0
- package/src/file-facts.ts +3 -0
- package/src/findings/boundary.ts +2 -0
- package/src/findings/completion.ts +76 -30
- package/src/findings/intra-function.ts +4 -2
- package/src/findings/reads-and-writes.ts +7 -6
- package/src/findings/unused-declarations.ts +6 -1
- package/src/graph.ts +5 -3
- package/src/intra-function-parts.ts +55 -16
- package/src/kinds.ts +8 -8
- package/src/manifest.ts +21 -3
- package/src/matrix.ts +51 -4
- package/src/query.ts +11 -0
- package/src/report.ts +56 -16
- package/src/reporters/annotations.ts +21 -10
- package/src/reporters/reporter.ts +1 -3
- package/src/reporters/sarif.ts +16 -8
- package/src/roots.ts +226 -46
- package/src/serialization-contract.ts +758 -12
- package/src/sweep.ts +23 -9
- package/src/test-globals.ts +275 -0
- package/src/type-errors.ts +14 -3
- package/src/unseen-loads.ts +145 -0
- package/src/verbs/analyze.ts +28 -3
- package/src/workflow-steps.ts +35 -17
- package/src/yaml-document.ts +377 -0
|
@@ -772,10 +772,9 @@ function calleeSteers(project, signature, at) {
|
|
|
772
772
|
}
|
|
773
773
|
/**
|
|
774
774
|
* The parts with each name of `contextual` judged where the compiler gives its function a
|
|
775
|
-
* contextual type:
|
|
776
|
-
*
|
|
777
|
-
*
|
|
778
|
-
* name read.
|
|
775
|
+
* contextual type: a name an object pattern binds is marked as one, and an annotated
|
|
776
|
+
* parameter with whether the call's inference may read its annotation. A question the
|
|
777
|
+
* checker leaves unanswered keeps the name read.
|
|
779
778
|
*/
|
|
780
779
|
function withContextualRead(project, parts, contextual) {
|
|
781
780
|
if (contextual.length === 0) {
|
|
@@ -791,15 +790,17 @@ function withContextualRead(project, parts, contextual) {
|
|
|
791
790
|
continue;
|
|
792
791
|
}
|
|
793
792
|
const place = one.part.parameter;
|
|
794
|
-
judged.set(one.part,
|
|
793
|
+
judged.set(one.part, answer === UNANSWERED || place === undefined
|
|
795
794
|
? { ...one.part, used: true }
|
|
796
|
-
:
|
|
797
|
-
...one.part,
|
|
798
|
-
|
|
799
|
-
...
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
795
|
+
: one.pattern
|
|
796
|
+
? { ...one.part, parameter: { ...place, contextualPattern: true } }
|
|
797
|
+
: {
|
|
798
|
+
...one.part,
|
|
799
|
+
parameter: {
|
|
800
|
+
...place,
|
|
801
|
+
annotated: calleeSteers(project, one.signature, one.at) ? "steers" : "free",
|
|
802
|
+
},
|
|
803
|
+
});
|
|
803
804
|
}
|
|
804
805
|
return parts.map((part) => judged.get(part) ?? part);
|
|
805
806
|
}
|
|
@@ -884,15 +885,28 @@ function functionOf(block) {
|
|
|
884
885
|
}
|
|
885
886
|
}
|
|
886
887
|
/**
|
|
887
|
-
* The locals one block declares with `let`, `const
|
|
888
|
-
* block that spell it. A `var` of a nested
|
|
889
|
-
*
|
|
888
|
+
* The locals one block declares with `let`, `const`, `var` or a function declaration
|
|
889
|
+
* inside a function, each with the names of the block that spell it. A `var` of a nested
|
|
890
|
+
* block is one where no nested function of its function names it, since the function scope
|
|
891
|
+
* holds it past the block's end.
|
|
890
892
|
*/
|
|
891
893
|
function localsOf(block) {
|
|
892
894
|
const declared = [];
|
|
893
895
|
const scope = functionOf(block);
|
|
894
896
|
const outlives = scope?.body !== block;
|
|
895
897
|
block.statements.forEach((statement, at) => {
|
|
898
|
+
if (isFunctionDeclaration(statement)) {
|
|
899
|
+
if (scope !== undefined && statement.name !== undefined && statement.body !== undefined) {
|
|
900
|
+
declared.push({
|
|
901
|
+
name: statement.name,
|
|
902
|
+
statement: at,
|
|
903
|
+
initialized: true,
|
|
904
|
+
outlives: false,
|
|
905
|
+
hoisted: true,
|
|
906
|
+
});
|
|
907
|
+
}
|
|
908
|
+
return;
|
|
909
|
+
}
|
|
896
910
|
if (!isVariableStatement(statement)) {
|
|
897
911
|
return;
|
|
898
912
|
}
|
|
@@ -902,6 +916,11 @@ function localsOf(block) {
|
|
|
902
916
|
return;
|
|
903
917
|
}
|
|
904
918
|
for (const declaration of list.declarations) {
|
|
919
|
+
// A write to a local typed `never` is the compiler's exhaustiveness check, which
|
|
920
|
+
// fails to compile once a case goes unhandled.
|
|
921
|
+
if (declaration.type?.kind === SyntaxKind.NeverKeyword) {
|
|
922
|
+
continue;
|
|
923
|
+
}
|
|
905
924
|
for (const name of boundNames(declaration.name)) {
|
|
906
925
|
if (!blockScoped &&
|
|
907
926
|
outlives &&
|
|
@@ -913,6 +932,7 @@ function localsOf(block) {
|
|
|
913
932
|
statement: at,
|
|
914
933
|
initialized: declaration.initializer !== undefined,
|
|
915
934
|
outlives: !blockScoped && outlives,
|
|
935
|
+
hoisted: false,
|
|
916
936
|
});
|
|
917
937
|
}
|
|
918
938
|
}
|
|
@@ -953,12 +973,20 @@ function deadStores(file, root, block, holder, locals, ids) {
|
|
|
953
973
|
used: false,
|
|
954
974
|
});
|
|
955
975
|
for (const local of locals) {
|
|
956
|
-
const
|
|
976
|
+
const own = local.hoisted ? block.statements[local.statement] : undefined;
|
|
977
|
+
// A function's reads of itself keep it no more than its absence would.
|
|
978
|
+
const uses = local.uses.filter((use) => readsBinding(use, local.name, ids) && (own === undefined || !within(use, own)));
|
|
957
979
|
if (!local.outlives && uses.every(isPlainWrite)) {
|
|
958
|
-
|
|
980
|
+
// A declaration with no initializer writes `undefined`, the one store left to name.
|
|
981
|
+
const writes = [...(local.initialized ? [local.name] : []), ...uses];
|
|
982
|
+
const targets = writes.length === 0 ? [local.name] : writes;
|
|
959
983
|
found.push(...targets.map((target) => deadAt(local, target)));
|
|
960
984
|
continue;
|
|
961
985
|
}
|
|
986
|
+
// A read anywhere in the block reads a function declaration, which is written first.
|
|
987
|
+
if (local.hoisted) {
|
|
988
|
+
continue;
|
|
989
|
+
}
|
|
962
990
|
if (uses.some((use) => inNestedFunction(use, block))) {
|
|
963
991
|
continue;
|
|
964
992
|
}
|
package/dist/src/kinds.js
CHANGED
|
@@ -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. 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.",
|
|
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. A production declaration whose reachability class is `possible` because programs outside the analysis may use it, being published API of a library whose run declares no consumer, and in Go a declaration of a package no build links or an export of a unit a dropped module requires, counts as a live target symbol of every test that references it, so such a test is no test of dead code. The declaration is still reported at `possible`. 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: '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.',
|
|
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, while a file a build script\'s bundler call names is one, because the bundle exposes what 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",
|
|
@@ -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. 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.",
|
|
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. A literal whose type the compiler infers, as one a callback returns to a generic call, writes in the same way the member of each property's name that each object type a value of the literal's type reaches declares, through array elements, type arguments and the parameters and results of functions, so `ids.map((id) => ({ id }))` returned as `Row[]` writes `Row.id`. 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",
|
|
@@ -174,8 +174,8 @@ const ROWS = [
|
|
|
174
174
|
code: "DS1303",
|
|
175
175
|
name: "unused-type-parameter",
|
|
176
176
|
languages: ["go", "ts"],
|
|
177
|
-
rule: "A type parameter of a function
|
|
178
|
-
precondition: "Function and method type parameters
|
|
177
|
+
rule: "A type parameter of a function, a method or a TypeScript type alias that no part of the declaration's signature, body or aliased type 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 declaration that is itself dead falls with it and is reported under no code of its own.",
|
|
178
|
+
precondition: "Function and method type parameters, and in TypeScript those of a type alias. A TypeScript alias names no type of its own, so two instantiations that differ only in a parameter its type never names are one type. A Go type declaration's type parameter 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. Nor is one of a TypeScript class or interface, which merges only with declarations of the same type parameters. A method signature an interface or an object type declares belongs to that type declaration, so its type parameters are never reported either.",
|
|
179
179
|
defaultSeverity: "deny",
|
|
180
180
|
maxClass: "certain",
|
|
181
181
|
fixability: "deletable",
|
|
@@ -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 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.
|
|
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. A name an object binding pattern of a parameter of such a function binds, annotated or not, that the body never reads is reported for deletion at `probable`, because the pattern reads the property it names from the argument and the code that hands the argument may act on that read, which nothing in the program shows. Any other TypeScript parameter that is a binding pattern is judged by the names it binds: each name the body never reads is reported wherever the pattern stands, because removing it from the pattern moves no argument, except a name beside a rest element of the same object pattern, whose removal changes what that element holds, and the pattern counts as a read parameter when the body reads any name it binds. A rest parameter is judged as the last parameter. A TypeScript `this` parameter declares the type of `this` and receives no argument, so it is never reported. A TypeScript constructor is used as a value where its class is used as a value other than as the callee of a `new` expression or the class an `extends` clause names, and its signature is not free where its class carries a decorator or a parameter of the constructor carries one, because the code that decorator or a container runs may construct the class. A parameter property is read by the write to its member the constructor makes, so it is never reported under this kind, and its member is judged under DS1301. A TypeScript name a parameter binds, whole or through a binding pattern, that starts with an underscore is never reported, because a leading underscore is the spelling unused-parameter rules read as declared unread, and no other name exempts a parameter. A Go parameter named by the blank identifier declares no name a body could read and is never reported.",
|
|
293
293
|
defaultSeverity: "warn",
|
|
294
294
|
maxClass: "certain",
|
|
295
295
|
fixability: "manual",
|
|
@@ -313,7 +313,7 @@ const ROWS = [
|
|
|
313
313
|
name: "unused-result",
|
|
314
314
|
languages: ["go", "ts"],
|
|
315
315
|
rule: "A result value that no call site of the function uses, on a function whose signature is free to change.",
|
|
316
|
-
precondition: "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. A call that is the operand of an await expression written as a statement of its own uses a result whose type has a member named then, a promise or another thenable, because the caller sequences on it, and discards any other result. A call written as a statement of its own, or as the operand of void, discards its result whatever its type.",
|
|
316
|
+
precondition: "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. A function a program run by naming the file names, a file under the `ignore` tag or a script of a dropped module, has call sites outside the loaded graph. A call that is the operand of an await expression written as a statement of its own uses a result whose type has a member named then, a promise or another thenable, because the caller sequences on it, and discards any other result. A call written as a statement of its own, or as the operand of void, discards its result whatever its type.",
|
|
317
317
|
defaultSeverity: "warn",
|
|
318
318
|
maxClass: "certain",
|
|
319
319
|
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. 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.",
|
|
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 function declaration of a block of a function is a TypeScript local too, written with its function when the block starts, wherever it stands in the block, so one that nothing outside its own body reads is a dead store positioned at its name, and a read anywhere else in the block reads it. A `let` or `var` declaration with no initializer writes `undefined`, so one that nothing reads and nothing writes is a dead store positioned at its name. A local whose declaration carries the type annotation `never` is no subject: a write to it is the compiler's exhaustiveness check, which fails to compile once a case goes unhandled, so deleting it changes what the program checks. 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/manifest.js
CHANGED
|
@@ -110,6 +110,24 @@ export function readManifest(host, targetRoot) {
|
|
|
110
110
|
found.push({ member, path: value, role: "import", published: true });
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
|
+
// A `browser` string replaces `main` in a browser bundle, and an object replaces each
|
|
114
|
+
// module it maps with the file it names: https://github.com/defunctzombie/package-browser-field-spec
|
|
115
|
+
const browser = manifest["browser"];
|
|
116
|
+
if (typeof browser === "string" && isTarget(browser, false)) {
|
|
117
|
+
found.push({ member: "browser", path: browser, role: "import", published: true });
|
|
118
|
+
}
|
|
119
|
+
else if (isRecord(browser)) {
|
|
120
|
+
for (const [replaced, value] of Object.entries(browser)) {
|
|
121
|
+
if (typeof value === "string" && isTarget(value, true)) {
|
|
122
|
+
found.push({
|
|
123
|
+
member: below("browser", replaced),
|
|
124
|
+
path: value,
|
|
125
|
+
role: "import",
|
|
126
|
+
published: true,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
113
131
|
const bin = manifest["bin"];
|
|
114
132
|
if (typeof bin === "string" && isTarget(bin, false)) {
|
|
115
133
|
found.push({ member: "bin", path: bin, role: "run", published: false });
|
package/dist/src/matrix.js
CHANGED
|
@@ -103,18 +103,24 @@ export function sweepMatrix(matrix, input) {
|
|
|
103
103
|
]));
|
|
104
104
|
const union = matrix.union;
|
|
105
105
|
const heldBy = union.symbols.map(() => undefined);
|
|
106
|
-
const
|
|
106
|
+
const held = [
|
|
107
107
|
...input.marked,
|
|
108
108
|
...(input.exempt ?? []).map((record) => record.id),
|
|
109
109
|
...(input.unanswered ?? []),
|
|
110
|
-
]
|
|
111
|
-
const
|
|
110
|
+
];
|
|
111
|
+
const testReached = reachedWithTheTests(union, held);
|
|
112
|
+
// A test uses what it names: a file a test reads through a star re-export or a
|
|
113
|
+
// namespace keeps the exports nothing names at their own class.
|
|
114
|
+
const testNamed = reachedWithTheTests(union, held, false);
|
|
115
|
+
const everywhere = union.symbols.map((symbol, at) => {
|
|
112
116
|
const held = matrix.heldIn[at] ?? [];
|
|
113
117
|
const found = held.map((configuration) => byConfiguration.get(configuration)?.get(symbol.id));
|
|
114
118
|
return held.length === 0 || found.some((candidate) => candidate === undefined)
|
|
115
119
|
? undefined
|
|
116
120
|
: found.filter((candidate) => candidate !== undefined);
|
|
117
121
|
});
|
|
122
|
+
const compiled = compiledReferences(matrix, new Set(union.symbols.flatMap((symbol, at) => (everywhere[at] === undefined ? [] : [symbol.id]))), input.mode);
|
|
123
|
+
const judged = everywhere.map((found, at) => compiled.has(union.symbols[at]?.id ?? "") ? undefined : found);
|
|
118
124
|
// A configuration that does not hold a test's subject's caller finds the subject dead,
|
|
119
125
|
// so a test is of dead code only where every production subject it names is dead in
|
|
120
126
|
// every configuration that holds it.
|
|
@@ -125,7 +131,7 @@ export function sweepMatrix(matrix, input) {
|
|
|
125
131
|
judged[edge.to] !== undefined);
|
|
126
132
|
const admittedAt = (at) => judged[at]?.every((candidate) => candidate.testOfDeadCode) === true && subjectsDead(at);
|
|
127
133
|
const kept = keptByTests(union, testReached, admittedAt);
|
|
128
|
-
const testUsed = testUsedReach(union, union.symbols.map((_symbol, at) => matrix.testUsed[at] === true &&
|
|
134
|
+
const testUsed = testUsedReach(union, union.symbols.map((_symbol, at) => matrix.testUsed[at] === true && testNamed[at] === true), judged.map((one) => one !== undefined));
|
|
129
135
|
const candidates = [];
|
|
130
136
|
union.symbols.forEach((symbol, at) => {
|
|
131
137
|
const all = judged[at];
|
|
@@ -164,6 +170,34 @@ export function sweepMatrix(matrix, input) {
|
|
|
164
170
|
components: deadComponents(matrix, { liveUnder, candidates }, new Set()),
|
|
165
171
|
};
|
|
166
172
|
}
|
|
173
|
+
/**
|
|
174
|
+
* Every declaration of `dead`, those dead in every configuration that holds them, that a
|
|
175
|
+
* configuration's graph references from a judged declaration outside `dead` or already
|
|
176
|
+
* kept, until none joins: deleting one would break that configuration's compile. A
|
|
177
|
+
* production run counts no reference a test file made.
|
|
178
|
+
*/
|
|
179
|
+
function compiledReferences(matrix, dead, mode) {
|
|
180
|
+
const kept = new Set();
|
|
181
|
+
for (let changed = true; changed;) {
|
|
182
|
+
changed = false;
|
|
183
|
+
for (const graph of matrix.graphs) {
|
|
184
|
+
graph.out.forEach((edges, from) => {
|
|
185
|
+
const id = graph.symbols[from]?.id ?? "";
|
|
186
|
+
if (graph.subject[from] !== true || (dead.has(id) && !kept.has(id))) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
for (const edge of edges) {
|
|
190
|
+
const to = graph.symbols[edge.to]?.id ?? "";
|
|
191
|
+
if ((!mode.production || !edge.test) && dead.has(to) && !kept.has(to)) {
|
|
192
|
+
kept.add(to);
|
|
193
|
+
changed = true;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return kept;
|
|
200
|
+
}
|
|
167
201
|
/** Per declaration of the union, whether one of `seeds` is it or reaches it through `dead` declarations. */
|
|
168
202
|
function testUsedReach(union, seeds, dead) {
|
|
169
203
|
// A file is no candidate, and its top level is what reaches what it alone calls.
|
package/dist/src/query.js
CHANGED
|
@@ -220,6 +220,7 @@ export function queriesOf(checker, configFile, batch, log, ask = ASK_DIRECTLY) {
|
|
|
220
220
|
symbolOfType: (type) => one("getSymbol", () => typeLocation(type), () => type.getSymbol()),
|
|
221
221
|
signaturesOf: (type, kind) => one("getSignaturesOfType", () => typeLocation(type), () => checker.getSignaturesOfType(type, kind)),
|
|
222
222
|
resolvedSignature: (node) => one("getResolvedSignature", () => nodeLocation(node), () => checker.getResolvedSignature(node)),
|
|
223
|
+
resolvedSignatures: (nodes, cap = DEFAULT_BATCH_CAP) => each("getResolvedSignature", nodes, cap, nodeLocation, (node) => checker.getResolvedSignature.gen(node), (node) => checker.getResolvedSignature(node)),
|
|
223
224
|
parameterType: (signature, index) => one("getParameterType", () => `signature ${String(signature.id)} parameter ${String(index)}`, () => checker.getParameterType(signature, index)),
|
|
224
225
|
genericOf: (signature) => signature.target === undefined
|
|
225
226
|
? undefined
|
package/dist/src/report.js
CHANGED
|
@@ -11,6 +11,21 @@ export const SCHEMA_VERSIONS_ACCEPTED = [SCHEMA_VERSION];
|
|
|
11
11
|
export const ANALYZER_NAME = "deadset-ts";
|
|
12
12
|
/** The language this analyzer claims. */
|
|
13
13
|
export const LANGUAGE = "ts";
|
|
14
|
+
/**
|
|
15
|
+
* Each component the findings name, once, with the members the first finding naming it
|
|
16
|
+
* carries, in the order the findings are: `findings` paired with their wire forms and
|
|
17
|
+
* sorted, then the edge evaluations' findings.
|
|
18
|
+
*/
|
|
19
|
+
function componentsOf(findings) {
|
|
20
|
+
const listed = new Map();
|
|
21
|
+
for (const [wire, finding] of findings) {
|
|
22
|
+
const { members } = finding.component;
|
|
23
|
+
if (members !== undefined && !listed.has(wire.component.id)) {
|
|
24
|
+
listed.set(wire.component.id, { id: wire.component.id, members: members.map(wireSymbol) });
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return [...listed.values()];
|
|
28
|
+
}
|
|
14
29
|
/** Two strings ordered bytewise. */
|
|
15
30
|
function compare(a, b) {
|
|
16
31
|
if (a === b) {
|
|
@@ -85,9 +100,6 @@ export function wireFinding(finding) {
|
|
|
85
100
|
root: finding.component.root,
|
|
86
101
|
symbol_count: finding.component.symbolCount,
|
|
87
102
|
deletable_lines: finding.component.deletableLines,
|
|
88
|
-
...(finding.component.members === undefined
|
|
89
|
-
? {}
|
|
90
|
-
: { members: finding.component.members.map(wireSymbol) }),
|
|
91
103
|
},
|
|
92
104
|
retained_by: finding.retainedBy,
|
|
93
105
|
configurations: finding.configurations,
|
|
@@ -198,7 +210,11 @@ function totalsOf(findings, result) {
|
|
|
198
210
|
}
|
|
199
211
|
/** Builds the report of one run, every array in the order the Contract fixes for it. */
|
|
200
212
|
export function buildReport(input) {
|
|
201
|
-
const
|
|
213
|
+
const paired = input.result.findings
|
|
214
|
+
.map((finding) => [wireFinding(finding), finding])
|
|
215
|
+
.sort(([a], [b]) => canonical(a, b));
|
|
216
|
+
const findings = paired.map(([wire]) => wire);
|
|
217
|
+
const evaluated = input.result.edgeEvaluations.flatMap((one) => one.finding === undefined ? [] : [[wireFinding(one.finding), one.finding]]);
|
|
202
218
|
const unavailable = [...new Map(input.unavailable.map((one) => [one.id, one])).values()]
|
|
203
219
|
.sort((a, b) => compare(a.id, b.id))
|
|
204
220
|
.map((one) => ({ id: one.id, role: "consumer", reason: one.reason }));
|
|
@@ -228,6 +244,9 @@ export function buildReport(input) {
|
|
|
228
244
|
.map((one) => ({ id: one.id, project: one.project, error: one.error })),
|
|
229
245
|
consumers: { declared: loaded.length + unavailable.length, loaded, unavailable },
|
|
230
246
|
findings,
|
|
247
|
+
...(input.listsComponents === true
|
|
248
|
+
? { components: componentsOf([...paired, ...evaluated]) }
|
|
249
|
+
: {}),
|
|
231
250
|
edge_evaluations: input.result.edgeEvaluations.map(wireEvaluation).sort(byEdge),
|
|
232
251
|
stale_suppressions: input.result.staleSuppressions.map(wireStale).sort(canonicalStale),
|
|
233
252
|
// Every gap shares the one component of the canonical key a gap supplies, the analyzer's
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { fails } from "../config.js";
|
|
2
1
|
import { coalesced } from "../json-chunks.js";
|
|
3
2
|
import { KINDS } from "../kinds.js";
|
|
4
3
|
/** The escapes a workflow command's message needs, so a line break does not end the command. */
|
|
@@ -19,6 +18,12 @@ function escapeProperty(value) {
|
|
|
19
18
|
function kindName(code) {
|
|
20
19
|
return KINDS.get(code)?.name ?? code;
|
|
21
20
|
}
|
|
21
|
+
/** The command each finding severity is annotated with, whatever the failing severity. */
|
|
22
|
+
const LEVELS = {
|
|
23
|
+
deny: "error",
|
|
24
|
+
warn: "warning",
|
|
25
|
+
allow: "notice",
|
|
26
|
+
};
|
|
22
27
|
function command(level, at, endLine, title, message) {
|
|
23
28
|
return `::${level} file=${escapeProperty(at.path)},line=${String(at.line)},col=${String(at.column)},endLine=${String(endLine)},title=${escapeProperty(title)}::${escapeData(message)}`;
|
|
24
29
|
}
|
|
@@ -26,16 +31,15 @@ function command(level, at, endLine, title, message) {
|
|
|
26
31
|
const SKIP_TITLE = "type error skipped";
|
|
27
32
|
const SKIP_MESSAGE = "the analysis did not evaluate the function or statement holding this type error: ";
|
|
28
33
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* is fixed on at the failing severity.
|
|
34
|
+
* The annotations `contract/grammar/annotations.md` states: one per finding, at the
|
|
35
|
+
* command its severity names, and one error per stale suppression, each naming its file,
|
|
36
|
+
* line, column and last line and titled by its code and kind; then one warning per
|
|
37
|
+
* type-error skip naming its file and line, and one per note naming its directory.
|
|
34
38
|
*/
|
|
35
|
-
export function annotations(report
|
|
39
|
+
export function annotations(report) {
|
|
36
40
|
return coalesced((function* lines() {
|
|
37
41
|
for (const found of report.findings) {
|
|
38
|
-
yield `${command(
|
|
42
|
+
yield `${command(LEVELS[found.severity], found.position, found.position.end_line, `${found.code} ${found.kind}`, found.message)}\n`;
|
|
39
43
|
}
|
|
40
44
|
for (const stale of report.stale_suppressions) {
|
|
41
45
|
yield `${command("error", stale.position, stale.position.line, `${stale.code} ${kindName(stale.code)}`, stale.message)}\n`;
|
|
@@ -43,5 +47,8 @@ export function annotations(report, options) {
|
|
|
43
47
|
for (const skip of report.type_error_skips) {
|
|
44
48
|
yield `::warning file=${escapeProperty(skip.path)},line=${String(skip.line)},title=${escapeProperty(SKIP_TITLE)}::${escapeData(SKIP_MESSAGE + skip.message)}\n`;
|
|
45
49
|
}
|
|
50
|
+
for (const note of report.notes) {
|
|
51
|
+
yield `::warning file=${escapeProperty(note.path)},title=${escapeProperty(note.kind)}::${escapeData(note.message)}\n`;
|
|
52
|
+
}
|
|
46
53
|
})());
|
|
47
54
|
}
|
|
@@ -114,7 +114,7 @@ function lineHashCache(read) {
|
|
|
114
114
|
};
|
|
115
115
|
}
|
|
116
116
|
/** Every position a finding names beyond its own, in the mapping's order, the first hundred. */
|
|
117
|
-
function relatedOf(found) {
|
|
117
|
+
function relatedOf(found, members) {
|
|
118
118
|
const related = [];
|
|
119
119
|
for (const one of found.details.implementations ?? []) {
|
|
120
120
|
related.push({ label: "implementation", at: one.position, endLine: one.position.end_line });
|
|
@@ -126,7 +126,7 @@ function relatedOf(found) {
|
|
|
126
126
|
const at = found.details.name_literal;
|
|
127
127
|
related.push({ label: "name", at, endLine: at.end_line });
|
|
128
128
|
}
|
|
129
|
-
for (const one of found.component.
|
|
129
|
+
for (const one of members(found.component.id)) {
|
|
130
130
|
if (declarationKey(one.ref, one.position.path) !==
|
|
131
131
|
declarationKey(found.symbol.ref, found.position.path)) {
|
|
132
132
|
related.push({ label: "member", at: one.position, endLine: one.position.end_line });
|
|
@@ -143,7 +143,9 @@ function messageWithLinks(message, related) {
|
|
|
143
143
|
return `${message} (see ${links.join(", ")})`;
|
|
144
144
|
}
|
|
145
145
|
/** Every member of the finding the mapping places nowhere else, under its schema name. */
|
|
146
|
-
|
|
146
|
+
/** A result's member bag, its component holding the members the report lists for it once. */
|
|
147
|
+
function propertiesOf(found, members) {
|
|
148
|
+
const listed = members(found.component.id);
|
|
147
149
|
return {
|
|
148
150
|
language: found.language,
|
|
149
151
|
symbol: found.symbol,
|
|
@@ -154,7 +156,7 @@ function propertiesOf(found) {
|
|
|
154
156
|
: { liveness_relation: found.liveness_relation }),
|
|
155
157
|
test_only: found.test_only,
|
|
156
158
|
generated: found.generated,
|
|
157
|
-
component: found.component,
|
|
159
|
+
component: listed.length === 0 ? found.component : { ...found.component, members: listed },
|
|
158
160
|
retained_by: found.retained_by,
|
|
159
161
|
configurations: found.configurations,
|
|
160
162
|
consumers_loaded: found.consumers_loaded,
|
|
@@ -169,8 +171,8 @@ function ruleIndex(index, code) {
|
|
|
169
171
|
}
|
|
170
172
|
return at;
|
|
171
173
|
}
|
|
172
|
-
function findingResult(found, index, hashOf) {
|
|
173
|
-
const related = relatedOf(found);
|
|
174
|
+
function findingResult(found, index, hashOf, members) {
|
|
175
|
+
const related = relatedOf(found, members);
|
|
174
176
|
return {
|
|
175
177
|
ruleId: found.code,
|
|
176
178
|
ruleIndex: ruleIndex(index, found.code),
|
|
@@ -190,7 +192,7 @@ function findingResult(found, index, hashOf) {
|
|
|
190
192
|
primaryLocationLineHash: hashOf(found.position),
|
|
191
193
|
"deadsetSymbolRef/v1": symbolFingerprint(found.code, found.symbol.ref),
|
|
192
194
|
},
|
|
193
|
-
properties: propertiesOf(found),
|
|
195
|
+
properties: propertiesOf(found, members),
|
|
194
196
|
};
|
|
195
197
|
}
|
|
196
198
|
/** A stale suppression at the failing level, at its own site; it is no finding, so it carries no member bag. */
|
|
@@ -218,8 +220,10 @@ export function sarif(report, options) {
|
|
|
218
220
|
const ruleList = rules(kinds);
|
|
219
221
|
const index = new Map(kinds.map((kind, at) => [kind.code, at]));
|
|
220
222
|
const hashOf = lineHashCache(options.readSource);
|
|
223
|
+
const listed = new Map((report.components ?? []).map((one) => [one.id, one.members]));
|
|
224
|
+
const members = (id) => listed.get(id) ?? [];
|
|
221
225
|
const results = [
|
|
222
|
-
...report.findings.map((found) => findingResult(found, index, hashOf)),
|
|
226
|
+
...report.findings.map((found) => findingResult(found, index, hashOf, members)),
|
|
223
227
|
...report.stale_suppressions.map((stale) => staleResult(stale, index, hashOf)),
|
|
224
228
|
];
|
|
225
229
|
const languages = [...report.analyzer.languages].sort().join("+");
|