@eagleoutice/flowr 2.15.10 → 2.16.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 +23 -26
- package/abstract-interpretation/data-frame/arguments.js +11 -7
- package/cli/flowr-main-options.d.ts +15 -0
- package/cli/flowr-main-options.js +18 -0
- package/cli/flowr.d.ts +18 -0
- package/cli/flowr.js +13 -2
- package/cli/repl/commands/repl-clipboard.js +2 -1
- package/cli/repl/commands/repl-commands.js +2 -0
- package/cli/repl/commands/repl-main.d.ts +5 -0
- package/cli/repl/commands/repl-signature.js +2 -0
- package/cli/repl/core.d.ts +7 -1
- package/cli/repl/core.js +17 -8
- package/cli/repl/execute.js +2 -0
- package/cli/repl/server/connection.js +2 -1
- package/cli/repl/server/net.d.ts +10 -0
- package/cli/repl/server/net.js +34 -1
- package/cli/slicer-app.js +2 -1
- package/config.d.ts +12 -2
- package/config.js +91 -14
- 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 +185 -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 +64 -42
- 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 +42 -4
- package/dataflow/internal/control-flow.js +76 -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 +441 -79
- 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 +290 -252
- 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 +120 -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 +60 -58
- 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 +44 -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/doc-capabilities.js +4 -1
- package/documentation/wiki-interface.js +4 -0
- package/documentation/wiki-setup.js +23 -0
- package/engines.js +11 -3
- package/linter/linter-executor.js +19 -1
- 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 +117 -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 +130 -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-rda-file.d.ts +14 -5
- package/project/plugins/file-plugins/files/flowr-rda-file.js +35 -24
- 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 +18 -42
- package/project/sigdb/decompress.js +3 -1
- package/project/sigdb/sigdb-download.js +9 -6
- package/queries/base-query-format.js +1 -2
- package/queries/catalog/absint-query/absint-query-format.js +1 -1
- package/queries/catalog/config-query/config-query-executor.js +9 -2
- 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-executor.js +2 -0
- package/r-bridge/shell.js +8 -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 +120 -79
- package/slicing/static/visiting-queue.d.ts +4 -6
- package/slicing/static/visiting-queue.js +9 -13
- package/util/files.d.ts +6 -0
- package/util/files.js +12 -0
- package/util/parallel.js +2 -0
- 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/secure-mode.d.ts +42 -0
- package/util/secure-mode.js +70 -0
- package/util/text/playground-link.d.ts +12 -3
- package/util/text/playground-link.js +18 -27
- package/util/version.js +4 -10
|
@@ -13,6 +13,7 @@ const assert_1 = require("../../util/assert");
|
|
|
13
13
|
const range_1 = require("../../util/range");
|
|
14
14
|
const linter_format_1 = require("../linter-format");
|
|
15
15
|
const linter_tags_1 = require("../linter-tags");
|
|
16
|
+
const unused_definition_1 = require("./unused-definition");
|
|
16
17
|
var CasingConvention;
|
|
17
18
|
(function (CasingConvention) {
|
|
18
19
|
CasingConvention["CamelCase"] = "camelCase";
|
|
@@ -26,6 +27,9 @@ var CasingConvention;
|
|
|
26
27
|
function containsAlpha(s) {
|
|
27
28
|
return /[A-Za-z]/.test(s);
|
|
28
29
|
}
|
|
30
|
+
function withoutPrefix(identifier, ignorePrefix) {
|
|
31
|
+
return ignorePrefix ? identifier.replace(new RegExp(`^(${ignorePrefix})`), '') : identifier;
|
|
32
|
+
}
|
|
29
33
|
/**
|
|
30
34
|
* Attempts to detect the possible casing conventions used in the given identifier and returns an array ordered by likelihood of the casing convention being correct.
|
|
31
35
|
*/
|
|
@@ -33,9 +37,7 @@ function detectPotentialCasings(identifier, ignorePrefix) {
|
|
|
33
37
|
if (identifier.trim() === '' || !containsAlpha(identifier)) {
|
|
34
38
|
return [];
|
|
35
39
|
}
|
|
36
|
-
|
|
37
|
-
identifier = identifier.replace(new RegExp(`^(${ignorePrefix})`), '');
|
|
38
|
-
}
|
|
40
|
+
identifier = withoutPrefix(identifier, ignorePrefix);
|
|
39
41
|
const upper = identifier.toUpperCase();
|
|
40
42
|
const lower = identifier.toLowerCase();
|
|
41
43
|
const isAllUpper = identifier === upper;
|
|
@@ -70,23 +72,26 @@ function detectPotentialCasings(identifier, ignorePrefix) {
|
|
|
70
72
|
* The function {@link detectPotentialCasings} is generally preferred, as it returns all potential casings and not just the first one.
|
|
71
73
|
*/
|
|
72
74
|
function detectCasing(identifier, ignorePrefix) {
|
|
73
|
-
|
|
74
|
-
return casings.length > 0 ? casings[0] : CasingConvention.Unknown;
|
|
75
|
+
return detectPotentialCasings(identifier, ignorePrefix)[0] ?? CasingConvention.Unknown;
|
|
75
76
|
}
|
|
76
77
|
/**
|
|
77
78
|
* Determines the most used casing convention in the given list of symbols.
|
|
78
79
|
*/
|
|
79
80
|
function getMostUsedCasing(symbols) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
81
|
+
const counts = new Map();
|
|
82
|
+
for (const { detectedCasing } of symbols) {
|
|
83
|
+
counts.set(detectedCasing, (counts.get(detectedCasing) ?? 0) + 1);
|
|
84
|
+
}
|
|
85
|
+
/* on a tie, the casing counted last wins */
|
|
86
|
+
let mostUsed = CasingConvention.Unknown;
|
|
87
|
+
let mostCount = 0;
|
|
88
|
+
for (const [casing, count] of counts) {
|
|
89
|
+
if (count >= mostCount) {
|
|
90
|
+
mostUsed = casing;
|
|
91
|
+
mostCount = count;
|
|
92
|
+
}
|
|
87
93
|
}
|
|
88
|
-
|
|
89
|
-
return [...map].reduce((p, c) => p[1] > c[1] ? p : c)[0];
|
|
94
|
+
return mostUsed;
|
|
90
95
|
}
|
|
91
96
|
/**
|
|
92
97
|
* Attempts to fix the casing of the given identifier to match the provided convention.
|
|
@@ -95,17 +100,9 @@ function fixCasing(identifier, convention, ignorePrefix) {
|
|
|
95
100
|
if (!containsAlpha(identifier)) {
|
|
96
101
|
return undefined;
|
|
97
102
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const splitOn = identifier.includes('_') ? /_/ : /(?=[A-Z])/;
|
|
102
|
-
const tokens = identifier.split(splitOn).map(s => s.toLowerCase());
|
|
103
|
-
const firstUp = (s) => {
|
|
104
|
-
if (s.length < 1) {
|
|
105
|
-
return s.toUpperCase();
|
|
106
|
-
}
|
|
107
|
-
return `${s[0].toUpperCase()}${s.slice(1)}`;
|
|
108
|
-
};
|
|
103
|
+
identifier = withoutPrefix(identifier, ignorePrefix);
|
|
104
|
+
const tokens = identifier.split(identifier.includes('_') ? /_/ : /(?=[A-Z])/).map(s => s.toLowerCase());
|
|
105
|
+
const firstUp = (s) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
109
106
|
switch (convention) {
|
|
110
107
|
case CasingConvention.CamelCase: // camelCase
|
|
111
108
|
return `${tokens[0]}${tokens.slice(1).map(firstUp).join('')}`;
|
|
@@ -125,6 +122,10 @@ function fixCasing(identifier, convention, ignorePrefix) {
|
|
|
125
122
|
(0, assert_1.assertUnreachable)(convention);
|
|
126
123
|
}
|
|
127
124
|
}
|
|
125
|
+
function unquoteName(lexeme) {
|
|
126
|
+
const quoted = /^(["'`])(.*)\1$/s.exec(lexeme);
|
|
127
|
+
return quoted ? { quote: quoted[1], name: quoted[2] } : { quote: '', name: lexeme };
|
|
128
|
+
}
|
|
128
129
|
/**
|
|
129
130
|
* Creates quick fixes for renaming all references to the given node to match the provided replacement.
|
|
130
131
|
*/
|
|
@@ -135,7 +136,8 @@ function createNamingConventionQuickFixes(graph, nodeId, replacement, conv) {
|
|
|
135
136
|
return undefined;
|
|
136
137
|
}
|
|
137
138
|
/* the name as it is written, which is the only text a rename may overwrite */
|
|
138
|
-
const
|
|
139
|
+
const lexeme = idMap.get(nodeId)?.lexeme;
|
|
140
|
+
const original = lexeme === undefined ? undefined : unquoteName(lexeme).name;
|
|
139
141
|
if (original === undefined || original === replacement) {
|
|
140
142
|
/* a replacement equal to what is already there is no fix at all */
|
|
141
143
|
return undefined;
|
|
@@ -143,7 +145,8 @@ function createNamingConventionQuickFixes(graph, nodeId, replacement, conv) {
|
|
|
143
145
|
const result = [];
|
|
144
146
|
for (const ref of refs) {
|
|
145
147
|
const node = idMap.get(ref);
|
|
146
|
-
|
|
148
|
+
const written = node?.lexeme === undefined ? undefined : unquoteName(node.lexeme);
|
|
149
|
+
if (node?.lexeme === undefined || written?.name !== original) {
|
|
147
150
|
/* a reference reached through something else, as `myfield(x) <- v` reaches `x` through the call it
|
|
148
151
|
names, sits at a place holding another name, and writing over it would rename that one instead */
|
|
149
152
|
continue;
|
|
@@ -154,48 +157,57 @@ function createNamingConventionQuickFixes(graph, nodeId, replacement, conv) {
|
|
|
154
157
|
loc[3] = loc[1] + node.lexeme.length - 1;
|
|
155
158
|
result.push({
|
|
156
159
|
type: 'replace',
|
|
157
|
-
replacement: replacement
|
|
160
|
+
replacement: `${written.quote}${replacement}${written.quote}`,
|
|
158
161
|
description: `Rename to match naming convention ${conv}`,
|
|
159
|
-
loc
|
|
162
|
+
loc
|
|
160
163
|
});
|
|
161
164
|
}
|
|
162
165
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
result.sort((a, b) => range_1.SourceLocation.compare(b.loc, a.loc));
|
|
166
|
+
// We sort so that when applied in order the fixes will start from the end of the line to avoid conflicts
|
|
167
|
+
return result.length === 0 ? undefined : result.sort((a, b) => range_1.SourceLocation.compare(b.loc, a.loc));
|
|
166
168
|
}
|
|
167
169
|
exports.NAMING_CONVENTION = {
|
|
168
|
-
createSearch: (
|
|
170
|
+
createSearch: () => flowr_search_builder_1.Q.all().filter(vertex_1.VertexType.VariableDefinition),
|
|
169
171
|
processSearchResult: async (elements, config, data) => {
|
|
170
172
|
const dataflow = await data.dataflow();
|
|
173
|
+
const called = (0, unused_definition_1.collectCalledNames)(dataflow.graph);
|
|
171
174
|
const symbols = elements.getElements()
|
|
172
|
-
.map(m =>
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
175
|
+
.map(m => {
|
|
176
|
+
const name = unquoteName(m.node.lexeme).name;
|
|
177
|
+
return {
|
|
178
|
+
certainty: linter_format_1.LintingResultCertainty.Certain,
|
|
179
|
+
detectedCasing: detectCasing(name, config.ignorePrefix),
|
|
180
|
+
name,
|
|
181
|
+
loc: range_1.SourceLocation.fromNode(m.node),
|
|
182
|
+
id: m.node.info.id
|
|
183
|
+
};
|
|
184
|
+
})
|
|
185
|
+
/* an S3 method is named after its generic and class, renaming it breaks the dispatch */
|
|
186
|
+
.filter(e => (0, assert_1.isNotUndefined)(e.loc) && !(0, unused_definition_1.isS3MethodName)(e.name, data.inspectContext(), called));
|
|
187
|
+
/* a name that reads as several conventions, like a single word, says nothing about which one is in use */
|
|
188
|
+
const unambiguous = symbols.filter(s => detectPotentialCasings(s.name, config.ignorePrefix).length === 1);
|
|
189
|
+
const casing = config.caseing === 'auto' ? getMostUsedCasing(unambiguous) : config.caseing;
|
|
190
|
+
const taken = new Set(dataflow.graph.vertices(true).map(([id]) => {
|
|
191
|
+
const lexeme = dataflow.graph.idMap?.get(id)?.lexeme;
|
|
192
|
+
return lexeme === undefined ? undefined : unquoteName(lexeme).name;
|
|
193
|
+
}));
|
|
194
|
+
const results = casing === CasingConvention.Unknown ? [] : symbols
|
|
185
195
|
/* a name that already reads as the wanted convention is no violation, whatever else it could also be
|
|
186
196
|
read as: `f` carries no separator and no capital, so it is snake_case and camelCase at once */
|
|
187
197
|
.filter(m => !detectPotentialCasings(m.name, config.ignorePrefix).includes(casing)
|
|
188
198
|
&& (!config.ignoreNonAlpha || containsAlpha(m.name)))
|
|
189
199
|
.map(({ id, ...m }) => {
|
|
190
200
|
const fix = fixCasing(m.name, casing, config.ignorePrefix);
|
|
201
|
+
/* renaming onto a name already in use would merge two variables */
|
|
202
|
+
const canRename = fix !== undefined && !taken.has(fix);
|
|
191
203
|
return {
|
|
192
204
|
...m,
|
|
193
205
|
involvedId: id,
|
|
194
|
-
quickFix:
|
|
206
|
+
quickFix: canRename ? createNamingConventionQuickFixes(dataflow.graph, id, fix, casing) : undefined
|
|
195
207
|
};
|
|
196
208
|
});
|
|
197
209
|
return {
|
|
198
|
-
results
|
|
210
|
+
results,
|
|
199
211
|
'.meta': {
|
|
200
212
|
numMatches: symbols.length - results.length,
|
|
201
213
|
numBreak: results.length
|
|
@@ -36,6 +36,11 @@ function addressParam(params) {
|
|
|
36
36
|
function networkFunctions(index) {
|
|
37
37
|
const resources = new Map();
|
|
38
38
|
for (const param of index.params(built_in_props_1.ArgProp.Resource)) {
|
|
39
|
+
/* R opens a path it writes to as a local file (or a `|` pipe), never as a url */
|
|
40
|
+
const tags = index.get(param.call)?.tags;
|
|
41
|
+
if (tags?.includes(built_in_props_1.SemanticCallTag.Writes) && !tags.includes(built_in_props_1.SemanticCallTag.Reads)) {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
39
44
|
const key = identifier_1.Identifier.toString(param.call);
|
|
40
45
|
resources.set(key, [...resources.get(key) ?? [], param]);
|
|
41
46
|
}
|
|
@@ -56,14 +61,15 @@ function networkFunctions(index) {
|
|
|
56
61
|
});
|
|
57
62
|
}
|
|
58
63
|
exports.NETWORK_FUNCTIONS = {
|
|
59
|
-
createSearch:
|
|
64
|
+
createSearch: config => function_finder_util_1.functionFinderUtil.createSearch(config.fns.map(f => identifier_1.Identifier.is(f) ? f : f.name)),
|
|
60
65
|
processSearchResult: async (e, c, d) => {
|
|
61
66
|
const df = await d.dataflow();
|
|
62
67
|
const fnPool = new Map([
|
|
63
|
-
...(0,
|
|
64
|
-
...c.fns.flatMap(f => identifier_1.Identifier.is(f) ? [] : f.info === undefined ? [] : [
|
|
68
|
+
...(0, write_functions_1.writeFunctions)(d.inspectContext()).concat((0, read_functions_1.readFunctions)(d.inspectContext()), source_functions_1.SourceFunctions).map(f => [identifier_1.Identifier.toString(identifier_1.Identifier.make(f.name, f.package)), f]),
|
|
69
|
+
...c.fns.flatMap(f => identifier_1.Identifier.is(f) ? [] : f.info === undefined ? [] : [identifier_1.Identifier.getName(f.name), identifier_1.Identifier.toString(f.name)].map(key => [key, { name: identifier_1.Identifier.toString(f.name), ...f.info }]))
|
|
65
70
|
]);
|
|
66
|
-
|
|
71
|
+
/* a call whose package flowR cannot name still answers to the entry for its bare name */
|
|
72
|
+
const onlyTriggerLookup = new Map(c.fns.flatMap(f => identifier_1.Identifier.is(f) ? [] : [identifier_1.Identifier.getName(f.name), identifier_1.Identifier.toString(f.name)].map(key => [key, f.onlyTriggerWithArgument])));
|
|
67
73
|
return function_finder_util_1.functionFinderUtil.processSearchResult(e, c, d, async (es) => {
|
|
68
74
|
const res = [];
|
|
69
75
|
for (const e of es) {
|
|
@@ -77,9 +83,7 @@ exports.NETWORK_FUNCTIONS = {
|
|
|
77
83
|
if (val === logic_1.Ternary.Never) {
|
|
78
84
|
continue;
|
|
79
85
|
}
|
|
80
|
-
|
|
81
|
-
x.certainty = val === logic_1.Ternary.Always ? linter_format_1.LintingResultCertainty.Certain : linter_format_1.LintingResultCertainty.Uncertain;
|
|
82
|
-
res.push(x);
|
|
86
|
+
res.push(Object.assign(e, { certainty: val === logic_1.Ternary.Always ? linter_format_1.LintingResultCertainty.Certain : linter_format_1.LintingResultCertainty.Uncertain }));
|
|
83
87
|
}
|
|
84
88
|
return res;
|
|
85
89
|
});
|
|
@@ -7,6 +7,7 @@ const range_1 = require("../../util/range");
|
|
|
7
7
|
const linter_tags_1 = require("../linter-tags");
|
|
8
8
|
const vertex_1 = require("../../dataflow/graph/vertex");
|
|
9
9
|
const edge_1 = require("../../dataflow/graph/edge");
|
|
10
|
+
const frame_reflection_1 = require("../../dataflow/fn/frame-reflection");
|
|
10
11
|
const r_string_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-string");
|
|
11
12
|
const defaultCredentialNamePattern = '(?:password|passwd|pwd|secret|api[_.]?key|api[_.]?token|access[_.]?token|auth[_.]?token|bearer[_.]?token|private[_.]?key|credential)';
|
|
12
13
|
const defaultCredentialValuePattern = '^(?:AKIA|AIPA|ASIA|AROA)[A-Z0-9]{16}' + // AWS access key IDs (exact 20-char format)
|
|
@@ -32,27 +33,23 @@ exports.NO_LEAKED_CREDENTIALS = {
|
|
|
32
33
|
let totalChecked = 0;
|
|
33
34
|
const results = elements.getElements().flatMap(element => {
|
|
34
35
|
totalChecked++;
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
if (!vertex_1.DfgVertex.isVariableDefinition(vertex)) {
|
|
36
|
+
const id = element.node.info.id;
|
|
37
|
+
if (!vertex_1.DfgVertex.isVariableDefinition(dfg.getVertex(id))) {
|
|
38
38
|
return [];
|
|
39
39
|
}
|
|
40
|
+
const name = element.node.lexeme ?? '';
|
|
40
41
|
const nameMatches = namePattern.test(name);
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}];
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return [];
|
|
42
|
+
/* a credential-like name only leaks a non-empty string, a credential-like value leaks under any name */
|
|
43
|
+
const leaks = (0, frame_reflection_1.edgeTargets)(dfg, id, edge_1.EdgeType.DefinedBy).some(target => {
|
|
44
|
+
const value = normalize.idMap.get(target);
|
|
45
|
+
return r_string_1.RString.is(value) && ((nameMatches && value.content.str !== '') || valuePattern.test(value.content.str));
|
|
46
|
+
});
|
|
47
|
+
return leaks ? [{
|
|
48
|
+
certainty: linter_format_1.LintingResultCertainty.Uncertain,
|
|
49
|
+
involvedId: id,
|
|
50
|
+
variableName: name,
|
|
51
|
+
loc: range_1.SourceLocation.fromNode(element.node) ?? range_1.SourceLocation.invalid()
|
|
52
|
+
}] : [];
|
|
56
53
|
});
|
|
57
54
|
return { results, '.meta': { totalChecked } };
|
|
58
55
|
},
|
|
@@ -2,6 +2,7 @@ import { type LintingResult, LintingRuleCertainty } from '../linter-format';
|
|
|
2
2
|
import type { MergeableRecord } from '../../util/objects';
|
|
3
3
|
import { LintingRuleTag } from '../linter-tags';
|
|
4
4
|
import type { InputClassifierConfig, InputSources } from '../../queries/catalog/input-sources-query/simple-input-classifier';
|
|
5
|
+
import type { ReadOnlyFlowrAnalyzerContext } from '../../project/context/flowr-analyzer-context';
|
|
5
6
|
export interface PipeCommandFunctionSpec {
|
|
6
7
|
pattern: string;
|
|
7
8
|
argIdx: number;
|
|
@@ -31,7 +32,7 @@ export declare const PROBLEMATIC_INPUTS: {
|
|
|
31
32
|
readonly description: "Detects uses of dynamic calls (e.g. eval, system) with non-constant inputs, and graphics-device calls (pdf, postscript) where a filename starts with '|' indicating a pipe command injection.";
|
|
32
33
|
readonly tags: readonly [LintingRuleTag.Security, LintingRuleTag.Smell, LintingRuleTag.Readability, LintingRuleTag.Performance];
|
|
33
34
|
readonly certainty: LintingRuleCertainty.BestEffort;
|
|
34
|
-
readonly defaultConfig: (ctx:
|
|
35
|
+
readonly defaultConfig: (ctx: ReadOnlyFlowrAnalyzerContext) => {
|
|
35
36
|
consider: readonly string[];
|
|
36
37
|
pipeCommandFunctions: readonly PipeCommandFunctionSpec[];
|
|
37
38
|
};
|
|
@@ -9,8 +9,10 @@ const linter_tags_1 = require("../linter-tags");
|
|
|
9
9
|
const simple_input_classifier_1 = require("../../queries/catalog/input-sources-query/simple-input-classifier");
|
|
10
10
|
const parse_1 = require("../../slicing/criterion/parse");
|
|
11
11
|
const graph_1 = require("../../dataflow/graph/graph");
|
|
12
|
+
const vertex_1 = require("../../dataflow/graph/vertex");
|
|
12
13
|
const built_in_props_1 = require("../../dataflow/environments/built-in-props");
|
|
13
14
|
const identifier_1 = require("../../dataflow/environments/identifier");
|
|
15
|
+
const resolve_argument_1 = require("../../dataflow/eval/resolve/resolve-argument");
|
|
14
16
|
function defaultConsider(index) {
|
|
15
17
|
return ['^eval$', ...index.with(built_in_props_1.SemanticCallTag.Process).map(n => `^${identifier_1.Identifier.quote(identifier_1.Identifier.getName(n))}$`)];
|
|
16
18
|
}
|
|
@@ -25,20 +27,16 @@ function normalizePipeSpecs(cfg) {
|
|
|
25
27
|
const raw = cfg === undefined ? defaultPipeCommandFunctions
|
|
26
28
|
: (0, arrays_1.isArray)(cfg) ? (cfg.length === 0 ? defaultPipeCommandFunctions : cfg)
|
|
27
29
|
: [cfg];
|
|
28
|
-
return raw.map(s => ({ pattern: new RegExp(s.pattern)
|
|
30
|
+
return raw.map(s => ({ ...s, pattern: new RegExp(s.pattern) }));
|
|
29
31
|
}
|
|
30
|
-
function formatInputSources(inputs, inline
|
|
31
|
-
|
|
32
|
-
return inline ? '' : [];
|
|
33
|
-
}
|
|
34
|
-
const fmt = (s) => {
|
|
32
|
+
function formatInputSources(inputs, inline) {
|
|
33
|
+
return inputs.map(s => {
|
|
35
34
|
const t = '[' + s.types.join(',') + ']';
|
|
36
35
|
const c = s.cds ? ', cds: [' + s.cds.join(',') + ']' : '';
|
|
37
36
|
return inline
|
|
38
37
|
? `${s.id} (type: ${t}, trace: ${s.trace}${c})`
|
|
39
38
|
: `- ${s.id}: type=${t}, trace=${s.trace}${c}`;
|
|
40
|
-
};
|
|
41
|
-
return inline ? inputs.map(fmt).join('; ') : inputs.map(fmt);
|
|
39
|
+
});
|
|
42
40
|
}
|
|
43
41
|
function hasUnknownSource(sources) {
|
|
44
42
|
return sources.some(s => s.types.includes(simple_input_classifier_1.InputType.Unknown));
|
|
@@ -46,6 +44,7 @@ function hasUnknownSource(sources) {
|
|
|
46
44
|
function isProblematicForAllowed(sources, allowed) {
|
|
47
45
|
return sources.some(s => s.types.some(t => !allowed.includes(t)));
|
|
48
46
|
}
|
|
47
|
+
/** A path starting with `|` runs a command, so anything but a constant path, user input included, may start one. */
|
|
49
48
|
function getPipeCommandValue(sources) {
|
|
50
49
|
for (const s of sources) {
|
|
51
50
|
if (typeof s.value === 'string' && s.value.startsWith('|')) {
|
|
@@ -54,37 +53,19 @@ function getPipeCommandValue(sources) {
|
|
|
54
53
|
}
|
|
55
54
|
return undefined;
|
|
56
55
|
}
|
|
57
|
-
function resolveFileArgId(vertex, argIdx, argName) {
|
|
58
|
-
|
|
59
|
-
if (!args) {
|
|
60
|
-
return undefined;
|
|
61
|
-
}
|
|
62
|
-
let idx = args.findIndex(a => graph_1.FunctionArgument.isNamed(a) && a.name === argName);
|
|
63
|
-
if (idx < 0) {
|
|
64
|
-
idx = argIdx;
|
|
65
|
-
}
|
|
66
|
-
if (idx >= args.length) {
|
|
56
|
+
function resolveFileArgId(graph, vertex, argIdx, argName, ctx) {
|
|
57
|
+
if (!vertex_1.DfgVertex.isFunctionCall(vertex)) {
|
|
67
58
|
return undefined;
|
|
68
59
|
}
|
|
69
|
-
const arg = args[
|
|
70
|
-
return
|
|
71
|
-
}
|
|
72
|
-
function checkPipeInjection(nid, loc, name, sources) {
|
|
73
|
-
const pipeCmd = getPipeCommandValue(sources);
|
|
74
|
-
if (pipeCmd !== undefined) {
|
|
75
|
-
return { involvedId: nid, certainty: linter_format_1.LintingResultCertainty.Certain, loc, name, sources, pipeCommand: pipeCmd };
|
|
76
|
-
}
|
|
77
|
-
if (hasUnknownSource(sources)) {
|
|
78
|
-
return { involvedId: nid, certainty: linter_format_1.LintingResultCertainty.Uncertain, loc, name, sources };
|
|
79
|
-
}
|
|
80
|
-
return undefined;
|
|
60
|
+
const arg = vertex.args[(0, resolve_argument_1.boundArgumentIndex)(graph, vertex, argIdx, argName, ctx)];
|
|
61
|
+
return arg === undefined ? undefined : graph_1.FunctionArgument.getReference(arg);
|
|
81
62
|
}
|
|
82
63
|
exports.PROBLEMATIC_INPUTS = {
|
|
83
|
-
createSearch:
|
|
64
|
+
createSearch: config => {
|
|
84
65
|
const toQ = (name, subkind) => ({ type: 'call-context', callName: name, callNameExact: false, subkind });
|
|
85
66
|
return flowr_search_builder_1.Q.fromQuery([
|
|
86
67
|
...normalizePatternList(config.consider).map((n, i) => toQ(n, `fn-${i}`)),
|
|
87
|
-
...normalizePipeSpecs(config
|
|
68
|
+
...normalizePipeSpecs(config.pipeCommandFunctions).map((s, i) => toQ(s.pattern, `pipe-${i}`))
|
|
88
69
|
]);
|
|
89
70
|
},
|
|
90
71
|
processSearchResult: async (elements, config, data) => {
|
|
@@ -93,7 +74,7 @@ exports.PROBLEMATIC_INPUTS = {
|
|
|
93
74
|
const seen = new Set();
|
|
94
75
|
const defaultAccept = [simple_input_classifier_1.InputType.Constant, simple_input_classifier_1.InputType.DerivedConstant];
|
|
95
76
|
const considerPats = normalizePatternList(config.consider);
|
|
96
|
-
const pipePats = normalizePipeSpecs(config
|
|
77
|
+
const pipePats = normalizePipeSpecs(config.pipeCommandFunctions);
|
|
97
78
|
for (const element of elements.getElements()) {
|
|
98
79
|
const nid = element.node.info.id;
|
|
99
80
|
if (seen.has(nid)) {
|
|
@@ -101,33 +82,32 @@ exports.PROBLEMATIC_INPUTS = {
|
|
|
101
82
|
}
|
|
102
83
|
const name = element.node.lexeme ?? '';
|
|
103
84
|
const pipeSpec = pipePats.find(s => s.pattern.test(name));
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
continue;
|
|
107
|
-
}
|
|
108
|
-
const loc = range_1.SourceLocation.fromNode(element.node) ?? range_1.SourceLocation.invalid();
|
|
85
|
+
/* a pipe spec checks the file argument of the call, a considered call the call itself */
|
|
86
|
+
let target;
|
|
109
87
|
if (pipeSpec !== undefined) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
if (r !== undefined) {
|
|
118
|
-
seen.add(nid);
|
|
119
|
-
results.push(r);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
88
|
+
target = resolveFileArgId(df.graph, df.graph.getVertex(nid), pipeSpec.argIdx, pipeSpec.argName, data.inspectContext());
|
|
89
|
+
}
|
|
90
|
+
else if (considerPats.some(p => p.test(name))) {
|
|
91
|
+
target = nid;
|
|
92
|
+
}
|
|
93
|
+
if (target === undefined) {
|
|
94
|
+
continue;
|
|
122
95
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
96
|
+
const criterion = parse_1.SlicingCriterion.fromId(target);
|
|
97
|
+
const all = await data.query([{ type: 'input-sources', criterion, config: config.inputFns }]);
|
|
98
|
+
const sources = all['input-sources']?.results?.[criterion] ?? [];
|
|
99
|
+
const pipeCommand = pipeSpec === undefined ? undefined : getPipeCommandValue(sources);
|
|
100
|
+
if (pipeCommand !== undefined || isProblematicForAllowed(sources, defaultAccept)) {
|
|
101
|
+
seen.add(nid);
|
|
102
|
+
const uncertain = pipeCommand === undefined && hasUnknownSource(sources);
|
|
103
|
+
results.push({
|
|
104
|
+
involvedId: nid,
|
|
105
|
+
certainty: uncertain ? linter_format_1.LintingResultCertainty.Uncertain : linter_format_1.LintingResultCertainty.Certain,
|
|
106
|
+
loc: range_1.SourceLocation.fromNode(element.node) ?? range_1.SourceLocation.invalid(),
|
|
107
|
+
name,
|
|
108
|
+
sources,
|
|
109
|
+
...(pipeCommand === undefined ? {} : { pipeCommand })
|
|
110
|
+
});
|
|
131
111
|
}
|
|
132
112
|
}
|
|
133
113
|
return { results };
|
|
@@ -137,7 +117,7 @@ exports.PROBLEMATIC_INPUTS = {
|
|
|
137
117
|
if (result.pipeCommand !== undefined) {
|
|
138
118
|
return `Pipe command injection via '${result.pipeCommand}' in call to ${result.name} at ${range_1.SourceLocation.format(result.loc)}`;
|
|
139
119
|
}
|
|
140
|
-
const src = formatInputSources(result.sources ?? [], true);
|
|
120
|
+
const src = formatInputSources(result.sources ?? [], true).join('; ');
|
|
141
121
|
return 'Use of configured dynamic call at ' + range_1.SourceLocation.format(result.loc) + (src ? '; inputs: ' + src : '');
|
|
142
122
|
},
|
|
143
123
|
[linter_format_1.LintingPrettyPrintContext.Full]: result => {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { type LintingResult, LintingRuleCertainty } from '../linter-format';
|
|
1
|
+
import { type LintingResult, LintingResultCertainty, LintingRuleCertainty } from '../linter-format';
|
|
2
2
|
import type { MergeableRecord } from '../../util/objects';
|
|
3
3
|
import { LintingRuleTag } from '../linter-tags';
|
|
4
|
-
import type { Writable } from 'ts-essentials';
|
|
5
4
|
export interface RoxygenArgsResult extends LintingResult {
|
|
6
5
|
readonly overDocumented?: string[];
|
|
7
6
|
readonly underDocumented?: string[];
|
|
@@ -10,8 +9,14 @@ export type RoxygenArgsConfig = MergeableRecord;
|
|
|
10
9
|
export type RoxygenArgsMetadata = MergeableRecord;
|
|
11
10
|
export declare const ROXYGEN_ARGS: {
|
|
12
11
|
readonly createSearch: () => import("../../search/flowr-search-builder").FlowrSearchBuilder<"all", ["filter", "with"], 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>[]>>>;
|
|
13
|
-
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>[]
|
|
14
|
-
results:
|
|
12
|
+
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>[]>) => {
|
|
13
|
+
results: {
|
|
14
|
+
certainty: LintingResultCertainty.Uncertain;
|
|
15
|
+
involvedId: import("../..").NodeId;
|
|
16
|
+
loc: [startLine: number, startColumn: number, endLine: number, endColumn: number, f?: string | undefined];
|
|
17
|
+
underDocumented: string[];
|
|
18
|
+
overDocumented: string[];
|
|
19
|
+
}[];
|
|
15
20
|
'.meta': {};
|
|
16
21
|
};
|
|
17
22
|
readonly prettyPrint: {
|
|
@@ -5,27 +5,22 @@ const linter_format_1 = require("../linter-format");
|
|
|
5
5
|
const range_1 = require("../../util/range");
|
|
6
6
|
const flowr_search_builder_1 = require("../../search/flowr-search-builder");
|
|
7
7
|
const linter_tags_1 = require("../linter-tags");
|
|
8
|
-
const assert_1 = require("../../util/assert");
|
|
9
8
|
const vertex_1 = require("../../dataflow/graph/vertex");
|
|
10
9
|
const roxygen_ast_1 = require("../../r-bridge/roxygen2/roxygen-ast");
|
|
11
10
|
const r_function_definition_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-definition");
|
|
12
11
|
const search_enrichers_1 = require("../../search/search-executor/search-enrichers");
|
|
12
|
+
const identifier_1 = require("../../dataflow/environments/identifier");
|
|
13
13
|
function calculateArgumentDiff(inheritedParams, functionParam, roxygenParam) {
|
|
14
14
|
//match documented against existing params
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
let overDocumented = new Set(roxygenParam);
|
|
18
|
-
const commonParams = underDocumented.intersection(overDocumented);
|
|
19
|
-
underDocumented = underDocumented.difference(commonParams);
|
|
20
|
-
overDocumented = overDocumented.difference(commonParams);
|
|
15
|
+
const underDocumented = new Set(functionParam).difference(new Set(roxygenParam));
|
|
16
|
+
let overDocumented = new Set(roxygenParam).difference(new Set(functionParam));
|
|
21
17
|
//case: '...', overdocumentation not possible
|
|
22
|
-
if (
|
|
18
|
+
if (functionParam.includes('...')) {
|
|
23
19
|
//if still remaining overdocumented parameters, "..." doesn't need to be documented
|
|
24
20
|
if (overDocumented.size > 0) {
|
|
25
21
|
underDocumented.delete('...');
|
|
26
22
|
}
|
|
27
|
-
|
|
28
|
-
overDocumented.clear();
|
|
23
|
+
overDocumented = new Set();
|
|
29
24
|
}
|
|
30
25
|
//inherited params removed from list of overdocumented params
|
|
31
26
|
overDocumented = overDocumented.difference(new Set(inheritedParams));
|
|
@@ -35,44 +30,30 @@ exports.ROXYGEN_ARGS = {
|
|
|
35
30
|
createSearch: () => flowr_search_builder_1.Q.all()
|
|
36
31
|
.filter(vertex_1.VertexType.FunctionDefinition)
|
|
37
32
|
.with(search_enrichers_1.Enrichment.Roxygen),
|
|
38
|
-
processSearchResult:
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
overDocumented.push(...result.over);
|
|
63
|
-
return true;
|
|
64
|
-
})
|
|
65
|
-
.map(({ element, overDocumented, underDocumented }) => ({
|
|
66
|
-
certainty: linter_format_1.LintingResultCertainty.Uncertain,
|
|
67
|
-
involvedId: element.node.info.id,
|
|
68
|
-
loc: range_1.SourceLocation.fromNode(element.node),
|
|
69
|
-
underDocumented: underDocumented,
|
|
70
|
-
overDocumented: overDocumented
|
|
71
|
-
}))
|
|
72
|
-
.filter(element => (0, assert_1.isNotUndefined)(element.loc)),
|
|
73
|
-
'.meta': {}
|
|
74
|
-
};
|
|
75
|
-
},
|
|
33
|
+
processSearchResult: elements => ({
|
|
34
|
+
results: elements.getElements().flatMap(element => {
|
|
35
|
+
const node = element.node;
|
|
36
|
+
const roxygen = (0, search_enrichers_1.enrichmentContent)(element, search_enrichers_1.Enrichment.Roxygen);
|
|
37
|
+
if (!roxygen.documentation.length) {
|
|
38
|
+
return [];
|
|
39
|
+
}
|
|
40
|
+
const params = roxygen.tags[roxygen_ast_1.KnownRoxygenTags.Param] ?? [];
|
|
41
|
+
const functionParamNames = getParameters(node).map(p => identifier_1.Identifier.make(identifier_1.Identifier.getName(p.name.content)).toString());
|
|
42
|
+
/* one `@param a,b` documents several parameters */
|
|
43
|
+
const documented = (tag) => tag.value.name.split(',').map(n => n.trim()).filter(n => n.length > 0);
|
|
44
|
+
const inheritedParams = params.filter(tag => tag.inherited).flatMap(documented);
|
|
45
|
+
const diff = calculateArgumentDiff(inheritedParams, functionParamNames, params.flatMap(documented));
|
|
46
|
+
const loc = range_1.SourceLocation.fromNode(node);
|
|
47
|
+
return diff === false || loc === undefined ? [] : [{
|
|
48
|
+
certainty: linter_format_1.LintingResultCertainty.Uncertain,
|
|
49
|
+
involvedId: node.info.id,
|
|
50
|
+
loc,
|
|
51
|
+
underDocumented: diff.under,
|
|
52
|
+
overDocumented: diff.over
|
|
53
|
+
}];
|
|
54
|
+
}),
|
|
55
|
+
'.meta': {}
|
|
56
|
+
}),
|
|
76
57
|
prettyPrint: {
|
|
77
58
|
[linter_format_1.LintingPrettyPrintContext.Query]: result => `Function at ${range_1.SourceLocation.format(result.loc)} has ${describeArgumentDiff(result)}`,
|
|
78
59
|
[linter_format_1.LintingPrettyPrintContext.Full]: result => `Function at ${range_1.SourceLocation.format(result.loc)} has ${describeArgumentDiff(result)}`
|