@eagleoutice/flowr 2.16.2 → 2.16.3

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 (445) hide show
  1. package/README.md +10 -10
  2. package/abstract-interpretation/data-frame/arguments.js +4 -3
  3. package/abstract-interpretation/data-frame/dataframe-semantics.js +1 -2
  4. package/abstract-interpretation/data-frame/semantics.d.ts +2 -2
  5. package/abstract-interpretation/data-frame/semantics.js +2 -6
  6. package/benchmark/slicer.js +1 -3
  7. package/benchmark/summarizer/first-phase/input.js +1 -12
  8. package/benchmark/summarizer/second-phase/process.d.ts +7 -0
  9. package/benchmark/summarizer/second-phase/process.js +15 -12
  10. package/cli/repl/commands/repl-cfg.js +18 -49
  11. package/cli/repl/commands/repl-clipboard.d.ts +2 -0
  12. package/cli/repl/commands/repl-clipboard.js +5 -0
  13. package/cli/repl/commands/repl-commands.js +2 -2
  14. package/cli/repl/commands/repl-dataflow.js +21 -55
  15. package/cli/repl/commands/repl-normalize.js +15 -28
  16. package/cli/repl/commands/repl-parse.js +2 -2
  17. package/cli/repl/commands/repl-query.js +10 -10
  18. package/cli/repl/commands/repl-signature.js +4 -4
  19. package/cli/repl/server/connection.d.ts +1 -0
  20. package/cli/repl/server/connection.js +8 -30
  21. package/cli/repl/server/messages/message-analysis.js +1 -1
  22. package/config.d.ts +6 -0
  23. package/config.js +7 -4
  24. package/control-flow/cfg-dead-code.js +5 -14
  25. package/control-flow/cfg-to-basic-blocks.js +1 -6
  26. package/control-flow/control-flow-graph.d.ts +2 -16
  27. package/control-flow/control-flow-graph.js +8 -66
  28. package/control-flow/diff-cfg.js +10 -23
  29. package/control-flow/semantic-cfg-guided-visitor.js +5 -11
  30. package/control-flow/simple-visitor.js +2 -2
  31. package/core/steps/pipeline/default-pipelines.d.ts +138 -138
  32. package/data/r-base-packages.generated.js +0 -1
  33. package/data/r-base-primitives.generated.js +0 -1
  34. package/data/r-s3-generics.generated.d.ts +5 -0
  35. package/data/r-s3-generics.generated.js +103 -0
  36. package/dataflow/cluster.js +2 -1
  37. package/dataflow/environments/append.d.ts +1 -0
  38. package/dataflow/environments/built-in-props.d.ts +10 -0
  39. package/dataflow/environments/built-in-props.js +25 -1
  40. package/dataflow/environments/built-in.js +15 -9
  41. package/dataflow/environments/clone.d.ts +1 -0
  42. package/dataflow/environments/clone.js +1 -0
  43. package/dataflow/environments/default-builtin-config.d.ts +188 -14
  44. package/dataflow/environments/default-builtin-config.js +125 -65
  45. package/dataflow/environments/define.d.ts +1 -0
  46. package/dataflow/environments/define.js +1 -0
  47. package/dataflow/environments/environment.d.ts +27 -0
  48. package/dataflow/environments/environment.js +37 -16
  49. package/dataflow/environments/frame-memory.d.ts +9 -1
  50. package/dataflow/environments/frame-memory.js +12 -1
  51. package/dataflow/environments/identifier.d.ts +0 -2
  52. package/dataflow/environments/identifier.js +5 -7
  53. package/dataflow/environments/overwrite.js +1 -0
  54. package/dataflow/environments/query-fn-props.js +2 -3
  55. package/dataflow/environments/scoping.d.ts +3 -0
  56. package/dataflow/environments/scoping.js +3 -0
  57. package/dataflow/eval/resolve/alias-tracking.js +3 -3
  58. package/dataflow/eval/resolve/resolve-argument.d.ts +7 -3
  59. package/dataflow/eval/resolve/resolve-argument.js +16 -11
  60. package/dataflow/eval/resolve/resolve-numbers.js +5 -2
  61. package/dataflow/eval/resolve/resolve-strings.d.ts +1 -1
  62. package/dataflow/eval/resolve/resolve-working-directory.js +2 -2
  63. package/dataflow/eval/resolve/resolve.js +1 -2
  64. package/dataflow/eval/values/intervals/interval-constants.js +1 -6
  65. package/dataflow/eval/values/r-value.js +1 -6
  66. package/dataflow/extractor.js +17 -17
  67. package/dataflow/fn/argument-roles.js +15 -15
  68. package/dataflow/fn/class-declaration.js +7 -7
  69. package/dataflow/fn/frame-reflection.d.ts +1 -23
  70. package/dataflow/fn/frame-reflection.js +8 -95
  71. package/dataflow/fn/function-props.d.ts +0 -3
  72. package/dataflow/fn/function-props.js +9 -11
  73. package/dataflow/fn/function-semantics.d.ts +1 -0
  74. package/dataflow/fn/strict-function.js +15 -14
  75. package/dataflow/graph/call-graph.d.ts +8 -0
  76. package/dataflow/graph/call-graph.js +40 -25
  77. package/dataflow/graph/dataflowgraph-builder.d.ts +0 -60
  78. package/dataflow/graph/dataflowgraph-builder.js +15 -135
  79. package/dataflow/graph/df-helper.d.ts +56 -4
  80. package/dataflow/graph/df-helper.js +116 -1
  81. package/dataflow/graph/diff-dataflow-graph.js +13 -15
  82. package/dataflow/graph/graph-helper.d.ts +20 -0
  83. package/dataflow/graph/graph-helper.js +18 -0
  84. package/dataflow/graph/graph.js +3 -8
  85. package/dataflow/graph/match-args.d.ts +1 -1
  86. package/dataflow/graph/match-args.js +3 -3
  87. package/dataflow/internal/linker.d.ts +4 -10
  88. package/dataflow/internal/linker.js +21 -29
  89. package/dataflow/internal/process/functions/call/built-in/built-in-access.js +2 -8
  90. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.d.ts +5 -2
  91. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +39 -22
  92. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +19 -21
  93. package/dataflow/internal/process/functions/call/built-in/built-in-attach.js +3 -7
  94. package/dataflow/internal/process/functions/call/built-in/built-in-env-contents.js +6 -11
  95. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +6 -8
  96. package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +14 -13
  97. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +27 -13
  98. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +6 -8
  99. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +33 -35
  100. package/dataflow/internal/process/functions/call/built-in/built-in-get.js +3 -5
  101. package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +6 -7
  102. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +12 -5
  103. package/dataflow/internal/process/functions/call/built-in/built-in-list.js +3 -4
  104. package/dataflow/internal/process/functions/call/built-in/built-in-load.js +7 -8
  105. package/dataflow/internal/process/functions/call/built-in/built-in-local.js +5 -6
  106. package/dataflow/internal/process/functions/call/built-in/built-in-new-env.js +3 -4
  107. package/dataflow/internal/process/functions/call/built-in/built-in-pipe.js +2 -3
  108. package/dataflow/internal/process/functions/call/built-in/built-in-purrr-formula.js +5 -7
  109. package/dataflow/internal/process/functions/call/built-in/built-in-quote.js +6 -5
  110. package/dataflow/internal/process/functions/call/built-in/built-in-repeat-loop.js +1 -2
  111. package/dataflow/internal/process/functions/call/built-in/built-in-replacement.js +5 -6
  112. package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +4 -4
  113. package/dataflow/internal/process/functions/call/built-in/built-in-s-four.js +7 -7
  114. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +1 -2
  115. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.js +2 -3
  116. package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +1 -1
  117. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +5 -7
  118. package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.d.ts +1 -1
  119. package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.js +4 -5
  120. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +8 -9
  121. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +4 -5
  122. package/dataflow/internal/process/functions/call/built-in/built-in-with.js +3 -3
  123. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +36 -38
  124. package/dataflow/internal/process/functions/call/common.d.ts +3 -1
  125. package/dataflow/internal/process/functions/call/common.js +6 -7
  126. package/dataflow/internal/process/functions/call/deferred.js +8 -8
  127. package/dataflow/internal/process/functions/call/known-call-handling.d.ts +11 -4
  128. package/dataflow/internal/process/functions/call/known-call-handling.js +11 -7
  129. package/dataflow/internal/process/functions/call/named-call-handling.js +4 -3
  130. package/dataflow/internal/process/functions/call/nse.js +4 -4
  131. package/dataflow/internal/process/functions/call/quoted.js +16 -14
  132. package/dataflow/internal/process/functions/call/unnamed-call-handling.js +2 -2
  133. package/dataflow/internal/process/functions/process-parameter.js +2 -2
  134. package/dataflow/internal/process/process-named-call.js +1 -1
  135. package/dataflow/origin/dfg-get-origin.js +2 -2
  136. package/dataflow/origin/dfg-get-symbol-refs.d.ts +1 -0
  137. package/dataflow/origin/dfg-get-symbol-refs.js +3 -8
  138. package/documentation/data/faq/wiki-faq-store.js +2 -2
  139. package/documentation/doc-capabilities.js +2 -1
  140. package/documentation/doc-util/doc-functions.js +2 -2
  141. package/documentation/doc-util/doc-repl.js +4 -4
  142. package/documentation/doc-util/doc-types.js +2 -2
  143. package/documentation/wiki-absint.js +2 -1
  144. package/documentation/wiki-cfg.js +2 -1
  145. package/documentation/wiki-create-linting-rules.js +1 -1
  146. package/documentation/wiki-dataflow-graph.js +6 -6
  147. package/documentation/wiki-interface.js +3 -2
  148. package/documentation/wiki-linter.js +54 -4
  149. package/documentation/wiki-mk/doc-maker.js +1 -2
  150. package/documentation/wiki-query.js +25 -0
  151. package/documentation/wiki-search.js +2 -1
  152. package/documentation/wiki-signature-database.js +0 -2
  153. package/linter/linter-executor.js +4 -0
  154. package/linter/linter-rules.d.ts +518 -1
  155. package/linter/linter-rules.js +39 -1
  156. package/linter/linter-tags.d.ts +6 -0
  157. package/linter/linter-tags.js +6 -0
  158. package/linter/rules/absolute-path.js +4 -3
  159. package/linter/rules/cmd-check/bogus-return.d.ts +29 -0
  160. package/linter/rules/cmd-check/bogus-return.js +63 -0
  161. package/linter/rules/cmd-check/call-arguments.d.ts +63 -0
  162. package/linter/rules/cmd-check/call-arguments.js +211 -0
  163. package/linter/rules/cmd-check/class-string-comparison.d.ts +48 -0
  164. package/linter/rules/cmd-check/class-string-comparison.js +135 -0
  165. package/linter/rules/cmd-check/cmd-check-util.d.ts +67 -0
  166. package/linter/rules/cmd-check/cmd-check-util.js +169 -0
  167. package/linter/rules/cmd-check/compiled-code.d.ts +86 -0
  168. package/linter/rules/cmd-check/compiled-code.js +350 -0
  169. package/linter/rules/cmd-check/conformance.d.ts +47 -0
  170. package/linter/rules/cmd-check/conformance.js +166 -0
  171. package/linter/rules/cmd-check/dependency-declaration.d.ts +95 -0
  172. package/linter/rules/cmd-check/dependency-declaration.js +299 -0
  173. package/linter/rules/cmd-check/description-metadata.d.ts +63 -0
  174. package/linter/rules/cmd-check/description-metadata.js +393 -0
  175. package/linter/rules/cmd-check/documentation-mismatch.d.ts +54 -0
  176. package/linter/rules/cmd-check/documentation-mismatch.js +407 -0
  177. package/linter/rules/cmd-check/file-checks.d.ts +29 -0
  178. package/linter/rules/cmd-check/file-checks.js +34 -0
  179. package/linter/rules/cmd-check/foreign-function-calls.d.ts +54 -0
  180. package/linter/rules/cmd-check/foreign-function-calls.js +115 -0
  181. package/linter/rules/cmd-check/global-environment-modification.d.ts +61 -0
  182. package/linter/rules/cmd-check/global-environment-modification.js +237 -0
  183. package/linter/rules/cmd-check/namespace-tampering.d.ts +52 -0
  184. package/linter/rules/cmd-check/namespace-tampering.js +162 -0
  185. package/linter/rules/cmd-check/non-ascii-code.d.ts +51 -0
  186. package/linter/rules/cmd-check/non-ascii-code.js +112 -0
  187. package/linter/rules/cmd-check/package-code.d.ts +30 -0
  188. package/linter/rules/cmd-check/package-code.js +141 -0
  189. package/linter/rules/cmd-check/package-data.d.ts +49 -0
  190. package/linter/rules/cmd-check/package-data.js +181 -0
  191. package/linter/rules/cmd-check/package-files.d.ts +41 -0
  192. package/linter/rules/cmd-check/package-files.js +157 -0
  193. package/linter/rules/cmd-check/package-hooks.d.ts +57 -0
  194. package/linter/rules/cmd-check/package-hooks.js +165 -0
  195. package/linter/rules/cmd-check/package-metafiles.d.ts +49 -0
  196. package/linter/rules/cmd-check/package-metafiles.js +292 -0
  197. package/linter/rules/cmd-check/package-runtime.d.ts +67 -0
  198. package/linter/rules/cmd-check/package-runtime.js +284 -0
  199. package/linter/rules/cmd-check/package-structure.d.ts +85 -0
  200. package/linter/rules/cmd-check/package-structure.js +320 -0
  201. package/linter/rules/cmd-check/rd-files.d.ts +67 -0
  202. package/linter/rules/cmd-check/rd-files.js +621 -0
  203. package/linter/rules/cmd-check/s-three-method-consistency.d.ts +72 -0
  204. package/linter/rules/cmd-check/s-three-method-consistency.js +206 -0
  205. package/linter/rules/cmd-check/true-false-abbreviation.d.ts +45 -0
  206. package/linter/rules/cmd-check/true-false-abbreviation.js +121 -0
  207. package/linter/rules/deprecated-functions.js +4 -4
  208. package/linter/rules/naming-convention.d.ts +1 -1
  209. package/linter/rules/naming-convention.js +13 -14
  210. package/linter/rules/no-leaked-credentials.js +4 -4
  211. package/linter/rules/problematic-inputs.js +2 -1
  212. package/linter/rules/seeded-randomness.js +5 -5
  213. package/linter/rules/software-has-license.d.ts +1 -1
  214. package/linter/rules/software-has-license.js +1 -1
  215. package/linter/rules/unclosed-connection.js +3 -3
  216. package/linter/rules/undefined-symbol-util.js +16 -32
  217. package/linter/rules/undefined-symbol.d.ts +2 -0
  218. package/linter/rules/undefined-symbol.js +33 -3
  219. package/linter/rules/unescaped-arguments.js +10 -9
  220. package/linter/rules/unused-definition.js +13 -19
  221. package/package.json +1 -1
  222. package/project/cache/flowr-analyzer-cache.js +1 -1
  223. package/project/context/flowr-analyzer-context.js +1 -1
  224. package/project/context/flowr-analyzer-environment-context.d.ts +1 -1
  225. package/project/context/flowr-analyzer-files-context.d.ts +6 -0
  226. package/project/context/flowr-analyzer-files-context.js +3 -0
  227. package/project/context/flowr-analyzer-incremental-analysis-context.d.ts +0 -2
  228. package/project/context/flowr-analyzer-incremental-analysis-context.js +0 -4
  229. package/project/context/flowr-file.d.ts +4 -0
  230. package/project/context/flowr-file.js +4 -0
  231. package/project/flowr-analyzer-builder.js +1 -1
  232. package/project/plugins/file-plugins/files/flowr-description-file.js +2 -2
  233. package/project/plugins/file-plugins/files/flowr-jupyter-file.d.ts +2 -0
  234. package/project/plugins/file-plugins/files/flowr-jupyter-file.js +4 -0
  235. package/project/plugins/file-plugins/files/flowr-manifest-files.d.ts +2 -0
  236. package/project/plugins/file-plugins/files/flowr-manifest-files.js +11 -14
  237. package/project/plugins/file-plugins/files/flowr-namespace-file.d.ts +3 -0
  238. package/project/plugins/file-plugins/files/flowr-namespace-file.js +25 -15
  239. package/project/plugins/file-plugins/files/flowr-rd-file.d.ts +44 -0
  240. package/project/plugins/file-plugins/files/flowr-rd-file.js +130 -61
  241. package/project/plugins/file-plugins/files/flowr-rda-file.d.ts +0 -1
  242. package/project/plugins/file-plugins/files/flowr-rda-file.js +4 -16
  243. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.d.ts +2 -0
  244. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +4 -0
  245. package/project/plugins/file-plugins/files/flowr-sweave-file.d.ts +2 -0
  246. package/project/plugins/file-plugins/files/flowr-sweave-file.js +4 -0
  247. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-description-file-plugin.d.ts +0 -1
  248. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-description-file-plugin.js +1 -5
  249. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.d.ts +2 -0
  250. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.js +2 -0
  251. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-session-info-plugin.js +3 -7
  252. package/project/sigdb/build.js +16 -30
  253. package/project/sigdb/dict.d.ts +4 -6
  254. package/project/sigdb/dict.js +125 -31
  255. package/project/sigdb/reader.js +2 -18
  256. package/project/sigdb/sigdb-download.js +14 -23
  257. package/queries/base-query-format.d.ts +2 -0
  258. package/queries/base-query-format.js +10 -2
  259. package/queries/catalog/absint-query/absint-query-format.d.ts +1 -1
  260. package/queries/catalog/absint-query/absint-query-format.js +5 -7
  261. package/queries/catalog/call-context-query/call-context-query-executor.js +24 -32
  262. package/queries/catalog/call-context-query/call-context-query-format.d.ts +1 -1
  263. package/queries/catalog/call-context-query/call-context-query-format.js +1 -3
  264. package/queries/catalog/call-context-query/identify-link-to-last-call-relation.js +2 -4
  265. package/queries/catalog/call-context-query/identify-link-to-nested-call-relation.js +1 -4
  266. package/queries/catalog/call-graph-query/call-graph-query-format.js +2 -3
  267. package/queries/catalog/config-query/config-query-format.js +3 -3
  268. package/queries/catalog/dataflow-lens-query/dataflow-lens-query-format.js +2 -3
  269. package/queries/catalog/dataflow-query/dataflow-query-format.js +2 -3
  270. package/queries/catalog/dependencies-query/data-flow.d.ts +43 -0
  271. package/queries/catalog/dependencies-query/data-flow.js +173 -0
  272. package/queries/catalog/dependencies-query/dependencies-query-executor.d.ts +18 -0
  273. package/queries/catalog/dependencies-query/dependencies-query-executor.js +108 -12
  274. package/queries/catalog/dependencies-query/dependencies-query-format.d.ts +17 -1
  275. package/queries/catalog/dependencies-query/dependencies-query-format.js +14 -11
  276. package/queries/catalog/dependencies-query/function-info/derived-functions.js +2 -1
  277. package/queries/catalog/dependencies-query/function-info/function-info.d.ts +2 -0
  278. package/queries/catalog/dependencies-query/function-info/library-functions.js +13 -13
  279. package/queries/catalog/dependencies-query/function-info/read-functions.js +1 -1
  280. package/queries/catalog/dependencies-query/function-info/remote-functions.js +3 -3
  281. package/queries/catalog/dependencies-query/function-info/source-functions.js +2 -2
  282. package/queries/catalog/dependencies-query/function-info/test-functions.js +8 -8
  283. package/queries/catalog/dependencies-query/function-info/transform-functions.d.ts +8 -0
  284. package/queries/catalog/dependencies-query/function-info/transform-functions.js +17 -0
  285. package/queries/catalog/dependencies-query/function-info/write-functions.js +4 -0
  286. package/queries/catalog/dependencies-query/implicit-echo.d.ts +5 -3
  287. package/queries/catalog/dependencies-query/implicit-echo.js +33 -34
  288. package/queries/catalog/dependencies-query/link-devices.d.ts +3 -2
  289. package/queries/catalog/dependencies-query/link-devices.js +9 -6
  290. package/queries/catalog/dependencies-query/plot-description.d.ts +10 -0
  291. package/queries/catalog/dependencies-query/plot-description.js +119 -0
  292. package/queries/catalog/dependencies-query/plot-objects.d.ts +13 -0
  293. package/queries/catalog/dependencies-query/plot-objects.js +61 -0
  294. package/queries/catalog/dice-query/dice-query-format.d.ts +2 -2
  295. package/queries/catalog/dice-query/dice-query-format.js +3 -40
  296. package/queries/catalog/does-call-query/does-call-query-format.d.ts +1 -1
  297. package/queries/catalog/does-call-query/does-call-query-format.js +2 -2
  298. package/queries/catalog/function-info-query/function-info-query-format.js +2 -2
  299. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-executor.js +2 -1
  300. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-format.js +2 -2
  301. package/queries/catalog/happens-before-query/happens-before-query-format.js +2 -2
  302. package/queries/catalog/id-map-query/id-map-query-format.js +1 -3
  303. package/queries/catalog/input-sources-query/input-sources-query-executor.js +2 -2
  304. package/queries/catalog/input-sources-query/input-sources-query-format.js +2 -3
  305. package/queries/catalog/input-sources-query/simple-input-classifier.js +28 -29
  306. package/queries/catalog/inspect-exceptions-query/inspect-exception-query-format.js +4 -7
  307. package/queries/catalog/inspect-fn-props-query/inspect-fn-props-query-executor.js +1 -1
  308. package/queries/catalog/inspect-fn-props-query/inspect-fn-props-query-format.js +3 -2
  309. package/queries/catalog/inspect-recursion-query/inspect-recursion-query-executor.js +2 -2
  310. package/queries/catalog/linter-query/linter-query-executor.js +10 -3
  311. package/queries/catalog/linter-query/linter-query-format.d.ts +4 -1
  312. package/queries/catalog/linter-query/linter-query-format.js +32 -21
  313. package/queries/catalog/location-map-query/location-map-query-format.d.ts +1 -1
  314. package/queries/catalog/location-map-query/location-map-query-format.js +1 -3
  315. package/queries/catalog/normalized-ast-query/normalized-ast-query-format.js +2 -3
  316. package/queries/catalog/origin-query/origin-query-executor.d.ts +1 -1
  317. package/queries/catalog/origin-query/origin-query-executor.js +3 -3
  318. package/queries/catalog/origin-query/origin-query-format.d.ts +1 -1
  319. package/queries/catalog/origin-query/origin-query-format.js +4 -5
  320. package/queries/catalog/project-query/project-query-format.js +2 -2
  321. package/queries/catalog/provenance-query/provenance-query-format.js +2 -3
  322. package/queries/catalog/resolve-value-query/resolve-value-query-format.d.ts +1 -1
  323. package/queries/catalog/resolve-value-query/resolve-value-query-format.js +4 -4
  324. package/queries/catalog/search-query/search-query-format.js +1 -3
  325. package/queries/catalog/signature-query/signature-query-executor.js +3 -3
  326. package/queries/catalog/signature-query/signature-query-format.js +2 -2
  327. package/queries/catalog/slice-query-options.d.ts +16 -0
  328. package/queries/catalog/slice-query-options.js +28 -0
  329. package/queries/catalog/static-slice-query/static-slice-query-format.d.ts +2 -2
  330. package/queries/catalog/static-slice-query/static-slice-query-format.js +3 -42
  331. package/queries/query-print.d.ts +4 -0
  332. package/queries/query-print.js +17 -1
  333. package/queries/query.d.ts +3 -3
  334. package/queries/query.js +3 -4
  335. package/r-bridge/lang-4.x/ast/model/model.d.ts +27 -3
  336. package/r-bridge/lang-4.x/ast/model/model.js +28 -1
  337. package/r-bridge/lang-4.x/ast/model/nodes/info/r-delimiter.d.ts +1 -0
  338. package/r-bridge/lang-4.x/ast/model/nodes/info/r-delimiter.js +1 -0
  339. package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +2 -0
  340. package/r-bridge/lang-4.x/ast/model/nodes/r-access.js +1 -0
  341. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +20 -1
  342. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.js +25 -1
  343. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +2 -0
  344. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.js +1 -0
  345. package/r-bridge/lang-4.x/ast/model/nodes/r-break.d.ts +2 -0
  346. package/r-bridge/lang-4.x/ast/model/nodes/r-break.js +1 -0
  347. package/r-bridge/lang-4.x/ast/model/nodes/r-comment.d.ts +2 -0
  348. package/r-bridge/lang-4.x/ast/model/nodes/r-comment.js +1 -0
  349. package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +2 -0
  350. package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.js +1 -0
  351. package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.d.ts +2 -0
  352. package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.js +1 -0
  353. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +18 -2
  354. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.js +15 -6
  355. package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +2 -0
  356. package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.js +1 -0
  357. package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.d.ts +2 -0
  358. package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.js +1 -0
  359. package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.d.ts +2 -0
  360. package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.js +1 -0
  361. package/r-bridge/lang-4.x/ast/model/nodes/r-logical.d.ts +2 -0
  362. package/r-bridge/lang-4.x/ast/model/nodes/r-logical.js +1 -0
  363. package/r-bridge/lang-4.x/ast/model/nodes/r-next.d.ts +2 -0
  364. package/r-bridge/lang-4.x/ast/model/nodes/r-next.js +1 -0
  365. package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +2 -0
  366. package/r-bridge/lang-4.x/ast/model/nodes/r-number.js +1 -0
  367. package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.d.ts +2 -0
  368. package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.js +1 -0
  369. package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.d.ts +2 -0
  370. package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.js +1 -0
  371. package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.d.ts +2 -0
  372. package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.js +1 -0
  373. package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +17 -0
  374. package/r-bridge/lang-4.x/ast/model/nodes/r-string.js +20 -0
  375. package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.d.ts +2 -0
  376. package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.js +1 -0
  377. package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.d.ts +2 -0
  378. package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.js +1 -0
  379. package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.d.ts +2 -0
  380. package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.js +1 -0
  381. package/r-bridge/lang-4.x/ast/model/operators.js +0 -2
  382. package/r-bridge/lang-4.x/ast/model/processing/decorate.js +1 -6
  383. package/r-bridge/lang-4.x/ast/model/processing/fold.js +1 -6
  384. package/r-bridge/lang-4.x/ast/model/processing/node-id.js +4 -3
  385. package/r-bridge/lang-4.x/ast/parser/json/format.js +2 -2
  386. package/r-bridge/lang-4.x/ast/parser/main/internal/control/normalize-if-then.js +1 -5
  387. package/r-bridge/lang-4.x/ast/parser/main/internal/functions/normalize-argument.js +2 -2
  388. package/r-bridge/lang-4.x/ast/parser/main/internal/functions/normalize-call.js +4 -20
  389. package/r-bridge/lang-4.x/ast/parser/main/internal/functions/normalize-definition.js +1 -5
  390. package/r-bridge/lang-4.x/ast/parser/main/internal/loops/normalize-next.js +1 -5
  391. package/r-bridge/lang-4.x/ast/parser/main/internal/loops/normalize-repeat.js +1 -5
  392. package/r-bridge/lang-4.x/ast/parser/main/internal/loops/normalize-while.js +2 -9
  393. package/r-bridge/lang-4.x/ast/parser/main/internal/normalize-access.js +1 -5
  394. package/r-bridge/lang-4.x/ast/parser/main/internal/operators/normalize-binary.js +2 -10
  395. package/r-bridge/lang-4.x/ast/parser/main/internal/operators/normalize-unary.js +2 -11
  396. package/r-bridge/lang-4.x/ast/parser/main/internal/structure/normalize-expressions.js +3 -11
  397. package/r-bridge/lang-4.x/ast/parser/main/internal/values/normalize-number.js +1 -5
  398. package/r-bridge/lang-4.x/ast/parser/main/internal/values/normalize-string.js +1 -5
  399. package/r-bridge/lang-4.x/ast/parser/main/internal/values/normalize-symbol.js +1 -5
  400. package/r-bridge/lang-4.x/ast/parser/main/normalize-meta.d.ts +6 -1
  401. package/r-bridge/lang-4.x/ast/parser/main/normalize-meta.js +7 -0
  402. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-normalize.d.ts +0 -10
  403. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-normalize.js +30 -82
  404. package/r-bridge/retriever.d.ts +0 -4
  405. package/r-bridge/retriever.js +0 -13
  406. package/r-bridge/roxygen2/documentation-provider.js +3 -7
  407. package/r-bridge/shell.js +3 -8
  408. package/reconstruct/auto-select/magic-comments.js +8 -7
  409. package/reconstruct/inline/source-inline-map.d.ts +3 -0
  410. package/reconstruct/inline/source-inline-map.js +8 -7
  411. package/reconstruct/reconstruct.d.ts +1 -1
  412. package/reconstruct/reconstruct.js +33 -109
  413. package/search/flowr-search-printer.js +4 -15
  414. package/search/search-executor/search-generators.js +1 -1
  415. package/slicing/criterion/filters/all-variables.js +1 -2
  416. package/slicing/static/fingerprint.js +11 -2
  417. package/slicing/static/slice-call.d.ts +2 -8
  418. package/slicing/static/slice-call.js +8 -18
  419. package/slicing/static/static-slicer.js +81 -6
  420. package/util/collections/arrays.js +1 -1
  421. package/util/collections/set.js +1 -1
  422. package/util/diff-graph.d.ts +4 -0
  423. package/util/diff-graph.js +12 -0
  424. package/util/files.js +2 -6
  425. package/util/json.js +1 -15
  426. package/util/mermaid/cfg.js +10 -17
  427. package/util/mermaid/dfg.js +6 -8
  428. package/util/objects.d.ts +1 -1
  429. package/util/quads.js +4 -13
  430. package/util/r-author.js +5 -5
  431. package/util/range.d.ts +9 -0
  432. package/util/range.js +11 -0
  433. package/util/schema.js +3 -3
  434. package/util/simple-df/dfg-view.js +2 -1
  435. package/util/text/ansi.js +1 -2
  436. package/util/text/playground-link.js +2 -1
  437. package/util/text/r-highlight.js +2 -1
  438. package/util/text/strings.d.ts +2 -0
  439. package/util/text/strings.js +5 -0
  440. package/util/text/time.js +1 -2
  441. package/util/version.js +4 -3
  442. package/dataflow/fn/recursive-function.d.ts +0 -6
  443. package/dataflow/fn/recursive-function.js +0 -32
  444. package/dataflow/internal/process/functions/call/argument/unpack-argument.d.ts +0 -16
  445. package/dataflow/internal/process/functions/call/argument/unpack-argument.js +0 -27
