@eagleoutice/flowr 2.11.1 → 2.12.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 +193 -263
- package/abstract-interpretation/data-frame/mappers/arguments.js +7 -1
- package/abstract-interpretation/domains/set-range-domain.js +1 -1
- package/abstract-interpretation/domains/set-upper-bound-domain.js +6 -2
- package/benchmark/slicer.d.ts +1 -1
- package/benchmark/slicer.js +3 -1
- package/benchmark/summarizer/second-phase/graph.js +5 -0
- package/cli/common/options.d.ts +8 -0
- package/cli/common/options.js +2 -0
- package/cli/common/scripts-info.d.ts +8 -0
- package/cli/repl/commands/repl-commands.d.ts +1 -0
- package/cli/repl/commands/repl-commands.js +66 -15
- package/cli/repl/commands/repl-dataflow.js +48 -4
- package/cli/repl/commands/repl-main.d.ts +2 -0
- package/cli/repl/commands/repl-main.js +5 -0
- package/cli/repl/commands/repl-query.d.ts +4 -1
- package/cli/repl/commands/repl-query.js +72 -22
- package/cli/repl/commands/repl-signature.d.ts +7 -0
- package/cli/repl/commands/repl-signature.js +119 -0
- package/cli/repl/core.d.ts +8 -1
- package/cli/repl/core.js +46 -6
- package/cli/repl/ghost-hint.d.ts +37 -0
- package/cli/repl/ghost-hint.js +72 -0
- package/cli/repl/parser/slice-query-parser.d.ts +11 -1
- package/cli/repl/parser/slice-query-parser.js +45 -16
- package/cli/repl/print-version.d.ts +2 -4
- package/cli/repl/print-version.js +41 -23
- package/cli/repl/server/connection.js +19 -17
- package/cli/slicer-app.d.ts +2 -0
- package/cli/slicer-app.js +3 -3
- package/cli/wiki.d.ts +2 -2
- package/cli/wiki.js +2 -2
- package/config.d.ts +63 -2
- package/config.js +64 -8
- package/control-flow/cfg-dead-code.js +0 -1
- package/control-flow/control-flow-graph.js +6 -6
- package/control-flow/diff-cfg.js +2 -2
- package/control-flow/semantic-cfg-guided-visitor.js +2 -0
- package/core/print/slice-diff-ansi.js +8 -8
- package/core/steps/all/core/20-dataflow.d.ts +2 -2
- package/core/steps/all/static-slicing/00-slice.d.ts +5 -0
- package/core/steps/all/static-slicing/00-slice.js +1 -1
- package/core/steps/all/static-slicing/10-reconstruct.d.ts +7 -0
- package/core/steps/all/static-slicing/10-reconstruct.js +6 -2
- package/core/steps/pipeline/default-pipelines.d.ts +20 -16
- package/data/r-base-packages.generated.d.ts +44 -0
- package/data/r-base-packages.generated.js +32 -0
- package/data/r-base-primitives.generated.d.ts +1 -0
- package/data/r-base-primitives.generated.js +15 -0
- package/data/sigdb/sigdb.remote.json +112 -0
- package/dataflow/environments/built-in-proc-name.d.ts +4 -0
- package/dataflow/environments/built-in-proc-name.js +4 -0
- package/dataflow/environments/built-in.d.ts +14 -4
- package/dataflow/environments/built-in.js +13 -2
- package/dataflow/environments/data-masking-functions.d.ts +12 -0
- package/dataflow/environments/data-masking-functions.js +46 -0
- package/dataflow/environments/default-builtin-config.d.ts +72 -19
- package/dataflow/environments/default-builtin-config.js +48 -14
- package/dataflow/environments/diff.js +1 -1
- package/dataflow/environments/environment.js +1 -2
- package/dataflow/environments/identifier.d.ts +11 -4
- package/dataflow/environments/identifier.js +28 -10
- package/dataflow/environments/resolve-by-name.js +16 -2
- package/dataflow/extractor.js +6 -3
- package/dataflow/graph/call-graph.d.ts +2 -2
- package/dataflow/graph/df-helper.d.ts +4 -4
- package/dataflow/graph/diff-dataflow-graph.js +2 -2
- package/dataflow/graph/edge.d.ts +3 -3
- package/dataflow/graph/edge.js +3 -3
- package/dataflow/graph/graph-helper.d.ts +2 -2
- package/dataflow/internal/linker.js +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +7 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +20 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +1 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +2 -49
- package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +6 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-get.js +7 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-library.d.ts +19 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-library.js +111 -6
- package/dataflow/internal/process/functions/call/built-in/built-in-pipe.js +13 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-replacement.js +2 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.d.ts +9 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +19 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-with.js +12 -4
- package/dataflow/internal/process/functions/call/common.js +8 -1
- package/dataflow/internal/process/functions/call/default-call-handling.js +6 -0
- package/dataflow/internal/process/functions/call/known-call-handling.d.ts +17 -0
- package/dataflow/internal/process/functions/call/known-call-handling.js +32 -0
- package/dataflow/internal/process/functions/call/named-call-handling.js +29 -7
- package/dataflow/internal/process/functions/process-argument.js +12 -1
- package/dataflow/internal/process/process-named-call.d.ts +18 -1
- package/dataflow/internal/process/process-named-call.js +94 -0
- package/dataflow/processor.d.ts +18 -0
- package/documentation/data/faq/faqs.js +5 -1
- package/documentation/doc-capabilities.js +1 -1
- package/documentation/doc-util/doc-cli-option.d.ts +10 -0
- package/documentation/doc-util/doc-cli-option.js +23 -0
- package/documentation/doc-util/doc-dfg.js +2 -1
- package/documentation/doc-util/doc-query.d.ts +9 -3
- package/documentation/doc-util/doc-query.js +9 -4
- package/documentation/wiki-dataflow-graph.js +8 -5
- package/documentation/wiki-interface.js +3 -1
- package/documentation/wiki-linter.js +1 -1
- package/documentation/wiki-linting-and-testing.js +4 -1
- package/documentation/wiki-mk/doc-context.d.ts +14 -0
- package/documentation/wiki-mk/doc-context.js +3 -0
- package/documentation/wiki-mk/doc-maker.js +3 -1
- package/documentation/wiki-query.js +19 -1
- package/documentation/wiki-setup.js +10 -7
- package/documentation/wiki-signature-database.d.ts +16 -0
- package/documentation/wiki-signature-database.js +293 -0
- package/linter/linter-format.d.ts +7 -0
- package/linter/linter-rules.d.ts +10 -9
- package/linter/rules/naming-convention.d.ts +1 -0
- package/linter/rules/naming-convention.js +2 -0
- package/linter/rules/no-leaked-credentials.js +1 -2
- package/linter/rules/roxygen-arguments.js +18 -5
- package/linter/rules/stop-with-call-arg.js +2 -2
- package/linter/rules/undefined-symbol-util.d.ts +36 -0
- package/linter/rules/undefined-symbol-util.js +149 -0
- package/linter/rules/undefined-symbol.d.ts +58 -17
- package/linter/rules/undefined-symbol.js +143 -33
- package/linter/rules/unused-definition.d.ts +8 -1
- package/linter/rules/unused-definition.js +126 -1
- package/package.json +22 -10
- package/project/context/abstract-flowr-analyzer-context.js +7 -1
- package/project/context/flowr-analyzer-context.d.ts +8 -0
- package/project/context/flowr-analyzer-context.js +10 -0
- package/project/context/flowr-analyzer-dependencies-context.d.ts +28 -4
- package/project/context/flowr-analyzer-dependencies-context.js +51 -2
- package/project/context/flowr-analyzer-files-context.d.ts +1 -0
- package/project/context/flowr-analyzer-files-context.js +2 -1
- package/project/context/flowr-analyzer-functions-context.js +1 -1
- package/project/context/flowr-file.d.ts +5 -0
- package/project/context/flowr-file.js +5 -0
- package/project/flowr-analyzer-builder.js +12 -2
- package/project/plugins/file-plugins/files/flowr-description-file.js +6 -3
- package/project/plugins/file-plugins/files/flowr-namespace-file.js +9 -3
- package/project/plugins/file-plugins/files/flowr-news-file.js +1 -3
- package/project/plugins/file-plugins/flowr-analyzer-inst-file-plugin.d.ts +26 -0
- package/project/plugins/file-plugins/flowr-analyzer-inst-file-plugin.js +39 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-description-file-plugin.js +1 -1
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.js +2 -2
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-namespace-file-plugin.js +1 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-plugin.d.ts +18 -2
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-plugin.js +19 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.d.ts +120 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +518 -0
- package/project/plugins/package-version-plugins/package.d.ts +5 -3
- package/project/plugins/package-version-plugins/package.js +27 -25
- package/project/plugins/plugin-registry.d.ts +3 -2
- package/project/plugins/plugin-registry.js +4 -2
- package/project/plugins/project-discovery/flowr-analyzer-gitignore-project-discovery-plugin.js +7 -2
- package/project/plugins/project-discovery/flowr-analyzer-project-discovery-plugin.js +3 -1
- package/project/sigdb/build.d.ts +131 -0
- package/project/sigdb/build.js +628 -0
- package/project/sigdb/codec.d.ts +51 -0
- package/project/sigdb/codec.js +122 -0
- package/project/sigdb/decode.d.ts +58 -0
- package/project/sigdb/decode.js +129 -0
- package/project/sigdb/decompress.d.ts +44 -0
- package/project/sigdb/decompress.js +176 -0
- package/project/sigdb/hash.d.ts +9 -0
- package/project/sigdb/hash.js +54 -0
- package/project/sigdb/index-format.d.ts +40 -0
- package/project/sigdb/index-format.js +28 -0
- package/project/sigdb/manifest.d.ts +68 -0
- package/project/sigdb/manifest.js +146 -0
- package/project/sigdb/reader.d.ts +250 -0
- package/project/sigdb/reader.js +692 -0
- package/project/sigdb/schema.d.ts +196 -0
- package/project/sigdb/schema.js +33 -0
- package/project/sigdb/sigdb-download.d.ts +65 -0
- package/project/sigdb/sigdb-download.js +237 -0
- package/project/sigdb/signature-match.d.ts +26 -0
- package/project/sigdb/signature-match.js +40 -0
- package/project/sigdb/version.d.ts +20 -0
- package/project/sigdb/version.js +55 -0
- package/queries/catalog/call-context-query/call-context-query-executor.js +1 -3
- package/queries/catalog/config-query/config-query-format.d.ts +3 -1
- package/queries/catalog/config-query/config-query-format.js +68 -9
- package/queries/catalog/dataflow-query/dataflow-query-format.js +11 -1
- package/queries/catalog/dependencies-query/dependencies-query-executor.js +1 -1
- package/queries/catalog/linter-query/linter-query-executor.d.ts +2 -0
- package/queries/catalog/linter-query/linter-query-executor.js +6 -1
- package/queries/catalog/linter-query/linter-query-format.d.ts +2 -1
- package/queries/catalog/linter-query/linter-query-format.js +40 -8
- package/queries/catalog/project-query/project-query-executor.d.ts +15 -0
- package/queries/catalog/project-query/project-query-executor.js +96 -4
- package/queries/catalog/project-query/project-query-format.d.ts +44 -0
- package/queries/catalog/project-query/project-query-format.js +33 -2
- package/queries/catalog/signature-query/signature-query-executor.d.ts +29 -0
- package/queries/catalog/signature-query/signature-query-executor.js +461 -0
- package/queries/catalog/signature-query/signature-query-format.d.ts +138 -0
- package/queries/catalog/signature-query/signature-query-format.js +76 -0
- package/queries/catalog/signature-query/signature-query-render.d.ts +15 -0
- package/queries/catalog/signature-query/signature-query-render.js +155 -0
- package/queries/catalog/static-slice-query/static-slice-query-executor.js +9 -3
- package/queries/catalog/static-slice-query/static-slice-query-format.d.ts +10 -0
- package/queries/catalog/static-slice-query/static-slice-query-format.js +19 -1
- package/queries/query-print.js +5 -0
- package/queries/query.d.ts +10 -1
- package/queries/query.js +5 -2
- package/r-bridge/init.js +5 -1
- package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +10 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.js +55 -0
- package/r-bridge/lang-4.x/ast/model/processing/node-id.d.ts +16 -0
- package/r-bridge/lang-4.x/ast/model/processing/node-id.js +27 -0
- package/r-bridge/lang-4.x/ast/parser/json/format.js +89 -2
- package/r-bridge/lang-4.x/ast/parser/main/internal/structure/normalize-expressions.js +2 -4
- package/r-bridge/lang-4.x/tree-sitter/tree-sitter-normalize.js +2 -1
- package/r-bridge/parser.d.ts +2 -0
- package/r-bridge/retriever.js +4 -1
- package/r-bridge/roxygen2/documentation-provider.js +2 -1
- package/r-bridge/shell.d.ts +5 -0
- package/r-bridge/shell.js +17 -1
- package/reconstruct/inline/source-inline-map.d.ts +48 -0
- package/reconstruct/inline/source-inline-map.js +94 -0
- package/reconstruct/reconstruct.d.ts +19 -2
- package/reconstruct/reconstruct.js +79 -16
- package/search/search-executor/search-generators.js +5 -22
- package/search/search-executor/search-transformer.js +10 -6
- package/slicing/criterion/parse.d.ts +22 -4
- package/slicing/criterion/parse.js +125 -18
- package/slicing/static/slice-call.d.ts +24 -1
- package/slicing/static/slice-call.js +90 -0
- package/slicing/static/static-slicer.d.ts +7 -0
- package/slicing/static/static-slicer.js +38 -3
- package/util/collections/arrays.d.ts +4 -5
- package/util/collections/arrays.js +7 -18
- package/util/hash.d.ts +14 -0
- package/util/hash.js +31 -0
- package/util/mermaid/dfg.d.ts +7 -2
- package/util/mermaid/dfg.js +53 -13
- package/util/r-base-packages.d.ts +19 -0
- package/util/r-base-packages.js +72 -0
- package/util/r-license.js +2 -10
- package/util/r-version.d.ts +45 -15
- package/util/r-version.js +97 -36
- package/util/range.d.ts +15 -0
- package/util/range.js +39 -0
- package/util/schema.d.ts +10 -0
- package/util/schema.js +22 -0
- package/util/text/ansi.d.ts +3 -0
- package/util/text/ansi.js +10 -0
- package/util/text/args.js +1 -2
- package/util/version.js +28 -8
- package/data/pkgdb/pkgdb-latest.json.br +0 -0
- package/data/pkgdb/pkgdb-tiny.json.br +0 -0
- package/documentation/wiki-package-database.d.ts +0 -9
- package/documentation/wiki-package-database.js +0 -63
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-pkgdb-plugin.d.ts +0 -63
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-pkgdb-plugin.js +0 -176
- package/project/plugins/package-version-plugins/pkgdb.d.ts +0 -133
- package/project/plugins/package-version-plugins/pkgdb.js +0 -370
|
@@ -1,28 +1,65 @@
|
|
|
1
1
|
import type { MergeableRecord } from '../../util/objects';
|
|
2
|
-
import
|
|
2
|
+
import type { FlowrSearchElement } from '../../search/flowr-search';
|
|
3
|
+
import type { ParentInformation } from '../../r-bridge/lang-4.x/ast/model/processing/decorate';
|
|
4
|
+
import { type LintingResult, LintingRuleCertainty } from '../linter-format';
|
|
3
5
|
import { LintingRuleTag } from '../linter-tags';
|
|
6
|
+
/** whether the flagged symbol is used in a function-call position or as a plain variable */
|
|
7
|
+
export type UndefinedSymbolKind = 'function' | 'variable';
|
|
4
8
|
export interface UndefinedSymbolResult extends LintingResult {
|
|
5
|
-
/** the
|
|
9
|
+
/** the name that could not be resolved */
|
|
6
10
|
name: string;
|
|
11
|
+
/** whether the name is used as a function call or as a variable read */
|
|
12
|
+
kind: UndefinedSymbolKind;
|
|
13
|
+
/** packages that export this name - a hint that a `library()`/`::` might be missing (empty if none known) */
|
|
14
|
+
availableInPackages?: readonly string[];
|
|
15
|
+
/** an unresolved `library()` is in scope that could define this name; treat as low-confidence */
|
|
16
|
+
mayBeProvidedByUnresolvedLibrary?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export interface UndefinedSymbolConfig extends MergeableRecord {
|
|
19
|
+
/** flag names used in a function-call position that cannot be resolved (default `true`) */
|
|
20
|
+
checkFunctions: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* flag names used as a variable read that cannot be resolved (default `true`). Formulas and data-masking
|
|
23
|
+
* (dplyr/tidyr/ggplot, `subset`/`with`) are recognised via flowR's dataflow, so this is precise; residual
|
|
24
|
+
* false positives are possible in dynamic `eval`/`attach`.
|
|
25
|
+
*/
|
|
26
|
+
checkVariables: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* flag unresolved symbols used as `[`/`[[` subscripts (default `false`). Off by default to mute
|
|
29
|
+
* `data.table`'s `DT[i, j, by]` column masking, which flowR cannot distinguish from ordinary indexing.
|
|
30
|
+
*/
|
|
31
|
+
checkSubscripts: boolean;
|
|
32
|
+
}
|
|
33
|
+
/** Why unresolved candidates were suppressed instead of reported, kept in the metadata for auditability. */
|
|
34
|
+
export interface SuppressionCounts {
|
|
35
|
+
/** file below `inst/` (installed resource, not namespace source) */
|
|
36
|
+
installed: number;
|
|
37
|
+
/** exported by a package in scope: a loaded/DESCRIPTION package or a default-attached base package */
|
|
38
|
+
loadedPackage: number;
|
|
39
|
+
/** unconditionally bound in an enclosing scope that flowR's dataflow did not statically link */
|
|
40
|
+
enclosingScope: number;
|
|
41
|
+
/** consumed by non-standard evaluation (a quoting edge) */
|
|
42
|
+
nonStandardEval: number;
|
|
43
|
+
/** used as a `[`/`[[` subscript (muted `data.table`-style column masking) */
|
|
44
|
+
subscript: number;
|
|
7
45
|
}
|
|
8
|
-
export type UndefinedSymbolConfig = MergeableRecord;
|
|
9
46
|
export interface UndefinedSymbolMetadata extends MergeableRecord {
|
|
10
|
-
|
|
47
|
+
totalFunctionCalls: number;
|
|
48
|
+
totalVariableUses: number;
|
|
49
|
+
/** breakdown of unresolved candidates that were suppressed rather than reported */
|
|
50
|
+
suppressed: SuppressionCounts;
|
|
11
51
|
}
|
|
12
52
|
/**
|
|
13
|
-
* Flags calls
|
|
14
|
-
* package
|
|
15
|
-
*
|
|
53
|
+
* Flags function calls (`sd()`) and, opt-in, variable reads (`x`) that are neither defined locally, a
|
|
54
|
+
* builtin, nor exported by a package in scope - the DESCRIPTION/`library()` packages plus the default-attached
|
|
55
|
+
* base packages, all resolved from the `flowr-sigdb` database. To stay precise it consults flowR's dataflow:
|
|
56
|
+
* non-standard evaluation (quoting) is not reported, and an unloaded package that exports the name is offered
|
|
57
|
+
* as a hint. Over-approximative: NSE beyond what flowR models can still cause false positives.
|
|
16
58
|
*/
|
|
17
59
|
export declare const UNDEFINED_SYMBOL: {
|
|
18
|
-
readonly createSearch: (_config: UndefinedSymbolConfig) => import("../../search/flowr-search-builder").FlowrSearchBuilder<"all", ["filter"],
|
|
19
|
-
readonly processSearchResult: (elements: import("../../search/flowr-search").FlowrSearchElements<
|
|
20
|
-
results:
|
|
21
|
-
certainty: LintingResultCertainty.Uncertain;
|
|
22
|
-
name: import("../../dataflow/environments/identifier").BrandedIdentifier;
|
|
23
|
-
involvedId: import("../../r-bridge/lang-4.x/ast/model/processing/node-id").NodeId;
|
|
24
|
-
loc: [startLine: number, startColumn: number, endLine: number, endColumn: number, f?: string | undefined];
|
|
25
|
-
}[];
|
|
60
|
+
readonly createSearch: (_config: UndefinedSymbolConfig) => import("../../search/flowr-search-builder").FlowrSearchBuilder<"all", ["filter"], ParentInformation, Promise<import("../../search/flowr-search").FlowrSearchElements<ParentInformation, [] | FlowrSearchElement<ParentInformation>[]>>>;
|
|
61
|
+
readonly processSearchResult: (elements: import("../../search/flowr-search").FlowrSearchElements<ParentInformation, FlowrSearchElement<ParentInformation>[]>, config: UndefinedSymbolConfig, data: import("../../project/flowr-analyzer").ReadonlyFlowrAnalysisProvider<import("../../r-bridge/parser").KnownParser>) => Promise<{
|
|
62
|
+
results: UndefinedSymbolResult[];
|
|
26
63
|
'.meta': UndefinedSymbolMetadata;
|
|
27
64
|
}>;
|
|
28
65
|
readonly prettyPrint: {
|
|
@@ -32,8 +69,12 @@ export declare const UNDEFINED_SYMBOL: {
|
|
|
32
69
|
readonly info: {
|
|
33
70
|
readonly name: "Undefined Symbol";
|
|
34
71
|
readonly certainty: LintingRuleCertainty.OverApproximative;
|
|
35
|
-
readonly description: "Flags
|
|
72
|
+
readonly description: "Flags functions and variables that are neither defined locally, a base R builtin, nor exported by a loaded package.";
|
|
36
73
|
readonly tags: readonly [LintingRuleTag.Bug, LintingRuleTag.Experimental];
|
|
37
|
-
readonly defaultConfig: {
|
|
74
|
+
readonly defaultConfig: {
|
|
75
|
+
readonly checkFunctions: true;
|
|
76
|
+
readonly checkVariables: true;
|
|
77
|
+
readonly checkSubscripts: false;
|
|
78
|
+
};
|
|
38
79
|
};
|
|
39
80
|
};
|
|
@@ -5,76 +5,186 @@ const vertex_1 = require("../../dataflow/graph/vertex");
|
|
|
5
5
|
const dfg_get_origin_1 = require("../../dataflow/origin/dfg-get-origin");
|
|
6
6
|
const identifier_1 = require("../../dataflow/environments/identifier");
|
|
7
7
|
const flowr_search_builder_1 = require("../../search/flowr-search-builder");
|
|
8
|
+
const flowr_search_filters_1 = require("../../search/flowr-search-filters");
|
|
8
9
|
const assert_1 = require("../../util/assert");
|
|
9
10
|
const range_1 = require("../../util/range");
|
|
11
|
+
const flowr_file_1 = require("../../project/context/flowr-file");
|
|
12
|
+
const type_1 = require("../../r-bridge/lang-4.x/ast/model/type");
|
|
13
|
+
const r_base_primitives_generated_1 = require("../../data/r-base-primitives.generated");
|
|
10
14
|
const linter_format_1 = require("../linter-format");
|
|
11
15
|
const linter_tags_1 = require("../linter-tags");
|
|
16
|
+
const undefined_symbol_util_1 = require("./undefined-symbol-util");
|
|
12
17
|
/** calls that load a package; an unresolved one means we cannot enumerate all exports in scope */
|
|
13
18
|
const LibraryLoadFunctions = new Set(['library', 'require', 'requireNamespace', 'loadNamespace', 'attachNamespace', 'load_all', 'use', 'p_load']);
|
|
14
19
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
20
|
+
* Packages a standard R session attaches by default (`getOption("defaultPackages")` plus `base`); their
|
|
21
|
+
* exports are in scope without an explicit `library()`. Non-attached base-priority packages (`tools`,
|
|
22
|
+
* `parallel`, `grid`, ...) still need loading and are flagged with a hint. Hardcoded for now; making this
|
|
23
|
+
* configurable (to respect `R_DEFAULT_PACKAGES`/`.Rprofile`) is left for later.
|
|
24
|
+
*/
|
|
25
|
+
const AttachedBasePackages = ['base', 'stats', 'graphics', 'grDevices', 'utils', 'datasets', 'methods'];
|
|
26
|
+
/** upper bound on the number of packages named in a "did you forget to load it" hint */
|
|
27
|
+
const MaxHintPackages = 5;
|
|
28
|
+
/**
|
|
29
|
+
* Flags function calls (`sd()`) and, opt-in, variable reads (`x`) that are neither defined locally, a
|
|
30
|
+
* builtin, nor exported by a package in scope - the DESCRIPTION/`library()` packages plus the default-attached
|
|
31
|
+
* base packages, all resolved from the `flowr-sigdb` database. To stay precise it consults flowR's dataflow:
|
|
32
|
+
* non-standard evaluation (quoting) is not reported, and an unloaded package that exports the name is offered
|
|
33
|
+
* as a hint. Over-approximative: NSE beyond what flowR models can still cause false positives.
|
|
18
34
|
*/
|
|
19
35
|
exports.UNDEFINED_SYMBOL = {
|
|
20
|
-
createSearch: (_config) => flowr_search_builder_1.Q.all().filter(vertex_1.VertexType.FunctionCall),
|
|
36
|
+
createSearch: (_config) => flowr_search_builder_1.Q.all().filter(flowr_search_filters_1.F.or(vertex_1.VertexType.FunctionCall, vertex_1.VertexType.Use)),
|
|
21
37
|
processSearchResult: async (elements, config, data) => {
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
38
|
+
const graph = (await data.dataflow()).graph;
|
|
39
|
+
const ctx = data.inspectContext();
|
|
40
|
+
const deps = ctx.deps;
|
|
41
|
+
const meta = {
|
|
42
|
+
totalFunctionCalls: 0,
|
|
43
|
+
totalVariableUses: 0,
|
|
44
|
+
suppressed: { installed: 0, loadedPackage: 0, enclosingScope: 0, nonStandardEval: 0, subscript: 0 }
|
|
45
|
+
};
|
|
46
|
+
// `inst/` files are installed verbatim (resources, not namespace source); skip them. Key off the
|
|
47
|
+
// FileRole.Install role, with a path fallback for requests that bypass the file-role plugins.
|
|
48
|
+
const installedFiles = new Set(ctx.files.getFilesByRole(flowr_file_1.FileRole.Install).map(f => f.path()));
|
|
49
|
+
const isInstalledFile = (file) => file !== undefined && (installedFiles.has(file) || (0, undefined_symbol_util_1.isInstalledResourceFile)(file));
|
|
50
|
+
// a library() we could not resolve could export any of these symbols; we still report but flag the
|
|
51
|
+
// findings as low-confidence (`mayBeProvidedByUnresolvedLibrary`) so the severity can be lowered
|
|
27
52
|
const unknownIds = new Set();
|
|
28
|
-
for (const e of
|
|
53
|
+
for (const e of graph.unknownSideEffects) {
|
|
29
54
|
unknownIds.add(String(typeof e === 'object' ? e.id : e));
|
|
30
55
|
}
|
|
56
|
+
let unresolvedLibraryInScope = false;
|
|
31
57
|
if (unknownIds.size > 0) {
|
|
32
|
-
for (const [id, v] of
|
|
58
|
+
for (const [id, v] of graph.verticesOfType(vertex_1.VertexType.FunctionCall)) {
|
|
33
59
|
if (LibraryLoadFunctions.has(identifier_1.Identifier.getName(v.name)) && unknownIds.has(String(id))) {
|
|
34
|
-
|
|
60
|
+
unresolvedLibraryInScope = true;
|
|
61
|
+
break;
|
|
35
62
|
}
|
|
36
63
|
}
|
|
37
64
|
}
|
|
65
|
+
// scope-defined names, a fallback for closure variables flowR's dataflow did not statically link
|
|
66
|
+
const scopeDefined = (0, undefined_symbol_util_1.collectScopeDefinedNames)(graph);
|
|
67
|
+
// packages whose exports are in scope: DESCRIPTION/library() deps plus the default-attached base
|
|
68
|
+
// packages, each resolved (exports enriched) from the package database via getDependency
|
|
69
|
+
const loadedPackages = [
|
|
70
|
+
...deps.getDependencies().map(p => deps.getDependency(p.name) ?? p),
|
|
71
|
+
...AttachedBasePackages.map(n => deps.getDependency(n)).filter(assert_1.isNotUndefined)
|
|
72
|
+
];
|
|
73
|
+
// hint an unloaded package that exports `name` (e.g. `ggplot` -> `ggplot2`), from the package database
|
|
74
|
+
const attached = new Set(AttachedBasePackages);
|
|
75
|
+
const hintPackagesFor = (name) => deps.packagesExporting(name).filter(p => !attached.has(p)).slice(0, MaxHintPackages);
|
|
38
76
|
const results = elements.getElements().map(element => {
|
|
39
|
-
const
|
|
40
|
-
|
|
77
|
+
const id = element.node.info.id;
|
|
78
|
+
const vtx = graph.getVertex(id);
|
|
79
|
+
if (!vtx) {
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
const inInstalledFile = isInstalledFile(element.node.info.file);
|
|
83
|
+
if ((0, vertex_1.isFunctionCallVertex)(vtx)) {
|
|
84
|
+
if (vtx.origin === 'unnamed' || !config.checkFunctions) {
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
meta.totalFunctionCalls++;
|
|
88
|
+
if (inInstalledFile) {
|
|
89
|
+
meta.suppressed.installed++;
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
return check(element, id, identifier_1.Identifier.getName(vtx.name), identifier_1.Identifier.getNamespace(vtx.name), 'function');
|
|
93
|
+
}
|
|
94
|
+
// variable use: only plain symbols (not argument names, `...`, or empty)
|
|
95
|
+
if (vtx.tag === vertex_1.VertexType.Use && config.checkVariables) {
|
|
96
|
+
const node = element.node;
|
|
97
|
+
if (node.type !== type_1.RType.Symbol || node.lexeme === '...' || node.lexeme === undefined) {
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
meta.totalVariableUses++;
|
|
101
|
+
if (inInstalledFile) {
|
|
102
|
+
meta.suppressed.installed++;
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
return check(element, id, node.lexeme, undefined, 'variable');
|
|
106
|
+
}
|
|
107
|
+
return undefined;
|
|
108
|
+
}).filter(assert_1.isNotUndefined);
|
|
109
|
+
/** shared resolution logic for a name used either as a function call or a variable */
|
|
110
|
+
function check(element, id, name, namespace, kind) {
|
|
111
|
+
// resolved by flowR itself (local/param/builtin) - never a candidate, so not counted as suppressed
|
|
112
|
+
if (kind === 'variable' ? (0, undefined_symbol_util_1.useResolvesToDefinitionOrBuiltin)(graph, id) : ((0, dfg_get_origin_1.getOriginInDfg)(graph, id)?.length ?? 0) > 0) {
|
|
41
113
|
return undefined;
|
|
42
114
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
//
|
|
46
|
-
|
|
47
|
-
if (origins && origins.length > 0) {
|
|
115
|
+
// a bare call to a registered flowR builtin whose dataflow origin was rewritten away from its
|
|
116
|
+
// builtin marker (e.g. a fully-resolved `UseMethod` dispatch is re-tagged as a plain function
|
|
117
|
+
// call) is still defined, so recognise it directly from the built-in environment
|
|
118
|
+
if (kind === 'function' && namespace === undefined && ctx.env.builtInEnvironment.memory.has(name)) {
|
|
48
119
|
return undefined;
|
|
49
120
|
}
|
|
50
|
-
//
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
? deps.getDependency(namespace)?.has(name) === true
|
|
54
|
-
: deps.getDependencies().some(p => p.has(name));
|
|
55
|
-
if (known) {
|
|
121
|
+
// a bare base-R primitive/internal (`is.na`) or base data constant (`.Machine`) is defined but
|
|
122
|
+
// missing from the sigdb export list, so recognise it directly (covers calls and variable reads)
|
|
123
|
+
if (namespace === undefined && r_base_primitives_generated_1.RBasePrimitives.has(name)) {
|
|
56
124
|
return undefined;
|
|
57
125
|
}
|
|
126
|
+
// exported by a package in scope (`pkg::fn`, a loaded package, or a default-attached base package)
|
|
127
|
+
if (namespace !== undefined ? deps.getDependency(namespace)?.has(name) === true : loadedPackages.some(p => p.has(name))) {
|
|
128
|
+
return suppress('loadedPackage');
|
|
129
|
+
}
|
|
130
|
+
// forward-referenced closure binding flowR's dataflow did not link (unconditional bindings only)
|
|
131
|
+
if ((0, undefined_symbol_util_1.isDefinedInEnclosingScope)(graph, scopeDefined, id, name)) {
|
|
132
|
+
return suppress('enclosingScope');
|
|
133
|
+
}
|
|
134
|
+
// consumed by non-standard evaluation (quoting), hence not an ordinary read
|
|
135
|
+
if ((0, undefined_symbol_util_1.isNonStandardEvaluated)(graph, id)) {
|
|
136
|
+
return suppress('nonStandardEval');
|
|
137
|
+
}
|
|
138
|
+
// `[`/`[[` subscript: muted by default (indistinguishable from `data.table` column masking)
|
|
139
|
+
if (kind === 'variable' && !config.checkSubscripts && (0, undefined_symbol_util_1.isInSubscript)(graph, id)) {
|
|
140
|
+
return suppress('subscript');
|
|
141
|
+
}
|
|
58
142
|
const loc = range_1.SourceLocation.fromNode(element.node);
|
|
59
|
-
|
|
143
|
+
if (loc === undefined) {
|
|
144
|
+
return undefined;
|
|
145
|
+
}
|
|
146
|
+
const availableInPackages = namespace === undefined ? hintPackagesFor(name) : [];
|
|
147
|
+
return {
|
|
60
148
|
certainty: linter_format_1.LintingResultCertainty.Uncertain,
|
|
61
149
|
name,
|
|
62
|
-
|
|
63
|
-
|
|
150
|
+
kind,
|
|
151
|
+
involvedId: id,
|
|
152
|
+
loc,
|
|
153
|
+
...(availableInPackages.length > 0 ? { availableInPackages } : {}),
|
|
154
|
+
...(unresolvedLibraryInScope ? { mayBeProvidedByUnresolvedLibrary: true } : {})
|
|
64
155
|
};
|
|
65
|
-
}
|
|
156
|
+
}
|
|
157
|
+
function suppress(reason) {
|
|
158
|
+
meta.suppressed[reason]++;
|
|
159
|
+
return undefined;
|
|
160
|
+
}
|
|
66
161
|
return { results, '.meta': meta };
|
|
67
162
|
},
|
|
68
163
|
prettyPrint: {
|
|
69
|
-
[linter_format_1.LintingPrettyPrintContext.Query]: result =>
|
|
70
|
-
[linter_format_1.LintingPrettyPrintContext.Full]: result =>
|
|
164
|
+
[linter_format_1.LintingPrettyPrintContext.Query]: result => `${result.mayBeProvidedByUnresolvedLibrary ? 'Possibly undefined' : 'Undefined'} ${result.kind} \`${result.name}\` at ${range_1.SourceLocation.format(result.loc)}`,
|
|
165
|
+
[linter_format_1.LintingPrettyPrintContext.Full]: result => {
|
|
166
|
+
const where = range_1.SourceLocation.format(result.loc);
|
|
167
|
+
const caveat = result.mayBeProvidedByUnresolvedLibrary ? ' (an unresolved library is loaded that might provide it)' : '';
|
|
168
|
+
if (result.availableInPackages && result.availableInPackages.length > 0) {
|
|
169
|
+
const pkgs = result.availableInPackages.map(p => `\`${p}\``).join(', ');
|
|
170
|
+
const hint = result.availableInPackages.length === 1 ? `\`library(${result.availableInPackages[0]})\`` : `one of ${pkgs}`;
|
|
171
|
+
return `\`${result.name}\` at ${where} is used but not defined; it is exported by ${pkgs} - did you forget to load it (e.g. ${hint})?${caveat}`;
|
|
172
|
+
}
|
|
173
|
+
return result.kind === 'function'
|
|
174
|
+
? `\`${result.name}\` at ${where} is called but is neither defined locally, a base R builtin, nor exported by a loaded package${caveat}`
|
|
175
|
+
: `\`${result.name}\` at ${where} is used as a variable but is never defined in scope${caveat}`;
|
|
176
|
+
}
|
|
71
177
|
},
|
|
72
178
|
info: {
|
|
73
179
|
name: 'Undefined Symbol',
|
|
74
180
|
certainty: linter_format_1.LintingRuleCertainty.OverApproximative,
|
|
75
|
-
description: 'Flags
|
|
181
|
+
description: 'Flags functions and variables that are neither defined locally, a base R builtin, nor exported by a loaded package.',
|
|
76
182
|
tags: [linter_tags_1.LintingRuleTag.Bug, linter_tags_1.LintingRuleTag.Experimental],
|
|
77
|
-
defaultConfig: {
|
|
183
|
+
defaultConfig: {
|
|
184
|
+
checkFunctions: true,
|
|
185
|
+
checkVariables: true,
|
|
186
|
+
checkSubscripts: false
|
|
187
|
+
}
|
|
78
188
|
}
|
|
79
189
|
};
|
|
80
190
|
//# sourceMappingURL=undefined-symbol.js.map
|
|
@@ -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 { ParentInformation } from '../../r-bridge/lang-4.x/ast/model/processing/decorate';
|
|
5
|
+
import type { ReadonlyFlowrAnalysisProvider } from '../../project/flowr-analyzer';
|
|
5
6
|
export interface UnusedDefinitionResult extends LintingResult {
|
|
6
7
|
variableName?: string;
|
|
7
8
|
}
|
|
@@ -10,13 +11,18 @@ export interface UnusedDefinitionConfig extends MergeableRecord {
|
|
|
10
11
|
* Whether to include (potentially anonymous) function definitions in the search (e.g., should we report uncalled anonymous functions?).
|
|
11
12
|
*/
|
|
12
13
|
includeFunctionDefinitions: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Whether to suppress definitions that the analyzed project exports via its `NAMESPACE` (the package's public API).
|
|
16
|
+
* flowR cannot observe external callers, so exported names would otherwise be reported as (uncertain) false positives.
|
|
17
|
+
*/
|
|
18
|
+
excludeExportedDefinitions: boolean;
|
|
13
19
|
}
|
|
14
20
|
export interface UnusedDefinitionMetadata extends MergeableRecord {
|
|
15
21
|
totalConsidered: number;
|
|
16
22
|
}
|
|
17
23
|
export declare const UNUSED_DEFINITION: {
|
|
18
24
|
readonly createSearch: (config: UnusedDefinitionConfig) => import("../../search/flowr-search-builder").FlowrSearchBuilder<"all", ["filter"], ParentInformation, Promise<import("../../search/flowr-search").FlowrSearchElements<ParentInformation, [] | import("../../search/flowr-search").FlowrSearchElement<ParentInformation>[]>>>;
|
|
19
|
-
readonly processSearchResult: (elements: import("../../search/flowr-search").FlowrSearchElements<ParentInformation, import("../../search/flowr-search").FlowrSearchElement<ParentInformation>[]>, config: UnusedDefinitionConfig, data:
|
|
25
|
+
readonly processSearchResult: (elements: import("../../search/flowr-search").FlowrSearchElements<ParentInformation, import("../../search/flowr-search").FlowrSearchElement<ParentInformation>[]>, config: UnusedDefinitionConfig, data: ReadonlyFlowrAnalysisProvider<import("../../r-bridge/parser").KnownParser>) => Promise<{
|
|
20
26
|
results: UnusedDefinitionResult[];
|
|
21
27
|
".meta": UnusedDefinitionMetadata;
|
|
22
28
|
}>;
|
|
@@ -31,6 +37,7 @@ export declare const UNUSED_DEFINITION: {
|
|
|
31
37
|
readonly certainty: LintingRuleCertainty.BestEffort;
|
|
32
38
|
readonly defaultConfig: {
|
|
33
39
|
readonly includeFunctionDefinitions: true;
|
|
40
|
+
readonly excludeExportedDefinitions: true;
|
|
34
41
|
};
|
|
35
42
|
};
|
|
36
43
|
};
|
|
@@ -9,6 +9,121 @@ const assert_1 = require("../../util/assert");
|
|
|
9
9
|
const vertex_1 = require("../../dataflow/graph/vertex");
|
|
10
10
|
const edge_1 = require("../../dataflow/graph/edge");
|
|
11
11
|
const flowr_search_filters_1 = require("../../search/flowr-search-filters");
|
|
12
|
+
const flowr_file_1 = require("../../project/context/flowr-file");
|
|
13
|
+
const flowr_namespace_file_1 = require("../../project/plugins/file-plugins/files/flowr-namespace-file");
|
|
14
|
+
const identifier_1 = require("../../dataflow/environments/identifier");
|
|
15
|
+
const retriever_1 = require("../../r-bridge/retriever");
|
|
16
|
+
const r_function_call_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
|
|
17
|
+
const r_function_definition_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-definition");
|
|
18
|
+
/**
|
|
19
|
+
* The dots parameter is a special parameter and must never be reported as an unused definition.
|
|
20
|
+
*/
|
|
21
|
+
const DotsParameter = '...';
|
|
22
|
+
/**
|
|
23
|
+
* Common base/standard-library S3 generics. A definition named `generic.class` where `generic` is one of these
|
|
24
|
+
* is an S3 method dispatched indirectly (e.g. `print(x)` on an object of class `class`), so it is used even
|
|
25
|
+
* without a direct textual call.
|
|
26
|
+
*/
|
|
27
|
+
const KnownS3Generics = new Set([
|
|
28
|
+
'print', 'format', 'summary', 'plot', 'coef', 'vcov', 'residuals', 'fitted', 'predict',
|
|
29
|
+
'as.character', 'as.data.frame', 'as.list', 'as.matrix', 'as.vector', 'as.numeric',
|
|
30
|
+
'length', 'dim', 'dimnames', 'names', 'str', 'toString', 'all.equal', 'aggregate',
|
|
31
|
+
'update', 'anova', 'confint', 'logLik', 'AIC', 'BIC', 'deviance', 'df.residual',
|
|
32
|
+
'model.matrix', 'terms', 'weights', 'simulate', 'lines', 'points', 'head', 'tail',
|
|
33
|
+
'merge', 'rbind', 'cbind', 'split', 'window', 'subset', 'sort', 'rev', 'unique',
|
|
34
|
+
'mean', 'median', 'quantile', 'range', 'diff', 't'
|
|
35
|
+
]);
|
|
36
|
+
/**
|
|
37
|
+
* R package lifecycle hooks called automatically by R's package machinery.
|
|
38
|
+
* These functions are invoked by the package system, so they are used even without textual callers.
|
|
39
|
+
*/
|
|
40
|
+
const PackageHookFunctions = new Set([
|
|
41
|
+
'.onLoad', '.onAttach', '.onUnload', '.onDetach', '.Last.lib', '.First.lib'
|
|
42
|
+
]);
|
|
43
|
+
/** Gathers the analyzed project's own `NAMESPACE` exports and declared S3 generics (empty when it is not a package). */
|
|
44
|
+
function collectPackageInfo(data) {
|
|
45
|
+
const exported = new Set();
|
|
46
|
+
const s3Generics = new Set();
|
|
47
|
+
for (const ns of data.inspectContext().files.getFilesByRole(flowr_file_1.FileRole.Namespace)) {
|
|
48
|
+
const info = ns.content().current;
|
|
49
|
+
for (const name of (0, flowr_namespace_file_1.getExportedNames)(info)) {
|
|
50
|
+
exported.add(name);
|
|
51
|
+
}
|
|
52
|
+
for (const generic of info.exportS3Generics.keys()) {
|
|
53
|
+
s3Generics.add(generic);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return { exported, s3Generics };
|
|
57
|
+
}
|
|
58
|
+
/** Collects the names of every function call in the graph, so we can tell whether an S3 generic is dispatched anywhere. */
|
|
59
|
+
function collectCalledNames(dfg) {
|
|
60
|
+
const names = new Set();
|
|
61
|
+
for (const [, vertex] of dfg.verticesOfType(vertex_1.VertexType.FunctionCall)) {
|
|
62
|
+
names.add(identifier_1.Identifier.getName(vertex.name));
|
|
63
|
+
}
|
|
64
|
+
return names;
|
|
65
|
+
}
|
|
66
|
+
/** Checks if a function body is a single call to UseMethod. */
|
|
67
|
+
function isUseMethodOnlyBody(node) {
|
|
68
|
+
// Direct call to UseMethod
|
|
69
|
+
if (r_function_call_1.RFunctionCall.isNamed(node) && identifier_1.Identifier.getName(node.functionName.content) === 'UseMethod') {
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
const nodeWithChildren = node;
|
|
73
|
+
if (Array.isArray(nodeWithChildren.children) && nodeWithChildren.children.length === 1) {
|
|
74
|
+
const child = nodeWithChildren.children[0];
|
|
75
|
+
if (child && r_function_call_1.RFunctionCall.isNamed(child) && identifier_1.Identifier.getName(child.functionName.content) === 'UseMethod') {
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
/** Collects the parameter IDs of S3 generic functions (functions whose body is just UseMethod). */
|
|
82
|
+
function collectS3GenericParameterIds(ast) {
|
|
83
|
+
const paramIds = new Set();
|
|
84
|
+
for (const [, node] of ast.idMap) {
|
|
85
|
+
if (!r_function_definition_1.RFunctionDefinition.is(node)) {
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
if (isUseMethodOnlyBody(node.body)) {
|
|
89
|
+
for (const param of node.parameters) {
|
|
90
|
+
paramIds.add(param.name.info.id);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return paramIds;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* A definition is treated as used (and hence not reported) if it is the dots parameter, a package lifecycle hook,
|
|
98
|
+
* an S3 method for a dispatched generic, or - when {@link UnusedDefinitionConfig#excludeExportedDefinitions} is set -
|
|
99
|
+
* a package export.
|
|
100
|
+
*/
|
|
101
|
+
function isConsideredUsed(lexeme, config, pkg, called) {
|
|
102
|
+
if (lexeme === undefined) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
// non-syntactic definition names (e.g. S3 methods like `"[.irts"`) carry their R quotes in the lexeme
|
|
106
|
+
const name = (0, retriever_1.removeRQuotes)(lexeme);
|
|
107
|
+
// the dots are a special parameter and must never be reported
|
|
108
|
+
if (name === DotsParameter) {
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
// package lifecycle hooks are called by R's package machinery
|
|
112
|
+
if (PackageHookFunctions.has(name)) {
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
const dot = name.indexOf('.');
|
|
116
|
+
if (dot > 0) {
|
|
117
|
+
const generic = name.slice(0, dot);
|
|
118
|
+
if (KnownS3Generics.has(generic) || pkg.s3Generics.has(generic) || called.has(generic)) {
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (config.excludeExportedDefinitions && pkg.exported.has(name)) {
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
12
127
|
const InterestingEdgesVariable = edge_1.EdgeType.Reads | edge_1.EdgeType.Calls | edge_1.EdgeType.DefinesOnCall;
|
|
13
128
|
const InterestingEdgesFunction = edge_1.EdgeType.Reads | edge_1.EdgeType.Calls; // include read as this could print the function definition
|
|
14
129
|
const InterestingEdgesTargets = edge_1.EdgeType.SideEffectOnCall;
|
|
@@ -62,6 +177,9 @@ exports.UNUSED_DEFINITION = {
|
|
|
62
177
|
processSearchResult: async (elements, config, data) => {
|
|
63
178
|
const normalize = await data.normalize();
|
|
64
179
|
const dataflow = await data.dataflow();
|
|
180
|
+
const packageInfo = collectPackageInfo(data);
|
|
181
|
+
const calledNames = collectCalledNames(dataflow.graph);
|
|
182
|
+
const s3GenericParams = collectS3GenericParameterIds(normalize);
|
|
65
183
|
const metadata = {
|
|
66
184
|
totalConsidered: 0
|
|
67
185
|
};
|
|
@@ -73,6 +191,12 @@ exports.UNUSED_DEFINITION = {
|
|
|
73
191
|
&& (0, vertex_1.isFunctionDefinitionVertex)(dfgVertex) && !config.includeFunctionDefinitions)) {
|
|
74
192
|
return undefined;
|
|
75
193
|
}
|
|
194
|
+
if (s3GenericParams.has(element.node.info.id)) {
|
|
195
|
+
return undefined;
|
|
196
|
+
}
|
|
197
|
+
if (isConsideredUsed(element.node.lexeme, config, packageInfo, calledNames)) {
|
|
198
|
+
return undefined;
|
|
199
|
+
}
|
|
76
200
|
const ingoingEdges = dataflow.graph.ingoingEdges(dfgVertex.id);
|
|
77
201
|
const interestedIn = (0, vertex_1.isVariableDefinitionVertex)(dfgVertex) ? InterestingEdgesVariable : InterestingEdgesFunction;
|
|
78
202
|
const ingoingInteresting = ingoingEdges?.values().some(e => edge_1.DfEdge.includesType(e, interestedIn));
|
|
@@ -103,7 +227,8 @@ exports.UNUSED_DEFINITION = {
|
|
|
103
227
|
// our limited analysis causes unused definitions involving complex reflection etc. not to be included in our result, but unused definitions are correctly validated
|
|
104
228
|
certainty: linter_format_1.LintingRuleCertainty.BestEffort,
|
|
105
229
|
defaultConfig: {
|
|
106
|
-
includeFunctionDefinitions: true
|
|
230
|
+
includeFunctionDefinitions: true,
|
|
231
|
+
excludeExportedDefinitions: true
|
|
107
232
|
}
|
|
108
233
|
}
|
|
109
234
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eagleoutice/flowr",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.12.0",
|
|
4
4
|
"description": "Static Dataflow Analyzer and Program Slicer for the R Programming Language",
|
|
5
5
|
"types": "dist/src/index.d.ts",
|
|
6
6
|
"repository": {
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"setup:dev": "git lfs fetch && npm ci && git config --local core.hooksPath .githooks/ && git push --dry-run",
|
|
16
16
|
"main": "npm run build:bundle-flowr && node dist/src/cli/flowr.min.js",
|
|
17
17
|
"flowr": "npm run main --",
|
|
18
|
-
"flowr:dev": "npm run main-dev --",
|
|
18
|
+
"flowr:dev": "npm run gen:base-packages && npm run main-dev --",
|
|
19
19
|
"main-dev": "node -r ts-node/register --watch src/cli/flowr.ts",
|
|
20
20
|
"publish-library": "cp .npmignore package.json README.md LICENSE dist/src/ && cd dist/src && npm publish --access public",
|
|
21
21
|
"release": "npx release-it --ci",
|
|
@@ -27,8 +27,11 @@
|
|
|
27
27
|
"capabilities-markdown": "ts-node src/documentation/doc-capabilities.ts",
|
|
28
28
|
"wiki": "ts-node src/cli/wiki.ts",
|
|
29
29
|
"wiki:watch": "node -r ts-node/register --watch src/cli/wiki.ts --keep-alive",
|
|
30
|
-
"build": "tsc --project . && npm run build:copy-data",
|
|
31
|
-
"
|
|
30
|
+
"build": "npm run gen:base-packages && tsc --project . && npm run build:copy-data",
|
|
31
|
+
"gen:base-packages": "ts-node --transpile-only scripts/gen-base-packages.ts",
|
|
32
|
+
"sync:sigdb": "ts-node --transpile-only scripts/sigdb-remote.ts",
|
|
33
|
+
"publish:sigdb": "ts-node scripts/publish-sigdb.ts",
|
|
34
|
+
"build:copy-data": "npm run sync:sigdb && ts-node --transpile-only scripts/sigdb-copy.ts",
|
|
32
35
|
"build-dev": "npm run build && npm run build:copy-wasm",
|
|
33
36
|
"build:bundle-flowr": "npm run build && esbuild --bundle dist/src/cli/flowr.js --platform=node --tree-shaking=true --minify --external:clipboardy --target=node22 --outfile=dist/src/cli/flowr.min.js && npm run build:copy-wasm",
|
|
34
37
|
"build:copy-wasm": "mkdir -p dist/node_modules/@davisvaughan/tree-sitter-r/ && mkdir -p dist/node_modules/web-tree-sitter && cp node_modules/@davisvaughan/tree-sitter-r/tree-sitter-r.wasm dist/node_modules/@davisvaughan/tree-sitter-r/ && cp node_modules/web-tree-sitter/tree-sitter.wasm dist/node_modules/web-tree-sitter/",
|
|
@@ -47,7 +50,7 @@
|
|
|
47
50
|
"test:performance": "npm run performance-test --",
|
|
48
51
|
"test:docker": "func() { for df in scripts/Dockerfile scripts/Dockerfile-NoR; do echo \"=== building $df ===\"; docker build -t flowr-docker-test -f \"$df\" . || return 1; echo \"=== smoke-testing $df ===\"; docker run --rm flowr-docker-test --version || return 1; done; }; func",
|
|
49
52
|
"detect-circular-deps": "npx madge --extensions ts,tsx --circular src/",
|
|
50
|
-
"checkup": "
|
|
53
|
+
"checkup": "ts-node scripts/checkup-parallel.ts"
|
|
51
54
|
},
|
|
52
55
|
"keywords": [
|
|
53
56
|
"static code analysis",
|
|
@@ -158,11 +161,19 @@
|
|
|
158
161
|
},
|
|
159
162
|
"plugins": {
|
|
160
163
|
"@j-ulrich/release-it-regex-bumper": {
|
|
161
|
-
"out":
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
164
|
+
"out": [
|
|
165
|
+
{
|
|
166
|
+
"file": "src/util/version.ts",
|
|
167
|
+
"search": "const version = '[\\d.]+'",
|
|
168
|
+
"replace": "const version = '{{version}}'"
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
"file": "src/util/version.ts",
|
|
172
|
+
"search": "const versionDate = '[\\d-]+'",
|
|
173
|
+
"replace": "const versionDate = '{{now}}'",
|
|
174
|
+
"dateFormat": "yyyy-MM-dd"
|
|
175
|
+
}
|
|
176
|
+
]
|
|
166
177
|
}
|
|
167
178
|
}
|
|
168
179
|
},
|
|
@@ -209,6 +220,7 @@
|
|
|
209
220
|
"commonmark": "^0.31.2",
|
|
210
221
|
"dagre": "^0.8.5",
|
|
211
222
|
"gray-matter": "^4.0.3",
|
|
223
|
+
"ignore": "^5.3.2",
|
|
212
224
|
"joi": "^18.0.1",
|
|
213
225
|
"lz-string": "^1.5.0",
|
|
214
226
|
"n-readlines": "^3.4.1",
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AbstractFlowrAnalyzerContext = void 0;
|
|
4
4
|
const assert_1 = require("../../util/assert");
|
|
5
|
+
const log_1 = require("../../util/log");
|
|
5
6
|
/**
|
|
6
7
|
* Abstract class representing the context, a context may be modified and enriched by plugins (see {@link FlowrAnalyzerPlugin}).
|
|
7
8
|
*
|
|
@@ -31,7 +32,12 @@ class AbstractFlowrAnalyzerContext {
|
|
|
31
32
|
applyPlugins(args) {
|
|
32
33
|
const res = [];
|
|
33
34
|
for (const plugin of this.plugins) {
|
|
34
|
-
|
|
35
|
+
try {
|
|
36
|
+
res.push(plugin.processor(this.ctx, args));
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
log_1.log.warn(`Plugin ${plugin.name} fail in ctx ${this.name}: ${e instanceof Error ? e.message : String(e)}`);
|
|
40
|
+
}
|
|
35
41
|
}
|
|
36
42
|
return res.filter(assert_1.isNotUndefined);
|
|
37
43
|
}
|
|
@@ -26,6 +26,8 @@ export interface ReadOnlyFlowrAnalyzerContext {
|
|
|
26
26
|
readonly env: ReadOnlyFlowrAnalyzerEnvironmentContext;
|
|
27
27
|
/** The configuration options used by the analyzer. */
|
|
28
28
|
readonly config: FlowrConfig;
|
|
29
|
+
/** The R version analysis assumes when resolving versioned (base-R) exports (see `solver.sigdb.assumedRVersion`). */
|
|
30
|
+
readonly resolvedRVersion: string;
|
|
29
31
|
/**
|
|
30
32
|
* Resource-usage guard (gas).
|
|
31
33
|
* Call `ctx.gas.checkGas(key)` at expensive analysis sites to obtain the current pressure level.
|
|
@@ -52,6 +54,8 @@ export declare class FlowrAnalyzerContext implements ReadOnlyFlowrAnalyzerContex
|
|
|
52
54
|
readonly env: FlowrAnalyzerEnvironmentContext;
|
|
53
55
|
readonly gas: FlowrAnalyzerGasContext;
|
|
54
56
|
private _analyzer;
|
|
57
|
+
/** an auto-detected R version (from the engine), recorded once at the analyzer boundary; see {@link resolvedRVersion} */
|
|
58
|
+
private _detectedR;
|
|
55
59
|
readonly config: FlowrConfig;
|
|
56
60
|
constructor(config: FlowrConfig, plugins: ReadonlyMap<PluginType, readonly FlowrAnalyzerPlugin[]>);
|
|
57
61
|
/**
|
|
@@ -61,6 +65,10 @@ export declare class FlowrAnalyzerContext implements ReadOnlyFlowrAnalyzerContex
|
|
|
61
65
|
*/
|
|
62
66
|
get analyzer(): FlowrAnalyzer | undefined;
|
|
63
67
|
setAnalyzer(analyzer: FlowrAnalyzer): void;
|
|
68
|
+
/** Record the engine's auto-detected R version (used when `solver.sigdb.assumedRVersion` is `"auto"`). */
|
|
69
|
+
setDetectedRVersion(version: string): void;
|
|
70
|
+
/** The R version analysis assumes when resolving versioned (base-R) exports (see {@link resolveAssumedRVersion}). */
|
|
71
|
+
get resolvedRVersion(): string;
|
|
64
72
|
/** delegate request addition */
|
|
65
73
|
addRequests(requests: readonly RAnalysisRequest[]): void;
|
|
66
74
|
addFile(f: string | FlowrFileProvider | RParseRequestFromFile): void;
|