@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
|
@@ -10,6 +10,8 @@ const assert_1 = require("../../util/assert");
|
|
|
10
10
|
const range_1 = require("../../util/range");
|
|
11
11
|
const flowr_file_1 = require("../../project/context/flowr-file");
|
|
12
12
|
const r_base_packages_1 = require("../../util/r-base-packages");
|
|
13
|
+
const unused_import_1 = require("./unused-import");
|
|
14
|
+
const defaultmap_1 = require("../../util/collections/defaultmap");
|
|
13
15
|
const linter_format_1 = require("../linter-format");
|
|
14
16
|
const linter_tags_1 = require("../linter-tags");
|
|
15
17
|
const undefined_symbol_util_1 = require("./undefined-symbol-util");
|
|
@@ -17,11 +19,13 @@ const df_helper_1 = require("../../dataflow/graph/df-helper");
|
|
|
17
19
|
const r_symbol_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-symbol");
|
|
18
20
|
/** calls that load a package; an unresolved one means we cannot enumerate all exports in scope */
|
|
19
21
|
const LibraryLoadFunctions = new Set(['library', 'require', 'requireNamespace', 'loadNamespace', 'attachNamespace', 'load_all', 'use', 'p_load']);
|
|
20
|
-
// standard packages attached by default; exports are in scope without library()
|
|
21
22
|
/** test frameworks whose namespace a test file runs under implicitly (e.g. `tests/testthat/test-*.R` sees testthat's exports without a `library()`) */
|
|
22
23
|
const ImplicitTestFrameworks = ['testthat', 'tinytest', 'RUnit'];
|
|
23
24
|
/** whether name is an export of a default-attached base package (needs no library()) */
|
|
24
25
|
function isAttachedBaseName(name) {
|
|
26
|
+
if (r_base_packages_1.BaseDatasets.has(name)) {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
25
29
|
const owner = (0, r_base_packages_1.baseRExportOwner)(name);
|
|
26
30
|
return owner !== undefined && r_base_packages_1.AttachedBasePackages.includes(owner);
|
|
27
31
|
}
|
|
@@ -43,7 +47,11 @@ exports.UNDEFINED_SYMBOL = {
|
|
|
43
47
|
const meta = {
|
|
44
48
|
totalFunctionCalls: 0,
|
|
45
49
|
totalVariableUses: 0,
|
|
46
|
-
suppressed: { installed: 0, loadedPackage: 0, enclosingScope: 0, nonStandardEval: 0, subscript: 0 }
|
|
50
|
+
suppressed: { installed: 0, loadedPackage: 0, enclosingScope: 0, nonStandardEval: 0, subscript: 0, unresolvedLibrary: 0 }
|
|
51
|
+
};
|
|
52
|
+
const suppress = (reason) => {
|
|
53
|
+
meta.suppressed[reason]++;
|
|
54
|
+
return undefined;
|
|
47
55
|
};
|
|
48
56
|
// `inst/` files are installed verbatim (resources, not namespace source); skip them. Key off the
|
|
49
57
|
// FileRole.Install role, with a path fallback for requests that bypass the file-role plugins.
|
|
@@ -53,21 +61,10 @@ exports.UNDEFINED_SYMBOL = {
|
|
|
53
61
|
const testFiles = new Set(ctx.files.getFilesByRole(flowr_file_1.FileRole.Test).map(f => f.path()));
|
|
54
62
|
const testExports = new Set(testFiles.size === 0 ? [] : deps.signatureSources().flatMap(src => ImplicitTestFrameworks.flatMap(pkg => src.lookup(pkg)?.exported ?? [])));
|
|
55
63
|
const isImplicitTestExport = (name, file) => file !== undefined && testFiles.has(file) && testExports.has(name);
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
unknownIds.add(graph_1.UnknownSideEffect.id(e));
|
|
61
|
-
}
|
|
62
|
-
let unresolvedLibraryInScope = false;
|
|
63
|
-
if (unknownIds.size > 0) {
|
|
64
|
-
for (const [id, v] of graph.verticesOfType(vertex_1.VertexType.FunctionCall)) {
|
|
65
|
-
if (LibraryLoadFunctions.has(identifier_1.Identifier.getName(v.name)) && unknownIds.has(id)) {
|
|
66
|
-
unresolvedLibraryInScope = true;
|
|
67
|
-
break;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
64
|
+
/* a library() we could not resolve could export any bare name, so such names are suppressed rather than guessed */
|
|
65
|
+
const unknownIds = new Set([...graph.unknownSideEffects].map(e => graph_1.UnknownSideEffect.id(e)));
|
|
66
|
+
const unresolvedLibraryInScope = unknownIds.size > 0 && [...graph.verticesOfType(vertex_1.VertexType.FunctionCall)]
|
|
67
|
+
.some(([id, v]) => unknownIds.has(id) && LibraryLoadFunctions.has(identifier_1.Identifier.getName(v.name)));
|
|
71
68
|
// scope-defined names, a fallback for closure variables flowR's dataflow did not statically link
|
|
72
69
|
const scopeDefined = (0, undefined_symbol_util_1.collectScopeDefinedNames)(graph);
|
|
73
70
|
// packages whose exports are in scope: DESCRIPTION/library() deps plus the default-attached base
|
|
@@ -76,53 +73,16 @@ exports.UNDEFINED_SYMBOL = {
|
|
|
76
73
|
...deps.getDependencies().map(p => deps.getDependency(p.name) ?? p),
|
|
77
74
|
...r_base_packages_1.AttachedBasePackages.map(n => deps.getDependency(n)).filter(assert_1.isNotUndefined)
|
|
78
75
|
];
|
|
79
|
-
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
known = loadedPackages.some(p => p.has(name));
|
|
84
|
-
exportedByLoaded.set(name, known);
|
|
85
|
-
}
|
|
86
|
-
return known;
|
|
87
|
-
};
|
|
76
|
+
/* a package may re-export what it imports, as dplyr does tibble's `as_tibble` */
|
|
77
|
+
const src = deps.signatures().sources();
|
|
78
|
+
const importedByLoaded = new Set(loadedPackages.flatMap(p => src.isBaseR(p.name) ? [] : (0, unused_import_1.nonBaseImports)(src, p.name, p.resolvedVersion)));
|
|
79
|
+
const isExportedByLoadedPackage = (0, defaultmap_1.memoize)((name) => loadedPackages.some(p => p.has(name)) || (importedByLoaded.size > 0 && deps.packagesExporting(name).some(p => importedByLoaded.has(p))));
|
|
88
80
|
// hint an unloaded package that exports `name` (e.g. `ggplot` -> `ggplot2`), from the package database
|
|
89
81
|
const attached = new Set(r_base_packages_1.AttachedBasePackages);
|
|
90
82
|
const hintPackagesFor = (name) => deps.packagesExporting(name).filter(p => !attached.has(p)).slice(0, MaxHintPackages);
|
|
91
|
-
const results = elements.getElements().map(element => {
|
|
92
|
-
const id = element.node.info.id;
|
|
93
|
-
const vtx = graph.getVertex(id);
|
|
94
|
-
if (!vtx) {
|
|
95
|
-
return undefined;
|
|
96
|
-
}
|
|
97
|
-
const inInstalledFile = isInstalledFile(element.node.info.file);
|
|
98
|
-
if (vertex_1.DfgVertex.isFunctionCall(vtx)) {
|
|
99
|
-
if (vtx.origin === 'unnamed' || !config.checkFunctions) {
|
|
100
|
-
return undefined;
|
|
101
|
-
}
|
|
102
|
-
meta.totalFunctionCalls++;
|
|
103
|
-
if (inInstalledFile) {
|
|
104
|
-
meta.suppressed.installed++;
|
|
105
|
-
return undefined;
|
|
106
|
-
}
|
|
107
|
-
return check(element, id, identifier_1.Identifier.getName(vtx.name), identifier_1.Identifier.getNamespace(vtx.name), 'function');
|
|
108
|
-
}
|
|
109
|
-
// variable use: only plain symbols (not argument names, `...`, or empty)
|
|
110
|
-
if (vertex_1.DfgVertex.isUse(vtx) && config.checkVariables) {
|
|
111
|
-
const node = element.node;
|
|
112
|
-
if (!r_symbol_1.RSymbol.is(node) || node.lexeme === '...' || node.lexeme === undefined) {
|
|
113
|
-
return undefined;
|
|
114
|
-
}
|
|
115
|
-
meta.totalVariableUses++;
|
|
116
|
-
if (inInstalledFile) {
|
|
117
|
-
meta.suppressed.installed++;
|
|
118
|
-
return undefined;
|
|
119
|
-
}
|
|
120
|
-
return check(element, id, node.lexeme, undefined, 'variable');
|
|
121
|
-
}
|
|
122
|
-
return undefined;
|
|
123
|
-
}).filter(assert_1.isNotUndefined);
|
|
124
83
|
/** shared resolution logic for a name used either as a function call or a variable */
|
|
125
|
-
|
|
84
|
+
const check = (node, name, namespace, kind) => {
|
|
85
|
+
const id = node.info.id;
|
|
126
86
|
// resolved by flowR itself (local/param/builtin) - never a candidate, so not counted as suppressed
|
|
127
87
|
if (kind === 'variable' ? (0, undefined_symbol_util_1.useResolvesToDefinitionOrBuiltin)(graph, id) : (df_helper_1.Dataflow.origin(graph, id)?.length ?? 0) > 0) {
|
|
128
88
|
return undefined;
|
|
@@ -138,11 +98,16 @@ exports.UNDEFINED_SYMBOL = {
|
|
|
138
98
|
return undefined;
|
|
139
99
|
}
|
|
140
100
|
// a bare name a test framework exports, used in a test file where that framework's namespace is attached
|
|
141
|
-
if (namespace === undefined && isImplicitTestExport(name,
|
|
101
|
+
if (namespace === undefined && isImplicitTestExport(name, node.info.file)) {
|
|
142
102
|
return suppress('loadedPackage');
|
|
143
103
|
}
|
|
144
104
|
// exported by a package in scope (`pkg::fn`, a loaded package, or a default-attached base package)
|
|
145
|
-
|
|
105
|
+
/* the database records no data sets, so `pkg::x` read as a variable may be lazy data of a known package */
|
|
106
|
+
const nsPackage = namespace === undefined ? undefined : deps.getDependency(namespace);
|
|
107
|
+
const exported = namespace === undefined
|
|
108
|
+
? isExportedByLoadedPackage(name)
|
|
109
|
+
: nsPackage !== undefined && (kind === 'variable' || nsPackage.has(name));
|
|
110
|
+
if (exported) {
|
|
146
111
|
return suppress('loadedPackage');
|
|
147
112
|
}
|
|
148
113
|
// forward-referenced closure binding flowR's dataflow did not link (unconditional bindings only)
|
|
@@ -157,7 +122,10 @@ exports.UNDEFINED_SYMBOL = {
|
|
|
157
122
|
if (kind === 'variable' && !config.checkSubscripts && (0, undefined_symbol_util_1.isInSubscript)(graph, id)) {
|
|
158
123
|
return suppress('subscript');
|
|
159
124
|
}
|
|
160
|
-
|
|
125
|
+
if (unresolvedLibraryInScope && namespace === undefined) {
|
|
126
|
+
return suppress('unresolvedLibrary');
|
|
127
|
+
}
|
|
128
|
+
const loc = range_1.SourceLocation.fromNode(node);
|
|
161
129
|
if (loc === undefined) {
|
|
162
130
|
return undefined;
|
|
163
131
|
}
|
|
@@ -168,29 +136,44 @@ exports.UNDEFINED_SYMBOL = {
|
|
|
168
136
|
kind,
|
|
169
137
|
involvedId: id,
|
|
170
138
|
loc,
|
|
171
|
-
...(availableInPackages.length > 0 ? { availableInPackages } : {})
|
|
172
|
-
...(unresolvedLibraryInScope ? { mayBeProvidedByUnresolvedLibrary: true } : {})
|
|
139
|
+
...(availableInPackages.length > 0 ? { availableInPackages } : {})
|
|
173
140
|
};
|
|
174
|
-
}
|
|
175
|
-
function
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
141
|
+
};
|
|
142
|
+
/** the symbol to check if the config asks for it: a called function, or a plain symbol read */
|
|
143
|
+
const symbolOf = (node) => {
|
|
144
|
+
const vtx = graph.getVertex(node.info.id);
|
|
145
|
+
if (vertex_1.DfgVertex.isFunctionCall(vtx)) {
|
|
146
|
+
return vtx.origin !== 'unnamed' && config.checkFunctions ? ['function', vtx.name] : undefined;
|
|
147
|
+
}
|
|
148
|
+
const plainSymbol = r_symbol_1.RSymbol.is(node) && node.lexeme !== '...' && node.lexeme !== undefined;
|
|
149
|
+
return vertex_1.DfgVertex.isUse(vtx) && config.checkVariables && plainSymbol ? ['variable', node.content] : undefined;
|
|
150
|
+
};
|
|
151
|
+
const results = elements.getElements().map(({ node }) => {
|
|
152
|
+
const symbol = symbolOf(node);
|
|
153
|
+
if (symbol === undefined) {
|
|
154
|
+
return undefined;
|
|
155
|
+
}
|
|
156
|
+
const [kind, identifier] = symbol;
|
|
157
|
+
meta[kind === 'function' ? 'totalFunctionCalls' : 'totalVariableUses']++;
|
|
158
|
+
if (isInstalledFile(node.info.file)) {
|
|
159
|
+
return suppress('installed');
|
|
160
|
+
}
|
|
161
|
+
return check(node, identifier_1.Identifier.getName(identifier), identifier_1.Identifier.getNamespace(identifier), kind);
|
|
162
|
+
}).filter(assert_1.isNotUndefined);
|
|
179
163
|
return { results, '.meta': meta };
|
|
180
164
|
},
|
|
181
165
|
prettyPrint: {
|
|
182
|
-
[linter_format_1.LintingPrettyPrintContext.Query]: result =>
|
|
166
|
+
[linter_format_1.LintingPrettyPrintContext.Query]: result => `Undefined ${result.kind} \`${result.name}\` at ${range_1.SourceLocation.format(result.loc)}`,
|
|
183
167
|
[linter_format_1.LintingPrettyPrintContext.Full]: result => {
|
|
184
168
|
const where = range_1.SourceLocation.format(result.loc);
|
|
185
|
-
const caveat = result.mayBeProvidedByUnresolvedLibrary ? ' (an unresolved library is loaded that might provide it)' : '';
|
|
186
169
|
if (result.availableInPackages && result.availableInPackages.length > 0) {
|
|
187
170
|
const pkgs = result.availableInPackages.map(p => `\`${p}\``).join(', ');
|
|
188
171
|
const hint = result.availableInPackages.length === 1 ? `\`library(${result.availableInPackages[0]})\`` : `one of ${pkgs}`;
|
|
189
|
-
return `\`${result.name}\` at ${where} is used but not defined; it is exported by ${pkgs} - did you forget to load it (e.g. ${hint})
|
|
172
|
+
return `\`${result.name}\` at ${where} is used but not defined; it is exported by ${pkgs} - did you forget to load it (e.g. ${hint})?`;
|
|
190
173
|
}
|
|
191
174
|
return result.kind === 'function'
|
|
192
|
-
? `\`${result.name}\` at ${where} is called but is neither defined locally, a base R builtin, nor exported by a loaded package
|
|
193
|
-
: `\`${result.name}\` at ${where} is used as a variable but is never defined in scope
|
|
175
|
+
? `\`${result.name}\` at ${where} is called but is neither defined locally, a base R builtin, nor exported by a loaded package`
|
|
176
|
+
: `\`${result.name}\` at ${where} is used as a variable but is never defined in scope`;
|
|
194
177
|
}
|
|
195
178
|
},
|
|
196
179
|
info: {
|
|
@@ -46,39 +46,16 @@ const UncertainInputs = [simple_input_classifier_1.InputType.Unknown, simple_inp
|
|
|
46
46
|
const UnescapedArgumentCategories = record_1.Record.values(UnescapedArgumentCategory);
|
|
47
47
|
/** Get the critical calls of every category that is not disabled */
|
|
48
48
|
function getEnabledCriticalCalls(config, index) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
for (const entry of index.entries) {
|
|
57
|
-
if (function_semantics_1.FunctionSemantics.call.props.hasAny(entry, criticalCallProps) && entry.sig?.some(([, prop]) => (prop & criticalArgProps) !== 0)) {
|
|
58
|
-
result.push({ category, name: entry.name, signature: entry.sig });
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return result;
|
|
63
|
-
}
|
|
64
|
-
/** Index the critical calls of the enabled categories by function name */
|
|
65
|
-
function indexCriticalCalls(config, builtIns) {
|
|
66
|
-
const index = new Map();
|
|
67
|
-
for (const call of getEnabledCriticalCalls(config, builtIns)) {
|
|
68
|
-
const name = identifier_1.Identifier.getName(call.name);
|
|
69
|
-
const known = index.get(name);
|
|
70
|
-
if (known !== undefined) {
|
|
71
|
-
known.push(call);
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
index.set(name, [call]);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return index;
|
|
49
|
+
return UnescapedArgumentCategories.filter(category => !config.disabledCategories.includes(category)).flatMap(category => {
|
|
50
|
+
const { criticalCalls, criticalArgs } = config.categories[category];
|
|
51
|
+
const hasCriticalArg = (sig) => sig?.some(([, prop]) => (prop & criticalArgs) !== 0) ?? false;
|
|
52
|
+
return index.entries.filter(entry => function_semantics_1.FunctionSemantics.call.props.hasAny(entry, criticalCalls) && hasCriticalArg(entry.sig))
|
|
53
|
+
.map(entry => ({ category, name: entry.name, signature: entry.sig }));
|
|
54
|
+
});
|
|
78
55
|
}
|
|
79
56
|
/** Gets all critical arguments of critical function calls in the data flow graph */
|
|
80
57
|
function getCriticalTargets(elements, graph, config, builtIns) {
|
|
81
|
-
const criticalCalls =
|
|
58
|
+
const criticalCalls = Map.groupBy(getEnabledCriticalCalls(config, builtIns), call => identifier_1.Identifier.getName(call.name));
|
|
82
59
|
const targets = [];
|
|
83
60
|
const seen = new Set();
|
|
84
61
|
for (const { node } of elements) {
|
|
@@ -95,7 +72,7 @@ function getCriticalTargets(elements, graph, config, builtIns) {
|
|
|
95
72
|
const key = `${category}-${call.id}-${arg}`;
|
|
96
73
|
if (location !== undefined && !seen.has(key)) {
|
|
97
74
|
seen.add(key);
|
|
98
|
-
targets.push({ category, call
|
|
75
|
+
targets.push({ category, call, signature, arg, location });
|
|
99
76
|
}
|
|
100
77
|
}
|
|
101
78
|
}
|
|
@@ -104,14 +81,10 @@ function getCriticalTargets(elements, graph, config, builtIns) {
|
|
|
104
81
|
}
|
|
105
82
|
function mapInputSourceToArgs(call, sources) {
|
|
106
83
|
const args = call.args.map(graph_1.FunctionArgument.getReference).filter(assert_1.isNotUndefined);
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
result.push([args[i], source]);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return result;
|
|
84
|
+
return args.flatMap((arg, i) => {
|
|
85
|
+
const source = sources.find(source => source.id === arg) ?? (sources.length === args.length ? sources[i] : undefined);
|
|
86
|
+
return source === undefined ? [] : [[arg, source]];
|
|
87
|
+
});
|
|
115
88
|
}
|
|
116
89
|
/**
|
|
117
90
|
* Whether anything `start` reads is a parameter of an enclosing function. What the call sites happen to pass says
|
|
@@ -153,9 +126,10 @@ function isCertainlyCritical(source, config) {
|
|
|
153
126
|
* Gets all unescaped sources for the critical target calls of the given category
|
|
154
127
|
*/
|
|
155
128
|
async function getUnescapedSources(category, targets, config, data, graph) {
|
|
156
|
-
const
|
|
157
|
-
const
|
|
158
|
-
const
|
|
129
|
+
const sanitizers = config.categories[category].sanitizers ?? [];
|
|
130
|
+
const sanitizerNames = new Set(sanitizers.map(call => identifier_1.Identifier.getName(call)));
|
|
131
|
+
const narrowing = [...(0, input_source_functions_1.narrowingFunctions)(data.inspectContext().env.builtInIndex), ...sanitizers.map(call => ({ call }))];
|
|
132
|
+
const queryConfig = { narrowing };
|
|
159
133
|
const found = new Map();
|
|
160
134
|
let entries = targets.map(target => ({ target, call: target.call.id, only: new Set([target.arg]), depth: 0 }));
|
|
161
135
|
while (entries.length > 0) {
|
|
@@ -173,9 +147,9 @@ async function getUnescapedSources(category, targets, config, data, graph) {
|
|
|
173
147
|
/* a call passing a constant today makes the argument constant, but the function still escapes its
|
|
174
148
|
parameter, and it is one call away from being handed anything */
|
|
175
149
|
const viaParameter = isAcceptedInput(source, config)
|
|
176
|
-
&& source.types.length > 0 && source.types.every(t =>
|
|
150
|
+
&& source.types.length > 0 && source.types.every(t => AcceptedInputs.includes(t))
|
|
177
151
|
&& readsParameter(graph, arg, sanitizerNames);
|
|
178
|
-
if ((entry.only !== undefined && !entry.only.has(arg)) || (isAcceptedInput(source, config) && !viaParameter)) {
|
|
152
|
+
if ((entry.only !== undefined && !entry.only.has(arg)) || (isAcceptedInput(source, config) && !viaParameter) || model_1.RConstant.is(graph.idMap?.get(arg))) {
|
|
179
153
|
continue;
|
|
180
154
|
}
|
|
181
155
|
else if (entry.depth < config.maxDecentDepth && (source.trace === simple_input_classifier_1.InputTraceType.Known || viaParameter) && vertex_1.DfgVertex.isFunctionCall(vertex) && !vertex_1.DfgVertex.hasOrigin(vertex, built_in_proc_name_1.BuiltInProcName.Access)) {
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { type LintingResult, LintingRuleCertainty } from '../linter-format';
|
|
2
2
|
import type { MergeableRecord } from '../../util/objects';
|
|
3
3
|
import { LintingRuleTag } from '../linter-tags';
|
|
4
|
+
import type { DataflowGraph } from '../../dataflow/graph/graph';
|
|
4
5
|
import type { ParentInformation } from '../../r-bridge/lang-4.x/ast/model/processing/decorate';
|
|
5
6
|
import type { ReadonlyFlowrAnalysisProvider } from '../../project/flowr-analyzer';
|
|
7
|
+
import type { ReadOnlyFlowrAnalyzerContext } from '../../project/context/flowr-analyzer-context';
|
|
6
8
|
export interface UnusedDefinitionResult extends LintingResult {
|
|
7
9
|
variableName?: string;
|
|
8
10
|
}
|
|
@@ -17,6 +19,10 @@ export interface UnusedDefinitionConfig extends MergeableRecord {
|
|
|
17
19
|
*/
|
|
18
20
|
excludeExportedDefinitions: boolean;
|
|
19
21
|
}
|
|
22
|
+
/** Collects the names of every function call in the graph, so we can tell whether an S3 generic is dispatched anywhere. */
|
|
23
|
+
export declare function collectCalledNames(dfg: DataflowGraph): ReadonlySet<string>;
|
|
24
|
+
/** Whether `name` reads as `generic.class` for a generic that is known, declared, or called, so R dispatches to it by that name. */
|
|
25
|
+
export declare function isS3MethodName(name: string, ctx: ReadOnlyFlowrAnalyzerContext, called: ReadonlySet<string>, declared?: ReadonlySet<string>): boolean;
|
|
20
26
|
export interface UnusedDefinitionMetadata extends MergeableRecord {
|
|
21
27
|
totalConsidered: number;
|
|
22
28
|
}
|