@eagleoutice/flowr 2.14.0 → 2.14.1
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 +39 -28
- package/benchmark/calibration.d.ts +13 -11
- package/benchmark/calibration.js +25 -26
- package/benchmark/slicer.d.ts +2 -1
- package/benchmark/slicer.js +6 -3
- package/cli/benchmark-app.js +4 -1
- package/cli/benchmark-helper-app.d.ts +1 -0
- package/cli/benchmark-helper-app.js +2 -2
- package/cli/common/options.d.ts +5 -0
- package/cli/common/options.js +1 -0
- package/cli/common/scripts-info.d.ts +5 -0
- package/cli/repl/execute.d.ts +2 -2
- package/cli/repl/execute.js +2 -2
- package/config.js +5 -6
- package/dataflow/environments/apply-kill.js +1 -1
- package/dataflow/environments/built-in-props.d.ts +6 -2
- package/dataflow/environments/built-in-props.js +5 -1
- package/dataflow/environments/default-builtin-config.d.ts +76 -1
- package/dataflow/environments/default-builtin-config.js +30 -5
- package/dataflow/environments/environment.d.ts +9 -1
- package/dataflow/environments/environment.js +25 -7
- package/dataflow/environments/identifier.d.ts +1 -0
- package/dataflow/environments/query-fn-props.d.ts +6 -0
- package/dataflow/environments/query-fn-props.js +20 -0
- package/dataflow/environments/resolve-by-name.js +14 -2
- package/dataflow/eval/resolve/resolve-operators.js +1 -1
- package/dataflow/eval/resolve/resolve-working-directory.d.ts +1 -1
- package/dataflow/eval/resolve/resolve-working-directory.js +1 -2
- package/dataflow/fn/exceptions-of-function.d.ts +3 -1
- package/dataflow/fn/exceptions-of-function.js +85 -38
- package/dataflow/fn/strict-function.d.ts +40 -0
- package/dataflow/fn/strict-function.js +337 -0
- package/dataflow/graph/df-helper.d.ts +9 -1
- package/dataflow/graph/df-helper.js +19 -3
- package/dataflow/graph/graph.d.ts +28 -2
- package/dataflow/graph/graph.js +59 -2
- package/dataflow/info.d.ts +26 -0
- package/dataflow/info.js +28 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-rm.d.ts +1 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +27 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-source.js +1 -1
- package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +29 -8
- package/documentation/wiki-core.js +1 -1
- package/documentation/wiki-dataflow-graph.js +1 -0
- package/documentation/wiki-linter.js +1 -0
- package/documentation/wiki-query.js +53 -0
- package/linter/linter-output.js +1 -1
- package/linter/linter-rules.d.ts +24 -0
- package/linter/linter-rules.js +3 -1
- package/linter/rules/network-functions.d.ts +1 -1
- package/linter/rules/unclosed-connection.d.ts +44 -0
- package/linter/rules/unclosed-connection.js +200 -0
- package/package.json +4 -7
- package/project/dependency-version-space.d.ts +3 -3
- package/project/dependency-version-space.js +2 -2
- package/project/plugins/file-plugins/files/flowr-description-file.d.ts +1 -1
- package/project/plugins/file-plugins/files/flowr-description-file.js +1 -1
- package/project/plugins/file-plugins/files/flowr-namespace-file.d.ts +1 -1
- package/project/plugins/file-plugins/files/flowr-namespace-file.js +1 -1
- package/project/plugins/file-plugins/files/flowr-news-file.d.ts +1 -1
- package/project/plugins/file-plugins/files/flowr-news-file.js +1 -1
- package/project/plugins/file-plugins/files/flowr-rda-file.d.ts +1 -1
- package/project/plugins/file-plugins/files/flowr-rda-file.js +1 -1
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.d.ts +5 -5
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +33 -6
- package/project/plugins/project-discovery/flowr-analyzer-project-discovery-plugin.js +2 -2
- package/project/sigdb/manifest.d.ts +3 -1
- package/project/sigdb/manifest.js +50 -9
- package/project/sigdb/reader.js +1 -1
- package/project/sigdb/schema.d.ts +2 -2
- package/project/sigdb/schema.js +2 -2
- package/queries/catalog/dependencies-query/link-devices.js +2 -8
- package/queries/catalog/inspect-exceptions-query/inspect-exception-query-executor.js +2 -1
- package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-executor.js +1 -0
- package/queries/catalog/inspect-strictness-query/inspect-strictness-query-executor.d.ts +6 -0
- package/queries/catalog/inspect-strictness-query/inspect-strictness-query-executor.js +25 -0
- package/queries/catalog/inspect-strictness-query/inspect-strictness-query-format.d.ts +31 -0
- package/queries/catalog/inspect-strictness-query/inspect-strictness-query-format.js +56 -0
- package/queries/catalog/slice-query-options.d.ts +1 -1
- package/queries/catalog/slice-query-options.js +1 -1
- package/queries/query-function-filter.d.ts +8 -2
- package/queries/query-function-filter.js +11 -1
- package/queries/query.d.ts +11 -1
- package/queries/query.js +2 -0
- package/r-bridge/lang-4.x/ast/model/model.d.ts +4 -4
- package/r-bridge/lang-4.x/ast/model/model.js +4 -4
- package/search/flowr-search-filters.js +1 -13
- package/slicing/criterion/parse.d.ts +2 -2
- package/slicing/criterion/parse.js +2 -2
- package/slicing/static/fingerprint.js +1 -1
- package/util/objects.d.ts +12 -0
- package/util/objects.js +48 -0
- package/util/simple-df/dfg-ascii.js +14 -3
- package/util/text/name-rank.d.ts +1 -1
- package/util/text/name-rank.js +1 -1
- package/util/version.js +1 -1
package/dataflow/info.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DataflowInformation = void 0;
|
|
3
|
+
exports.DataflowInformation = exports.ControlDependency = void 0;
|
|
4
4
|
exports.appendCds = appendCds;
|
|
5
5
|
exports.withCds = withCds;
|
|
6
6
|
exports.negateControlDependency = negateControlDependency;
|
|
@@ -15,10 +15,37 @@ exports.diffControlDependency = diffControlDependency;
|
|
|
15
15
|
exports.diffControlDependencies = diffControlDependencies;
|
|
16
16
|
const graph_1 = require("./graph/graph");
|
|
17
17
|
const assert_1 = require("../util/assert");
|
|
18
|
+
const model_1 = require("../r-bridge/lang-4.x/ast/model/model");
|
|
18
19
|
/** Whether the two control dependencies trigger on the same condition and branch. */
|
|
19
20
|
function sameControlDependency(a, b) {
|
|
20
21
|
return a.id === b.id && a.when === b.when;
|
|
21
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Utility functions to work with {@link ControlDependency|control dependencies}.
|
|
25
|
+
*/
|
|
26
|
+
exports.ControlDependency = {
|
|
27
|
+
name: 'ControlDependency',
|
|
28
|
+
/** Whether the two trigger on the same condition and branch. */
|
|
29
|
+
same: sameControlDependency,
|
|
30
|
+
/** @see {@link appendCds} */
|
|
31
|
+
append: appendCds,
|
|
32
|
+
/** @see {@link withCds} */
|
|
33
|
+
with: withCds,
|
|
34
|
+
/** @see {@link negateControlDependency} */
|
|
35
|
+
negate: negateControlDependency,
|
|
36
|
+
/** @see {@link happensInEveryBranch} */
|
|
37
|
+
happensInEveryBranch,
|
|
38
|
+
/** @see {@link happensInEveryBranchSet} */
|
|
39
|
+
happensInEveryBranchSet,
|
|
40
|
+
/** Whether the dependency stems from a loop, so what it guards may happen more than once. */
|
|
41
|
+
isIterated(cd, idMap) {
|
|
42
|
+
return cd.byIteration === true || model_1.RLoopConstructs.loopConstructTypes.has(idMap?.get(cd.id)?.type);
|
|
43
|
+
},
|
|
44
|
+
/** The dependencies of `a` that `b` is not subject to as well. */
|
|
45
|
+
minus(a, b) {
|
|
46
|
+
return a.filter(cd => !b.some(other => sameControlDependency(other, cd)));
|
|
47
|
+
}
|
|
48
|
+
};
|
|
22
49
|
/** Appends the given control dependencies to `target`, skipping the ones that are already in there. */
|
|
23
50
|
function appendCds(target, toAdd) {
|
|
24
51
|
if (!toAdd) {
|
|
@@ -7,5 +7,6 @@ import type { NodeId } from '../../../../../../r-bridge/lang-4.x/ast/model/proce
|
|
|
7
7
|
/**
|
|
8
8
|
* Process an `rm` call, marking the removed variables as {@link KillReference|killed} so the removal is
|
|
9
9
|
* carried to the enclosing scope even when it happens nested within a branch or block.
|
|
10
|
+
* As in R, the names to remove are not evaluated, so `rm(x)` does not read `x`.
|
|
10
11
|
*/
|
|
11
12
|
export declare function processRm<OtherInfo>(name: RSymbol<OtherInfo & ParentInformation>, args: readonly PotentiallyEmptyRArgument<OtherInfo & ParentInformation>[], rootId: NodeId, data: DataflowProcessorInformation<OtherInfo & ParentInformation>): DataflowInformation;
|
|
@@ -123,16 +123,42 @@ function removeFromCustomEnv(res, envir, targets, rootId, cds) {
|
|
|
123
123
|
const environment = (0, define_1.define)({ ...envir.envDef, definedAt: rootId, envState: newEnvState }, false, res.environment);
|
|
124
124
|
return { ...res, environment };
|
|
125
125
|
}
|
|
126
|
+
/** The arguments `rm` swallows with its `...`: they name what to remove instead of being evaluated. */
|
|
127
|
+
function nonStandardArguments(args) {
|
|
128
|
+
const indices = new Set();
|
|
129
|
+
for (const [i, arg] of args.entries()) {
|
|
130
|
+
if (arg !== r_function_call_1.EmptyArgument && (arg.name === undefined || (0, prefix_1.findByPrefixIfUnique)(arg.name.content, RmNamedFormals) === undefined)) {
|
|
131
|
+
indices.add(i);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return indices;
|
|
135
|
+
}
|
|
126
136
|
/**
|
|
127
137
|
* Process an `rm` call, marking the removed variables as {@link KillReference|killed} so the removal is
|
|
128
138
|
* carried to the enclosing scope even when it happens nested within a branch or block.
|
|
139
|
+
* As in R, the names to remove are not evaluated, so `rm(x)` does not read `x`.
|
|
129
140
|
*/
|
|
130
141
|
function processRm(name, args, rootId, data) {
|
|
131
142
|
if (args.length === 0) {
|
|
132
143
|
logger_1.dataflowLogger.warn('empty rm, skipping');
|
|
133
144
|
return (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: 'default' }).information;
|
|
134
145
|
}
|
|
135
|
-
const
|
|
146
|
+
const nse = nonStandardArguments(args);
|
|
147
|
+
const { information, processedArguments, fnRef } = (0, known_call_handling_1.processKnownFunctionCall)({
|
|
148
|
+
name, args, rootId, data,
|
|
149
|
+
origin: built_in_proc_name_1.BuiltInProcName.Rm,
|
|
150
|
+
/* an unevaluated name must not resolve against the environment */
|
|
151
|
+
patchData: (d, i) => nse.has(i) ? { ...d, environment: d.ctx.env.makeCleanEnv() } : d
|
|
152
|
+
});
|
|
153
|
+
(0, known_call_handling_1.markArgumentsAsNonStandardEvaluation)(information.graph, rootId, processedArguments, [...nse]);
|
|
154
|
+
/* the enclosing scope would link the unevaluated names, so they must not escape this call */
|
|
155
|
+
const evaluated = processedArguments.filter((p, i) => p !== undefined && !nse.has(i));
|
|
156
|
+
const res = {
|
|
157
|
+
...information,
|
|
158
|
+
in: [fnRef, ...evaluated.flatMap(p => p.in)],
|
|
159
|
+
out: evaluated.flatMap(p => p.out),
|
|
160
|
+
unknownReferences: evaluated.flatMap(p => p.unknownReferences)
|
|
161
|
+
};
|
|
136
162
|
const targets = collectRmTargets(args, data);
|
|
137
163
|
// `rm(x, envir=e)` removes from a tracked custom environment instead of the lexical scope
|
|
138
164
|
if (data.ctx.config.solver.trackEnvironments) {
|
|
@@ -194,7 +194,7 @@ function processSourceCall(name, args, rootId, data, config) {
|
|
|
194
194
|
* Otherwise, this can be an {@link RProjectFile} representing a standalone source file
|
|
195
195
|
*/
|
|
196
196
|
function sourceRequest(rootId, request, data, information, makeMaybe, getId, evaluatedByRoot = false) {
|
|
197
|
-
// parse, normalize and dataflow the sourced file
|
|
197
|
+
// parse, normalize, and dataflow the sourced file
|
|
198
198
|
let dataflow;
|
|
199
199
|
let fst;
|
|
200
200
|
let filePath;
|
|
@@ -96,6 +96,20 @@ function computeCallGraphSummaries(graph, own) {
|
|
|
96
96
|
* Only vertices created on demand (exports actually referenced) get an edge, keeping the graph small.
|
|
97
97
|
*/
|
|
98
98
|
function linkMaterializedExportsToLoaders(graph, environment) {
|
|
99
|
+
/* the attached namespaces hold every export of every package, far more than the graph ever materializes, so the
|
|
100
|
+
* cheap direction is to ask the graph first: an export earns an edge only if it is a vertex or the target of a
|
|
101
|
+
* `calls` edge. Both are read off the graph once here instead of per export binding. */
|
|
102
|
+
const called = new Set();
|
|
103
|
+
for (const [id] of graph.vertices(true)) {
|
|
104
|
+
called.add(id);
|
|
105
|
+
}
|
|
106
|
+
for (const [, outgoing] of graph.edges()) {
|
|
107
|
+
for (const [target, edge] of outgoing) {
|
|
108
|
+
if (edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Calls)) {
|
|
109
|
+
called.add(target);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
99
113
|
// export node id -> its loading `library()`/`use()` call, from the final environment
|
|
100
114
|
const loaders = new Map();
|
|
101
115
|
for (let e = environment.current; e !== undefined && !e.builtInEnv; e = e.parent) {
|
|
@@ -104,19 +118,16 @@ function linkMaterializedExportsToLoaders(graph, environment) {
|
|
|
104
118
|
}
|
|
105
119
|
for (const defs of e.memory.values()) {
|
|
106
120
|
for (const d of defs) {
|
|
107
|
-
if (!node_id_1.NodeId.isBuiltIn(d.definedAt)) {
|
|
121
|
+
if (called.has(d.nodeId) && !node_id_1.NodeId.isBuiltIn(d.definedAt)) {
|
|
108
122
|
loaders.set(d.nodeId, d.definedAt);
|
|
109
123
|
}
|
|
110
124
|
}
|
|
111
125
|
}
|
|
112
126
|
}
|
|
113
|
-
|
|
127
|
+
/* the loader targets are `library()` call ids, never export ids, so the edges added here never make a further
|
|
128
|
+
* export qualify -- the lazy checks this replaces could not have observed one either */
|
|
114
129
|
for (const [id, loadedAt] of loaders) {
|
|
115
|
-
|
|
116
|
-
|| [...graph.ingoingEdges(id)?.values() ?? []].some(e => edge_1.DfEdge.includesType(e, edge_1.EdgeType.Calls));
|
|
117
|
-
if (called) {
|
|
118
|
-
graph.addEdge(id, loadedAt, edge_1.EdgeType.Reads | edge_1.EdgeType.Calls);
|
|
119
|
-
}
|
|
130
|
+
graph.addEdge(id, loadedAt, edge_1.EdgeType.Reads | edge_1.EdgeType.Calls);
|
|
120
131
|
}
|
|
121
132
|
}
|
|
122
133
|
/** The packages (see {@link EnvType}) attached directly within a function body, i.e. its own `library()` calls. */
|
|
@@ -156,7 +167,17 @@ function escapedDefinitions() {
|
|
|
156
167
|
for (const e of escapeTargetFrames(fdef)) {
|
|
157
168
|
let escaped = perFrame.get(e.memory);
|
|
158
169
|
if (escaped === undefined) {
|
|
159
|
-
|
|
170
|
+
/* a package frame holds thousands of entries and keeps none of them, so this walks them in place
|
|
171
|
+
* rather than through a spread/flatMap/filter/map chain that allocates an array per step */
|
|
172
|
+
const collected = [];
|
|
173
|
+
for (const ds of e.memory.values()) {
|
|
174
|
+
for (const d of ds) {
|
|
175
|
+
if (!node_id_1.NodeId.isBuiltIn(d.nodeId)) {
|
|
176
|
+
collected.push(d.nodeId);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
escaped = collected;
|
|
160
181
|
perFrame.set(e.memory, escaped);
|
|
161
182
|
}
|
|
162
183
|
for (const d of escaped) {
|
|
@@ -476,7 +476,7 @@ to produce a new dataflow information to pass upwards in the fold. The ${ctx.lin
|
|
|
476
476
|
* the ${ctx.link(graph_1.DataflowGraph)} of the current subtree
|
|
477
477
|
* the currently active ${ctx.link('REnvironmentInformation')} as an abstraction of all active definitions linking to potential definition locations (see [Advanced R::Environments](https://adv-r.hadley.nz/environments.html))
|
|
478
478
|
* control flow information in ${ctx.link('DataflowCfgInformation')} which is used to enrich the dataflow information with control flow information
|
|
479
|
-
* sets of currently ingoing (read), outgoing (write) and unknown ${ctx.link('IdentifierReference')}s.
|
|
479
|
+
* sets of currently ingoing (read), outgoing (write), and unknown ${ctx.link('IdentifierReference')}s.
|
|
480
480
|
* and a set of ${ctx.link('KillReference')}s which tracks variables that go out of scope within the current subtree (e.g., due to \`rm\`). Just like the reference sets above, kills are carried upwards in the fold so that the enclosing scope (expression list, branch, loop, or function body) can apply the removal (via ${ctx.link('applyKills')}) at the correct location, even when the \`rm\` happens nested within a branch or block. This also covers clearing the whole environment with \`rm(list=ls())\` and conservatively handling removals whose target cannot be resolved statically.
|
|
481
481
|
|
|
482
482
|
While all of them are essentially empty when processing an “uninteresting leaf”, handling a constant is slightly more interesting with ${ctx.link(process_value_1.processValue)}:
|
|
@@ -194,6 +194,7 @@ In general the vertex provides you with information about
|
|
|
194
194
|
the _name_ of the called function, the passed _arguments_, and the _environment_ in which the call happens (if it is of importance).
|
|
195
195
|
|
|
196
196
|
Whenever flowR can determine which package a call resolves to — via a loaded \`library()\`/\`::\`, or via the always-available base-R packages taken from the ${ctx.linkPage('wiki/Signature Database', 'signature database')} — the mermaid visualization prints the **package-qualified name** in place of the bare one (e.g. \`acf\` is shown as \`stats::acf\`). To obtain this qualified identifier programmatically, prefer ${ctx.linkO(df_helper_1.Dataflow, 'qualify')} which, given only a call's id and its graph, reconstructs the \`pkg::fn\` identifier from the origins (and, for base R, from the exporting package) — the compact form of \`Identifier.toQualified\` (see the \`origin\` property below and the ${ctx.linkPage('wiki/Signature Database', 'signature database')} for where the base-R knowledge comes from).
|
|
197
|
+
The graph caches what it resolved, with and without the base-R step, and drops the cache whenever it changes, so asking twice costs a map lookup. If you want the qualified name of every call, use ${ctx.linkO(df_helper_1.Dataflow, 'qualifyAll')}: it walks the call vertices once and pays the (expensive) origin resolution once per call instead of once per ask.
|
|
197
198
|
|
|
198
199
|
However, the implementation reveals that it may hold an additional \`onlyBuiltin\` flag to indicate that the call is only calling builtin functions — however, this is only a flag to improve performance,
|
|
199
200
|
and it should not be relied on as it may under-approximate the actual calling targets (e.g., being \`false\` even though all calls resolve to builtins).
|
|
@@ -134,6 +134,7 @@ function(x) {
|
|
|
134
134
|
rule(knownParser, 'no-leaked-credentials', 'NoLeakedCredentialsConfig', 'NO_LEAKED_CREDENTIALS', 'lint-no-leaked-credentials', 'password <- "s3cr3t"', tagTypes);
|
|
135
135
|
rule(knownParser, 'undefined-symbol', 'UndefinedSymbolConfig', 'UNDEFINED_SYMBOL', 'lint-undefined-symbol', 'undefined_helper(42)', tagTypes);
|
|
136
136
|
rule(knownParser, 'syntactically-valid', 'SyntacticallyValidConfig', 'SYNTACTICALLY_VALID', 'lint-syntactically-valid', 'x <- c(1, 2', tagTypes);
|
|
137
|
+
rule(knownParser, 'unclosed-connection', 'UnclosedConnectionConfig', 'UNCLOSED_CONNECTION', 'lint-unclosed-connection', 'con <- file("data.csv")\nreadLines(con)', tagTypes);
|
|
137
138
|
function rule(parser, name, configType, ruleType, testfile, example, types) {
|
|
138
139
|
const rule = linter_rules_1.LintingRules[name];
|
|
139
140
|
const tags = rule.info.tags.toSorted((a, b) => {
|
|
@@ -35,6 +35,7 @@ const doc_maker_1 = require("./wiki-mk/doc-maker");
|
|
|
35
35
|
const files_query_executor_1 = require("../queries/catalog/files-query/files-query-executor");
|
|
36
36
|
const call_graph_query_executor_1 = require("../queries/catalog/call-graph-query/call-graph-query-executor");
|
|
37
37
|
const inspect_recursion_query_executor_1 = require("../queries/catalog/inspect-recursion-query/inspect-recursion-query-executor");
|
|
38
|
+
const inspect_strictness_query_executor_1 = require("../queries/catalog/inspect-strictness-query/inspect-strictness-query-executor");
|
|
38
39
|
const does_call_query_executor_1 = require("../queries/catalog/does-call-query/does-call-query-executor");
|
|
39
40
|
const inspect_exception_query_executor_1 = require("../queries/catalog/inspect-exceptions-query/inspect-exception-query-executor");
|
|
40
41
|
const slice_direction_1 = require("../util/slice-direction");
|
|
@@ -314,6 +315,58 @@ ${await (0, doc_query_1.showQuery)(shell, exampleCode, [{
|
|
|
314
315
|
`;
|
|
315
316
|
}
|
|
316
317
|
});
|
|
318
|
+
(0, doc_query_1.registerQueryDocumentation)('inspect-strictness', {
|
|
319
|
+
type: 'active',
|
|
320
|
+
shortDescription: 'Determine whether functions force their arguments',
|
|
321
|
+
functionName: inspect_strictness_query_executor_1.executeStrictnessQuery.name,
|
|
322
|
+
functionFile: '../queries/catalog/inspect-strictness-query/inspect-strictness-query-executor.ts',
|
|
323
|
+
buildExplanation: async (shell, ctx) => {
|
|
324
|
+
const exampleCode = 'f <- function(a, b, c) { print(a); if(runif(1) > .5) print(b); 42 }';
|
|
325
|
+
return `
|
|
326
|
+
R hands arguments over as promises, so a parameter is only evaluated once something reads it.
|
|
327
|
+
With this query you can find out which functions rely on that: a function is \`always\` strict if every call
|
|
328
|
+
forces every one of its parameters, \`never\` strict if no call forces all of them, and \`conditionally\`
|
|
329
|
+
strict if it depends on the path taken, on the caller, or on a function flowR could not resolve.
|
|
330
|
+
The result carries the same verdict per parameter, keyed by the id of the parameter's name.
|
|
331
|
+
|
|
332
|
+
Please note that a read that only hands the parameter to another function does not force it by itself.
|
|
333
|
+
Whether it is forced then depends on the function receiving it, which is resolved through the call graph.
|
|
334
|
+
A read within a nested function definition, within a loop, or under a condition leaves the parameter
|
|
335
|
+
\`conditionally\` strict, as does a call whose target flowR does not know.
|
|
336
|
+
|
|
337
|
+
What a built-in does with an argument is taken from what flowR states about it rather than from its name: an
|
|
338
|
+
argument declared as quoted or as one whose presence alone matters (\`quote(expr)\`, \`missing(x)\`) is never
|
|
339
|
+
evaluated, one declared as forced (\`force(x)\`) always is, and the calls that reach an argument only on the
|
|
340
|
+
way the run happens to take are the ones flowR hands to the processor saying so (\`switch\` picking a branch,
|
|
341
|
+
\`tryCatch\` reaching a handler, \`on.exit\` running at exit, and the short-circuiting \`&&\`/\`||\`).
|
|
342
|
+
A definition of your own shadowing such a name is judged by its own body instead, as R would.
|
|
343
|
+
A parameter read only in the default of another parameter is \`conditionally\` strict, as that default is
|
|
344
|
+
evaluated only when the argument is left out.
|
|
345
|
+
|
|
346
|
+
A generic mentions none of its arguments, so its verdict comes from the methods that S3 dispatch reaches: if
|
|
347
|
+
they agree the answer is theirs, otherwise the parameter is \`conditionally\` strict. The object the dispatch
|
|
348
|
+
is on is forced by the dispatch itself, which also covers \`standardGeneric\`. A \`NextMethod\` carries the
|
|
349
|
+
question on to the methods it reaches, matched by the position the parameter is written in, and an argument
|
|
350
|
+
travelling in \`...\` is followed to the parameter it binds to. The method of an object flowR cannot resolve,
|
|
351
|
+
such as \`obj$m(x)\`, leaves the parameter \`conditionally\` strict:
|
|
352
|
+
${await (0, doc_query_1.showQuery)(shell, 'f <- function(x, y) UseMethod("f")\nf.default <- function(x, y) x\nf.numeric <- function(x, y) y', [{
|
|
353
|
+
type: 'inspect-strictness',
|
|
354
|
+
}], { showCode: true, collapseQuery: true, ctx })}
|
|
355
|
+
|
|
356
|
+
Using the example code \`${exampleCode}\` the following query returns the information for all identified
|
|
357
|
+
function definitions whether they are strict:
|
|
358
|
+
${await (0, doc_query_1.showQuery)(shell, exampleCode, [{
|
|
359
|
+
type: 'inspect-strictness',
|
|
360
|
+
}], { showCode: true, collapseQuery: true, ctx })}
|
|
361
|
+
|
|
362
|
+
This query also supports a slicing criterion based query mode that only returns information for functions matching the given criteria:
|
|
363
|
+
${await (0, doc_query_1.showQuery)(shell, exampleCode, [{
|
|
364
|
+
type: 'inspect-strictness',
|
|
365
|
+
filter: ['1@function']
|
|
366
|
+
}], { showCode: true, shorthand: (0, doc_query_1.sliceQueryShorthand)(['1@function'], (0, doc_escape_1.escapeNewline)(exampleCode)), ctx })}
|
|
367
|
+
`;
|
|
368
|
+
}
|
|
369
|
+
});
|
|
317
370
|
(0, doc_query_1.registerQueryDocumentation)('inspect-exception', {
|
|
318
371
|
type: 'active',
|
|
319
372
|
shortDescription: 'Determine whether functions throw exceptions (known to flowR)',
|
package/linter/linter-output.js
CHANGED
|
@@ -88,7 +88,7 @@ function lintsToSarif(results, flowrVersion) {
|
|
|
88
88
|
}
|
|
89
89
|
/** GitHub has no 'note' */
|
|
90
90
|
const githubCommand = { error: 'error', warning: 'warning', note: 'notice' };
|
|
91
|
-
/** `%`, `\r
|
|
91
|
+
/** `%`, `\r`, and `\n` would end the workflow command */
|
|
92
92
|
function escapeGithubData(text) {
|
|
93
93
|
return text.replaceAll('%', '%25').replaceAll('\r', '%0D').replaceAll('\n', '%0A');
|
|
94
94
|
}
|
package/linter/linter-rules.d.ts
CHANGED
|
@@ -400,6 +400,30 @@ export declare const LintingRules: {
|
|
|
400
400
|
};
|
|
401
401
|
};
|
|
402
402
|
};
|
|
403
|
+
readonly 'unclosed-connection': {
|
|
404
|
+
readonly createSearch: () => import("../search/flowr-search-builder").FlowrSearchBuilder<"all", ["filter"], import("../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation, Promise<import("../search/flowr-search").FlowrSearchElements<import("../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation, [] | import("../search/flowr-search").FlowrSearchElement<import("../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation>[]>>>;
|
|
405
|
+
readonly processSearchResult: (elements: import("../search/flowr-search").FlowrSearchElements<import("../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation, import("../search/flowr-search").FlowrSearchElement<import("../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation>[]>, config: import("./rules/unclosed-connection").UnclosedConnectionConfig, data: import("../project/flowr-analyzer").ReadonlyFlowrAnalysisProvider<import("../r-bridge/parser").KnownParser>) => Promise<{
|
|
406
|
+
results: import("./linter-format").LintingResult[];
|
|
407
|
+
'.meta': {
|
|
408
|
+
totalOpened: number;
|
|
409
|
+
totalClosed: number;
|
|
410
|
+
};
|
|
411
|
+
}>;
|
|
412
|
+
readonly prettyPrint: {
|
|
413
|
+
readonly query: (result: import("./linter-format").LintingResult) => string;
|
|
414
|
+
readonly full: (result: import("./linter-format").LintingResult) => string;
|
|
415
|
+
};
|
|
416
|
+
readonly info: {
|
|
417
|
+
readonly name: "Unclosed Connection";
|
|
418
|
+
readonly tags: readonly [import("./linter-tags").LintingRuleTag.Robustness, import("./linter-tags").LintingRuleTag.Smell];
|
|
419
|
+
readonly certainty: import("./linter-format").LintingRuleCertainty.BestEffort;
|
|
420
|
+
readonly description: "Flags connections that are opened but not closed on every path opening them.";
|
|
421
|
+
readonly defaultConfig: {
|
|
422
|
+
readonly openFns: readonly [];
|
|
423
|
+
readonly closeFns: readonly [];
|
|
424
|
+
};
|
|
425
|
+
};
|
|
426
|
+
};
|
|
403
427
|
};
|
|
404
428
|
export type LintingRuleNames = keyof typeof LintingRules;
|
|
405
429
|
export type LintingRuleMetadata<Name extends LintingRuleNames> = typeof LintingRules[Name] extends LintingRule<infer _Result, infer Metadata, infer _Config, infer _Info, infer _Elements> ? Metadata : never;
|
package/linter/linter-rules.js
CHANGED
|
@@ -19,6 +19,7 @@ const software_has_tests_1 = require("./rules/software-has-tests");
|
|
|
19
19
|
const no_leaked_credentials_1 = require("./rules/no-leaked-credentials");
|
|
20
20
|
const undefined_symbol_1 = require("./rules/undefined-symbol");
|
|
21
21
|
const syntactically_valid_1 = require("./rules/syntactically-valid");
|
|
22
|
+
const unclosed_connection_1 = require("./rules/unclosed-connection");
|
|
22
23
|
/**
|
|
23
24
|
* The registry of currently supported linting rules.
|
|
24
25
|
* A linting rule can be executed on a dataflow pipeline result using {@link executeLintingRule}.
|
|
@@ -41,6 +42,7 @@ exports.LintingRules = {
|
|
|
41
42
|
'software-has-tests': software_has_tests_1.SOFTWARE_HAS_TESTS,
|
|
42
43
|
'no-leaked-credentials': no_leaked_credentials_1.NO_LEAKED_CREDENTIALS,
|
|
43
44
|
'undefined-symbol': undefined_symbol_1.UNDEFINED_SYMBOL,
|
|
44
|
-
'syntactically-valid': syntactically_valid_1.SYNTACTICALLY_VALID
|
|
45
|
+
'syntactically-valid': syntactically_valid_1.SYNTACTICALLY_VALID,
|
|
46
|
+
'unclosed-connection': unclosed_connection_1.UNCLOSED_CONNECTION
|
|
45
47
|
};
|
|
46
48
|
//# sourceMappingURL=linter-rules.js.map
|
|
@@ -19,7 +19,7 @@ export interface NetworkFunction extends MergeableRecord {
|
|
|
19
19
|
name: Identifier;
|
|
20
20
|
/**
|
|
21
21
|
* The {@link FunctionInfo} to use for querying the argument whose value should match {@link onlyTriggerWithArgument}.
|
|
22
|
-
* If this is not specified, flowR's default database of functions ({@link ReadFunctions}, {@link SourceFunctions} and {@link WriteFunctions}) is queried for appropriate information on the function's read argument.
|
|
22
|
+
* If this is not specified, flowR's default database of functions ({@link ReadFunctions}, {@link SourceFunctions}, and {@link WriteFunctions}) is queried for appropriate information on the function's read argument.
|
|
23
23
|
*/
|
|
24
24
|
info?: Omit<FunctionInfo, 'name'>;
|
|
25
25
|
/**
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { ParentInformation } from '../../r-bridge/lang-4.x/ast/model/processing/decorate';
|
|
2
|
+
import { Identifier } from '../../dataflow/environments/identifier';
|
|
3
|
+
import type { MergeableRecord } from '../../util/objects';
|
|
4
|
+
import type { LintingResult } from '../linter-format';
|
|
5
|
+
import { LintingRuleCertainty } from '../linter-format';
|
|
6
|
+
import { LintingRuleTag } from '../linter-tags';
|
|
7
|
+
import type { FlowrSearchElement } from '../../search/flowr-search';
|
|
8
|
+
export type UnclosedConnectionResult = LintingResult;
|
|
9
|
+
export interface UnclosedConnectionMetadata extends MergeableRecord {
|
|
10
|
+
/** the number of calls opening a connection */
|
|
11
|
+
totalOpened: number;
|
|
12
|
+
/** the number of calls closing a connection */
|
|
13
|
+
totalClosed: number;
|
|
14
|
+
}
|
|
15
|
+
export interface UnclosedConnectionConfig extends MergeableRecord {
|
|
16
|
+
/** functions opening a connection, besides the ones flowR states {@link CallProp.Opens} for */
|
|
17
|
+
openFns: readonly Identifier[];
|
|
18
|
+
/** functions closing the connection they are handed, besides the ones flowR states {@link CallProp.Closes} for */
|
|
19
|
+
closeFns: readonly Identifier[];
|
|
20
|
+
}
|
|
21
|
+
export declare const UNCLOSED_CONNECTION: {
|
|
22
|
+
readonly createSearch: () => import("../../search/flowr-search-builder").FlowrSearchBuilder<"all", ["filter"], ParentInformation, Promise<import("../../search/flowr-search").FlowrSearchElements<ParentInformation, [] | FlowrSearchElement<ParentInformation>[]>>>;
|
|
23
|
+
readonly processSearchResult: (elements: import("../../search/flowr-search").FlowrSearchElements<ParentInformation, FlowrSearchElement<ParentInformation>[]>, config: UnclosedConnectionConfig, data: import("../../project/flowr-analyzer").ReadonlyFlowrAnalysisProvider<import("../../r-bridge/parser").KnownParser>) => Promise<{
|
|
24
|
+
results: LintingResult[];
|
|
25
|
+
'.meta': {
|
|
26
|
+
totalOpened: number;
|
|
27
|
+
totalClosed: number;
|
|
28
|
+
};
|
|
29
|
+
}>;
|
|
30
|
+
readonly prettyPrint: {
|
|
31
|
+
readonly query: (result: LintingResult) => string;
|
|
32
|
+
readonly full: (result: LintingResult) => string;
|
|
33
|
+
};
|
|
34
|
+
readonly info: {
|
|
35
|
+
readonly name: "Unclosed Connection";
|
|
36
|
+
readonly tags: readonly [LintingRuleTag.Robustness, LintingRuleTag.Smell];
|
|
37
|
+
readonly certainty: LintingRuleCertainty.BestEffort;
|
|
38
|
+
readonly description: "Flags connections that are opened but not closed on every path opening them.";
|
|
39
|
+
readonly defaultConfig: {
|
|
40
|
+
readonly openFns: readonly [];
|
|
41
|
+
readonly closeFns: readonly [];
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
};
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UNCLOSED_CONNECTION = void 0;
|
|
4
|
+
const node_id_1 = require("../../r-bridge/lang-4.x/ast/model/processing/node-id");
|
|
5
|
+
const type_1 = require("../../r-bridge/lang-4.x/ast/model/type");
|
|
6
|
+
const graph_1 = require("../../dataflow/graph/graph");
|
|
7
|
+
const edge_1 = require("../../dataflow/graph/edge");
|
|
8
|
+
const vertex_1 = require("../../dataflow/graph/vertex");
|
|
9
|
+
const info_1 = require("../../dataflow/info");
|
|
10
|
+
const built_in_props_1 = require("../../dataflow/environments/built-in-props");
|
|
11
|
+
const query_fn_props_1 = require("../../dataflow/environments/query-fn-props");
|
|
12
|
+
const identifier_1 = require("../../dataflow/environments/identifier");
|
|
13
|
+
const flowr_search_builder_1 = require("../../search/flowr-search-builder");
|
|
14
|
+
const range_1 = require("../../util/range");
|
|
15
|
+
const assert_1 = require("../../util/assert");
|
|
16
|
+
const linter_format_1 = require("../linter-format");
|
|
17
|
+
const linter_tags_1 = require("../linter-tags");
|
|
18
|
+
/** the edges the connection flows along, from the call opening it to the argument of the call closing it */
|
|
19
|
+
const ConnectionFlow = edge_1.EdgeType.Reads | edge_1.EdgeType.DefinedBy | edge_1.EdgeType.DefinedByOnCall | edge_1.EdgeType.Returns | edge_1.EdgeType.Argument;
|
|
20
|
+
/** The arguments holding the handle the call acts on, all of them if it does not state which. */
|
|
21
|
+
function handleArguments(vertex, sig) {
|
|
22
|
+
const stated = sig && built_in_props_1.FnSig.posWith(built_in_props_1.FnSig.layout(sig), vertex.args.length, built_in_props_1.ArgProp.Handle);
|
|
23
|
+
return stated?.length ? stated.map(i => vertex.args[i]) : vertex.args;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Adds every opening call whose connection may reach `start`, an argument of a closing call, to `out`.
|
|
27
|
+
* Unlike {@link Dataflow.provenance} this stops at an opening call and follows no control dependency,
|
|
28
|
+
* so a close in a branch does not claim what that branch opens beside it.
|
|
29
|
+
*/
|
|
30
|
+
function openCallsReaching(graph, start, opens, out) {
|
|
31
|
+
const visited = new Set([start]);
|
|
32
|
+
const pending = [start];
|
|
33
|
+
while (pending.length > 0) {
|
|
34
|
+
const current = pending.pop();
|
|
35
|
+
if (opens.has(current)) {
|
|
36
|
+
out.add(current);
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
for (const [target, edge] of graph.outgoingEdges(current) ?? graph_1.NoEdges) {
|
|
40
|
+
if (edge_1.DfEdge.includesType(edge, ConnectionFlow) && !visited.has(target)) {
|
|
41
|
+
visited.add(target);
|
|
42
|
+
pending.push(target);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/** The variable definition the opened connection is bound to, if it is bound to one. */
|
|
48
|
+
function bindingOf(graph, open) {
|
|
49
|
+
for (const [source, edge] of graph.ingoingEdges(open) ?? graph_1.NoEdges) {
|
|
50
|
+
if (edge_1.DfEdge.includesType(edge, edge_1.EdgeType.DefinedBy) && vertex_1.VariableDefinitionVertex.is(graph.getVertex(source))) {
|
|
51
|
+
return source;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
/** The statement `id` belongs to, i.e. the ancestor that is an element of an expression list. */
|
|
57
|
+
function enclosingStatement(idMap, id) {
|
|
58
|
+
let node = idMap.get(id);
|
|
59
|
+
while (node !== undefined) {
|
|
60
|
+
const parent = node.info.parent === undefined ? undefined : idMap.get(node.info.parent);
|
|
61
|
+
if (parent === undefined || parent.type === type_1.RType.ExpressionList) {
|
|
62
|
+
return node;
|
|
63
|
+
}
|
|
64
|
+
node = parent;
|
|
65
|
+
}
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
/** A fix closing the connection after the last statement using it, if it is bound to a name to close. */
|
|
69
|
+
function closeFix(graph, open) {
|
|
70
|
+
const idMap = graph.idMap;
|
|
71
|
+
const definition = bindingOf(graph, open);
|
|
72
|
+
const name = idMap && definition !== undefined ? (0, node_id_1.recoverName)(definition, idMap) : undefined;
|
|
73
|
+
if (idMap === undefined || definition === undefined || name === undefined) {
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
const reads = (graph.ingoingEdges(definition) ?? graph_1.NoEdges).entries()
|
|
77
|
+
.filter(([, edge]) => edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Reads)).map(([source]) => source);
|
|
78
|
+
const statements = [definition, ...reads]
|
|
79
|
+
.map(id => range_1.SourceLocation.fromNode(enclosingStatement(idMap, id)))
|
|
80
|
+
.filter(assert_1.isNotUndefined);
|
|
81
|
+
const last = statements.reduce((a, b) => a === undefined || range_1.SourceRange.compare(range_1.SourceLocation.getRange(a), range_1.SourceLocation.getRange(b)) < 0 ? b : a, undefined);
|
|
82
|
+
if (last === undefined) {
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
const [startLine, startColumn, endLine, endColumn] = last;
|
|
86
|
+
return [{
|
|
87
|
+
type: 'replace',
|
|
88
|
+
loc: range_1.SourceLocation.from([endLine, endColumn + 1, endLine, endColumn], range_1.SourceLocation.getFile(last)),
|
|
89
|
+
description: `Close the connection with \`close(${name})\``,
|
|
90
|
+
replacement: `\n${' '.repeat(startLine === endLine ? startColumn - 1 : 0)}close(${name})`
|
|
91
|
+
}];
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* How certain we are that the connection opened at `open` is left open,
|
|
95
|
+
* or `undefined` if the given closing calls close it in every run that opens it.
|
|
96
|
+
*/
|
|
97
|
+
function unclosedCertainty(graph, open, closes) {
|
|
98
|
+
if (closes === undefined) {
|
|
99
|
+
return linter_format_1.LintingResultCertainty.Certain;
|
|
100
|
+
}
|
|
101
|
+
const openCds = graph.getVertex(open)?.cds ?? [];
|
|
102
|
+
const uncovered = new Set();
|
|
103
|
+
for (const close of closes) {
|
|
104
|
+
const closeCds = graph.getVertex(close)?.cds ?? [];
|
|
105
|
+
/* opening within a loop and closing outside of it closes the connection of the last iteration only */
|
|
106
|
+
if (info_1.ControlDependency.minus(openCds, closeCds).some(cd => info_1.ControlDependency.isIterated(cd, graph.idMap))) {
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
const only = info_1.ControlDependency.minus(closeCds, openCds);
|
|
110
|
+
if (only.length === 0) {
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
113
|
+
for (const cd of only) {
|
|
114
|
+
uncovered.add(cd);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/* the closes may still cover every branch between them, as in `if(p) close(c) else close(c)` */
|
|
118
|
+
return uncovered.size > 0 && info_1.ControlDependency.happensInEveryBranchSet(uncovered) ? undefined : linter_format_1.LintingResultCertainty.Uncertain;
|
|
119
|
+
}
|
|
120
|
+
/** The calls opening and the calls closing a connection, as the props state and the configuration adds. */
|
|
121
|
+
function connectionCalls(elements, dataflow, config) {
|
|
122
|
+
const opensByName = config.openFns.length > 0 ? identifier_1.Identifier.regex(...config.openFns) : undefined;
|
|
123
|
+
const closesByName = config.closeFns.length > 0 ? identifier_1.Identifier.regex(...config.closeFns) : undefined;
|
|
124
|
+
const opens = new Map();
|
|
125
|
+
const closes = [];
|
|
126
|
+
for (const { node } of elements) {
|
|
127
|
+
const stated = (0, query_fn_props_1.callFnProps)(node.info.id, dataflow);
|
|
128
|
+
if (stated === undefined) {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
const props = stated.props ?? 0;
|
|
132
|
+
const name = identifier_1.Identifier.toString(stated.name);
|
|
133
|
+
const loc = range_1.SourceLocation.fromNode(node);
|
|
134
|
+
if (loc !== undefined && ((props & built_in_props_1.CallProp.Opens) !== 0 || opensByName?.test(name))) {
|
|
135
|
+
opens.set(node.info.id, loc);
|
|
136
|
+
}
|
|
137
|
+
else if ((props & built_in_props_1.CallProp.Closes) !== 0 || closesByName?.test(name)) {
|
|
138
|
+
const vertex = dataflow.graph.getVertex(node.info.id);
|
|
139
|
+
if (vertex_1.FunctionCallVertex.is(vertex)) {
|
|
140
|
+
closes.push([vertex, stated.sig]);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return { opens, closes };
|
|
145
|
+
}
|
|
146
|
+
exports.UNCLOSED_CONNECTION = {
|
|
147
|
+
createSearch: () => flowr_search_builder_1.Q.all().filter(vertex_1.VertexType.FunctionCall),
|
|
148
|
+
processSearchResult: async (elements, config, data) => {
|
|
149
|
+
const dataflow = await data.dataflow();
|
|
150
|
+
const graph = dataflow.graph;
|
|
151
|
+
const { opens, closes } = connectionCalls(elements.getElements(), dataflow, config);
|
|
152
|
+
const openIds = new Set(opens.keys());
|
|
153
|
+
const closedBy = new Map();
|
|
154
|
+
for (const [close, sig] of opens.size > 0 ? closes : []) {
|
|
155
|
+
const reached = new Set();
|
|
156
|
+
for (const arg of handleArguments(close, sig)) {
|
|
157
|
+
const ref = graph_1.FunctionArgument.getReference(arg);
|
|
158
|
+
if (ref !== undefined) {
|
|
159
|
+
openCallsReaching(graph, ref, openIds, reached);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
for (const open of reached) {
|
|
163
|
+
const known = closedBy.get(open);
|
|
164
|
+
if (known) {
|
|
165
|
+
known.push(close.id);
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
closedBy.set(open, [close.id]);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
const results = [];
|
|
173
|
+
for (const [open, loc] of opens) {
|
|
174
|
+
const certainty = unclosedCertainty(graph, open, closedBy.get(open));
|
|
175
|
+
if (certainty === undefined) {
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
/* closing what another path closes as well errors in R, so only a connection nothing closes gets a fix */
|
|
179
|
+
const quickFix = certainty === linter_format_1.LintingResultCertainty.Certain ? closeFix(graph, open) : undefined;
|
|
180
|
+
results.push({ certainty, involvedId: open, loc, ...(quickFix ? { quickFix } : {}) });
|
|
181
|
+
}
|
|
182
|
+
return { results, '.meta': { totalOpened: opens.size, totalClosed: closes.length } };
|
|
183
|
+
},
|
|
184
|
+
prettyPrint: {
|
|
185
|
+
[linter_format_1.LintingPrettyPrintContext.Query]: result => `Unclosed connection at ${range_1.SourceLocation.format(result.loc)}`,
|
|
186
|
+
[linter_format_1.LintingPrettyPrintContext.Full]: result => `The connection opened at ${range_1.SourceLocation.format(result.loc)} is not closed on every path that opens it`
|
|
187
|
+
},
|
|
188
|
+
info: {
|
|
189
|
+
name: 'Unclosed Connection',
|
|
190
|
+
tags: [linter_tags_1.LintingRuleTag.Robustness, linter_tags_1.LintingRuleTag.Smell],
|
|
191
|
+
/* a connection handed to code flowR cannot resolve, as in `lapply(cons, close)`, is reported although it is closed */
|
|
192
|
+
certainty: linter_format_1.LintingRuleCertainty.BestEffort,
|
|
193
|
+
description: 'Flags connections that are opened but not closed on every path opening them.',
|
|
194
|
+
defaultConfig: {
|
|
195
|
+
openFns: [],
|
|
196
|
+
closeFns: []
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
//# sourceMappingURL=unclosed-connection.js.map
|