@eagleoutice/flowr 2.15.9 → 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.
Files changed (244) hide show
  1. package/README.md +47 -41
  2. package/abstract-interpretation/absint-inference.d.ts +2 -2
  3. package/abstract-interpretation/absint-inference.js +32 -79
  4. package/abstract-interpretation/data-frame/arguments.js +11 -7
  5. package/benchmark/slicer.d.ts +0 -1
  6. package/benchmark/slicer.js +1 -2
  7. package/cli/repl/commands/repl-signature.js +12 -3
  8. package/config.d.ts +5 -1
  9. package/control-flow/cfg-properties.js +0 -22
  10. package/control-flow/happens-before.d.ts +7 -2
  11. package/control-flow/happens-before.js +55 -31
  12. package/control-flow/useless-loop.d.ts +1 -1
  13. package/control-flow/useless-loop.js +29 -42
  14. package/dataflow/environments/apply-kill.js +6 -2
  15. package/dataflow/environments/built-in-config.d.ts +2 -0
  16. package/dataflow/environments/built-in-props.d.ts +16 -1
  17. package/dataflow/environments/built-in-props.js +33 -20
  18. package/dataflow/environments/built-in.d.ts +8 -3
  19. package/dataflow/environments/built-in.js +52 -82
  20. package/dataflow/environments/default-builtin-config.d.ts +551 -21
  21. package/dataflow/environments/default-builtin-config.js +121 -45
  22. package/dataflow/environments/define.d.ts +3 -2
  23. package/dataflow/environments/define.js +4 -3
  24. package/dataflow/environments/deprecation-info.d.ts +45 -0
  25. package/dataflow/environments/deprecation-info.js +13 -0
  26. package/dataflow/environments/environment.d.ts +7 -5
  27. package/dataflow/environments/environment.js +55 -121
  28. package/dataflow/environments/identifier.d.ts +6 -2
  29. package/dataflow/environments/identifier.js +23 -69
  30. package/dataflow/environments/reference-to-maybe.d.ts +9 -0
  31. package/dataflow/environments/reference-to-maybe.js +23 -51
  32. package/dataflow/environments/resolve-by-name.js +37 -76
  33. package/dataflow/eval/resolve/resolve-argument.d.ts +3 -1
  34. package/dataflow/eval/resolve/resolve-argument.js +61 -64
  35. package/dataflow/eval/resolve/resolve-working-directory.d.ts +8 -2
  36. package/dataflow/eval/resolve/resolve-working-directory.js +12 -20
  37. package/dataflow/eval/resolve/resolve.d.ts +4 -0
  38. package/dataflow/eval/resolve/resolve.js +23 -14
  39. package/dataflow/extractor.js +180 -58
  40. package/dataflow/fn/class-declaration.d.ts +8 -13
  41. package/dataflow/fn/class-declaration.js +95 -116
  42. package/dataflow/fn/exceptions-of-function.js +68 -37
  43. package/dataflow/fn/frame-reflection.d.ts +12 -4
  44. package/dataflow/fn/frame-reflection.js +51 -41
  45. package/dataflow/fn/function-props.js +15 -33
  46. package/dataflow/fn/function-semantics.d.ts +11 -3
  47. package/dataflow/fn/function-semantics.js +6 -0
  48. package/dataflow/fn/higher-order-function.d.ts +9 -1
  49. package/dataflow/fn/higher-order-function.js +27 -24
  50. package/dataflow/fn/strict-function.d.ts +13 -0
  51. package/dataflow/fn/strict-function.js +291 -123
  52. package/dataflow/graph/call-graph.d.ts +7 -6
  53. package/dataflow/graph/call-graph.js +35 -46
  54. package/dataflow/graph/graph.d.ts +13 -1
  55. package/dataflow/graph/graph.js +74 -66
  56. package/dataflow/graph/vertex.d.ts +1 -1
  57. package/dataflow/info.d.ts +8 -1
  58. package/dataflow/info.js +24 -30
  59. package/dataflow/internal/control-flow.d.ts +31 -4
  60. package/dataflow/internal/control-flow.js +61 -39
  61. package/dataflow/internal/linker.d.ts +17 -8
  62. package/dataflow/internal/linker.js +286 -213
  63. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.d.ts +179 -0
  64. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +874 -0
  65. package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +3 -1
  66. package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +60 -48
  67. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +4 -2
  68. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +135 -198
  69. package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.js +7 -9
  70. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +5 -1
  71. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +21 -14
  72. package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +14 -4
  73. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.d.ts +1 -1
  74. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +141 -146
  75. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +56 -24
  76. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +292 -253
  77. package/dataflow/internal/process/functions/call/built-in/built-in-get.d.ts +1 -1
  78. package/dataflow/internal/process/functions/call/built-in/built-in-get.js +30 -32
  79. package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +68 -67
  80. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +91 -129
  81. package/dataflow/internal/process/functions/call/built-in/built-in-local.d.ts +1 -3
  82. package/dataflow/internal/process/functions/call/built-in/built-in-local.js +16 -12
  83. package/dataflow/internal/process/functions/call/built-in/built-in-quote.d.ts +4 -4
  84. package/dataflow/internal/process/functions/call/built-in/built-in-quote.js +9 -35
  85. package/dataflow/internal/process/functions/call/built-in/built-in-repeat-loop.js +2 -0
  86. package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +8 -3
  87. package/dataflow/internal/process/functions/call/built-in/built-in-s-four.d.ts +5 -3
  88. package/dataflow/internal/process/functions/call/built-in/built-in-s-four.js +13 -31
  89. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.d.ts +1 -1
  90. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +42 -119
  91. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.d.ts +1 -3
  92. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.js +21 -21
  93. package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +2 -0
  94. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +93 -102
  95. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.d.ts +7 -3
  96. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +173 -114
  97. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.d.ts +1 -3
  98. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +23 -26
  99. package/dataflow/internal/process/functions/call/built-in/built-in-with.d.ts +1 -1
  100. package/dataflow/internal/process/functions/call/built-in/built-in-with.js +34 -9
  101. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.d.ts +1 -1
  102. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +119 -93
  103. package/dataflow/internal/process/functions/call/common.d.ts +4 -4
  104. package/dataflow/internal/process/functions/call/common.js +49 -71
  105. package/dataflow/internal/process/functions/call/deferred.d.ts +12 -2
  106. package/dataflow/internal/process/functions/call/deferred.js +81 -63
  107. package/dataflow/internal/process/functions/call/known-call-handling.d.ts +4 -2
  108. package/dataflow/internal/process/functions/call/known-call-handling.js +65 -68
  109. package/dataflow/internal/process/functions/call/named-call-handling.d.ts +3 -5
  110. package/dataflow/internal/process/functions/call/named-call-handling.js +48 -19
  111. package/dataflow/internal/process/functions/call/quoted.d.ts +2 -0
  112. package/dataflow/internal/process/functions/call/quoted.js +257 -154
  113. package/dataflow/internal/process/functions/call/unnamed-call-handling.js +17 -38
  114. package/dataflow/internal/process/functions/process-parameter.js +25 -32
  115. package/dataflow/internal/process/process-symbol.js +4 -3
  116. package/dataflow/internal/program-order.d.ts +26 -0
  117. package/dataflow/internal/program-order.js +49 -0
  118. package/documentation/data/faq/faqs.js +3 -3
  119. package/documentation/data/interface/doc-writing-code.js +1 -2
  120. package/documentation/data/server/doc-data-server-messages.js +7 -7
  121. package/documentation/doc-capabilities.js +80 -34
  122. package/documentation/doc-util/doc-query.d.ts +0 -3
  123. package/documentation/doc-util/doc-query.js +4 -3
  124. package/documentation/wiki-analyzer.js +1 -1
  125. package/documentation/wiki-cfg.js +5 -6
  126. package/documentation/wiki-core.js +8 -8
  127. package/documentation/wiki-dataflow-graph.js +10 -11
  128. package/documentation/wiki-interface.js +2 -2
  129. package/documentation/wiki-linting-and-testing.js +3 -3
  130. package/documentation/wiki-overview.js +6 -6
  131. package/documentation/wiki-query.js +9 -101
  132. package/documentation/wiki-setup.js +23 -0
  133. package/documentation/wiki-signature-database.js +1 -1
  134. package/linter/linter-rules.d.ts +18 -9
  135. package/linter/rules/absolute-path.js +63 -87
  136. package/linter/rules/deprecated-functions.d.ts +1 -45
  137. package/linter/rules/deprecated-functions.js +24 -33
  138. package/linter/rules/file-path-validity.d.ts +4 -2
  139. package/linter/rules/file-path-validity.js +114 -80
  140. package/linter/rules/namespace-access.js +21 -33
  141. package/linter/rules/naming-convention.d.ts +1 -1
  142. package/linter/rules/naming-convention.js +60 -48
  143. package/linter/rules/network-functions.js +11 -7
  144. package/linter/rules/no-leaked-credentials.js +15 -18
  145. package/linter/rules/problematic-inputs.d.ts +2 -1
  146. package/linter/rules/problematic-inputs.js +39 -59
  147. package/linter/rules/roxygen-arguments.d.ts +9 -4
  148. package/linter/rules/roxygen-arguments.js +29 -48
  149. package/linter/rules/seeded-randomness.d.ts +7 -4
  150. package/linter/rules/seeded-randomness.js +128 -89
  151. package/linter/rules/stop-with-call-arg.d.ts +4 -2
  152. package/linter/rules/stop-with-call-arg.js +25 -22
  153. package/linter/rules/unclosed-connection.js +31 -24
  154. package/linter/rules/undefined-symbol.d.ts +4 -6
  155. package/linter/rules/undefined-symbol.js +58 -75
  156. package/linter/rules/unescaped-arguments.js +18 -44
  157. package/linter/rules/unused-definition.d.ts +6 -0
  158. package/linter/rules/unused-definition.js +105 -145
  159. package/linter/rules/unused-import.d.ts +3 -0
  160. package/linter/rules/unused-import.js +25 -43
  161. package/package.json +5 -2
  162. package/project/flowr-analyzer.d.ts +2 -0
  163. package/project/flowr-analyzer.js +28 -1
  164. package/project/plugins/file-plugins/files/flowr-jupyter-file.d.ts +2 -2
  165. package/project/plugins/file-plugins/files/flowr-jupyter-file.js +8 -12
  166. package/project/plugins/file-plugins/files/flowr-rda-file.d.ts +0 -2
  167. package/project/plugins/file-plugins/files/flowr-rda-file.js +10 -55
  168. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.d.ts +7 -5
  169. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +34 -56
  170. package/project/plugins/file-plugins/flowr-analyzer-file-plugin.js +2 -1
  171. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +22 -45
  172. package/project/plugins/project-discovery/flowr-analyzer-project-discovery-plugin.js +2 -2
  173. package/project/sigdb/build.js +4 -0
  174. package/project/sigdb/manifest.d.ts +2 -0
  175. package/project/sigdb/manifest.js +10 -1
  176. package/project/sigdb/reader.js +23 -61
  177. package/project/sigdb/sigdb-download.d.ts +29 -6
  178. package/project/sigdb/sigdb-download.js +212 -64
  179. package/queries/base-query-format.js +1 -2
  180. package/queries/catalog/absint-query/absint-query-format.js +1 -1
  181. package/queries/catalog/call-context-query/cascade-action.d.ts +3 -1
  182. package/queries/catalog/call-context-query/cascade-action.js +2 -0
  183. package/queries/catalog/call-context-query/identify-link-to-last-call-relation.js +3 -0
  184. package/queries/catalog/dataflow-query/dataflow-query-executor.js +2 -2
  185. package/queries/catalog/dataflow-query/dataflow-query-format.d.ts +2 -0
  186. package/queries/catalog/dataflow-query/dataflow-query-format.js +4 -7
  187. package/queries/catalog/dependencies-query/dependencies-query-executor.js +50 -114
  188. package/queries/catalog/dependencies-query/function-info/library-functions.d.ts +5 -9
  189. package/queries/catalog/dependencies-query/function-info/library-functions.js +6 -0
  190. package/queries/catalog/dependencies-query/function-info/read-functions.js +1 -1
  191. package/queries/catalog/dependencies-query/function-info/write-functions.js +7 -3
  192. package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +4 -4
  193. package/queries/catalog/input-sources-query/simple-input-classifier.js +192 -301
  194. package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-executor.js +2 -1
  195. package/queries/catalog/origin-query/origin-query-executor.d.ts +1 -1
  196. package/queries/catalog/origin-query/origin-query-executor.js +2 -2
  197. package/queries/catalog/origin-query/origin-query-format.d.ts +2 -2
  198. package/queries/catalog/origin-query/origin-query-format.js +1 -1
  199. package/queries/query.d.ts +1 -1
  200. package/r-bridge/data/data.d.ts +21 -14
  201. package/r-bridge/data/data.js +28 -20
  202. package/r-bridge/lang-4.x/ast/model/model.d.ts +3 -1
  203. package/r-bridge/lang-4.x/ast/model/model.js +19 -43
  204. package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +1 -0
  205. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +3 -0
  206. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.js +5 -12
  207. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +1 -0
  208. package/r-bridge/lang-4.x/ast/model/nodes/r-break.d.ts +1 -0
  209. package/r-bridge/lang-4.x/ast/model/nodes/r-comment.d.ts +1 -0
  210. package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +1 -0
  211. package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.d.ts +1 -0
  212. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +1 -0
  213. package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +1 -0
  214. package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.d.ts +1 -0
  215. package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.d.ts +1 -0
  216. package/r-bridge/lang-4.x/ast/model/nodes/r-logical.d.ts +1 -0
  217. package/r-bridge/lang-4.x/ast/model/nodes/r-next.d.ts +1 -0
  218. package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +1 -0
  219. package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.d.ts +1 -0
  220. package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.d.ts +1 -0
  221. package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.d.ts +1 -0
  222. package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +1 -0
  223. package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.d.ts +1 -0
  224. package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.d.ts +1 -0
  225. package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.d.ts +1 -0
  226. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.d.ts +2 -2
  227. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.js +11 -2
  228. package/r-bridge/roxygen2/roxygen-parse.js +28 -42
  229. package/r-bridge/shell.js +6 -0
  230. package/search/search-executor/search-enrichers.js +25 -37
  231. package/slicing/static/slice-call.d.ts +4 -3
  232. package/slicing/static/slice-call.js +56 -88
  233. package/slicing/static/static-slicer.js +115 -79
  234. package/slicing/static/visiting-queue.d.ts +4 -6
  235. package/slicing/static/visiting-queue.js +9 -13
  236. package/util/files.d.ts +2 -0
  237. package/util/files.js +3 -1
  238. package/util/mermaid/mermaid.js +6 -2
  239. package/util/proc.js +2 -1
  240. package/util/r-base-packages.d.ts +2 -0
  241. package/util/r-base-packages.js +23 -13
  242. package/util/text/playground-link.d.ts +12 -3
  243. package/util/text/playground-link.js +18 -27
  244. package/util/version.js +4 -10