@@ -0,0 +1,61 @@
1
+ import { LintingRuleCertainty } from '../../linter-format';
2
+ import type { MergeableRecord } from '../../../util/objects';
3
+ import { LintingRuleTag } from '../../linter-tags';
4
+ import type { ParentInformation } from '../../../r-bridge/lang-4.x/ast/model/processing/decorate';
5
+ import { type CmdCheckResult } from './cmd-check-util';
6
+ /** how the code changes the global environment or the search path */
7
+ export type GlobalEnvironmentModificationKind =
8
+ /** `assign(..., envir = globalenv())` */
9
+ 'assign'
10
+ /** `data(...)` loading into the global environment */
11
+ | 'data'
12
+ /** `attach(...)` */
13
+ | 'attach'
14
+ /** `x <<- v` without a binding of `x` in an enclosing function, which creates (or changes) a global variable */
15
+ | 'global-superassignment'
16
+ /** `x <<- v` targeting a variable of the package namespace, whose binding is locked once the package is loaded */
17
+ | 'locked-superassignment';
18
+ export interface GlobalEnvironmentModificationResult extends CmdCheckResult {
19
+ readonly kind: GlobalEnvironmentModificationKind;
20
+ /** the variable written, if known */
21
+ readonly variable?: string;
22
+ }
23
+ export interface GlobalEnvironmentModificationConfig extends MergeableRecord {
24
+ /** report `<<-` assignments that reach the global environment or a locked namespace binding (default `true`) */
25
+ readonly checkSuperAssignments: boolean;
26
+ /** variables that may be assigned in the global environment (default `.Random.seed`, as `R CMD check` allows) */
27
+ readonly allowedGlobals: readonly string[];
28
+ }
29
+ export interface GlobalEnvironmentModificationMetadata extends MergeableRecord {
30
+ /** calls of `assign`, `data` and `attach` inspected */
31
+ readonly consideredCalls: number;
32
+ }
33
+ /**
34
+ * Port of the `R CMD check` notes on code that changes the global environment
35
+ * (`checking R code for possible problems`): `tools:::.check_package_code_assign_to_globalenv`,
36
+ * `.check_package_code_data_into_globalenv`, `.check_package_code_attach`, and the `codetools` note
37
+ * "no visible binding for `<<-` assignment".
38
+ */
39
+ export declare const GLOBAL_ENVIRONMENT_MODIFICATION: {
40
+ readonly createSearch: () => import("../../../search/flowr-search-builder").FlowrSearchBuilder<"from", [], ParentInformation, import("../../../search/flowr-search").FlowrSearchElements<ParentInformation, import("../../../search/flowr-search").FlowrSearchElement<ParentInformation>[]>>;
41
+ readonly processSearchResult: (_elements: import("../../../search/flowr-search").FlowrSearchElements<ParentInformation, import("../../../search/flowr-search").FlowrSearchElement<ParentInformation>[]>, config: GlobalEnvironmentModificationConfig, data: import("../../..").ReadonlyFlowrAnalysisProvider<import("../../..").KnownParser>) => Promise<{
42
+ results: GlobalEnvironmentModificationResult[];
43
+ '.meta': {
44
+ consideredCalls: number;
45
+ };
46
+ }>;
47
+ readonly prettyPrint: {
48
+ query: (r: GlobalEnvironmentModificationResult) => string;
49
+ full: (r: GlobalEnvironmentModificationResult) => string;
50
+ };
51
+ readonly info: {
52
+ readonly name: "Global Environment Modification";
53
+ readonly tags: readonly [LintingRuleTag.CmdCheck, LintingRuleTag.Bug, LintingRuleTag.Robustness];
54
+ readonly certainty: LintingRuleCertainty.BestEffort;
55
+ readonly description: "Finds code that changes the global environment: `assign()` or `data()` into it, `attach()`, `<<-` without a binding in an enclosing function, and `<<-` to a package variable, whose binding is locked at run time.";
56
+ readonly defaultConfig: () => {
57
+ checkSuperAssignments: true;
58
+ allowedGlobals: string[];
59
+ };
60
+ };
61
+ };
@@ -0,0 +1,237 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GLOBAL_ENVIRONMENT_MODIFICATION = void 0;
4
+ const linter_format_1 = require("../../linter-format");
5
+ const r_symbol_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol");
6
+ const r_number_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-number");
7
+ const r_argument_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
8
+ const r_binary_op_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-binary-op");
9
+ const r_expression_list_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-expression-list");
10
+ const r_string_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-string");
11
+ const flowr_search_builder_1 = require("../../../search/flowr-search-builder");
12
+ const linter_tags_1 = require("../../linter-tags");
13
+ const identifier_1 = require("../../../dataflow/environments/identifier");
14
+ const edge_1 = require("../../../dataflow/graph/edge");
15
+ const function_semantics_1 = require("../../../dataflow/fn/function-semantics");
16
+ const default_builtin_config_1 = require("../../../dataflow/environments/default-builtin-config");
17
+ const built_in_stack_env_1 = require("../../../dataflow/internal/process/functions/call/built-in/built-in-stack-env");
18
+ const node_id_1 = require("../../../r-bridge/lang-4.x/ast/model/processing/node-id");
19
+ const type_1 = require("../../../r-bridge/lang-4.x/ast/model/type");
20
+ const r_function_definition_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-function-definition");
21
+ const r_function_call_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
22
+ const cmd_check_util_1 = require("./cmd-check-util");
23
+ const r_for_loop_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-for-loop");
24
+ const model_1 = require("../../../r-bridge/lang-4.x/ast/model/model");
25
+ /** the calls that may write into an environment they are handed, with the formals naming it */
26
+ const EnvironmentWriters = {
27
+ assign: { x: 'x', value: 'value', pos: 'pos', envir: 'envir', inherits: 'inherits', immediate: 'immediate' },
28
+ data: { '...': '...', list: 'list', package: 'package', 'lib.loc': 'lib.loc', verbose: 'verbose', envir: 'envir', overwrite: 'overwrite' },
29
+ attach: { what: 'what', pos: 'pos', name: 'name', 'warn.conflicts': 'warn.conflicts' }
30
+ };
31
+ const WriterNames = new Set(Object.keys(EnvironmentWriters));
32
+ /** whether `node` denotes the global environment, directly or through variables bound to it */
33
+ function denotesGlobalEnv(node, environment, df, idMap, ctx, depth = 0) {
34
+ if (node === undefined || depth > 8) {
35
+ return false;
36
+ }
37
+ if ((0, built_in_stack_env_1.stackEnvKindOf)(node, { environment }) === default_builtin_config_1.StackEnvKind.Global) {
38
+ return true;
39
+ }
40
+ /* `as.environment(1)`, `as.environment(".GlobalEnv")` */
41
+ if (r_function_call_1.RFunctionCall.isNamed(node, 'as.environment') && node.arguments.length === 1 && node.arguments[0] !== r_function_call_1.EmptyArgument) {
42
+ return denotesGlobalPos(node.arguments[0].value);
43
+ }
44
+ if (!r_symbol_1.RSymbol.is(node)) {
45
+ return false;
46
+ }
47
+ const defs = [...df.graph.edgesFrom(node.info.id)].filter(([t, e]) => edge_1.DfEdge.includesType(e, edge_1.EdgeType.Reads) && !node_id_1.NodeId.isBuiltIn(t)).map(([t]) => t);
48
+ return defs.length > 0 && defs.every(d => {
49
+ const def = idMap.get(d);
50
+ const assignment = def?.info.parent === undefined ? undefined : idMap.get(def.info.parent);
51
+ const value = !r_binary_op_1.RBinaryOp.is(assignment) ? undefined : assignment.lhs === def ? assignment.rhs : assignment.rhs === def ? assignment.lhs : undefined;
52
+ return value !== undefined && denotesGlobalEnv(value, df.graph.getVertex(d)?.environment ?? environment, df, idMap, ctx, depth + 1);
53
+ });
54
+ }
55
+ /** whether a `pos` argument names the global environment, which is the first entry of the search path */
56
+ function denotesGlobalPos(node) {
57
+ return (r_number_1.RNumber.is(node) && node.content.num === 1) || (r_string_1.RString.is(node) && node.content.str === '.GlobalEnv');
58
+ }
59
+ /** the variable an assignment target writes, looking through replacement calls and accesses (`names(x)`, `x$a`, `x[[1]]`) */
60
+ function targetVariable(lhs) {
61
+ switch (lhs.type) {
62
+ case type_1.RType.Symbol:
63
+ return identifier_1.Identifier.getName(lhs.content);
64
+ case type_1.RType.String:
65
+ return lhs.content.str;
66
+ case type_1.RType.Access:
67
+ return targetVariable(lhs.accessed);
68
+ case type_1.RType.FunctionCall:
69
+ return lhs.arguments[0] !== r_function_call_1.EmptyArgument && lhs.arguments[0]?.value !== undefined ? targetVariable(lhs.arguments[0].value) : undefined;
70
+ default:
71
+ return undefined;
72
+ }
73
+ }
74
+ const LocalAssignments = new Set(['<-', '=', '->']);
75
+ /**
76
+ * The names a scope (a function definition or `local` call) binds itself: its parameters, the targets of its plain
77
+ * assignments, its `for` variables, and the literal names it `assign`s; the functions nested in it bind their own.
78
+ */
79
+ function localBindings(scope, memo) {
80
+ const known = memo.get(scope.info.id);
81
+ if (known !== undefined) {
82
+ return known;
83
+ }
84
+ const names = new Set(r_function_definition_1.RFunctionDefinition.is(scope) ? scope.parameters.map(p => identifier_1.Identifier.getName(p.name.content)) : []);
85
+ model_1.RNode.visitAst(r_function_definition_1.RFunctionDefinition.is(scope) ? scope.body : scope, node => {
86
+ if (r_function_definition_1.RFunctionDefinition.is(node)) {
87
+ return true;
88
+ }
89
+ const name = r_binary_op_1.RBinaryOp.is(node) && LocalAssignments.has(node.operator) ? targetVariable(node.operator === '->' ? node.rhs : node.lhs)
90
+ : r_for_loop_1.RForLoop.is(node) ? identifier_1.Identifier.getName(node.variable.content)
91
+ : r_function_call_1.RFunctionCall.isNamed(node, 'assign') && node.arguments[0] !== r_function_call_1.EmptyArgument && r_string_1.RString.is(node.arguments[0]?.value) ? node.arguments[0].value.content.str
92
+ : undefined;
93
+ if (name !== undefined) {
94
+ names.add(name);
95
+ }
96
+ return false;
97
+ });
98
+ memo.set(scope.info.id, names);
99
+ return names;
100
+ }
101
+ /** whether the call is one of `local(...)`, which evaluates its argument in a fresh environment */
102
+ function isLocalCall(node) {
103
+ return r_function_call_1.RFunctionCall.isNamed(node, 'local');
104
+ }
105
+ /** the package hooks R runs before it locks the namespace, so a `<<-` in them may still set a package variable */
106
+ const BeforeLocking = new Set(['.onLoad']);
107
+ /** what a `<<-` in a package function writes: a binding of an enclosing scope, the package namespace, or the global environment */
108
+ function superAssignmentTarget(op, name, idMap, topLevel, memo) {
109
+ let first = true;
110
+ let outermost;
111
+ for (let cur = op.info.parent === undefined ? undefined : idMap.get(op.info.parent); cur !== undefined; cur = cur.info.parent === undefined ? undefined : idMap.get(cur.info.parent)) {
112
+ if (!r_function_definition_1.RFunctionDefinition.is(cur) && !isLocalCall(cur)) {
113
+ continue;
114
+ }
115
+ /* `<<-` starts its search in the parent of the frame it is evaluated in */
116
+ if (first && r_function_definition_1.RFunctionDefinition.is(cur)) {
117
+ first = false;
118
+ outermost = cur;
119
+ continue;
120
+ }
121
+ first = false;
122
+ outermost = r_function_definition_1.RFunctionDefinition.is(cur) ? cur : outermost;
123
+ if (localBindings(cur, memo).has(name)) {
124
+ return 'enclosing';
125
+ }
126
+ }
127
+ /* code outside of any function (`local({...})` included) runs as the package is installed, before anything is locked */
128
+ if (outermost === undefined || BeforeLocking.has((0, cmd_check_util_1.boundName)(outermost, idMap) ?? '')) {
129
+ return 'top-level';
130
+ }
131
+ return topLevel.has(name) ? 'namespace' : 'global';
132
+ }
133
+ /** the names the top level of the package code binds */
134
+ function topLevelBindings(ast, isPackageCode) {
135
+ const names = new Set();
136
+ const idMap = ast.idMap;
137
+ for (const node of (0, cmd_check_util_1.projectNodes)(ast)) {
138
+ if (!r_binary_op_1.RBinaryOp.is(node) || !LocalAssignments.has(node.operator) || !isPackageCode(node.info.file)) {
139
+ continue;
140
+ }
141
+ const parent = node.info.parent === undefined ? undefined : idMap.get(node.info.parent);
142
+ if (parent === undefined || (r_expression_list_1.RExpressionList.is(parent) && parent.info.parent === undefined)) {
143
+ const name = targetVariable(node.operator === '->' ? node.rhs : node.lhs);
144
+ if (name !== undefined) {
145
+ names.add(name);
146
+ }
147
+ }
148
+ }
149
+ return names;
150
+ }
151
+ /**
152
+ * Port of the `R CMD check` notes on code that changes the global environment
153
+ * (`checking R code for possible problems`): `tools:::.check_package_code_assign_to_globalenv`,
154
+ * `.check_package_code_data_into_globalenv`, `.check_package_code_attach`, and the `codetools` note
155
+ * "no visible binding for `<<-` assignment".
156
+ */
157
+ exports.GLOBAL_ENVIRONMENT_MODIFICATION = {
158
+ createSearch: () => flowr_search_builder_1.Q.from([]),
159
+ processSearchResult: async (_elements, config, data) => {
160
+ const df = await data.dataflow();
161
+ const ast = await data.normalize();
162
+ const idMap = ast.idMap;
163
+ const ctx = data.inspectContext();
164
+ const pkg = (0, cmd_check_util_1.packageInfo)(ctx);
165
+ const allowed = new Set(config.allowedGlobals);
166
+ const results = [];
167
+ let consideredCalls = 0;
168
+ const add = (node, kind, message, variable) => results.push({ ...(0, cmd_check_util_1.at)(node), kind, ...(variable !== undefined ? { variable } : {}), message });
169
+ for (const { name, node, vertex: call } of (0, cmd_check_util_1.packageCalls)(df.graph, idMap, pkg, WriterNames, true)) {
170
+ consideredCalls++;
171
+ const args = function_semantics_1.FunctionSemantics.call.match.toSpec(call.args, EnvironmentWriters[name]);
172
+ const arg = (formal) => {
173
+ const ids = args.get(formal);
174
+ return ids?.length === 1 ? idMap.get(ids[0]) : undefined;
175
+ };
176
+ const env = call.environment ?? df.environment;
177
+ const valueOf = (n) => r_argument_1.RArgument.is(n) ? n.value : n;
178
+ switch (name) {
179
+ case 'attach':
180
+ add(node, 'attach', 'attach() puts an object on the search path, where it masks and is masked by others; access it directly or use with() instead');
181
+ break;
182
+ case 'assign': {
183
+ const target = valueOf(arg('x'));
184
+ const variable = r_string_1.RString.is(target) ? target.content.str : undefined;
185
+ if (variable !== undefined && allowed.has(variable)) {
186
+ break;
187
+ }
188
+ if (denotesGlobalEnv(valueOf(arg('envir')), env, df, idMap, ctx) || denotesGlobalPos(valueOf(arg('pos'))) || denotesGlobalEnv(valueOf(arg('pos')), env, df, idMap, ctx)) {
189
+ add(node, 'assign', `assign() writes ${variable === undefined ? 'a variable' : `'${variable}'`} into the global environment, which belongs to the user`, variable);
190
+ }
191
+ break;
192
+ }
193
+ case 'data': {
194
+ const loads = (args.get('...')?.length ?? 0) > 0 || args.has('list');
195
+ const envir = valueOf(arg('envir'));
196
+ if (loads && (args.get('envir') === undefined || denotesGlobalEnv(envir, env, df, idMap, ctx))) {
197
+ add(node, 'data', 'data() loads into the global environment, use data(..., envir = environment()) or lazy data instead');
198
+ }
199
+ break;
200
+ }
201
+ }
202
+ }
203
+ if (config.checkSuperAssignments) {
204
+ const topLevel = topLevelBindings(ast, pkg.isPackageCode);
205
+ const scopes = new Map();
206
+ for (const node of (0, cmd_check_util_1.projectNodes)(ast)) {
207
+ if (!r_binary_op_1.RBinaryOp.is(node) || (node.operator !== '<<-' && node.operator !== '->>') || !pkg.isPackageCode(node.info.file)) {
208
+ continue;
209
+ }
210
+ const variable = targetVariable(node.operator === '->>' ? node.rhs : node.lhs);
211
+ if (variable === undefined || allowed.has(variable)) {
212
+ continue;
213
+ }
214
+ const target = superAssignmentTarget(node, variable, idMap, topLevel, scopes);
215
+ if (target === 'global') {
216
+ add(node, 'global-superassignment', `no visible binding for '<<-' assignment to '${variable}', which hence creates a variable in the global environment`, variable);
217
+ }
218
+ else if (target === 'namespace') {
219
+ add(node, 'locked-superassignment', `'<<-' assignment to the package variable '${variable}', whose binding is locked once the package is loaded (use an environment to keep state instead)`, variable);
220
+ }
221
+ }
222
+ }
223
+ return { results, '.meta': { consideredCalls } };
224
+ },
225
+ prettyPrint: (0, cmd_check_util_1.printer)(r => `${r.kind}${r.variable ? ` of ${r.variable}` : ''}`),
226
+ info: {
227
+ name: 'Global Environment Modification',
228
+ tags: [linter_tags_1.LintingRuleTag.CmdCheck, linter_tags_1.LintingRuleTag.Bug, linter_tags_1.LintingRuleTag.Robustness],
229
+ certainty: linter_format_1.LintingRuleCertainty.BestEffort,
230
+ description: 'Finds code that changes the global environment: `assign()` or `data()` into it, `attach()`, `<<-` without a binding in an enclosing function, and `<<-` to a package variable, whose binding is locked at run time.',
231
+ defaultConfig: () => ({
232
+ checkSuperAssignments: true,
233
+ allowedGlobals: ['.Random.seed']
234
+ })
235
+ }
236
+ };
237
+ //# sourceMappingURL=global-environment-modification.js.map
@@ -0,0 +1,52 @@
1
+ import { LintingRuleCertainty } from '../../linter-format';
2
+ import type { MergeableRecord } from '../../../util/objects';
3
+ import { LintingRuleTag } from '../../linter-tags';
4
+ import type { ParentInformation } from '../../../r-bridge/lang-4.x/ast/model/processing/decorate';
5
+ import { type CmdCheckResult } from './cmd-check-util';
6
+ export type NamespaceTamperingKind =
7
+ /** `unlockBinding` of a binding in another namespace */
8
+ 'unlock-binding'
9
+ /** `assignInNamespace` into another namespace */
10
+ | 'assign-in-namespace'
11
+ /** a call of R's internals through `.Internal` */
12
+ | 'internal'
13
+ /** `library.dynam` naming the file extension of the shared object */
14
+ | 'shared-object-extension';
15
+ export interface NamespaceTamperingResult extends CmdCheckResult {
16
+ readonly kind: NamespaceTamperingKind;
17
+ /** the namespace tampered with, if known */
18
+ readonly namespace?: string;
19
+ /** for `.Internal`, the internal function called */
20
+ readonly internal?: string;
21
+ }
22
+ export interface NamespaceTamperingConfig extends MergeableRecord {
23
+ /** report `.Internal` calls (default `true`) */
24
+ readonly checkInternal: boolean;
25
+ }
26
+ export type NamespaceTamperingMetadata = MergeableRecord;
27
+ /**
28
+ * Port of the `R CMD check` notes on calls that tamper with R or other packages
29
+ * (`checking R code for possible problems`): `tools:::.check_package_code_tampers`
30
+ * ("Found the following possibly unsafe calls"), `.check_dotInternal` ("Found .Internal call(s)"),
31
+ * and `.check_package_code_shlib`.
32
+ */
33
+ export declare const NAMESPACE_TAMPERING: {
34
+ readonly createSearch: () => import("../../../search/flowr-search-builder").FlowrSearchBuilder<"from", [], ParentInformation, import("../../../search/flowr-search").FlowrSearchElements<ParentInformation, import("../../../search/flowr-search").FlowrSearchElement<ParentInformation>[]>>;
35
+ readonly processSearchResult: (_elements: import("../../../search/flowr-search").FlowrSearchElements<ParentInformation, import("../../../search/flowr-search").FlowrSearchElement<ParentInformation>[]>, config: NamespaceTamperingConfig, data: import("../../..").ReadonlyFlowrAnalysisProvider<import("../../..").KnownParser>) => Promise<{
36
+ results: NamespaceTamperingResult[];
37
+ '.meta': {};
38
+ }>;
39
+ readonly prettyPrint: {
40
+ query: (r: NamespaceTamperingResult) => string;
41
+ full: (r: NamespaceTamperingResult) => string;
42
+ };
43
+ readonly info: {
44
+ readonly name: "Namespace Tampering";
45
+ readonly tags: readonly [LintingRuleTag.CmdCheck, LintingRuleTag.Robustness, LintingRuleTag.Security];
46
+ readonly certainty: LintingRuleCertainty.BestEffort;
47
+ readonly description: "Finds `unlockBinding()` and `assignInNamespace()` on other namespaces, `.Internal()` calls, and `library.dynam()` given a file extension.";
48
+ readonly defaultConfig: () => {
49
+ checkInternal: true;
50
+ };
51
+ };
52
+ };
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NAMESPACE_TAMPERING = void 0;
4
+ const linter_format_1 = require("../../linter-format");
5
+ const r_symbol_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol");
6
+ const r_binary_op_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-binary-op");
7
+ const edge_1 = require("../../../dataflow/graph/edge");
8
+ const df_helper_1 = require("../../../dataflow/graph/df-helper");
9
+ const r_argument_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
10
+ const flowr_search_builder_1 = require("../../../search/flowr-search-builder");
11
+ const linter_tags_1 = require("../../linter-tags");
12
+ const identifier_1 = require("../../../dataflow/environments/identifier");
13
+ const function_semantics_1 = require("../../../dataflow/fn/function-semantics");
14
+ const node_value_1 = require("../../../dataflow/eval/resolve/node-value");
15
+ const resolve_helper_1 = require("../../../dataflow/environments/resolve-helper");
16
+ const r_function_call_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
17
+ const cmd_check_util_1 = require("./cmd-check-util");
18
+ /** the calls this rule is about, which spares resolving every other call */
19
+ const TamperingCalls = new Set(['unlockBinding', 'assignInNamespace', '.Internal', 'library.dynam', 'library.dynam.unload']);
20
+ /** the calls that name a namespace by the package name they are handed */
21
+ const NamespaceGetters = new Set(['asNamespace', 'getNamespace', 'loadNamespace']);
22
+ /** the package a namespace argument names, `'own'` for the package's own one, `undefined` if unknown */
23
+ function namespaceOf(node, info, own, depth = 0) {
24
+ if (node === undefined) {
25
+ return undefined;
26
+ }
27
+ if (r_argument_1.RArgument.is(node)) {
28
+ return namespaceOf(node.value, info, own, depth);
29
+ }
30
+ let name;
31
+ if (r_function_call_1.RFunctionCall.isNamed(node)) {
32
+ const fn = identifier_1.Identifier.getName(node.functionName.content);
33
+ if (fn === 'topenv' || fn === 'environment') {
34
+ return 'own';
35
+ }
36
+ if (!NamespaceGetters.has(fn) || node.arguments.length < 1 || node.arguments[0] === r_function_call_1.EmptyArgument) {
37
+ return undefined;
38
+ }
39
+ name = node_value_1.NodeValue.singleStringOf(node.arguments[0].value?.info.id, info);
40
+ }
41
+ else {
42
+ /* `assignInNamespace` also takes the package name itself */
43
+ name = node_value_1.NodeValue.singleStringOf(node.info.id, info);
44
+ if (name === undefined && r_symbol_1.RSymbol.is(node)) {
45
+ return namespaceOfVariable(node, info, own, depth);
46
+ }
47
+ }
48
+ return name === undefined ? undefined : name === own ? 'own' : name;
49
+ }
50
+ /** the namespace a variable is bound to, if every definition reaching it binds the same one (`ns <- asNamespace("x")`) */
51
+ function namespaceOfVariable(node, info, own, depth) {
52
+ const graph = info.graph;
53
+ const idMap = graph?.idMap;
54
+ if (graph === undefined || idMap === undefined || depth > 8) {
55
+ return undefined;
56
+ }
57
+ const answers = new Set();
58
+ for (const def of df_helper_1.Dataflow.targetsOf(graph, node.info.id, edge_1.EdgeType.Reads)) {
59
+ const target = idMap.get(def);
60
+ const assignment = target?.info.parent === undefined ? undefined : idMap.get(target.info.parent);
61
+ const value = r_binary_op_1.RBinaryOp.is(assignment) ? (assignment.lhs === target ? assignment.rhs : assignment.rhs === target ? assignment.lhs : undefined) : undefined;
62
+ answers.add(value === undefined ? undefined : namespaceOf(value, info, own, depth + 1));
63
+ }
64
+ return answers.size === 1 ? [...answers][0] : undefined;
65
+ }
66
+ /** whether the call is the one a `.Internal` call is handed, which is reported with the `.Internal` */
67
+ function isInternalArgument(node, idMap) {
68
+ const arg = node.info.parent === undefined ? undefined : idMap.get(node.info.parent);
69
+ const call = arg?.info.parent === undefined ? undefined : idMap.get(arg.info.parent);
70
+ return r_function_call_1.RFunctionCall.isNamed(call, '.Internal');
71
+ }
72
+ /**
73
+ * Port of the `R CMD check` notes on calls that tamper with R or other packages
74
+ * (`checking R code for possible problems`): `tools:::.check_package_code_tampers`
75
+ * ("Found the following possibly unsafe calls"), `.check_dotInternal` ("Found .Internal call(s)"),
76
+ * and `.check_package_code_shlib`.
77
+ */
78
+ exports.NAMESPACE_TAMPERING = {
79
+ createSearch: () => flowr_search_builder_1.Q.from([]),
80
+ processSearchResult: async (_elements, config, data) => {
81
+ const df = await data.dataflow();
82
+ const idMap = (await data.normalize()).idMap;
83
+ const ctx = data.inspectContext();
84
+ const pkg = (0, cmd_check_util_1.packageInfo)(ctx);
85
+ const info = resolve_helper_1.Resolve.info(df.graph, ctx);
86
+ const results = [];
87
+ const add = (node, result, certain = true) => results.push({ ...(0, cmd_check_util_1.at)(node, certain), ...result });
88
+ for (const { name, node, vertex: call } of (0, cmd_check_util_1.packageCalls)(df.graph, idMap, pkg, TamperingCalls, true)) {
89
+ const arg = (formals, formal) => {
90
+ const ids = function_semantics_1.FunctionSemantics.call.match.toSpec(call.args, formals).get(formal);
91
+ return ids?.length === 1 ? idMap.get(ids[0]) : undefined;
92
+ };
93
+ switch (name) {
94
+ case 'unlockBinding': {
95
+ if (isInternalArgument(node, idMap)) {
96
+ break;
97
+ }
98
+ const ns = namespaceOf(arg({ sym: 'sym', env: 'env' }, 'env'), info, pkg.name);
99
+ if (ns !== 'own') {
100
+ add(node, {
101
+ kind: 'unlock-binding',
102
+ ...(ns !== undefined ? { namespace: ns } : {}),
103
+ message: `unlockBinding() ${ns === undefined ? 'of a binding outside of the package' : `in the namespace of '${ns}'`} changes code the package does not own`
104
+ }, ns !== undefined);
105
+ }
106
+ break;
107
+ }
108
+ case 'assignInNamespace': {
109
+ const ns = namespaceOf(arg({ x: 'x', value: 'value', ns: 'ns', pos: 'pos', envir: 'envir' }, 'ns'), info, pkg.name);
110
+ if (ns !== 'own') {
111
+ add(node, {
112
+ kind: 'assign-in-namespace',
113
+ ...(ns !== undefined ? { namespace: ns } : {}),
114
+ message: `assignInNamespace() ${ns === undefined ? 'into a namespace outside of the package' : `into the namespace of '${ns}'`} changes code the package does not own`
115
+ }, ns !== undefined);
116
+ }
117
+ break;
118
+ }
119
+ case '.Internal': {
120
+ if (!config.checkInternal) {
121
+ break;
122
+ }
123
+ const inner = r_function_call_1.RFunctionCall.is(node) && node.arguments[0] !== r_function_call_1.EmptyArgument ? node.arguments[0]?.value : undefined;
124
+ const internal = r_function_call_1.RFunctionCall.isNamed(inner) ? identifier_1.Identifier.getName(inner.functionName.content) : undefined;
125
+ add(node, {
126
+ kind: internal === 'unlockBinding' ? 'unlock-binding' : 'internal',
127
+ ...(internal !== undefined ? { internal } : {}),
128
+ message: internal === 'unlockBinding'
129
+ ? '.Internal(unlockBinding()) circumvents the protection of locked bindings'
130
+ : `.Internal(${internal ?? ''}) calls R's internals, which are not part of R's API and may change without notice`
131
+ });
132
+ break;
133
+ }
134
+ case 'library.dynam':
135
+ case 'library.dynam.unload': {
136
+ const chname = arg({ chname: 'chname', package: 'package', 'lib.loc': 'lib.loc' }, 'chname');
137
+ const value = r_argument_1.RArgument.is(chname) ? chname.value : chname;
138
+ const str = value === undefined ? undefined : node_value_1.NodeValue.singleStringOf(value.info.id, info);
139
+ if (str !== undefined && /\.(so|sl|dll)$/.test(str)) {
140
+ add(node, {
141
+ kind: 'shared-object-extension',
142
+ message: `${name}() is handed '${str}', but expects the name of the shared object without its platform-specific extension`
143
+ });
144
+ }
145
+ break;
146
+ }
147
+ }
148
+ }
149
+ return { results, '.meta': {} };
150
+ },
151
+ prettyPrint: (0, cmd_check_util_1.printer)(r => `${r.kind}${r.namespace ? ` of ${r.namespace}` : ''}`),
152
+ info: {
153
+ name: 'Namespace Tampering',
154
+ tags: [linter_tags_1.LintingRuleTag.CmdCheck, linter_tags_1.LintingRuleTag.Robustness, linter_tags_1.LintingRuleTag.Security],
155
+ certainty: linter_format_1.LintingRuleCertainty.BestEffort,
156
+ description: 'Finds `unlockBinding()` and `assignInNamespace()` on other namespaces, `.Internal()` calls, and `library.dynam()` given a file extension.',
157
+ defaultConfig: () => ({
158
+ checkInternal: true
159
+ })
160
+ }
161
+ };
162
+ //# sourceMappingURL=namespace-tampering.js.map
@@ -0,0 +1,51 @@
1
+ import { LintingRuleCertainty } from '../../linter-format';
2
+ import type { MergeableRecord } from '../../../util/objects';
3
+ import { LintingRuleTag } from '../../linter-tags';
4
+ import type { ParentInformation } from '../../../r-bridge/lang-4.x/ast/model/processing/decorate';
5
+ import { type CmdCheckResult } from './cmd-check-util';
6
+ export interface NonAsciiCodeResult extends CmdCheckResult {
7
+ /** whether a string literal, a symbol (identifier, function or parameter name), or a line of the NAMESPACE file holds the characters */
8
+ readonly kind: 'string' | 'symbol' | 'namespace';
9
+ /** the distinct non-ASCII characters the token contains */
10
+ readonly characters: readonly string[];
11
+ }
12
+ export interface NonAsciiCodeConfig extends MergeableRecord {
13
+ /** report string literals holding non-ASCII characters (default `true`, as `R CMD check` does) */
14
+ readonly checkStrings: boolean;
15
+ /** report symbols holding non-ASCII characters (default `true`, as `R CMD check` does) */
16
+ readonly checkSymbols: boolean;
17
+ }
18
+ export interface NonAsciiCodeMetadata extends MergeableRecord {
19
+ /** string literals and symbols inspected */
20
+ readonly consideredTokens: number;
21
+ }
22
+ /**
23
+ * Port of the `R CMD check` note "Found the following file with non-ASCII characters", from the check
24
+ * "checking code files for non-ASCII characters". Portable packages must use only ASCII in their R code outside
25
+ * of comments. Unlike the check, which only names the file, each offending string literal and symbol is reported
26
+ * with its characters. Comments and roxygen documentation are ignored, and so is code outside the R folder.
27
+ * The NAMESPACE file is inspected line by line, outside of comments, as `R CMD check` does.
28
+ */
29
+ export declare const NON_ASCII_CODE: {
30
+ readonly createSearch: () => import("../../../search/flowr-search-builder").FlowrSearchBuilder<"all", ["filter"], ParentInformation, Promise<import("../../../search/flowr-search").FlowrSearchElements<ParentInformation, [] | import("../../../search/flowr-search").FlowrSearchElement<ParentInformation>[]>>>;
31
+ readonly processSearchResult: (elements: import("../../../search/flowr-search").FlowrSearchElements<ParentInformation, import("../../../search/flowr-search").FlowrSearchElement<ParentInformation>[]>, config: NonAsciiCodeConfig, data: import("../../..").ReadonlyFlowrAnalysisProvider<import("../../..").KnownParser>) => {
32
+ results: NonAsciiCodeResult[];
33
+ '.meta': {
34
+ consideredTokens: number;
35
+ };
36
+ };
37
+ readonly prettyPrint: {
38
+ query: (r: NonAsciiCodeResult) => string;
39
+ full: (r: NonAsciiCodeResult) => string;
40
+ };
41
+ readonly info: {
42
+ readonly name: "Non-ASCII Code";
43
+ readonly tags: readonly [LintingRuleTag.CmdCheck, LintingRuleTag.QuickFix];
44
+ readonly certainty: LintingRuleCertainty.BestEffort;
45
+ readonly description: "Finds non-ASCII characters in R code and the NAMESPACE outside of comments. Offers `\\u` escapes for strings as a quick fix.";
46
+ readonly defaultConfig: () => {
47
+ checkStrings: true;
48
+ checkSymbols: true;
49
+ };
50
+ };
51
+ };