@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
|
@@ -2,6 +2,8 @@ import { type LintingResult, LintingRuleCertainty } from '../linter-format';
|
|
|
2
2
|
import type { MergeableRecord } from '../../util/objects';
|
|
3
3
|
import type { FunctionInfo } from '../../queries/catalog/dependencies-query/function-info/function-info';
|
|
4
4
|
import { LintingRuleTag } from '../linter-tags';
|
|
5
|
+
import type { ParentInformation } from '../../r-bridge/lang-4.x/ast/model/processing/decorate';
|
|
6
|
+
import type { ReadonlyFlowrAnalysisProvider } from '../../project/flowr-analyzer';
|
|
5
7
|
export interface FilePathValidityResult extends LintingResult {
|
|
6
8
|
filePath: string;
|
|
7
9
|
}
|
|
@@ -34,8 +36,8 @@ export interface FilePathValidityMetadata extends MergeableRecord {
|
|
|
34
36
|
totalValid: number;
|
|
35
37
|
}
|
|
36
38
|
export declare const FILE_PATH_VALIDITY: {
|
|
37
|
-
readonly createSearch: (config: FilePathValidityConfig) => import("../../search/flowr-search-builder").FlowrSearchBuilder<"from-query", ["with"],
|
|
38
|
-
readonly processSearchResult: (elements: import("../../search/flowr-search").FlowrSearchElements<
|
|
39
|
+
readonly createSearch: (config: FilePathValidityConfig) => import("../../search/flowr-search-builder").FlowrSearchBuilder<"from-query", ["with"], ParentInformation, Promise<import("../../search/flowr-search").FlowrSearchElements<ParentInformation, import("../../search/flowr-search").FlowrSearchElement<ParentInformation>[]>>>;
|
|
40
|
+
readonly processSearchResult: (elements: import("../../search/flowr-search").FlowrSearchElements<ParentInformation, import("../../search/flowr-search").FlowrSearchElement<ParentInformation>[]>, config: FilePathValidityConfig, data: ReadonlyFlowrAnalysisProvider<import("../..").KnownParser>) => Promise<{
|
|
39
41
|
results: FilePathValidityResult[];
|
|
40
42
|
".meta": FilePathValidityMetadata;
|
|
41
43
|
}>;
|
|
@@ -9,25 +9,42 @@ const dependencies_query_format_1 = require("../../queries/catalog/dependencies-
|
|
|
9
9
|
const built_in_source_1 = require("../../dataflow/internal/process/functions/call/built-in/built-in-source");
|
|
10
10
|
const logic_1 = require("../../util/logic");
|
|
11
11
|
const happens_before_1 = require("../../control-flow/happens-before");
|
|
12
|
+
const read_functions_1 = require("../../queries/catalog/dependencies-query/function-info/read-functions");
|
|
13
|
+
const library_functions_1 = require("../../queries/catalog/dependencies-query/function-info/library-functions");
|
|
14
|
+
const identifier_1 = require("../../dataflow/environments/identifier");
|
|
12
15
|
const linter_tags_1 = require("../linter-tags");
|
|
13
16
|
const search_enrichers_1 = require("../../search/search-executor/search-enrichers");
|
|
14
17
|
const resolve_working_directory_1 = require("../../dataflow/eval/resolve/resolve-working-directory");
|
|
15
18
|
const config_1 = require("../../config");
|
|
16
19
|
const r_function_call_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
|
|
17
20
|
const r_string_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-string");
|
|
21
|
+
const r_argument_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
|
|
22
|
+
const model_1 = require("../../r-bridge/lang-4.x/ast/model/model");
|
|
23
|
+
const r_function_definition_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-definition");
|
|
24
|
+
const r_if_then_else_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-if-then-else");
|
|
25
|
+
const r_while_loop_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-while-loop");
|
|
26
|
+
const vertex_1 = require("../../dataflow/graph/vertex");
|
|
27
|
+
const function_semantics_1 = require("../../dataflow/fn/function-semantics");
|
|
28
|
+
const query_fn_props_1 = require("../../dataflow/environments/query-fn-props");
|
|
29
|
+
const built_in_props_1 = require("../../dataflow/environments/built-in-props");
|
|
30
|
+
const resolve_argument_1 = require("../../dataflow/eval/resolve/resolve-argument");
|
|
31
|
+
const r_base_packages_1 = require("../../util/r-base-packages");
|
|
32
|
+
const DataSetExtensions = ['R', 'r', 'RData', 'rdata', 'rda', 'tab', 'txt', 'TXT', 'tab.gz', 'tab.bz2', 'tab.xz', 'txt.gz', 'txt.bz2', 'txt.xz', 'csv', 'CSV'];
|
|
33
|
+
function namesPackage(node) {
|
|
34
|
+
return r_function_call_1.RFunctionCall.is(node) && node.arguments.some(a => a !== r_function_call_1.EmptyArgument && a.name !== undefined && ['package', 'lib.loc'].includes(identifier_1.Identifier.getName(a.name.content)));
|
|
35
|
+
}
|
|
18
36
|
async function urlExists(url) {
|
|
19
37
|
try {
|
|
20
|
-
|
|
21
|
-
return response.ok;
|
|
38
|
+
return (await fetch(url, { method: 'HEAD' })).ok;
|
|
22
39
|
}
|
|
23
40
|
catch {
|
|
24
41
|
return false;
|
|
25
42
|
}
|
|
26
43
|
}
|
|
27
44
|
exports.FILE_PATH_VALIDITY = {
|
|
28
|
-
createSearch:
|
|
45
|
+
createSearch: config => flowr_search_builder_1.Q.fromQuery({
|
|
29
46
|
type: 'dependencies',
|
|
30
|
-
enabledCategories: ['read', 'write'],
|
|
47
|
+
enabledCategories: ['read', 'write', 'library'],
|
|
31
48
|
readFunctions: config.additionalReadFunctions,
|
|
32
49
|
writeFunctions: config.additionalWriteFunctions
|
|
33
50
|
}).with(search_enrichers_1.Enrichment.CfgInformation),
|
|
@@ -41,96 +58,89 @@ exports.FILE_PATH_VALIDITY = {
|
|
|
41
58
|
};
|
|
42
59
|
const results = elements.enrichmentContent(search_enrichers_1.Enrichment.QueryData).queries['dependencies'];
|
|
43
60
|
const ctx = data.inspectContext();
|
|
44
|
-
const
|
|
45
|
-
const
|
|
61
|
+
const df = await data.dataflow();
|
|
62
|
+
const dfg = df.graph;
|
|
63
|
+
const { resolveSource } = data.flowrConfig.solver;
|
|
46
64
|
const wdRootsFor = resolve_working_directory_1.WorkingDirectory.rootsResolver(dfg, cfg, ctx);
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
65
|
+
/* `data("x")` names a data set, not a file */
|
|
66
|
+
const namesOnly = new Set((0, read_functions_1.readFunctions)(ctx).concat(config.additionalReadFunctions).filter(f => f.resolveValue === 'library').map(f => f.name));
|
|
67
|
+
const attached = (results.library ?? []).filter(library_functions_1.attachesPackage);
|
|
68
|
+
const atTopLevel = (id) => dfg.idMap === undefined || model_1.RNode.findEnclosing(id, dfg.idMap, r_function_definition_1.RFunctionDefinition.is) === undefined;
|
|
69
|
+
const librariesLoadedBefore = (read) => attached.some(l => l.nodeId === undefined || !atTopLevel(l.nodeId) || !atTopLevel(read)
|
|
70
|
+
|| !cfg.hasVertex(l.nodeId) || (0, happens_before_1.happensBefore)(cfg, l.nodeId, read) !== logic_1.Ternary.Never);
|
|
71
|
+
const uniqueElements = [...new Map(elements.getElements().map(e => [e.node.info.id, e])).values()];
|
|
72
|
+
const reads = uniqueElements.flatMap(element => results.read
|
|
73
|
+
.filter(r => r.nodeId === element.node.info.id)
|
|
74
|
+
.map(matchingRead => ({ element, matchingRead })));
|
|
75
|
+
const findings = await Promise.all(reads.map(async ({ element, matchingRead }) => {
|
|
76
|
+
const { nodeId, value } = matchingRead;
|
|
77
|
+
/* data built from constants, like `matrix(1:6, 2)`, reads no file */
|
|
78
|
+
if (nodeId === undefined || value === dependencies_query_format_1.Constant) {
|
|
50
79
|
return [];
|
|
51
80
|
}
|
|
52
|
-
|
|
81
|
+
const { id, file } = element.node.info;
|
|
53
82
|
const loc = range_1.SourceLocation.fromNode(element.node);
|
|
83
|
+
const referenceChain = file ? [file] : [];
|
|
84
|
+
const verdict = (valid, filePath, certainty, quickFix) => {
|
|
85
|
+
if (valid) {
|
|
86
|
+
metadata.totalValid++;
|
|
87
|
+
return [];
|
|
88
|
+
}
|
|
89
|
+
return [{ involvedId: nodeId, loc: loc, filePath, certainty, ...(quickFix ? { quickFix } : {}) }];
|
|
90
|
+
};
|
|
91
|
+
if (namesOnly.has(identifier_1.Identifier.getName(matchingRead.functionName))) {
|
|
92
|
+
if (!loc || typeof value !== 'string' || value === dependencies_query_format_1.Unknown
|
|
93
|
+
|| librariesLoadedBefore(id) || r_base_packages_1.BaseDatasets.has(value) || namesPackage(element.node)) {
|
|
94
|
+
return [];
|
|
95
|
+
}
|
|
96
|
+
metadata.totalReads++;
|
|
97
|
+
const find = finderAt(resolveSource, wdRootsFor(id, file), file, ctx);
|
|
98
|
+
const exists = DataSetExtensions.some(ext => find(`data/${value}.${ext}`).length);
|
|
99
|
+
return verdict(exists, `data/${value}`, linter_format_1.LintingResultCertainty.Uncertain);
|
|
100
|
+
}
|
|
101
|
+
metadata.totalReads++;
|
|
54
102
|
if (!loc) {
|
|
55
103
|
return [];
|
|
56
104
|
}
|
|
57
105
|
// check if we can't parse the file path statically
|
|
58
|
-
if (
|
|
106
|
+
if (value === dependencies_query_format_1.Unknown) {
|
|
59
107
|
metadata.totalUnknown++;
|
|
60
|
-
|
|
61
|
-
return [{
|
|
62
|
-
involvedId: matchingRead.nodeId,
|
|
63
|
-
loc,
|
|
64
|
-
filePath: dependencies_query_format_1.Unknown,
|
|
65
|
-
certainty: linter_format_1.LintingResultCertainty.Uncertain
|
|
66
|
-
}];
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
return [];
|
|
70
|
-
}
|
|
108
|
+
return config.includeUnknown ? [{ involvedId: nodeId, loc, filePath: dependencies_query_format_1.Unknown, certainty: linter_format_1.LintingResultCertainty.Uncertain }] : [];
|
|
71
109
|
}
|
|
110
|
+
const path = value;
|
|
72
111
|
// file:// URIs are local paths; resolve and check existence directly
|
|
73
|
-
const localFromFileUrl = (0, strings_1.fileUrlToPath)(
|
|
112
|
+
const localFromFileUrl = (0, strings_1.fileUrlToPath)(path);
|
|
74
113
|
if (localFromFileUrl !== undefined) {
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
ctx: data.inspectContext()
|
|
78
|
-
});
|
|
79
|
-
if (paths && paths.length) {
|
|
80
|
-
metadata.totalValid++;
|
|
81
|
-
return [];
|
|
82
|
-
}
|
|
83
|
-
return [{
|
|
84
|
-
involvedId: matchingRead.nodeId,
|
|
85
|
-
loc,
|
|
86
|
-
filePath: localFromFileUrl,
|
|
87
|
-
certainty: linter_format_1.LintingResultCertainty.Certain
|
|
88
|
-
}];
|
|
114
|
+
const exists = !!(0, built_in_source_1.findSource)(resolveSource, localFromFileUrl, { referenceChain, ctx })?.length;
|
|
115
|
+
return verdict(exists, localFromFileUrl, linter_format_1.LintingResultCertainty.Certain);
|
|
89
116
|
}
|
|
90
117
|
// handle remote URLs separately from file paths
|
|
91
|
-
if ((0, strings_1.isUrl)(
|
|
92
|
-
|
|
93
|
-
return [];
|
|
94
|
-
}
|
|
95
|
-
const exists = await urlExists(matchingRead.value);
|
|
96
|
-
if (exists) {
|
|
97
|
-
metadata.totalValid++;
|
|
98
|
-
return [];
|
|
99
|
-
}
|
|
100
|
-
return [{
|
|
101
|
-
involvedId: matchingRead.nodeId,
|
|
102
|
-
loc,
|
|
103
|
-
filePath: matchingRead.value,
|
|
104
|
-
certainty: linter_format_1.LintingResultCertainty.Uncertain
|
|
105
|
-
}];
|
|
118
|
+
if ((0, strings_1.isUrl)(path)) {
|
|
119
|
+
return config.checkUrls ? verdict(await urlExists(path), path, linter_format_1.LintingResultCertainty.Uncertain) : [];
|
|
106
120
|
}
|
|
107
121
|
// check if any write to the same file happens before the read, and exclude this case if so
|
|
108
|
-
const writesToFile = results.write.filter((r) => r.nodeId !== undefined && samePath(r.value,
|
|
109
|
-
const writesBefore = writesToFile.map(w => (0, happens_before_1.happensBefore)(cfg, w.nodeId,
|
|
122
|
+
const writesToFile = results.write.filter((r) => r.nodeId !== undefined && samePath(r.value, path, resolveSource?.ignoreCapitalization));
|
|
123
|
+
const writesBefore = writesToFile.map(w => (0, happens_before_1.happensBefore)(cfg, w.nodeId, id));
|
|
110
124
|
if (writesBefore.includes(logic_1.Ternary.Always)) {
|
|
111
125
|
metadata.totalWritesBeforeAlways++;
|
|
112
126
|
return [];
|
|
113
127
|
}
|
|
114
128
|
// check if the file exists, resolving relative paths against the effective working directory
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
const withWd = { ...resolveSource, searchPath: [...(resolveSource?.searchPath ?? []), ...wdRoots] };
|
|
119
|
-
const paths = (0, built_in_source_1.findSource)(withWd, value, { referenceChain, ctx });
|
|
120
|
-
if (paths && paths.length) {
|
|
121
|
-
metadata.totalValid++;
|
|
122
|
-
return [];
|
|
129
|
+
const wdRoots = wdRootsFor(id, file);
|
|
130
|
+
if (finderAt(resolveSource, wdRoots, file, ctx)(path).length) {
|
|
131
|
+
return verdict(true, path, linter_format_1.LintingResultCertainty.Certain);
|
|
123
132
|
}
|
|
124
|
-
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
133
|
+
/* a lax retry (drop leading dirs, ignore case) may surface a near match to offer as a quick fix */
|
|
134
|
+
const laxOptions = {
|
|
135
|
+
...searchingFrom(resolveSource, wdRoots.roots),
|
|
136
|
+
ignoreCapitalization: true,
|
|
137
|
+
dropPaths: config_1.DropPathsOption.All
|
|
138
|
+
};
|
|
139
|
+
const near = (0, built_in_source_1.findSource)(laxOptions, path, { referenceChain, ctx });
|
|
140
|
+
const quickFix = dfg.idMap && near?.length ? buildDidYouMeanFix(dfg.idMap, nodeId, path, near[0]) : undefined;
|
|
141
|
+
const maybeWrittenBefore = writesBefore.length > 0 && writesBefore.every(w => w === logic_1.Ternary.Maybe);
|
|
142
|
+
const uncertain = maybeWrittenBefore || guardedByFileQuery(df, id, path, data);
|
|
143
|
+
return verdict(false, path, uncertain ? linter_format_1.LintingResultCertainty.Uncertain : linter_format_1.LintingResultCertainty.Certain, quickFix);
|
|
134
144
|
}));
|
|
135
145
|
return {
|
|
136
146
|
results: findings.flat(),
|
|
@@ -155,6 +165,35 @@ exports.FILE_PATH_VALIDITY = {
|
|
|
155
165
|
[linter_format_1.LintingPrettyPrintContext.Full]: result => `Path \`${result.filePath}\` at ${range_1.SourceLocation.format(result.loc)} does not point to a valid file`
|
|
156
166
|
}
|
|
157
167
|
};
|
|
168
|
+
/** Whether the read only runs depending on a condition that queries the same file, as in `if(file.exists(p)) readLines(p)`. */
|
|
169
|
+
function guardedByFileQuery(df, read, path, data) {
|
|
170
|
+
const dfg = df.graph;
|
|
171
|
+
return (dfg.getVertex(read)?.cds ?? []).some(cd => {
|
|
172
|
+
const construct = dfg.idMap?.get(cd.id);
|
|
173
|
+
const condition = r_if_then_else_1.RIfThenElse.is(construct) || r_while_loop_1.RWhileLoop.is(construct) ? construct.condition : undefined;
|
|
174
|
+
return [...model_1.RNode.collectAllIds(condition)].some(id => {
|
|
175
|
+
const call = dfg.getVertex(id);
|
|
176
|
+
if (!vertex_1.DfgVertex.isFunctionCall(call) || !function_semantics_1.FunctionSemantics.call.props.hasAny((0, query_fn_props_1.callFnProps)(call.id, df), built_in_props_1.SemanticCallTag.File)) {
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
const args = (0, resolve_argument_1.getArgumentStringValue)(data.flowrConfig.solver.variables, dfg, call, 'unnamed', undefined, true, data.inspectContext());
|
|
180
|
+
return args?.values().some(v => v.has(path)) ?? false;
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
function searchingFrom(resolveSource, roots) {
|
|
185
|
+
return { ...resolveSource, searchPath: [...(resolveSource?.searchPath ?? []), ...roots] };
|
|
186
|
+
}
|
|
187
|
+
/** looks a path up from the working directories a `setwd` pins down, and laxly along the configured search path if none does. */
|
|
188
|
+
function finderAt(resolveSource, { roots, pinned }, file, ctx) {
|
|
189
|
+
const referenceChain = file ? [file] : [];
|
|
190
|
+
if (!pinned) {
|
|
191
|
+
const lax = searchingFrom(resolveSource, roots);
|
|
192
|
+
return value => (0, built_in_source_1.findSource)(lax, value, { referenceChain, ctx }) ?? [];
|
|
193
|
+
}
|
|
194
|
+
const strict = { ...resolveSource, searchPath: [], dropPaths: config_1.DropPathsOption.No, inferWorkingDirectory: config_1.InferWorkingDirectory.No };
|
|
195
|
+
return value => roots.flatMap(root => (0, built_in_source_1.findSource)(strict, resolve_working_directory_1.WorkingDirectory.applyChange(root, value), { referenceChain, ctx }) ?? []);
|
|
196
|
+
}
|
|
158
197
|
function samePath(a, b, ignoreCapitalization) {
|
|
159
198
|
if (ignoreCapitalization === true) {
|
|
160
199
|
a = a.toLowerCase();
|
|
@@ -168,19 +207,14 @@ function pathArgStringNode(idMap, callId, value) {
|
|
|
168
207
|
if (!r_function_call_1.RFunctionCall.is(call)) {
|
|
169
208
|
return undefined;
|
|
170
209
|
}
|
|
171
|
-
|
|
172
|
-
if (arg !== r_function_call_1.EmptyArgument && arg.value && r_string_1.RString.is(arg.value) && arg.value.content.str === value) {
|
|
173
|
-
return arg.value;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
return undefined;
|
|
210
|
+
return call.arguments.map(r_argument_1.RArgument.valueOf).find(v => r_string_1.RString.is(v) && v.content.str === value);
|
|
177
211
|
}
|
|
178
212
|
/** rewrite the read path to `found`, an existing file surfaced by the lax retry */
|
|
179
213
|
function buildDidYouMeanFix(idMap, callId, value, found) {
|
|
180
214
|
const str = pathArgStringNode(idMap, callId, value);
|
|
181
215
|
const loc = str === undefined ? undefined : range_1.SourceLocation.fromNode(str);
|
|
182
|
-
if (!str || loc === undefined) {
|
|
183
|
-
/* a fix that names no place cannot be carried out, so none is offered */
|
|
216
|
+
if (!str || loc === undefined || found === value) {
|
|
217
|
+
/* a fix that names no place or changes nothing cannot be carried out, so none is offered */
|
|
184
218
|
return undefined;
|
|
185
219
|
}
|
|
186
220
|
return [{
|
|
@@ -8,6 +8,7 @@ const flowr_search_builder_1 = require("../../search/flowr-search-builder");
|
|
|
8
8
|
const range_1 = require("../../util/range");
|
|
9
9
|
const linter_format_1 = require("../linter-format");
|
|
10
10
|
const linter_tags_1 = require("../linter-tags");
|
|
11
|
+
const schema_1 = require("../../project/sigdb/schema");
|
|
11
12
|
/**
|
|
12
13
|
* Cross-checks every `pkg::name`/`pkg:::name` against the signature database's exported bit.
|
|
13
14
|
* An absent entry (unknown package, unresolved version, uncatalogued name) is never read as "not exported" -
|
|
@@ -21,39 +22,26 @@ exports.NAMESPACE_ACCESS = {
|
|
|
21
22
|
const db = data.inspectContext().deps.signatures();
|
|
22
23
|
const results = [];
|
|
23
24
|
let unresolved = 0;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
const loc = range_1.SourceLocation.fromNode(node);
|
|
46
|
-
if (loc === undefined) {
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
|
-
results.push({
|
|
50
|
-
certainty: linter_format_1.LintingResultCertainty.Certain,
|
|
51
|
-
involvedId: node.info.id,
|
|
52
|
-
loc,
|
|
53
|
-
pkg,
|
|
54
|
-
name,
|
|
55
|
-
kind
|
|
56
|
-
});
|
|
25
|
+
for (const { node } of db.available() ? elements.getElements() : []) {
|
|
26
|
+
if (!r_symbol_1.RSymbol.is(node)) {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
const [name, pkg, internal] = identifier_1.Identifier.toArray(node.content);
|
|
30
|
+
if (pkg === undefined) {
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
const raw = db.rawFunctionOf(node.content);
|
|
34
|
+
/* a registered S3 method counts as exported in the database although `::` does not reach it */
|
|
35
|
+
if (raw === undefined || (internal === true && raw.props.includes(schema_1.FnPropNames[512 /* FnProp.S3Method */]))) {
|
|
36
|
+
unresolved++;
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
const kind = internal === true
|
|
40
|
+
? (raw.exported ? 'unnecessary-internal' : undefined)
|
|
41
|
+
: (raw.exported ? undefined : 'not-exported');
|
|
42
|
+
const loc = range_1.SourceLocation.fromNode(node);
|
|
43
|
+
if (kind !== undefined && loc !== undefined) {
|
|
44
|
+
results.push({ certainty: linter_format_1.LintingResultCertainty.Certain, involvedId: node.info.id, loc, pkg, name, kind });
|
|
57
45
|
}
|
|
58
46
|
}
|
|
59
47
|
return { results, '.meta': { unresolved } };
|
|
@@ -57,7 +57,7 @@ export declare function fixCasing(identifier: string, convention: CasingConventi
|
|
|
57
57
|
*/
|
|
58
58
|
export declare function createNamingConventionQuickFixes(graph: DataflowGraph, nodeId: NodeId, replacement: string, conv: CasingConvention): LintQuickFixReplacement[] | undefined;
|
|
59
59
|
export declare const NAMING_CONVENTION: {
|
|
60
|
-
readonly createSearch: (
|
|
60
|
+
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>[]>>>;
|
|
61
61
|
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: NamingConventionConfig, data: import("../..").ReadonlyFlowrAnalysisProvider<import("../..").KnownParser>) => Promise<{
|
|
62
62
|
results: NamingConventionResult[];
|
|
63
63
|
'.meta': {
|
|
@@ -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
|
});
|