@@ -10,6 +10,8 @@ const assert_1 = require("../../util/assert");
10
10
  const range_1 = require("../../util/range");
11
11
  const flowr_file_1 = require("../../project/context/flowr-file");
12
12
  const r_base_packages_1 = require("../../util/r-base-packages");
13
+ const unused_import_1 = require("./unused-import");
14
+ const defaultmap_1 = require("../../util/collections/defaultmap");
13
15
  const linter_format_1 = require("../linter-format");
14
16
  const linter_tags_1 = require("../linter-tags");
15
17
  const undefined_symbol_util_1 = require("./undefined-symbol-util");
@@ -17,11 +19,13 @@ const df_helper_1 = require("../../dataflow/graph/df-helper");
17
19
  const r_symbol_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-symbol");
18
20
  /** calls that load a package; an unresolved one means we cannot enumerate all exports in scope */
19
21
  const LibraryLoadFunctions = new Set(['library', 'require', 'requireNamespace', 'loadNamespace', 'attachNamespace', 'load_all', 'use', 'p_load']);
20
- // standard packages attached by default; exports are in scope without library()
21
22
  /** test frameworks whose namespace a test file runs under implicitly (e.g. `tests/testthat/test-*.R` sees testthat's exports without a `library()`) */
22
23
  const ImplicitTestFrameworks = ['testthat', 'tinytest', 'RUnit'];
