@eagleoutice/flowr 2.15.10 → 2.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -26
- package/abstract-interpretation/data-frame/arguments.js +11 -7
- package/control-flow/happens-before.d.ts +5 -0
- package/control-flow/happens-before.js +48 -34
- package/control-flow/useless-loop.d.ts +1 -1
- package/control-flow/useless-loop.js +29 -42
- package/dataflow/environments/built-in-props.d.ts +9 -0
- package/dataflow/environments/built-in-props.js +25 -19
- package/dataflow/environments/built-in.d.ts +2 -2
- package/dataflow/environments/built-in.js +41 -77
- package/dataflow/environments/default-builtin-config.d.ts +181 -29
- package/dataflow/environments/default-builtin-config.js +38 -24
- package/dataflow/environments/environment.d.ts +6 -4
- package/dataflow/environments/environment.js +54 -121
- package/dataflow/environments/identifier.d.ts +4 -2
- package/dataflow/environments/identifier.js +23 -69
- package/dataflow/environments/reference-to-maybe.d.ts +9 -0
- package/dataflow/environments/reference-to-maybe.js +23 -51
- package/dataflow/environments/resolve-by-name.js +37 -76
- package/dataflow/eval/resolve/resolve-argument.d.ts +3 -1
- package/dataflow/eval/resolve/resolve-argument.js +61 -64
- package/dataflow/eval/resolve/resolve-working-directory.d.ts +8 -2
- package/dataflow/eval/resolve/resolve-working-directory.js +12 -20
- package/dataflow/eval/resolve/resolve.d.ts +4 -0
- package/dataflow/eval/resolve/resolve.js +23 -14
- package/dataflow/extractor.js +176 -59
- package/dataflow/fn/class-declaration.d.ts +8 -2
- package/dataflow/fn/class-declaration.js +96 -97
- package/dataflow/fn/exceptions-of-function.js +68 -37
- package/dataflow/fn/frame-reflection.d.ts +12 -4
- package/dataflow/fn/frame-reflection.js +51 -41
- package/dataflow/fn/function-props.js +15 -33
- package/dataflow/fn/function-semantics.d.ts +11 -3
- package/dataflow/fn/function-semantics.js +6 -0
- package/dataflow/fn/higher-order-function.js +13 -17
- package/dataflow/fn/strict-function.d.ts +13 -0
- package/dataflow/fn/strict-function.js +285 -122
- package/dataflow/graph/call-graph.d.ts +7 -6
- package/dataflow/graph/call-graph.js +35 -46
- package/dataflow/graph/graph.d.ts +6 -1
- package/dataflow/graph/graph.js +57 -66
- package/dataflow/info.d.ts +8 -1
- package/dataflow/info.js +24 -30
- package/dataflow/internal/control-flow.d.ts +31 -4
- package/dataflow/internal/control-flow.js +61 -39
- package/dataflow/internal/linker.d.ts +15 -9
- package/dataflow/internal/linker.js +253 -241
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.d.ts +80 -14
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +446 -78
- package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +3 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +51 -48
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +2 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +119 -185
- package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.js +7 -9
- package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +122 -147
- package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +55 -25
- package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +289 -251
- package/dataflow/internal/process/functions/call/built-in/built-in-get.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-get.js +30 -32
- package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +68 -67
- package/dataflow/internal/process/functions/call/built-in/built-in-library.js +72 -126
- package/dataflow/internal/process/functions/call/built-in/built-in-local.d.ts +1 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-local.js +10 -10
- package/dataflow/internal/process/functions/call/built-in/built-in-quote.d.ts +4 -4
- package/dataflow/internal/process/functions/call/built-in/built-in-quote.js +9 -35
- package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +8 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-s-four.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-s-four.js +12 -28
- package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +40 -118
- package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.d.ts +1 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.js +16 -24
- package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +2 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-source.js +93 -102
- package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.d.ts +7 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +173 -114
- package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.d.ts +1 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +22 -27
- package/dataflow/internal/process/functions/call/built-in/built-in-with.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-with.js +34 -9
- package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +119 -93
- package/dataflow/internal/process/functions/call/common.d.ts +1 -3
- package/dataflow/internal/process/functions/call/common.js +36 -76
- package/dataflow/internal/process/functions/call/deferred.d.ts +6 -2
- package/dataflow/internal/process/functions/call/deferred.js +54 -57
- package/dataflow/internal/process/functions/call/known-call-handling.d.ts +4 -2
- package/dataflow/internal/process/functions/call/known-call-handling.js +65 -68
- package/dataflow/internal/process/functions/call/named-call-handling.d.ts +3 -5
- package/dataflow/internal/process/functions/call/named-call-handling.js +35 -21
- package/dataflow/internal/process/functions/call/quoted.d.ts +2 -0
- package/dataflow/internal/process/functions/call/quoted.js +162 -172
- package/dataflow/internal/process/functions/call/unnamed-call-handling.js +17 -38
- package/dataflow/internal/process/functions/process-parameter.js +25 -32
- package/dataflow/internal/process/process-symbol.js +3 -6
- package/dataflow/internal/program-order.d.ts +26 -0
- package/dataflow/internal/program-order.js +49 -0
- package/documentation/wiki-setup.js +23 -0
- package/linter/linter-rules.d.ts +17 -8
- package/linter/rules/absolute-path.js +63 -87
- package/linter/rules/file-path-validity.d.ts +4 -2
- package/linter/rules/file-path-validity.js +114 -80
- package/linter/rules/namespace-access.js +21 -33
- package/linter/rules/naming-convention.d.ts +1 -1
- package/linter/rules/naming-convention.js +60 -48
- package/linter/rules/network-functions.js +11 -7
- package/linter/rules/no-leaked-credentials.js +15 -18
- package/linter/rules/problematic-inputs.d.ts +2 -1
- package/linter/rules/problematic-inputs.js +39 -59
- package/linter/rules/roxygen-arguments.d.ts +9 -4
- package/linter/rules/roxygen-arguments.js +29 -48
- package/linter/rules/seeded-randomness.d.ts +7 -4
- package/linter/rules/seeded-randomness.js +128 -89
- package/linter/rules/stop-with-call-arg.d.ts +4 -2
- package/linter/rules/stop-with-call-arg.js +25 -22
- package/linter/rules/unclosed-connection.js +31 -24
- package/linter/rules/undefined-symbol.d.ts +4 -6
- package/linter/rules/undefined-symbol.js +58 -75
- package/linter/rules/unescaped-arguments.js +18 -44
- package/linter/rules/unused-definition.d.ts +6 -0
- package/linter/rules/unused-definition.js +105 -145
- package/linter/rules/unused-import.d.ts +3 -0
- package/linter/rules/unused-import.js +25 -43
- package/package.json +5 -2
- package/project/flowr-analyzer.js +6 -2
- package/project/plugins/file-plugins/files/flowr-jupyter-file.d.ts +2 -2
- package/project/plugins/file-plugins/files/flowr-jupyter-file.js +8 -12
- package/project/plugins/file-plugins/files/flowr-rmarkdown-file.d.ts +7 -5
- package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +34 -56
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +16 -41
- package/queries/base-query-format.js +1 -2
- package/queries/catalog/absint-query/absint-query-format.js +1 -1
- package/queries/catalog/dataflow-query/dataflow-query-executor.js +2 -2
- package/queries/catalog/dataflow-query/dataflow-query-format.d.ts +2 -0
- package/queries/catalog/dataflow-query/dataflow-query-format.js +4 -7
- package/queries/catalog/dependencies-query/dependencies-query-executor.js +50 -114
- package/queries/catalog/dependencies-query/function-info/library-functions.d.ts +5 -9
- package/queries/catalog/dependencies-query/function-info/library-functions.js +6 -0
- package/queries/catalog/dependencies-query/function-info/read-functions.js +1 -1
- package/queries/catalog/dependencies-query/function-info/write-functions.js +7 -3
- package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +4 -4
- package/queries/catalog/input-sources-query/simple-input-classifier.js +192 -301
- package/r-bridge/lang-4.x/ast/model/model.d.ts +3 -1
- package/r-bridge/lang-4.x/ast/model/model.js +19 -43
- package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +3 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-argument.js +5 -12
- package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-break.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-comment.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-logical.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-next.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.d.ts +1 -0
- package/r-bridge/roxygen2/roxygen-parse.js +28 -42
- package/r-bridge/shell.js +6 -0
- package/search/search-executor/search-enrichers.js +25 -37
- package/slicing/static/slice-call.d.ts +4 -3
- package/slicing/static/slice-call.js +56 -88
- package/slicing/static/static-slicer.js +115 -79
- package/slicing/static/visiting-queue.d.ts +4 -6
- package/slicing/static/visiting-queue.js +9 -13
- package/util/proc.js +2 -1
- package/util/r-base-packages.d.ts +2 -0
- package/util/r-base-packages.js +23 -13
- package/util/text/playground-link.d.ts +12 -3
- package/util/text/playground-link.js +18 -27
- package/util/version.js +4 -10
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UNUSED_DEFINITION = void 0;
|
|
4
|
+
exports.collectCalledNames = collectCalledNames;
|
|
5
|
+
exports.isS3MethodName = isS3MethodName;
|
|
4
6
|
const linter_format_1 = require("../linter-format");
|
|
5
7
|
const function_semantics_1 = require("../../dataflow/fn/function-semantics");
|
|
6
8
|
const flowr_search_builder_1 = require("../../search/flowr-search-builder");
|
|
7
9
|
const range_1 = require("../../util/range");
|
|
8
10
|
const linter_tags_1 = require("../linter-tags");
|
|
9
|
-
const
|
|
11
|
+
const frame_reflection_1 = require("../../dataflow/fn/frame-reflection");
|
|
10
12
|
const vertex_1 = require("../../dataflow/graph/vertex");
|
|
11
13
|
const edge_1 = require("../../dataflow/graph/edge");
|
|
12
14
|
const flowr_search_filters_1 = require("../../search/flowr-search-filters");
|
|
@@ -23,6 +25,7 @@ const r_binary_op_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-binary-
|
|
|
23
25
|
const r_function_definition_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-definition");
|
|
24
26
|
const r_parameter_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-parameter");
|
|
25
27
|
const r_expression_list_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-expression-list");
|
|
28
|
+
const r_argument_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
|
|
26
29
|
/**
|
|
27
30
|
* The dots parameter is a special parameter and must never be reported as an unused definition.
|
|
28
31
|
*/
|
|
@@ -57,57 +60,37 @@ const PackageHookFunctions = new Set([
|
|
|
57
60
|
]);
|
|
58
61
|
/** Gathers the analyzed project's own `NAMESPACE` exports and declared S3 generics (empty when it is not a package). */
|
|
59
62
|
function collectPackageInfo(data) {
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
exported.add(name);
|
|
66
|
-
}
|
|
67
|
-
for (const generic of info.exportS3Generics.keys()) {
|
|
68
|
-
s3Generics.add(generic);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return { exported, s3Generics };
|
|
63
|
+
const namespaces = data.inspectContext().files.getFilesByRole(flowr_file_1.FileRole.Namespace).map(ns => ns.content().current);
|
|
64
|
+
return {
|
|
65
|
+
exported: new Set(namespaces.flatMap(flowr_namespace_file_1.getExportedNames)),
|
|
66
|
+
s3Generics: new Set(namespaces.flatMap(info => [...info.exportS3Generics.keys()]))
|
|
67
|
+
};
|
|
72
68
|
}
|
|
73
69
|
/** Collects the names of every function call in the graph, so we can tell whether an S3 generic is dispatched anywhere. */
|
|
74
70
|
function collectCalledNames(dfg) {
|
|
75
|
-
|
|
76
|
-
for (const [, vertex] of dfg.verticesOfType(vertex_1.VertexType.FunctionCall)) {
|
|
77
|
-
names.add(identifier_1.Identifier.getName(vertex.name));
|
|
78
|
-
}
|
|
79
|
-
return names;
|
|
71
|
+
return new Set(dfg.verticesOfType(vertex_1.VertexType.FunctionCall).map(([, vertex]) => identifier_1.Identifier.getName(vertex.name)));
|
|
80
72
|
}
|
|
81
73
|
/** S3 (`UseMethod`) and S4/S7 (`standardGeneric`) generic dispatchers, invoked indirectly by R's dispatch. */
|
|
82
74
|
const GenericDispatchers = new Set(['UseMethod', 'standardGeneric']);
|
|
83
75
|
/** Whether a function body is a single call to a generic dispatcher. */
|
|
84
76
|
function isGenericDispatcherOnlyBody(node) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
const nodeWithChildren = node;
|
|
89
|
-
if (Array.isArray(nodeWithChildren.children) && nodeWithChildren.children.length === 1) {
|
|
90
|
-
const child = nodeWithChildren.children[0];
|
|
91
|
-
if (child && r_function_call_1.RFunctionCall.isNamed(child) && GenericDispatchers.has(identifier_1.Identifier.getName(child.functionName.content))) {
|
|
92
|
-
return true;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return false;
|
|
77
|
+
const isDispatcherCall = (n) => r_function_call_1.RFunctionCall.isNamed(n) && GenericDispatchers.has(identifier_1.Identifier.getName(n.functionName.content));
|
|
78
|
+
return isDispatcherCall(node) || (r_expression_list_1.RExpressionList.is(node) && node.children.length === 1 && isDispatcherCall(node.children[0]));
|
|
96
79
|
}
|
|
97
|
-
/** Collects the parameter IDs of generic dispatcher functions. */
|
|
80
|
+
/** Collects the parameter IDs of generic dispatcher functions, which hand them on to their methods. */
|
|
98
81
|
function collectS3GenericParameterIds(ast) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
82
|
+
return new Set(ast.idMap.values().flatMap(node => r_function_definition_1.RFunctionDefinition.is(node) && isGenericDispatcherOnlyBody(node.body) ? node.parameters.map(param => param.name.info.id) : []));
|
|
83
|
+
}
|
|
84
|
+
/** Whether `name` reads as `generic.class` for a generic that is known, declared, or called, so R dispatches to it by that name. */
|
|
85
|
+
function isS3MethodName(name, ctx, called, declared = new Set()) {
|
|
86
|
+
/* every dot may be the one splitting method from class, as the generic may carry dots itself (`as.character.foo`) */
|
|
87
|
+
for (let dot = name.indexOf('.'); dot > 0; dot = name.indexOf('.', dot + 1)) {
|
|
88
|
+
const generic = name.slice(0, dot);
|
|
89
|
+
if (ctx.env.deriveFromIndex(knownS3Generics).has(generic) || declared.has(generic) || isDispatched(generic, called)) {
|
|
90
|
+
return true;
|
|
108
91
|
}
|
|
109
92
|
}
|
|
110
|
-
return
|
|
93
|
+
return false;
|
|
111
94
|
}
|
|
112
95
|
/**
|
|
113
96
|
* A definition is treated as used (and hence not reported) if it is the dots parameter, a package lifecycle hook,
|
|
@@ -118,36 +101,19 @@ function isConsideredUsed(lexeme, config, pkg, called, ctx) {
|
|
|
118
101
|
if (lexeme === undefined) {
|
|
119
102
|
return false;
|
|
120
103
|
}
|
|
121
|
-
|
|
104
|
+
/* non-syntactic definition names (e.g. S3 methods like `"[.irts"`) carry their R quotes or backticks in the lexeme */
|
|
122
105
|
const unquoted = (0, retriever_1.removeRQuotes)(lexeme);
|
|
123
106
|
const name = unquoted.length > 1 && unquoted.startsWith('`') && unquoted.endsWith('`') ? unquoted.slice(1, -1) : unquoted;
|
|
124
|
-
|
|
125
|
-
if (name === DotsParameter) {
|
|
126
|
-
return true;
|
|
127
|
-
}
|
|
128
|
-
// package lifecycle hooks are called by R's package machinery
|
|
129
|
-
if (PackageHookFunctions.has(name)) {
|
|
130
|
-
return true;
|
|
131
|
-
}
|
|
132
|
-
// every dot may be the one splitting method from class, as the generic may carry dots itself (`as.character.foo`)
|
|
133
|
-
for (let dot = name.indexOf('.'); dot > 0; dot = name.indexOf('.', dot + 1)) {
|
|
134
|
-
const generic = name.slice(0, dot);
|
|
135
|
-
if (ctx.env.deriveFromIndex(knownS3Generics).has(generic) || pkg.s3Generics.has(generic) || isDispatched(generic, called)) {
|
|
136
|
-
return true;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
if (config.excludeExportedDefinitions && pkg.exported.has(name)) {
|
|
107
|
+
/* the dots are a special parameter, and package lifecycle hooks are called by R's package machinery */
|
|
108
|
+
if (name === DotsParameter || PackageHookFunctions.has(name)) {
|
|
140
109
|
return true;
|
|
141
110
|
}
|
|
142
|
-
return
|
|
111
|
+
return isS3MethodName(name, ctx, called, pkg.s3Generics) || (config.excludeExportedDefinitions && pkg.exported.has(name));
|
|
143
112
|
}
|
|
144
113
|
const InterestingEdgesVariable = edge_1.EdgeType.Reads | edge_1.EdgeType.Calls | edge_1.EdgeType.DefinesOnCall;
|
|
145
|
-
|
|
114
|
+
/* include read as this could print the function definition */
|
|
115
|
+
const InterestingEdgesFunction = edge_1.EdgeType.Reads | edge_1.EdgeType.Calls;
|
|
146
116
|
const InterestingEdgesTargets = edge_1.EdgeType.SideEffectOnCall;
|
|
147
|
-
function getDefinitionArguments(def, dfg) {
|
|
148
|
-
return dfg.outgoingEdges(def)?.entries().filter(([, e]) => edge_1.DfEdge.includesType(e, edge_1.EdgeType.DefinedBy))
|
|
149
|
-
.map(([target]) => target).toArray() ?? [];
|
|
150
|
-
}
|
|
151
117
|
/**
|
|
152
118
|
* Whether the node names a parameter of a function whose signature something outside the code fixes: a package
|
|
153
119
|
* lifecycle hook R calls with a set of arguments, or an S3 method a generic dispatches to. Such a parameter is
|
|
@@ -155,20 +121,19 @@ function getDefinitionArguments(def, dfg) {
|
|
|
155
121
|
*/
|
|
156
122
|
function hasContractedSignature(node, ast, config, pkg, called, ctx) {
|
|
157
123
|
let inParameter = false;
|
|
158
|
-
for (
|
|
159
|
-
const parent = ast.idMap.get(up);
|
|
160
|
-
if (parent === undefined) {
|
|
161
|
-
return false;
|
|
162
|
-
}
|
|
124
|
+
for (const parent of model_1.RNode.iterateParents(node, ast.idMap)) {
|
|
163
125
|
inParameter ||= r_parameter_1.RParameter.is(parent);
|
|
164
126
|
if (r_function_definition_1.RFunctionDefinition.is(parent)) {
|
|
165
127
|
/* the name the definition is bound under is what reaches it, so that is what the contract goes by */
|
|
166
|
-
const bound =
|
|
128
|
+
const bound = model_1.RNode.directParent(parent, ast.idMap);
|
|
129
|
+
/* a function handed to a call is called by it, like a `tryCatch` handler or an `lapply` callback */
|
|
130
|
+
if (r_argument_1.RArgument.is(bound)) {
|
|
131
|
+
return inParameter;
|
|
132
|
+
}
|
|
167
133
|
const name = r_binary_op_1.RBinaryOp.is(bound) ? bound.lhs.lexeme
|
|
168
134
|
: r_function_call_1.RFunctionCall.is(bound) && bound.arguments[0] !== r_function_call_1.EmptyArgument ? bound.arguments[0]?.lexeme : undefined;
|
|
169
135
|
return inParameter && name !== undefined && isConsideredUsed(name, config, pkg, called, ctx);
|
|
170
136
|
}
|
|
171
|
-
up = parent.info.parent;
|
|
172
137
|
}
|
|
173
138
|
return false;
|
|
174
139
|
}
|
|
@@ -199,6 +164,17 @@ function getAssignmentPeer(node, ast) {
|
|
|
199
164
|
}
|
|
200
165
|
return undefined;
|
|
201
166
|
}
|
|
167
|
+
function yieldsFunctionValue(node, ast, dfg) {
|
|
168
|
+
const path = new Set([node.info.id]);
|
|
169
|
+
for (const up of model_1.RNode.iterateParents(node, ast.idMap)) {
|
|
170
|
+
if (r_function_definition_1.RFunctionDefinition.is(up)) {
|
|
171
|
+
const fn = dfg.getVertex(up.info.id);
|
|
172
|
+
return vertex_1.DfgVertex.isFunctionDefinition(fn) && fn.exitPoints.some(e => path.has(e.nodeId));
|
|
173
|
+
}
|
|
174
|
+
path.add(up.info.id);
|
|
175
|
+
}
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
202
178
|
function isStandaloneStatement(node, ast) {
|
|
203
179
|
if (node.info.role !== "el-c" /* RoleInParent.ExpressionListChild */) {
|
|
204
180
|
return false;
|
|
@@ -210,6 +186,13 @@ function isStandaloneStatement(node, ast) {
|
|
|
210
186
|
const opening = r_expression_list_1.RExpressionList.groupStart(parent);
|
|
211
187
|
return opening === undefined || opening.lexeme === '{';
|
|
212
188
|
}
|
|
189
|
+
/** Whether the definition's value has obligations, like side effects, so the definition cannot be removed. */
|
|
190
|
+
function hasImportantArgs(definedBys, df, binds) {
|
|
191
|
+
const dfg = df.graph;
|
|
192
|
+
return definedBys.some(d => dfg.unknownSideEffects.has(d) || doesMoreThanCompute(d, df, binds)
|
|
193
|
+
|| dfg.edgesTo(d).values().some(edge => edge_1.DfEdge.includesType(edge, InterestingEdgesTargets))
|
|
194
|
+
|| dfg.edgesFrom(d).entries().some(([target, edge]) => edge_1.DfEdge.includesType(edge, InterestingEdgesTargets) || dfg.unknownSideEffects.has(target)));
|
|
195
|
+
}
|
|
213
196
|
function buildQuickFix(variable, df, ast) {
|
|
214
197
|
const dfg = df.graph;
|
|
215
198
|
// first we check whether any of the 'Defined by' targets have any obligations - if so, we can not remove the definition
|
|
@@ -218,41 +201,27 @@ function buildQuickFix(variable, df, ast) {
|
|
|
218
201
|
// this is an access or a for variable, we can not remove it currently
|
|
219
202
|
return undefined;
|
|
220
203
|
}
|
|
221
|
-
const definedBys =
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|| definedBys.flatMap(e => Array.from(dfg.edgesFrom(e)))
|
|
225
|
-
.some(([target, e]) => {
|
|
226
|
-
return edge_1.DfEdge.includesType(e, InterestingEdgesTargets) || dfg.unknownSideEffects.has(target);
|
|
227
|
-
});
|
|
228
|
-
if (hasImportantArgs) {
|
|
229
|
-
return undefined; // we can not remove this definition, it has important arguments
|
|
204
|
+
const definedBys = (0, frame_reflection_1.edgeTargets)(dfg, variable.info.id, edge_1.EdgeType.DefinedBy);
|
|
205
|
+
if (hasImportantArgs(definedBys, df, variable.info.parent)) {
|
|
206
|
+
return undefined;
|
|
230
207
|
}
|
|
231
208
|
const assignment = getAssignmentPeer(variable, ast);
|
|
232
|
-
const totalRangeToRemove = range_1.SourceLocation.merge([
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
variable.info.fullRange ?? variable.location]);
|
|
209
|
+
const totalRangeToRemove = range_1.SourceLocation.merge([
|
|
210
|
+
...definedBys.map(d => range_1.SourceLocation.fromNode(ast.idMap.get(d))),
|
|
211
|
+
range_1.SourceLocation.fromNode(assignment?.value),
|
|
212
|
+
variable.info.fullRange ?? variable.location
|
|
213
|
+
]);
|
|
238
214
|
if (totalRangeToRemove === undefined) {
|
|
239
215
|
/* a fix that names no place cannot be carried out, so none is offered */
|
|
240
216
|
return undefined;
|
|
241
217
|
}
|
|
242
218
|
const description = `Remove unused definition of \`${variable.lexeme}\``;
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
const replacement = assignment !== undefined ? assignment.value.info.fullLexeme ?? assignment.value.lexeme : undefined;
|
|
247
|
-
if (replacement === undefined) {
|
|
248
|
-
return undefined;
|
|
219
|
+
const statement = assignment?.statement ?? variable;
|
|
220
|
+
if (isStandaloneStatement(statement, ast)) {
|
|
221
|
+
return yieldsFunctionValue(statement, ast, dfg) ? undefined : [{ type: 'remove', loc: totalRangeToRemove, description }];
|
|
249
222
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
loc: totalRangeToRemove,
|
|
253
|
-
replacement,
|
|
254
|
-
description
|
|
255
|
-
}];
|
|
223
|
+
const replacement = assignment?.value.info.fullLexeme ?? assignment?.value.lexeme;
|
|
224
|
+
return replacement === undefined ? undefined : [{ type: 'replace', loc: totalRangeToRemove, replacement, description }];
|
|
256
225
|
}
|
|
257
226
|
/**
|
|
258
227
|
* consider `x <- function() ...` if we say `x` is unused and propose to remove everything, there should be no separate quick fix for the function definition
|
|
@@ -270,77 +239,68 @@ function onlyKeepSupersetOfUnused(elements) {
|
|
|
270
239
|
/** Whether the node sits inside a promise, i.e. an argument default value or a `delayedAssign` body, which may never run. */
|
|
271
240
|
function isWithinPromise(node, idMap) {
|
|
272
241
|
let child = node;
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
if (parent === undefined) {
|
|
277
|
-
return false;
|
|
278
|
-
}
|
|
279
|
-
if (r_parameter_1.RParameter.is(parent) && parent.defaultValue?.info.id === child.info.id) {
|
|
280
|
-
return true;
|
|
281
|
-
}
|
|
282
|
-
if (r_function_call_1.RFunctionCall.isNamed(parent) && identifier_1.Identifier.getName(parent.functionName.content) === 'delayedAssign') {
|
|
242
|
+
for (const parent of model_1.RNode.iterateParents(node, idMap)) {
|
|
243
|
+
if ((r_parameter_1.RParameter.is(parent) && parent.defaultValue?.info.id === child.info.id)
|
|
244
|
+
|| (r_function_call_1.RFunctionCall.isNamed(parent) && identifier_1.Identifier.getName(parent.functionName.content) === 'delayedAssign')) {
|
|
283
245
|
return true;
|
|
284
246
|
}
|
|
285
247
|
child = parent;
|
|
286
|
-
parentId = parent.info.parent;
|
|
287
248
|
}
|
|
288
249
|
return false;
|
|
289
250
|
}
|
|
290
251
|
exports.UNUSED_DEFINITION = {
|
|
291
|
-
/* this can be done better once we have types */
|
|
292
252
|
createSearch: config => flowr_search_builder_1.Q.all().filter(config.includeFunctionDefinitions ? flowr_search_filters_1.F.or(vertex_1.VertexType.VariableDefinition, vertex_1.VertexType.FunctionDefinition) : vertex_1.VertexType.VariableDefinition),
|
|
293
253
|
processSearchResult: async (elements, config, data) => {
|
|
294
254
|
const normalize = await data.normalize();
|
|
295
255
|
const dataflow = await data.dataflow();
|
|
256
|
+
const graph = dataflow.graph;
|
|
257
|
+
const ctx = data.inspectContext();
|
|
296
258
|
const packageInfo = collectPackageInfo(data);
|
|
297
|
-
const calledNames = collectCalledNames(
|
|
259
|
+
const calledNames = collectCalledNames(graph);
|
|
298
260
|
const s3GenericParams = collectS3GenericParameterIds(normalize);
|
|
299
261
|
const metadata = {
|
|
300
262
|
totalConsidered: 0
|
|
301
263
|
};
|
|
264
|
+
const isUnused = (node) => {
|
|
265
|
+
if (isWithinPromise(node, normalize.idMap)) {
|
|
266
|
+
return false;
|
|
267
|
+
}
|
|
268
|
+
const vertex = graph.getVertex(node.info.id);
|
|
269
|
+
if (!vertex || (!vertex_1.DfgVertex.isVariableDefinition(vertex) && vertex_1.DfgVertex.isFunctionDefinition(vertex) && !config.includeFunctionDefinitions)) {
|
|
270
|
+
return false;
|
|
271
|
+
}
|
|
272
|
+
if (s3GenericParams.has(node.info.id)) {
|
|
273
|
+
return false;
|
|
274
|
+
}
|
|
275
|
+
// an anonymous dispatcher passed to setGeneric()/new_generic() runs on every dispatch, so it is used
|
|
276
|
+
if (vertex_1.DfgVertex.isFunctionDefinition(vertex) && r_function_definition_1.RFunctionDefinition.is(node) && isGenericDispatcherOnlyBody(node.body)) {
|
|
277
|
+
return false;
|
|
278
|
+
}
|
|
279
|
+
if (isConsideredUsed(node.lexeme, config, packageInfo, calledNames, ctx)) {
|
|
280
|
+
return false;
|
|
281
|
+
}
|
|
282
|
+
/* what calls a hook or dispatches to a method decides its parameters, so they are no more the
|
|
283
|
+
author's to drop than the name is: `print.foo` keeps the `x` the generic hands it */
|
|
284
|
+
if (hasContractedSignature(node, normalize, config, packageInfo, calledNames, ctx)) {
|
|
285
|
+
return false;
|
|
286
|
+
}
|
|
287
|
+
const interestedIn = vertex_1.DfgVertex.isVariableDefinition(vertex) ? InterestingEdgesVariable : InterestingEdgesFunction;
|
|
288
|
+
return !graph.edgesTo(vertex.id).values().some(e => edge_1.DfEdge.includesType(e, interestedIn));
|
|
289
|
+
};
|
|
302
290
|
return {
|
|
303
|
-
results: onlyKeepSupersetOfUnused(elements.getElements().flatMap(
|
|
291
|
+
results: onlyKeepSupersetOfUnused(elements.getElements().flatMap(({ node }) => {
|
|
304
292
|
metadata.totalConsidered++;
|
|
305
|
-
if (
|
|
293
|
+
if (!isUnused(node)) {
|
|
306
294
|
return [];
|
|
307
295
|
}
|
|
308
|
-
const dfgVertex = dataflow.graph.getVertex(element.node.info.id);
|
|
309
|
-
if (!dfgVertex || (!vertex_1.DfgVertex.isVariableDefinition(dfgVertex)
|
|
310
|
-
&& vertex_1.DfgVertex.isFunctionDefinition(dfgVertex) && !config.includeFunctionDefinitions)) {
|
|
311
|
-
return undefined;
|
|
312
|
-
}
|
|
313
|
-
if (s3GenericParams.has(element.node.info.id)) {
|
|
314
|
-
return undefined;
|
|
315
|
-
}
|
|
316
|
-
// an anonymous dispatcher passed to setGeneric()/new_generic() runs on every dispatch, so it is used
|
|
317
|
-
if (vertex_1.DfgVertex.isFunctionDefinition(dfgVertex) && r_function_definition_1.RFunctionDefinition.is(element.node) && isGenericDispatcherOnlyBody(element.node.body)) {
|
|
318
|
-
return undefined;
|
|
319
|
-
}
|
|
320
|
-
if (isConsideredUsed(element.node.lexeme, config, packageInfo, calledNames, data.inspectContext())) {
|
|
321
|
-
return undefined;
|
|
322
|
-
}
|
|
323
|
-
/* what calls a hook or dispatches to a method decides its parameters, so they are no more the
|
|
324
|
-
author's to drop than the name is: `print.foo` keeps the `x` the generic hands it */
|
|
325
|
-
if (hasContractedSignature(element.node, normalize, config, packageInfo, calledNames, data.inspectContext())) {
|
|
326
|
-
return undefined;
|
|
327
|
-
}
|
|
328
|
-
const ingoingEdges = dataflow.graph.ingoingEdges(dfgVertex.id);
|
|
329
|
-
const interestedIn = vertex_1.DfgVertex.isVariableDefinition(dfgVertex) ? InterestingEdgesVariable : InterestingEdgesFunction;
|
|
330
|
-
const ingoingInteresting = ingoingEdges?.values().some(e => edge_1.DfEdge.includesType(e, interestedIn));
|
|
331
|
-
if (ingoingInteresting) {
|
|
332
|
-
return undefined;
|
|
333
|
-
}
|
|
334
|
-
// found an unused definition
|
|
335
|
-
const variableName = element.node.lexeme;
|
|
336
296
|
return [{
|
|
337
297
|
certainty: linter_format_1.LintingResultCertainty.Uncertain,
|
|
338
|
-
variableName,
|
|
339
|
-
involvedId:
|
|
340
|
-
loc: range_1.SourceLocation.fromNode(
|
|
341
|
-
quickFix: buildQuickFix(
|
|
298
|
+
variableName: node.lexeme,
|
|
299
|
+
involvedId: node.info.id,
|
|
300
|
+
loc: range_1.SourceLocation.fromNode(node) ?? range_1.SourceLocation.invalid(),
|
|
301
|
+
quickFix: buildQuickFix(node, dataflow, normalize)
|
|
342
302
|
}];
|
|
343
|
-
})
|
|
303
|
+
})),
|
|
344
304
|
'.meta': metadata
|
|
345
305
|
};
|
|
346
306
|
},
|
|
@@ -3,6 +3,7 @@ import type { MergeableRecord } from '../../util/objects';
|
|
|
3
3
|
import { LintingRuleTag } from '../linter-tags';
|
|
4
4
|
import { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id';
|
|
5
5
|
import type { ParentInformation } from '../../r-bridge/lang-4.x/ast/model/processing/decorate';
|
|
6
|
+
import type { PackageSignatureSource } from '../../project/sigdb/reader';
|
|
6
7
|
export interface UnusedImportResult extends LintingResult {
|
|
7
8
|
/** the package the flagged call attaches */
|
|
8
9
|
readonly package: string;
|
|
@@ -23,6 +24,8 @@ export interface UnusedImportMetadata extends MergeableRecord {
|
|
|
23
24
|
/** the attaches reported as unused */
|
|
24
25
|
totalUnused: number;
|
|
25
26
|
}
|
|
27
|
+
/** The packages `name` imports from apart from base R, whose exports it may re-export. */
|
|
28
|
+
export declare function nonBaseImports(src: PackageSignatureSource, name: string, version?: string): string[];
|
|
26
29
|
/**
|
|
27
30
|
* Flags packages that are attached but never used, so dropping the `library`/`require` call would leave the code running
|
|
28
31
|
* just the same. A package counts as used as soon as any call resolves into it or anything reads one of its exports.
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UNUSED_IMPORT = void 0;
|
|
4
|
+
exports.nonBaseImports = nonBaseImports;
|
|
4
5
|
const linter_format_1 = require("../linter-format");
|
|
5
6
|
const range_1 = require("../../util/range");
|
|
6
7
|
const flowr_search_builder_1 = require("../../search/flowr-search-builder");
|
|
7
8
|
const linter_tags_1 = require("../linter-tags");
|
|
8
9
|
const df_helper_1 = require("../../dataflow/graph/df-helper");
|
|
10
|
+
const graph_1 = require("../../dataflow/graph/graph");
|
|
9
11
|
const edge_1 = require("../../dataflow/graph/edge");
|
|
10
12
|
const vertex_1 = require("../../dataflow/graph/vertex");
|
|
11
13
|
const identifier_1 = require("../../dataflow/environments/identifier");
|
|
@@ -14,14 +16,11 @@ const search_enrichers_1 = require("../../search/search-executor/search-enricher
|
|
|
14
16
|
const dependencies_query_format_1 = require("../../queries/catalog/dependencies-query/dependencies-query-format");
|
|
15
17
|
const library_functions_1 = require("../../queries/catalog/dependencies-query/function-info/library-functions");
|
|
16
18
|
const r_expression_list_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-expression-list");
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
*/
|
|
23
|
-
function attachesPackage(info) {
|
|
24
|
-
return library_functions_1.LibraryFunctions.some(loader => loader.attaches && identifier_1.Identifier.matches(loader.name, info.functionName));
|
|
19
|
+
const model_1 = require("../../r-bridge/lang-4.x/ast/model/model");
|
|
20
|
+
const built_in_proc_name_1 = require("../../dataflow/environments/built-in-proc-name");
|
|
21
|
+
/** The packages `name` imports from apart from base R, whose exports it may re-export. */
|
|
22
|
+
function nonBaseImports(src, name, version) {
|
|
23
|
+
return src.dependencies(name, version)?.filter(d => d.type === 1 /* DepType.Imports */ && !src.isBaseR(d.name)).map(d => d.name) ?? [];
|
|
25
24
|
}
|
|
26
25
|
/** whether the call reaches no definition of the analyzed code itself */
|
|
27
26
|
function isUnbound(graph, id) {
|
|
@@ -30,23 +29,18 @@ function isUnbound(graph, id) {
|
|
|
30
29
|
}
|
|
31
30
|
/** whether removing the call would empty a slot the syntax requires, as in an unbraced `if(c) library(x)` */
|
|
32
31
|
function removalWouldBreakSyntax(node, idMap) {
|
|
33
|
-
const parent =
|
|
32
|
+
const parent = model_1.RNode.directParent(node, idMap);
|
|
34
33
|
return r_expression_list_1.RExpressionList.isImplicit(parent) && parent.children.length === 1 && parent.info.role !== "root" /* RoleInParent.Root */;
|
|
35
34
|
}
|
|
36
35
|
/** whether anything reads out of the attach itself */
|
|
37
36
|
function isReadFrom(graph, id) {
|
|
38
|
-
|
|
39
|
-
if (edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Reads)) {
|
|
40
|
-
return true;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return false;
|
|
37
|
+
return graph.edgesTo(id).values().some(edge => edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Reads));
|
|
44
38
|
}
|
|
45
39
|
/**
|
|
46
40
|
* Which of the `attachments` the program never makes use of. A call that resolves names its package outright;
|
|
47
41
|
* one that does not bind yet (a call in a function body) keeps every attached package exporting its name.
|
|
48
42
|
*/
|
|
49
|
-
function unusedPackages(attachments, graph) {
|
|
43
|
+
function unusedPackages(attachments, graph, src) {
|
|
50
44
|
const pending = new Set(attachments.map(a => a.name));
|
|
51
45
|
const unbound = new Set();
|
|
52
46
|
for (const [id, qualified] of df_helper_1.Dataflow.qualifyAll(graph)) {
|
|
@@ -69,15 +63,10 @@ function unusedPackages(attachments, graph) {
|
|
|
69
63
|
}
|
|
70
64
|
}
|
|
71
65
|
}
|
|
72
|
-
for (const { name, callable } of attachments) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
for (const call of unbound) {
|
|
77
|
-
if (callable.has(call)) {
|
|
78
|
-
pending.delete(name);
|
|
79
|
-
break;
|
|
80
|
-
}
|
|
66
|
+
for (const { name, callable, imports } of attachments) {
|
|
67
|
+
const usesPackage = (call) => callable.has(call) || src.packagesExporting(call).some(p => imports.has(p));
|
|
68
|
+
if (pending.has(name) && unbound.values().some(usesPackage)) {
|
|
69
|
+
pending.delete(name);
|
|
81
70
|
}
|
|
82
71
|
}
|
|
83
72
|
return pending;
|
|
@@ -99,31 +88,21 @@ exports.UNUSED_IMPORT = {
|
|
|
99
88
|
return { results: [], '.meta': metadata };
|
|
100
89
|
}
|
|
101
90
|
const whitelist = new Set(config.whitelist);
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
continue;
|
|
107
|
-
}
|
|
108
|
-
const known = attachedBy.get(info.nodeId);
|
|
109
|
-
if (known === undefined) {
|
|
110
|
-
attachedBy.set(info.nodeId, [info]);
|
|
111
|
-
}
|
|
112
|
-
else {
|
|
113
|
-
known.push(info);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
91
|
+
const src = deps.signatures().sources();
|
|
92
|
+
/* one call may name more than one package, so the query can report it several times under the same id */
|
|
93
|
+
const libraryInfos = elements.enrichmentContent(search_enrichers_1.Enrichment.QueryData).queries['dependencies'].library;
|
|
94
|
+
const attachedBy = Map.groupBy(libraryInfos.filter(info => info.nodeId !== undefined), info => info.nodeId);
|
|
116
95
|
const attachments = [];
|
|
117
96
|
const seen = new Set();
|
|
118
97
|
for (const { node } of elements.getElements()) {
|
|
119
98
|
const infos = attachedBy.get(node.info.id);
|
|
120
|
-
if (infos === undefined || seen.has(node.info.id) || !attachesPackage(infos[0])) {
|
|
99
|
+
if (infos === undefined || seen.has(node.info.id) || !(0, library_functions_1.attachesPackage)(infos[0])) {
|
|
121
100
|
continue;
|
|
122
101
|
}
|
|
123
102
|
seen.add(node.info.id);
|
|
124
103
|
metadata.totalConsidered++;
|
|
125
104
|
if (infos.length > 1) {
|
|
126
|
-
|
|
105
|
+
/* a dynamic attach, e.g. `for(p in pkgs) library(p, character.only = TRUE)`; naming one of them would be a guess */
|
|
127
106
|
metadata.totalMultiPackage++;
|
|
128
107
|
continue;
|
|
129
108
|
}
|
|
@@ -150,7 +129,8 @@ exports.UNUSED_IMPORT = {
|
|
|
150
129
|
loc,
|
|
151
130
|
name,
|
|
152
131
|
version: pkg.resolvedVersion,
|
|
153
|
-
callable: new Set(pkg.namespaceInfo?.callable)
|
|
132
|
+
callable: new Set(pkg.namespaceInfo?.callable),
|
|
133
|
+
imports: new Set(nonBaseImports(src, name, pkg.resolvedVersion))
|
|
154
134
|
});
|
|
155
135
|
}
|
|
156
136
|
if (attachments.length === 0) {
|
|
@@ -158,7 +138,9 @@ exports.UNUSED_IMPORT = {
|
|
|
158
138
|
}
|
|
159
139
|
const { graph } = await data.dataflow();
|
|
160
140
|
const idMap = (await data.normalize()).idMap;
|
|
161
|
-
|
|
141
|
+
/* code a `source()` flowR could not resolve runs as well and may use any attached package */
|
|
142
|
+
const unseen = graph.unknownSideEffects.values().some(e => vertex_1.DfgVertex.hasOrigin(graph.getVertex(graph_1.UnknownSideEffect.id(e)), built_in_proc_name_1.BuiltInProcName.Source));
|
|
143
|
+
const unused = unseen ? new Set() : unusedPackages(attachments, graph, src);
|
|
162
144
|
const results = attachments.filter(({ id, name }) => unused.has(name) && !isReadFrom(graph, id)).map(({ id, node, loc, name, version }) => ({
|
|
163
145
|
certainty: linter_format_1.LintingResultCertainty.Uncertain,
|
|
164
146
|
involvedId: id,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eagleoutice/flowr",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.16.0",
|
|
4
4
|
"description": "Static Dataflow Analyzer and Program Slicer for the R Programming Language",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=22"
|
|
@@ -26,7 +26,10 @@
|
|
|
26
26
|
"author": "Florian Sihler",
|
|
27
27
|
"license": "ISC",
|
|
28
28
|
"overrides": {
|
|
29
|
-
"lodash.isequal": "npm:fast-deep-equal@^3.1.3"
|
|
29
|
+
"lodash.isequal": "npm:fast-deep-equal@^3.1.3",
|
|
30
|
+
"get-uri": {
|
|
31
|
+
"basic-ftp": "6.2.3"
|
|
32
|
+
}
|
|
30
33
|
},
|
|
31
34
|
"dependencies": {
|
|
32
35
|
"@davisvaughan/tree-sitter-r": "^1.2.0",
|
|
@@ -188,9 +188,13 @@ function qualifyInBackground(graph) {
|
|
|
188
188
|
df_helper_1.Dataflow.qualify(calls[next], graph, false);
|
|
189
189
|
}
|
|
190
190
|
if (next < calls.length) {
|
|
191
|
-
|
|
191
|
+
later(step);
|
|
192
192
|
}
|
|
193
193
|
};
|
|
194
|
-
|
|
194
|
+
later(step);
|
|
195
|
+
}
|
|
196
|
+
/** an unreferenced timer where there are such (node), a plain one elsewhere (the browser returns a number) */
|
|
197
|
+
function later(step) {
|
|
198
|
+
setTimeout(step, 0).unref?.();
|
|
195
199
|
}
|
|
196
200
|
//# sourceMappingURL=flowr-analyzer.js.map
|
|
@@ -8,9 +8,9 @@ export declare class FlowrJupyterFile extends FlowrFile {
|
|
|
8
8
|
private readonly wrapped;
|
|
9
9
|
/**
|
|
10
10
|
* Prefer the static {@link FlowrJupyterFile.from} method
|
|
11
|
-
* @param
|
|
11
|
+
* @param wrapped - the file to load as Jupyter
|
|
12
12
|
*/
|
|
13
|
-
constructor(
|
|
13
|
+
constructor(wrapped: FlowrFileProvider<string>);
|
|
14
14
|
/**
|
|
15
15
|
* Loads and parses the content of the wrapped file.
|
|
16
16
|
* @returns RmdInfo
|
|
@@ -10,11 +10,11 @@ class FlowrJupyterFile extends flowr_file_1.FlowrFile {
|
|
|
10
10
|
wrapped;
|
|
11
11
|
/**
|
|
12
12
|
* Prefer the static {@link FlowrJupyterFile.from} method
|
|
13
|
-
* @param
|
|
13
|
+
* @param wrapped - the file to load as Jupyter
|
|
14
14
|
*/
|
|
15
|
-
constructor(
|
|
16
|
-
super(
|
|
17
|
-
this.wrapped =
|
|
15
|
+
constructor(wrapped) {
|
|
16
|
+
super(wrapped.path(), wrapped.roles ? [...wrapped.roles, flowr_file_1.FileRole.Source] : [flowr_file_1.FileRole.Source]);
|
|
17
|
+
this.wrapped = wrapped;
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
20
|
* Loads and parses the content of the wrapped file.
|
|
@@ -37,14 +37,10 @@ class FlowrJupyterFile extends flowr_file_1.FlowrFile {
|
|
|
37
37
|
}
|
|
38
38
|
exports.FlowrJupyterFile = FlowrJupyterFile;
|
|
39
39
|
function loadJupyter(content) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
return typeof cell.source === 'object' ? cell.source.map(s => `# ${s}`).join('') : `# ${cell.source}`;
|
|
47
|
-
}
|
|
40
|
+
return JSON.parse(content).cells.map(cell => {
|
|
41
|
+
const source = typeof cell.source === 'object' ? cell.source.join('') : cell.source;
|
|
42
|
+
/* every line of a text cell becomes a comment, whether the notebook stores the cell as lines or as one string */
|
|
43
|
+
return cell.cell_type === 'code' ? source : source.replace(/^/gm, '# ');
|
|
48
44
|
}).join('\n');
|
|
49
45
|
}
|
|
50
46
|
//# sourceMappingURL=flowr-jupyter-file.js.map
|