23
24
  /** whether name is an export of a default-attached base package (needs no library()) */
24
25
  function isAttachedBaseName(name) {
26
+ if (r_base_packages_1.BaseDatasets.has(name)) {
27
+ return true;
28
+ }
25
29
  const owner = (0, r_base_packages_1.baseRExportOwner)(name);
26
30
  return owner !== undefined && r_base_packages_1.AttachedBasePackages.includes(owner);
27
31
  }
@@ -43,7 +47,11 @@ exports.UNDEFINED_SYMBOL = {
43
47
  const meta = {
44
48
  totalFunctionCalls: 0,
45
49
  totalVariableUses: 0,
46
- suppressed: { installed: 0, loadedPackage: 0, enclosingScope: 0, nonStandardEval: 0, subscript: 0 }
50
+ suppressed: { installed: 0, loadedPackage: 0, enclosingScope: 0, nonStandardEval: 0, subscript: 0, unresolvedLibrary: 0 }
51
+ };
52
+ const suppress = (reason) => {
53
+ meta.suppressed[reason]++;
54
+ return undefined;
47
55
  };
48
56
  // `inst/` files are installed verbatim (resources, not namespace source); skip them. Key off the
49
57
  // FileRole.Install role, with a path fallback for requests that bypass the file-role plugins.
@@ -53,21 +61,10 @@ exports.UNDEFINED_SYMBOL = {
53
61
  const testFiles = new Set(ctx.files.getFilesByRole(flowr_file_1.FileRole.Test).map(f => f.path()));
54
62
  const testExports = new Set(testFiles.size === 0 ? [] : deps.signatureSources().flatMap(src => ImplicitTestFrameworks.flatMap(pkg => src.lookup(pkg)?.exported ?? [])));
55
63
  const isImplicitTestExport = (name, file) => file !== undefined && testFiles.has(file) && testExports.has(name);
56
- // a library() we could not resolve could export any of these symbols; we still report but flag the
57
- // findings as low-confidence (`mayBeProvidedByUnresolvedLibrary`) so the severity can be lowered
58
- const unknownIds = new Set();
59
- for (const e of graph.unknownSideEffects) {
60
- unknownIds.add(graph_1.UnknownSideEffect.id(e));
61
- }
62
- let unresolvedLibraryInScope = false;
63
- if (unknownIds.size > 0) {
64
- for (const [id, v] of graph.verticesOfType(vertex_1.VertexType.FunctionCall)) {
65
- if (LibraryLoadFunctions.has(identifier_1.Identifier.getName(v.name)) && unknownIds.has(id)) {
66
- unresolvedLibraryInScope = true;
67
- break;
68
- }
69
- }
70
- }
64
+ /* a library() we could not resolve could export any bare name, so such names are suppressed rather than guessed */
65
+ const unknownIds = new Set([...graph.unknownSideEffects].map(e => graph_1.UnknownSideEffect.id(e)));
66
+ const unresolvedLibraryInScope = unknownIds.size > 0 && [...graph.verticesOfType(vertex_1.VertexType.FunctionCall)]
67
+ .some(([id, v]) => unknownIds.has(id) && LibraryLoadFunctions.has(identifier_1.Identifier.getName(v.name)));
71
68
  // scope-defined names, a fallback for closure variables flowR's dataflow did not statically link
72
69
  const scopeDefined = (0, undefined_symbol_util_1.collectScopeDefinedNames)(graph);
73
70
  // packages whose exports are in scope: DESCRIPTION/library() deps plus the default-attached base
@@ -76,53 +73,16 @@ exports.UNDEFINED_SYMBOL = {
76
73
  ...deps.getDependencies().map(p => deps.getDependency(p.name) ?? p),
77
74
  ...r_base_packages_1.AttachedBasePackages.map(n => deps.getDependency(n)).filter(assert_1.isNotUndefined)
78
75
  ];
79
- const exportedByLoaded = new Map();
80
- const isExportedByLoadedPackage = (name) => {
81
- let known = exportedByLoaded.get(name);
82
- if (known === undefined) {
83
- known = loadedPackages.some(p => p.has(name));
84
- exportedByLoaded.set(name, known);
85
- }
86
- return known;
87
- };
76
+ /* a package may re-export what it imports, as dplyr does tibble's `as_tibble` */
77
+ const src = deps.signatures().sources();
78
+ const importedByLoaded = new Set(loadedPackages.flatMap(p => src.isBaseR(p.name) ? [] : (0, unused_import_1.nonBaseImports)(src, p.name, p.resolvedVersion)));
79
+ const isExportedByLoadedPackage = (0, defaultmap_1.memoize)((name) => loadedPackages.some(p => p.has(name)) || (importedByLoaded.size > 0 && deps.packagesExporting(name).some(p => importedByLoaded.has(p))));
88
80
  // hint an unloaded package that exports `name` (e.g. `ggplot` -> `ggplot2`), from the package database
89
81
  const attached = new Set(r_base_packages_1.AttachedBasePackages);
90
82
  const hintPackagesFor = (name) => deps.packagesExporting(name).filter(p => !attached.has(p)).slice(0, MaxHintPackages);
91
- const results = elements.getElements().map(element => {
92
- const id = element.node.info.id;
93
- const vtx = graph.getVertex(id);
94
- if (!vtx) {
95
- return undefined;
96
- }
97
- const inInstalledFile = isInstalledFile(element.node.info.file);
98
- if (vertex_1.DfgVertex.isFunctionCall(vtx)) {
99
- if (vtx.origin === 'unnamed' || !config.checkFunctions) {
100
- return undefined;
101
- }
102
- meta.totalFunctionCalls++;
103
- if (inInstalledFile) {
104
- meta.suppressed.installed++;
105
- return undefined;
106
- }
107
- return check(element, id, identifier_1.Identifier.getName(vtx.name), identifier_1.Identifier.getNamespace(vtx.name), 'function');
108
- }
109
- // variable use: only plain symbols (not argument names, `...`, or empty)
110
- if (vertex_1.DfgVertex.isUse(vtx) && config.checkVariables) {
111
- const node = element.node;
112
- if (!r_symbol_1.RSymbol.is(node) || node.lexeme === '...' || node.lexeme === undefined) {
113
- return undefined;
114
- }
115
- meta.totalVariableUses++;
116
- if (inInstalledFile) {
117
- meta.suppressed.installed++;
118
- return undefined;
119
- }
120
- return check(element, id, node.lexeme, undefined, 'variable');
121
- }
122
- return undefined;
123
- }).filter(assert_1.isNotUndefined);
124
83
  /** shared resolution logic for a name used either as a function call or a variable */
125
- function check(element, id, name, namespace, kind) {
84
+ const check = (node, name, namespace, kind) => {
85
+ const id = node.info.id;
126
86
  // resolved by flowR itself (local/param/builtin) - never a candidate, so not counted as suppressed
127
87
  if (kind === 'variable' ? (0, undefined_symbol_util_1.useResolvesToDefinitionOrBuiltin)(graph, id) : (df_helper_1.Dataflow.origin(graph, id)?.length ?? 0) > 0) {
128
88
  return undefined;
@@ -138,11 +98,16 @@ exports.UNDEFINED_SYMBOL = {
138
98
  return undefined;
139
99
  }
140
100
  // a bare name a test framework exports, used in a test file where that framework's namespace is attached
141
- if (namespace === undefined && isImplicitTestExport(name, element.node.info.file)) {
101
+ if (namespace === undefined && isImplicitTestExport(name, node.info.file)) {
142
102
  return suppress('loadedPackage');
143
103
  }
144
104
  // exported by a package in scope (`pkg::fn`, a loaded package, or a default-attached base package)
145
- if (namespace !== undefined ? deps.getDependency(namespace)?.has(name) === true : isExportedByLoadedPackage(name)) {
105
+ /* the database records no data sets, so `pkg::x` read as a variable may be lazy data of a known package */
106
+ const nsPackage = namespace === undefined ? undefined : deps.getDependency(namespace);
107
+ const exported = namespace === undefined
108
+ ? isExportedByLoadedPackage(name)
109
+ : nsPackage !== undefined && (kind === 'variable' || nsPackage.has(name));
110
+ if (exported) {
146
111
  return suppress('loadedPackage');
147
112
  }
148
113
  // forward-referenced closure binding flowR's dataflow did not link (unconditional bindings only)
@@ -157,7 +122,10 @@ exports.UNDEFINED_SYMBOL = {
157
122
  if (kind === 'variable' && !config.checkSubscripts && (0, undefined_symbol_util_1.isInSubscript)(graph, id)) {
158
123
  return suppress('subscript');
159
124
  }
160
- const loc = range_1.SourceLocation.fromNode(element.node);
125
+ if (unresolvedLibraryInScope && namespace === undefined) {
126
+ return suppress('unresolvedLibrary');
127
+ }
128
+ const loc = range_1.SourceLocation.fromNode(node);
161
129
  if (loc === undefined) {
162
130
  return undefined;
163
131
  }
@@ -168,29 +136,44 @@ exports.UNDEFINED_SYMBOL = {
168
136
  kind,
169
137
  involvedId: id,
170
138
  loc,
171
- ...(availableInPackages.length > 0 ? { availableInPackages } : {}),
172
- ...(unresolvedLibraryInScope ? { mayBeProvidedByUnresolvedLibrary: true } : {})
139
+ ...(availableInPackages.length > 0 ? { availableInPackages } : {})
173
140
  };
174
- }
175
- function suppress(reason) {
176
- meta.suppressed[reason]++;
177
- return undefined;
178
- }
141
+ };
142
+ /** the symbol to check if the config asks for it: a called function, or a plain symbol read */
143
+ const symbolOf = (node) => {
144
+ const vtx = graph.getVertex(node.info.id);
145
+ if (vertex_1.DfgVertex.isFunctionCall(vtx)) {
146
+ return vtx.origin !== 'unnamed' && config.checkFunctions ? ['function', vtx.name] : undefined;
147
+ }
148
+ const plainSymbol = r_symbol_1.RSymbol.is(node) && node.lexeme !== '...' && node.lexeme !== undefined;
149
+ return vertex_1.DfgVertex.isUse(vtx) && config.checkVariables && plainSymbol ? ['variable', node.content] : undefined;
150
+ };
151
+ const results = elements.getElements().map(({ node }) => {
152
+ const symbol = symbolOf(node);
153
+ if (symbol === undefined) {
154
+ return undefined;
155
+ }
156
+ const [kind, identifier] = symbol;
157
+ meta[kind === 'function' ? 'totalFunctionCalls' : 'totalVariableUses']++;
158
+ if (isInstalledFile(node.info.file)) {
159
+ return suppress('installed');
160
+ }
161
+ return check(node, identifier_1.Identifier.getName(identifier), identifier_1.Identifier.getNamespace(identifier), kind);
162
+ }).filter(assert_1.isNotUndefined);
179
163
  return { results, '.meta': meta };
180
164
  },
181
165
  prettyPrint: {
182
- [linter_format_1.LintingPrettyPrintContext.Query]: result => `${result.mayBeProvidedByUnresolvedLibrary ? 'Possibly undefined' : 'Undefined'} ${result.kind} \`${result.name}\` at ${range_1.SourceLocation.format(result.loc)}`,
166
+ [linter_format_1.LintingPrettyPrintContext.Query]: result => `Undefined ${result.kind} \`${result.name}\` at ${range_1.SourceLocation.format(result.loc)}`,
183
167
  [linter_format_1.LintingPrettyPrintContext.Full]: result => {
184
168
  const where = range_1.SourceLocation.format(result.loc);
185
- const caveat = result.mayBeProvidedByUnresolvedLibrary ? ' (an unresolved library is loaded that might provide it)' : '';
186
169
  if (result.availableInPackages && result.availableInPackages.length > 0) {
187
170
  const pkgs = result.availableInPackages.map(p => `\`${p}\``).join(', ');
188
171
  const hint = result.availableInPackages.length === 1 ? `\`library(${result.availableInPackages[0]})\`` : `one of ${pkgs}`;
189
- return `\`${result.name}\` at ${where} is used but not defined; it is exported by ${pkgs} - did you forget to load it (e.g. ${hint})?${caveat}`;
172
+ return `\`${result.name}\` at ${where} is used but not defined; it is exported by ${pkgs} - did you forget to load it (e.g. ${hint})?`;
190
173
  }
191
174
  return result.kind === 'function'
192
- ? `\`${result.name}\` at ${where} is called but is neither defined locally, a base R builtin, nor exported by a loaded package${caveat}`
193
- : `\`${result.name}\` at ${where} is used as a variable but is never defined in scope${caveat}`;
175
+ ? `\`${result.name}\` at ${where} is called but is neither defined locally, a base R builtin, nor exported by a loaded package`
176
+ : `\`${result.name}\` at ${where} is used as a variable but is never defined in scope`;
194
177
  }
195
178
  },
196
179
  info: {
@@ -46,39 +46,16 @@ const UncertainInputs = [simple_input_classifier_1.InputType.Unknown, simple_inp
46
46
  const UnescapedArgumentCategories = record_1.Record.values(UnescapedArgumentCategory);
47
47
  /** Get the critical calls of every category that is not disabled */
48
48
  function getEnabledCriticalCalls(config, index) {
49
- const result = [];
50
- for (const category of UnescapedArgumentCategories) {
51
- const criticalCallProps = config.categories[category].criticalCalls;
52
- const criticalArgProps = config.categories[category].criticalArgs;
53
- if (config.disabledCategories.includes(category)) {
54
- continue;
55
- }
56
- for (const entry of index.entries) {
57
- if (function_semantics_1.FunctionSemantics.call.props.hasAny(entry, criticalCallProps) && entry.sig?.some(([, prop]) => (prop & criticalArgProps) !== 0)) {
58
- result.push({ category, name: entry.name, signature: entry.sig });
59
- }
60
- }
61
- }
62
- return result;
63
- }
64
- /** Index the critical calls of the enabled categories by function name */
65
- function indexCriticalCalls(config, builtIns) {
66
- const index = new Map();
67
- for (const call of getEnabledCriticalCalls(config, builtIns)) {
68
- const name = identifier_1.Identifier.getName(call.name);
69
- const known = index.get(name);
70
- if (known !== undefined) {
71
- known.push(call);
72
- }
73
- else {
74
- index.set(name, [call]);
75
- }
76
- }
77
- return index;
49
+ return UnescapedArgumentCategories.filter(category => !config.disabledCategories.includes(category)).flatMap(category => {
50
+ const { criticalCalls, criticalArgs } = config.categories[category];
51
+ const hasCriticalArg = (sig) => sig?.some(([, prop]) => (prop & criticalArgs) !== 0) ?? false;
52
+ return index.entries.filter(entry => function_semantics_1.FunctionSemantics.call.props.hasAny(entry, criticalCalls) && hasCriticalArg(entry.sig))
53
+ .map(entry => ({ category, name: entry.name, signature: entry.sig }));
54
+ });
78
55
  }
79
56
  /** Gets all critical arguments of critical function calls in the data flow graph */
80
57
  function getCriticalTargets(elements, graph, config, builtIns) {
81
- const criticalCalls = indexCriticalCalls(config, builtIns);
58
+ const criticalCalls = Map.groupBy(getEnabledCriticalCalls(config, builtIns), call => identifier_1.Identifier.getName(call.name));
82
59
  const targets = [];
83
60
  const seen = new Set();
84
61
  for (const { node } of elements) {
@@ -95,7 +72,7 @@ function getCriticalTargets(elements, graph, config, builtIns) {
95
72
  const key = `${category}-${call.id}-${arg}`;
96
73
  if (location !== undefined && !seen.has(key)) {
97
74
  seen.add(key);
98
- targets.push({ category, call: call, signature, arg, location });
75
+ targets.push({ category, call, signature, arg, location });
99
76
  }
100
77
  }
101
78
  }
@@ -104,14 +81,10 @@ function getCriticalTargets(elements, graph, config, builtIns) {
104
81
  }
105
82
  function mapInputSourceToArgs(call, sources) {
106
83
  const args = call.args.map(graph_1.FunctionArgument.getReference).filter(assert_1.isNotUndefined);
107
- const result = [];
108
- for (let i = 0; i < args.length; i++) {
109
- const source = sources.find(source => source.id === args[i]) ?? (sources.length === args.length ? sources[i] : undefined);
110
- if (source !== undefined) {
111
- result.push([args[i], source]);
112
- }
113
- }
114
- return result;
84
+ return args.flatMap((arg, i) => {
85
+ const source = sources.find(source => source.id === arg) ?? (sources.length === args.length ? sources[i] : undefined);
86
+ return source === undefined ? [] : [[arg, source]];
87
+ });
115
88
  }
116
89
  /**
117
90
  * Whether anything `start` reads is a parameter of an enclosing function. What the call sites happen to pass says
@@ -153,9 +126,10 @@ function isCertainlyCritical(source, config) {
153
126
  * Gets all unescaped sources for the critical target calls of the given category
154
127
  */
155
128
  async function getUnescapedSources(category, targets, config, data, graph) {
156
- const sanitizerNames = new Set((config.categories[category].sanitizers ?? []).map(call => identifier_1.Identifier.getName(call)));
157
- const sanitizers = (config.categories[category].sanitizers ?? []).map(call => ({ call }));
158
- const queryConfig = { narrowing: [...(0, input_source_functions_1.narrowingFunctions)(data.inspectContext().env.builtInIndex), ...sanitizers] };
129
+ const sanitizers = config.categories[category].sanitizers ?? [];
130
+ const sanitizerNames = new Set(sanitizers.map(call => identifier_1.Identifier.getName(call)));
131
+ const narrowing = [...(0, input_source_functions_1.narrowingFunctions)(data.inspectContext().env.builtInIndex), ...sanitizers.map(call => ({ call }))];
132
+ const queryConfig = { narrowing };
159
133
  const found = new Map();
160
134
  let entries = targets.map(target => ({ target, call: target.call.id, only: new Set([target.arg]), depth: 0 }));
161
135
  while (entries.length > 0) {
@@ -173,9 +147,9 @@ async function getUnescapedSources(category, targets, config, data, graph) {
173
147
  /* a call passing a constant today makes the argument constant, but the function still escapes its
174
148
  parameter, and it is one call away from being handed anything */
175
149
  const viaParameter = isAcceptedInput(source, config)
176
- && source.types.length > 0 && source.types.every(t => t === simple_input_classifier_1.InputType.Constant || t === simple_input_classifier_1.InputType.DerivedConstant)
150
+ && source.types.length > 0 && source.types.every(t => AcceptedInputs.includes(t))
177
151
  && readsParameter(graph, arg, sanitizerNames);
178
- if ((entry.only !== undefined && !entry.only.has(arg)) || (isAcceptedInput(source, config) && !viaParameter)) {
152
+ if ((entry.only !== undefined && !entry.only.has(arg)) || (isAcceptedInput(source, config) && !viaParameter) || model_1.RConstant.is(graph.idMap?.get(arg))) {
179
153
  continue;
180
154
  }
181
155
  else if (entry.depth < config.maxDecentDepth && (source.trace === simple_input_classifier_1.InputTraceType.Known || viaParameter) && vertex_1.DfgVertex.isFunctionCall(vertex) && !vertex_1.DfgVertex.hasOrigin(vertex, built_in_proc_name_1.BuiltInProcName.Access)) {
@@ -1,8 +1,10 @@
1
1
  import { type LintingResult, LintingRuleCertainty } from '../linter-format';
2
2
  import type { MergeableRecord } from '../../util/objects';
3
3
  import { LintingRuleTag } from '../linter-tags';
4
+ import type { DataflowGraph } from '../../dataflow/graph/graph';
4
5
  import type { ParentInformation } from '../../r-bridge/lang-4.x/ast/model/processing/decorate';
5
6
  import type { ReadonlyFlowrAnalysisProvider } from '../../project/flowr-analyzer';
7
+ import type { ReadOnlyFlowrAnalyzerContext } from '../../project/context/flowr-analyzer-context';
6
8
  export interface UnusedDefinitionResult extends LintingResult {
7
9
  variableName?: string;
8
10
  }
@@ -17,6 +19,10 @@ export interface UnusedDefinitionConfig extends MergeableRecord {
17
19
  */
18
20
  excludeExportedDefinitions: boolean;
19
21
  }
22
+ /** Collects the names of every function call in the graph, so we can tell whether an S3 generic is dispatched anywhere. */
23
+ export declare function collectCalledNames(dfg: DataflowGraph): ReadonlySet<string>;
24
+ /** Whether `name` reads as `generic.class` for a generic that is known, declared, or called, so R dispatches to it by that name. */
25
+ export declare function isS3MethodName(name: string, ctx: ReadOnlyFlowrAnalyzerContext, called: ReadonlySet<string>, declared?: ReadonlySet<string>): boolean;
20
26
  export interface UnusedDefinitionMetadata extends MergeableRecord {
21
27
  totalConsidered: number;
22
28
  }