@eagleoutice/flowr 2.16.1 → 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 (459) 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 +15 -2
  39. package/dataflow/environments/built-in-props.js +31 -4
  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 +385 -25
  44. package/dataflow/environments/default-builtin-config.js +186 -106
  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 +1 -2
  52. package/dataflow/environments/identifier.js +5 -7
  53. package/dataflow/environments/overwrite.js +1 -0
  54. package/dataflow/environments/query-fn-props.d.ts +3 -0
  55. package/dataflow/environments/query-fn-props.js +7 -0
  56. package/dataflow/environments/resolve-by-name.js +11 -4
  57. package/dataflow/environments/scoping.d.ts +3 -0
  58. package/dataflow/environments/scoping.js +3 -0
  59. package/dataflow/eval/resolve/alias-tracking.js +3 -3
  60. package/dataflow/eval/resolve/resolve-argument.d.ts +7 -3
  61. package/dataflow/eval/resolve/resolve-argument.js +21 -12
  62. package/dataflow/eval/resolve/resolve-numbers.js +5 -2
  63. package/dataflow/eval/resolve/resolve-strings.d.ts +1 -1
  64. package/dataflow/eval/resolve/resolve-working-directory.js +2 -2
  65. package/dataflow/eval/resolve/resolve.js +1 -2
  66. package/dataflow/eval/values/intervals/interval-constants.js +1 -6
  67. package/dataflow/eval/values/r-value.js +1 -6
  68. package/dataflow/extractor.js +17 -17
  69. package/dataflow/fn/argument-roles.js +15 -15
  70. package/dataflow/fn/class-declaration.js +7 -7
  71. package/dataflow/fn/frame-reflection.d.ts +1 -23
  72. package/dataflow/fn/frame-reflection.js +8 -95
  73. package/dataflow/fn/function-props.d.ts +0 -3
  74. package/dataflow/fn/function-props.js +9 -11
  75. package/dataflow/fn/function-semantics.d.ts +1 -0
  76. package/dataflow/fn/strict-function.js +15 -14
  77. package/dataflow/graph/call-graph.d.ts +8 -0
  78. package/dataflow/graph/call-graph.js +40 -25
  79. package/dataflow/graph/dataflowgraph-builder.d.ts +0 -60
  80. package/dataflow/graph/dataflowgraph-builder.js +15 -135
  81. package/dataflow/graph/df-helper.d.ts +56 -4
  82. package/dataflow/graph/df-helper.js +116 -1
  83. package/dataflow/graph/diff-dataflow-graph.js +13 -15
  84. package/dataflow/graph/graph-helper.d.ts +20 -0
  85. package/dataflow/graph/graph-helper.js +18 -0
  86. package/dataflow/graph/graph.js +15 -8
  87. package/dataflow/graph/match-args.d.ts +1 -1
  88. package/dataflow/graph/match-args.js +3 -3
  89. package/dataflow/internal/linker.d.ts +4 -10
  90. package/dataflow/internal/linker.js +21 -29
  91. package/dataflow/internal/process/functions/call/built-in/built-in-access.js +2 -8
  92. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.d.ts +5 -2
  93. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +39 -22
  94. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +19 -21
  95. package/dataflow/internal/process/functions/call/built-in/built-in-attach.js +3 -7
  96. package/dataflow/internal/process/functions/call/built-in/built-in-env-contents.js +6 -11
  97. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +6 -8
  98. package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +14 -13
  99. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +27 -13
  100. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +6 -8
  101. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +33 -35
  102. package/dataflow/internal/process/functions/call/built-in/built-in-get.js +3 -5
  103. package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +6 -7
  104. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +12 -5
  105. package/dataflow/internal/process/functions/call/built-in/built-in-list.js +3 -4
  106. package/dataflow/internal/process/functions/call/built-in/built-in-load.js +7 -8
  107. package/dataflow/internal/process/functions/call/built-in/built-in-local.js +5 -6
  108. package/dataflow/internal/process/functions/call/built-in/built-in-new-env.js +3 -4
  109. package/dataflow/internal/process/functions/call/built-in/built-in-pipe.js +2 -3
  110. package/dataflow/internal/process/functions/call/built-in/built-in-purrr-formula.js +14 -7
  111. package/dataflow/internal/process/functions/call/built-in/built-in-quote.js +6 -5
  112. package/dataflow/internal/process/functions/call/built-in/built-in-repeat-loop.js +1 -2
  113. package/dataflow/internal/process/functions/call/built-in/built-in-replacement.js +5 -6
  114. package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +4 -4
  115. package/dataflow/internal/process/functions/call/built-in/built-in-s-four.js +7 -7
  116. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +1 -2
  117. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.js +2 -3
  118. package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +1 -1
  119. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +5 -7
  120. package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.d.ts +1 -1
  121. package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.js +4 -5
  122. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +8 -9
  123. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +4 -5
  124. package/dataflow/internal/process/functions/call/built-in/built-in-with.js +3 -3
  125. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +36 -38
  126. package/dataflow/internal/process/functions/call/common.d.ts +3 -1
  127. package/dataflow/internal/process/functions/call/common.js +6 -7
  128. package/dataflow/internal/process/functions/call/deferred.js +8 -8
  129. package/dataflow/internal/process/functions/call/known-call-handling.d.ts +11 -4
  130. package/dataflow/internal/process/functions/call/known-call-handling.js +11 -7
  131. package/dataflow/internal/process/functions/call/named-call-handling.js +64 -11
  132. package/dataflow/internal/process/functions/call/nse.js +4 -4
  133. package/dataflow/internal/process/functions/call/quoted.js +16 -14
  134. package/dataflow/internal/process/functions/call/unnamed-call-handling.js +2 -2
  135. package/dataflow/internal/process/functions/process-parameter.js +2 -2
  136. package/dataflow/internal/process/process-named-call.js +1 -1
  137. package/dataflow/origin/dfg-get-origin.js +2 -2
  138. package/dataflow/origin/dfg-get-symbol-refs.d.ts +1 -0
  139. package/dataflow/origin/dfg-get-symbol-refs.js +3 -8
  140. package/documentation/data/faq/wiki-faq-store.js +2 -2
  141. package/documentation/doc-capabilities.js +2 -1
  142. package/documentation/doc-util/doc-functions.js +2 -2
  143. package/documentation/doc-util/doc-repl.js +4 -4
  144. package/documentation/doc-util/doc-types.js +2 -2
  145. package/documentation/wiki-absint.js +2 -1
  146. package/documentation/wiki-cfg.js +2 -1
  147. package/documentation/wiki-create-linting-rules.js +1 -1
  148. package/documentation/wiki-dataflow-graph.js +6 -6
  149. package/documentation/wiki-interface.js +3 -2
  150. package/documentation/wiki-linter.js +54 -4
  151. package/documentation/wiki-mk/doc-maker.js +1 -2
  152. package/documentation/wiki-query.js +25 -0
  153. package/documentation/wiki-search.js +2 -1
  154. package/documentation/wiki-signature-database.js +0 -2
  155. package/linter/linter-executor.js +4 -0
  156. package/linter/linter-rules.d.ts +526 -4
  157. package/linter/linter-rules.js +39 -1
  158. package/linter/linter-tags.d.ts +6 -0
  159. package/linter/linter-tags.js +6 -0
  160. package/linter/rules/absolute-path.js +4 -3
  161. package/linter/rules/cmd-check/bogus-return.d.ts +29 -0
  162. package/linter/rules/cmd-check/bogus-return.js +63 -0
  163. package/linter/rules/cmd-check/call-arguments.d.ts +63 -0
  164. package/linter/rules/cmd-check/call-arguments.js +211 -0
  165. package/linter/rules/cmd-check/class-string-comparison.d.ts +48 -0
  166. package/linter/rules/cmd-check/class-string-comparison.js +135 -0
  167. package/linter/rules/cmd-check/cmd-check-util.d.ts +67 -0
  168. package/linter/rules/cmd-check/cmd-check-util.js +169 -0
  169. package/linter/rules/cmd-check/compiled-code.d.ts +86 -0
  170. package/linter/rules/cmd-check/compiled-code.js +350 -0
  171. package/linter/rules/cmd-check/conformance.d.ts +47 -0
  172. package/linter/rules/cmd-check/conformance.js +166 -0
  173. package/linter/rules/cmd-check/dependency-declaration.d.ts +95 -0
  174. package/linter/rules/cmd-check/dependency-declaration.js +299 -0
  175. package/linter/rules/cmd-check/description-metadata.d.ts +63 -0
  176. package/linter/rules/cmd-check/description-metadata.js +393 -0
  177. package/linter/rules/cmd-check/documentation-mismatch.d.ts +54 -0
  178. package/linter/rules/cmd-check/documentation-mismatch.js +407 -0
  179. package/linter/rules/cmd-check/file-checks.d.ts +29 -0
  180. package/linter/rules/cmd-check/file-checks.js +34 -0
  181. package/linter/rules/cmd-check/foreign-function-calls.d.ts +54 -0
  182. package/linter/rules/cmd-check/foreign-function-calls.js +115 -0
  183. package/linter/rules/cmd-check/global-environment-modification.d.ts +61 -0
  184. package/linter/rules/cmd-check/global-environment-modification.js +237 -0
  185. package/linter/rules/cmd-check/namespace-tampering.d.ts +52 -0
  186. package/linter/rules/cmd-check/namespace-tampering.js +162 -0
  187. package/linter/rules/cmd-check/non-ascii-code.d.ts +51 -0
  188. package/linter/rules/cmd-check/non-ascii-code.js +112 -0
  189. package/linter/rules/cmd-check/package-code.d.ts +30 -0
  190. package/linter/rules/cmd-check/package-code.js +141 -0
  191. package/linter/rules/cmd-check/package-data.d.ts +49 -0
  192. package/linter/rules/cmd-check/package-data.js +181 -0
  193. package/linter/rules/cmd-check/package-files.d.ts +41 -0
  194. package/linter/rules/cmd-check/package-files.js +157 -0
  195. package/linter/rules/cmd-check/package-hooks.d.ts +57 -0
  196. package/linter/rules/cmd-check/package-hooks.js +165 -0
  197. package/linter/rules/cmd-check/package-metafiles.d.ts +49 -0
  198. package/linter/rules/cmd-check/package-metafiles.js +292 -0
  199. package/linter/rules/cmd-check/package-runtime.d.ts +67 -0
  200. package/linter/rules/cmd-check/package-runtime.js +284 -0
  201. package/linter/rules/cmd-check/package-structure.d.ts +85 -0
  202. package/linter/rules/cmd-check/package-structure.js +320 -0
  203. package/linter/rules/cmd-check/rd-files.d.ts +67 -0
  204. package/linter/rules/cmd-check/rd-files.js +621 -0
  205. package/linter/rules/cmd-check/s-three-method-consistency.d.ts +72 -0
  206. package/linter/rules/cmd-check/s-three-method-consistency.js +206 -0
  207. package/linter/rules/cmd-check/true-false-abbreviation.d.ts +45 -0
  208. package/linter/rules/cmd-check/true-false-abbreviation.js +121 -0
  209. package/linter/rules/deprecated-functions.js +4 -4
  210. package/linter/rules/function-finder-util.d.ts +1 -1
  211. package/linter/rules/function-finder-util.js +1 -3
  212. package/linter/rules/naming-convention.d.ts +1 -1
  213. package/linter/rules/naming-convention.js +13 -14
  214. package/linter/rules/network-functions.d.ts +4 -3
  215. package/linter/rules/network-functions.js +14 -12
  216. package/linter/rules/no-leaked-credentials.d.ts +8 -3
  217. package/linter/rules/no-leaked-credentials.js +134 -36
  218. package/linter/rules/problematic-inputs.d.ts +1 -1
  219. package/linter/rules/problematic-inputs.js +21 -14
  220. package/linter/rules/seeded-randomness.js +5 -5
  221. package/linter/rules/software-has-license.d.ts +1 -1
  222. package/linter/rules/software-has-license.js +1 -1
  223. package/linter/rules/unclosed-connection.js +3 -3
  224. package/linter/rules/undefined-symbol-util.js +16 -32
  225. package/linter/rules/undefined-symbol.d.ts +2 -0
  226. package/linter/rules/undefined-symbol.js +33 -3
  227. package/linter/rules/unescaped-arguments.d.ts +13 -2
  228. package/linter/rules/unescaped-arguments.js +104 -15
  229. package/linter/rules/unused-definition.js +13 -19
  230. package/package.json +1 -1
  231. package/project/cache/flowr-analyzer-cache.js +1 -1
  232. package/project/context/flowr-analyzer-context.js +1 -1
  233. package/project/context/flowr-analyzer-environment-context.d.ts +1 -1
  234. package/project/context/flowr-analyzer-files-context.d.ts +6 -0
  235. package/project/context/flowr-analyzer-files-context.js +3 -0
  236. package/project/context/flowr-analyzer-incremental-analysis-context.d.ts +0 -2
  237. package/project/context/flowr-analyzer-incremental-analysis-context.js +0 -4
  238. package/project/context/flowr-file.d.ts +4 -0
  239. package/project/context/flowr-file.js +4 -0
  240. package/project/flowr-analyzer-builder.js +1 -1
  241. package/project/plugins/file-plugins/files/flowr-description-file.js +2 -2
  242. package/project/plugins/file-plugins/files/flowr-jupyter-file.d.ts +2 -0
  243. package/project/plugins/file-plugins/files/flowr-jupyter-file.js +4 -0
  244. package/project/plugins/file-plugins/files/flowr-manifest-files.d.ts +2 -0
  245. package/project/plugins/file-plugins/files/flowr-manifest-files.js +11 -14
  246. package/project/plugins/file-plugins/files/flowr-namespace-file.d.ts +3 -0
  247. package/project/plugins/file-plugins/files/flowr-namespace-file.js +25 -15
  248. package/project/plugins/file-plugins/files/flowr-rd-file.d.ts +44 -0
  249. package/project/plugins/file-plugins/files/flowr-rd-file.js +130 -61
  250. package/project/plugins/file-plugins/files/flowr-rda-file.d.ts +0 -1
  251. package/project/plugins/file-plugins/files/flowr-rda-file.js +4 -16
  252. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.d.ts +2 -0
  253. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +4 -0
  254. package/project/plugins/file-plugins/files/flowr-sweave-file.d.ts +2 -0
  255. package/project/plugins/file-plugins/files/flowr-sweave-file.js +4 -0
  256. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-description-file-plugin.d.ts +0 -1
  257. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-description-file-plugin.js +1 -5
  258. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.d.ts +2 -0
  259. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.js +2 -0
  260. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-session-info-plugin.js +3 -7
  261. package/project/sigdb/build.js +16 -30
  262. package/project/sigdb/dict.d.ts +4 -6
  263. package/project/sigdb/dict.js +125 -31
  264. package/project/sigdb/reader.js +2 -18
  265. package/project/sigdb/sigdb-download.js +14 -23
  266. package/queries/base-query-format.d.ts +2 -0
  267. package/queries/base-query-format.js +10 -2
  268. package/queries/catalog/absint-query/absint-query-format.d.ts +1 -1
  269. package/queries/catalog/absint-query/absint-query-format.js +5 -7
  270. package/queries/catalog/call-context-query/call-context-query-executor.js +26 -33
  271. package/queries/catalog/call-context-query/call-context-query-format.d.ts +1 -1
  272. package/queries/catalog/call-context-query/call-context-query-format.js +1 -3
  273. package/queries/catalog/call-context-query/identify-link-to-last-call-relation.js +2 -4
  274. package/queries/catalog/call-context-query/identify-link-to-nested-call-relation.js +1 -4
  275. package/queries/catalog/call-graph-query/call-graph-query-format.js +2 -3
  276. package/queries/catalog/config-query/config-query-format.js +3 -3
  277. package/queries/catalog/dataflow-lens-query/dataflow-lens-query-format.js +2 -3
  278. package/queries/catalog/dataflow-query/dataflow-query-format.js +2 -3
  279. package/queries/catalog/dependencies-query/data-flow.d.ts +43 -0
  280. package/queries/catalog/dependencies-query/data-flow.js +173 -0
  281. package/queries/catalog/dependencies-query/dependencies-query-executor.d.ts +18 -0
  282. package/queries/catalog/dependencies-query/dependencies-query-executor.js +108 -12
  283. package/queries/catalog/dependencies-query/dependencies-query-format.d.ts +17 -1
  284. package/queries/catalog/dependencies-query/dependencies-query-format.js +14 -11
  285. package/queries/catalog/dependencies-query/function-info/derived-functions.js +2 -1
  286. package/queries/catalog/dependencies-query/function-info/function-info.d.ts +2 -0
  287. package/queries/catalog/dependencies-query/function-info/library-functions.js +13 -13
  288. package/queries/catalog/dependencies-query/function-info/read-functions.js +1 -1
  289. package/queries/catalog/dependencies-query/function-info/remote-functions.js +3 -3
  290. package/queries/catalog/dependencies-query/function-info/source-functions.js +2 -2
  291. package/queries/catalog/dependencies-query/function-info/test-functions.js +8 -8
  292. package/queries/catalog/dependencies-query/function-info/transform-functions.d.ts +8 -0
  293. package/queries/catalog/dependencies-query/function-info/transform-functions.js +17 -0
  294. package/queries/catalog/dependencies-query/function-info/write-functions.js +4 -0
  295. package/queries/catalog/dependencies-query/implicit-echo.d.ts +5 -3
  296. package/queries/catalog/dependencies-query/implicit-echo.js +33 -34
  297. package/queries/catalog/dependencies-query/link-devices.d.ts +3 -2
  298. package/queries/catalog/dependencies-query/link-devices.js +9 -6
  299. package/queries/catalog/dependencies-query/plot-description.d.ts +10 -0
  300. package/queries/catalog/dependencies-query/plot-description.js +119 -0
  301. package/queries/catalog/dependencies-query/plot-objects.d.ts +13 -0
  302. package/queries/catalog/dependencies-query/plot-objects.js +61 -0
  303. package/queries/catalog/dice-query/dice-query-format.d.ts +2 -2
  304. package/queries/catalog/dice-query/dice-query-format.js +3 -40
  305. package/queries/catalog/does-call-query/does-call-query-format.d.ts +1 -1
  306. package/queries/catalog/does-call-query/does-call-query-format.js +2 -2
  307. package/queries/catalog/function-info-query/function-info-query-format.js +2 -2
  308. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-executor.js +2 -1
  309. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-format.js +2 -2
  310. package/queries/catalog/happens-before-query/happens-before-query-format.js +2 -2
  311. package/queries/catalog/id-map-query/id-map-query-format.js +1 -3
  312. package/queries/catalog/input-sources-query/input-source-functions.d.ts +6 -4
  313. package/queries/catalog/input-sources-query/input-source-functions.js +11 -6
  314. package/queries/catalog/input-sources-query/input-sources-query-executor.js +3 -3
  315. package/queries/catalog/input-sources-query/input-sources-query-format.d.ts +1 -1
  316. package/queries/catalog/input-sources-query/input-sources-query-format.js +11 -5
  317. package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +12 -4
  318. package/queries/catalog/input-sources-query/simple-input-classifier.js +237 -40
  319. package/queries/catalog/inspect-exceptions-query/inspect-exception-query-format.js +4 -7
  320. package/queries/catalog/inspect-fn-props-query/inspect-fn-props-query-executor.js +1 -1
  321. package/queries/catalog/inspect-fn-props-query/inspect-fn-props-query-format.js +3 -2
  322. package/queries/catalog/inspect-recursion-query/inspect-recursion-query-executor.js +2 -2
  323. package/queries/catalog/linter-query/linter-query-executor.js +10 -3
  324. package/queries/catalog/linter-query/linter-query-format.d.ts +4 -1
  325. package/queries/catalog/linter-query/linter-query-format.js +32 -21
  326. package/queries/catalog/location-map-query/location-map-query-format.d.ts +1 -1
  327. package/queries/catalog/location-map-query/location-map-query-format.js +1 -3
  328. package/queries/catalog/normalized-ast-query/normalized-ast-query-format.js +2 -3
  329. package/queries/catalog/origin-query/origin-query-executor.d.ts +1 -1
  330. package/queries/catalog/origin-query/origin-query-executor.js +3 -3
  331. package/queries/catalog/origin-query/origin-query-format.d.ts +1 -1
  332. package/queries/catalog/origin-query/origin-query-format.js +4 -5
  333. package/queries/catalog/project-query/project-query-format.js +2 -2
  334. package/queries/catalog/provenance-query/provenance-query-format.js +2 -3
  335. package/queries/catalog/resolve-value-query/resolve-value-query-format.d.ts +1 -1
  336. package/queries/catalog/resolve-value-query/resolve-value-query-format.js +4 -4
  337. package/queries/catalog/search-query/search-query-format.js +1 -3
  338. package/queries/catalog/signature-query/signature-query-executor.js +3 -3
  339. package/queries/catalog/signature-query/signature-query-format.js +2 -2
  340. package/queries/catalog/slice-query-options.d.ts +16 -0
  341. package/queries/catalog/slice-query-options.js +28 -0
  342. package/queries/catalog/static-slice-query/static-slice-query-format.d.ts +2 -2
  343. package/queries/catalog/static-slice-query/static-slice-query-format.js +3 -42
  344. package/queries/query-print.d.ts +4 -0
  345. package/queries/query-print.js +17 -1
  346. package/queries/query.d.ts +3 -3
  347. package/queries/query.js +3 -4
  348. package/r-bridge/lang-4.x/ast/model/model.d.ts +27 -3
  349. package/r-bridge/lang-4.x/ast/model/model.js +28 -1
  350. package/r-bridge/lang-4.x/ast/model/nodes/info/r-delimiter.d.ts +1 -0
  351. package/r-bridge/lang-4.x/ast/model/nodes/info/r-delimiter.js +1 -0
  352. package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +2 -0
  353. package/r-bridge/lang-4.x/ast/model/nodes/r-access.js +1 -0
  354. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +20 -1
  355. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.js +25 -1
  356. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +2 -0
  357. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.js +1 -0
  358. package/r-bridge/lang-4.x/ast/model/nodes/r-break.d.ts +2 -0
  359. package/r-bridge/lang-4.x/ast/model/nodes/r-break.js +1 -0
  360. package/r-bridge/lang-4.x/ast/model/nodes/r-comment.d.ts +2 -0
  361. package/r-bridge/lang-4.x/ast/model/nodes/r-comment.js +1 -0
  362. package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +2 -0
  363. package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.js +1 -0
  364. package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.d.ts +2 -0
  365. package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.js +1 -0
  366. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +18 -2
  367. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.js +15 -6
  368. package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +2 -0
  369. package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.js +1 -0
  370. package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.d.ts +2 -0
  371. package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.js +1 -0
  372. package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.d.ts +2 -0
  373. package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.js +1 -0
  374. package/r-bridge/lang-4.x/ast/model/nodes/r-logical.d.ts +2 -0
  375. package/r-bridge/lang-4.x/ast/model/nodes/r-logical.js +1 -0
  376. package/r-bridge/lang-4.x/ast/model/nodes/r-next.d.ts +2 -0
  377. package/r-bridge/lang-4.x/ast/model/nodes/r-next.js +1 -0
  378. package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +2 -0
  379. package/r-bridge/lang-4.x/ast/model/nodes/r-number.js +1 -0
  380. package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.d.ts +2 -0
  381. package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.js +1 -0
  382. package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.d.ts +2 -0
  383. package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.js +1 -0
  384. package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.d.ts +2 -0
  385. package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.js +1 -0
  386. package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +17 -0
  387. package/r-bridge/lang-4.x/ast/model/nodes/r-string.js +20 -0
  388. package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.d.ts +2 -0
  389. package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.js +1 -0
  390. package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.d.ts +2 -0
  391. package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.js +1 -0
  392. package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.d.ts +2 -0
  393. package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.js +1 -0
  394. package/r-bridge/lang-4.x/ast/model/operators.js +0 -2
  395. package/r-bridge/lang-4.x/ast/model/processing/decorate.js +1 -6
  396. package/r-bridge/lang-4.x/ast/model/processing/fold.js +1 -6
  397. package/r-bridge/lang-4.x/ast/model/processing/node-id.js +4 -3
  398. package/r-bridge/lang-4.x/ast/parser/json/format.js +2 -2
  399. package/r-bridge/lang-4.x/ast/parser/main/internal/control/normalize-if-then.js +1 -5
  400. package/r-bridge/lang-4.x/ast/parser/main/internal/functions/normalize-argument.js +2 -2
  401. package/r-bridge/lang-4.x/ast/parser/main/internal/functions/normalize-call.js +4 -20
  402. package/r-bridge/lang-4.x/ast/parser/main/internal/functions/normalize-definition.js +1 -5
  403. package/r-bridge/lang-4.x/ast/parser/main/internal/loops/normalize-next.js +1 -5
  404. package/r-bridge/lang-4.x/ast/parser/main/internal/loops/normalize-repeat.js +1 -5
  405. package/r-bridge/lang-4.x/ast/parser/main/internal/loops/normalize-while.js +2 -9
  406. package/r-bridge/lang-4.x/ast/parser/main/internal/normalize-access.js +1 -5
  407. package/r-bridge/lang-4.x/ast/parser/main/internal/operators/normalize-binary.js +2 -10
  408. package/r-bridge/lang-4.x/ast/parser/main/internal/operators/normalize-unary.js +2 -11
  409. package/r-bridge/lang-4.x/ast/parser/main/internal/structure/normalize-expressions.js +3 -11
  410. package/r-bridge/lang-4.x/ast/parser/main/internal/values/normalize-number.js +1 -5
  411. package/r-bridge/lang-4.x/ast/parser/main/internal/values/normalize-string.js +1 -5
  412. package/r-bridge/lang-4.x/ast/parser/main/internal/values/normalize-symbol.js +1 -5
  413. package/r-bridge/lang-4.x/ast/parser/main/normalize-meta.d.ts +6 -1
  414. package/r-bridge/lang-4.x/ast/parser/main/normalize-meta.js +7 -0
  415. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-normalize.d.ts +0 -10
  416. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-normalize.js +30 -82
  417. package/r-bridge/retriever.d.ts +0 -4
  418. package/r-bridge/retriever.js +0 -13
  419. package/r-bridge/roxygen2/documentation-provider.js +3 -7
  420. package/r-bridge/shell.js +3 -8
  421. package/reconstruct/auto-select/magic-comments.js +8 -7
  422. package/reconstruct/inline/source-inline-map.d.ts +3 -0
  423. package/reconstruct/inline/source-inline-map.js +8 -7
  424. package/reconstruct/reconstruct.d.ts +1 -1
  425. package/reconstruct/reconstruct.js +33 -109
  426. package/search/flowr-search-printer.js +4 -15
  427. package/search/search-executor/search-enrichers.js +5 -3
  428. package/search/search-executor/search-generators.js +1 -1
  429. package/slicing/criterion/filters/all-variables.js +1 -2
  430. package/slicing/static/fingerprint.js +11 -2
  431. package/slicing/static/slice-call.d.ts +2 -8
  432. package/slicing/static/slice-call.js +8 -18
  433. package/slicing/static/static-slicer.js +81 -6
  434. package/util/collections/arrays.js +1 -1
  435. package/util/collections/set.js +1 -1
  436. package/util/diff-graph.d.ts +4 -0
  437. package/util/diff-graph.js +12 -0
  438. package/util/files.js +2 -6
  439. package/util/json.js +1 -15
  440. package/util/mermaid/cfg.js +10 -17
  441. package/util/mermaid/dfg.js +6 -8
  442. package/util/objects.d.ts +1 -1
  443. package/util/quads.js +4 -13
  444. package/util/r-author.js +5 -5
  445. package/util/range.d.ts +9 -0
  446. package/util/range.js +11 -0
  447. package/util/schema.js +3 -3
  448. package/util/simple-df/dfg-view.js +2 -1
  449. package/util/text/ansi.js +1 -2
  450. package/util/text/playground-link.js +2 -1
  451. package/util/text/r-highlight.js +2 -1
  452. package/util/text/strings.d.ts +2 -0
  453. package/util/text/strings.js +5 -0
  454. package/util/text/time.js +1 -2
  455. package/util/version.js +4 -3
  456. package/dataflow/fn/recursive-function.d.ts +0 -6
  457. package/dataflow/fn/recursive-function.js +0 -32
  458. package/dataflow/internal/process/functions/call/argument/unpack-argument.d.ts +0 -16
  459. package/dataflow/internal/process/functions/call/argument/unpack-argument.js +0 -27
@@ -0,0 +1,157 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.rootDescriptionFile = rootDescriptionFile;
7
+ exports.packageFiles = packageFiles;
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const path_1 = __importDefault(require("path"));
10
+ const flowr_file_1 = require("../../../project/context/flowr-file");
11
+ const range_1 = require("../../../util/range");
12
+ const files_1 = require("../../../util/files");
13
+ /** the version-control directories `R CMD build` drops (`tools:::.vc_dir_names`) */
14
+ const VcDirectories = new Set(['CVS', '.svn', '.arch-ids', '.bzr', '.git', '.hg', '_darcs', '.metadata']);
15
+ /** the hidden files `R CMD build` drops (`tools:::.hidden_file_exclusions`) */
16
+ const HiddenFileExclusions = new Set([
17
+ '.Renviron', '.Rprofile', '.Rproj.user', '.Rhistory', '.Rapp.history', '.tex', '.log', '.aux', '.pdf', '.png', '.backups',
18
+ '.cvsignore', '.cproject', '.directory', '.dropbox', '.exrc', '.gdb.history', '.gitattributes', '.gitignore', '.gitmodules',
19
+ '.hgignore', '.hgtags', '.htaccess', '.latex2html-init', '.project', '.seed', '.settings', '.tm_properties'
20
+ ]);
21
+ /** the patterns `R CMD build` always excludes (`tools:::get_exclude_patterns()`) */
22
+ const DefaultExcludePatterns = [
23
+ '^\\.Rbuildignore$', '(^|/)\\.DS_Store$', '^\\.(RData|Rhistory)$', '~$', '\\.bak$', '\\.sw.$', '(^|/)\\.#[^/]*$', '(^|/)#[^/]*#$',
24
+ '^TITLE$', '^data/00Index$', '^inst/doc/00Index\\.dcf$', '^config\\.(cache|log|status)$', '(^|/)autom4te\\.cache$', '^src/.*\\.d$',
25
+ '^src/Makedeps$', '^src/so_locations$', '^inst/doc/Rplots\\.(ps|pdf)$', '^(GPATH|GRTAGS|GTAGS)$'
26
+ ];
27
+ /**
28
+ * The DESCRIPTION of the analyzed package: the one closest to the project root, as packages vendored into it or
29
+ * test fixtures shipped with it (`src/library/x/DESCRIPTION`, `tests/testthat/fixtures/p/DESCRIPTION`) have their own.
30
+ */
31
+ function rootDescriptionFile(ctx) {
32
+ const descriptions = ctx.files.getFilesByRole(flowr_file_1.FileRole.Description);
33
+ return descriptions.length < 2 ? descriptions[0]
34
+ : descriptions.toSorted((a, b) => a.path().split(/[\\/]/).length - b.path().split(/[\\/]/).length || a.path().localeCompare(b.path()))[0];
35
+ }
36
+ /** do not walk deeper or wider than this, a package is no file system */
37
+ const MaxEntries = 50_000;
38
+ /** the `.Rbuildignore` patterns plus the defaults, compiled; a pattern that is no valid regular expression is skipped */
39
+ function excludePatterns(rbuildignore) {
40
+ const lines = [...DefaultExcludePatterns, ...(rbuildignore?.split(/\r?\n/) ?? [])].filter(l => l.trim() !== '');
41
+ const result = [];
42
+ for (const line of lines) {
43
+ try {
44
+ result.push(new RegExp(line, 'i'));
45
+ }
46
+ catch {
47
+ /* R would fail on it as well, but that is not this listing's finding to make */
48
+ }
49
+ }
50
+ return result;
51
+ }
52
+ /** whether `R CMD build` drops the entry (and, for a directory, everything below it) */
53
+ function isExcludedByBuild(relative, isDirectory, pkgName, patterns) {
54
+ const base = path_1.default.posix.basename(relative);
55
+ if (isDirectory && (VcDirectories.has(base) || base === 'check' || base === 'chm' || /([Oo]ld|\.Rcheck)$/.test(base) || /^src.*\/[.]deps$/.test(relative))) {
56
+ return true;
57
+ }
58
+ if (base === 'Read-and-delete-me' || base === 'GNUMakefile' || base.startsWith('._') || HiddenFileExclusions.has(base) || /^\.Rbuildindex[.]/.test(relative)) {
59
+ return true;
60
+ }
61
+ if (relative.endsWith('inst/doc/.Rinstignore') || relative.endsWith('inst/doc/.build.timestamp') || relative.endsWith('vignettes/.Rinstignore')) {
62
+ return true;
63
+ }
64
+ if (pkgName !== undefined && (relative === `src/${pkgName}_res.rc` || new RegExp(`^${pkgName.replace(/\./g, '\\.')}_[0-9.-]+\\.(tar\\.gz|tar|tar\\.bz2|tar\\.xz|tgz|zip)$`).test(relative))) {
65
+ return true;
66
+ }
67
+ return patterns.some(p => p.test(relative));
68
+ }
69
+ /**
70
+ * The files and directories of the analyzed package as `R CMD check` sees them, i.e. after `R CMD build` dropped
71
+ * what `.Rbuildignore` and its defaults exclude. When the package lives on disk, the whole folder is listed;
72
+ * otherwise (e.g. files only handed to flowR in memory) the files flowR knows below the package root are used.
73
+ * `undefined` without a DESCRIPTION.
74
+ */
75
+ function packageFiles(ctx, pkgName) {
76
+ const desc = rootDescriptionFile(ctx);
77
+ if (desc === undefined) {
78
+ return undefined;
79
+ }
80
+ const root = path_1.default.dirname(desc.path());
81
+ const known = new Map(ctx.files.getAllFiles().map(f => [files_1.RPath.normalize(f.path()), f]));
82
+ const readKnownOrDisk = (absolute) => {
83
+ const file = known.get(files_1.RPath.normalize(absolute));
84
+ try {
85
+ if (file !== undefined) {
86
+ return file.rawText?.() ?? file.content().toString();
87
+ }
88
+ return fs_1.default.existsSync(absolute) && fs_1.default.statSync(absolute).isFile() ? fs_1.default.readFileSync(absolute, 'utf-8') : undefined;
89
+ }
90
+ catch {
91
+ return undefined;
92
+ }
93
+ };
94
+ const patterns = excludePatterns(readKnownOrDisk(path_1.default.join(root, '.Rbuildignore')));
95
+ const toRelative = (absolute) => path_1.default.relative(root, absolute).split(path_1.default.sep).join('/');
96
+ const entries = [];
97
+ const onDisk = fs_1.default.existsSync(path_1.default.join(root, 'DESCRIPTION'));
98
+ if (onDisk) {
99
+ const stack = [root];
100
+ for (let dir = stack.pop(); dir !== undefined && entries.length < MaxEntries; dir = stack.pop()) {
101
+ let names;
102
+ try {
103
+ names = fs_1.default.readdirSync(dir);
104
+ }
105
+ catch {
106
+ continue;
107
+ }
108
+ for (const name of names) {
109
+ const absolute = path_1.default.join(dir, name);
110
+ let stats;
111
+ try {
112
+ stats = fs_1.default.lstatSync(absolute);
113
+ }
114
+ catch {
115
+ continue;
116
+ }
117
+ const relative = toRelative(absolute);
118
+ const isDirectory = stats.isDirectory();
119
+ if (isExcludedByBuild(relative, isDirectory, pkgName, patterns)) {
120
+ continue;
121
+ }
122
+ entries.push({ relative, absolute, isDirectory, stats });
123
+ if (isDirectory) {
124
+ stack.push(absolute);
125
+ }
126
+ }
127
+ }
128
+ }
129
+ else {
130
+ const dirs = new Set();
131
+ for (const absolute of known.keys()) {
132
+ const relative = toRelative(absolute);
133
+ if (relative.startsWith('..') || path_1.default.isAbsolute(relative) || isExcludedByBuild(relative, false, pkgName, patterns)) {
134
+ continue;
135
+ }
136
+ entries.push({ relative, absolute, isDirectory: false });
137
+ for (let d = path_1.default.posix.dirname(relative); d !== '.' && !dirs.has(d); d = path_1.default.posix.dirname(d)) {
138
+ dirs.add(d);
139
+ }
140
+ }
141
+ for (const d of dirs) {
142
+ entries.push({ relative: d, absolute: path_1.default.join(root, d), isDirectory: true });
143
+ }
144
+ }
145
+ entries.sort((a, b) => a.relative.localeCompare(b.relative));
146
+ return {
147
+ root,
148
+ entries,
149
+ onDisk,
150
+ read: relative => readKnownOrDisk(path_1.default.join(root, relative)),
151
+ locate: (relative, line, endLine) => {
152
+ const absolute = path_1.default.join(root, relative);
153
+ return range_1.SourceLocation.from([line ?? 1, 1, endLine ?? line ?? 1, 1], known.get(files_1.RPath.normalize(absolute))?.path() ?? absolute);
154
+ }
155
+ };
156
+ }
157
+ //# sourceMappingURL=package-files.js.map
@@ -0,0 +1,57 @@
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
+ /** what is wrong with a package hook */
7
+ export type PackageHookIssue = 'arguments' | 'search-path' | 'output' | 'unsafe-call' | 'misplaced-call' | 'obsolete' | 'unexported';
8
+ export interface PackageHooksResult extends CmdCheckResult {
9
+ /** the hook, e.g. `.onLoad` */
10
+ readonly hook: string;
11
+ readonly issue: PackageHookIssue;
12
+ /** the offending function called, if the issue is a call */
13
+ readonly call?: string;
14
+ }
15
+ export interface PackageHooksConfig extends MergeableRecord {
16
+ /** functions that print startup messages the way R wants them to, which are only allowed in `.onAttach` */
17
+ readonly startupMessageFunctions: readonly string[];
18
+ /** functions that may emit output in a startup hook nonetheless, as the user can silence them otherwise (default `warning`) */
19
+ readonly allowedOutput: readonly string[];
20
+ /** functions too costly or unsafe to call in a startup hook (default `installed.packages`) */
21
+ readonly unsafeCalls: readonly string[];
22
+ /** also report what the hook does through functions of the package it calls, which `R CMD check` does not see (default `true`) */
23
+ readonly followCalls: boolean;
24
+ }
25
+ export interface PackageHooksMetadata extends MergeableRecord {
26
+ /** the hooks the package defines */
27
+ readonly hooks: readonly string[];
28
+ }
29
+ /**
30
+ * Port of the `R CMD check` notes on package hooks (`checking R code for possible problems`, from
31
+ * `tools:::.check_package_code_startup_functions` and `tools:::.check_package_code_unload_functions`).
32
+ */
33
+ export declare const PACKAGE_HOOKS: {
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: PackageHooksConfig, data: import("../../..").ReadonlyFlowrAnalysisProvider<import("../../..").KnownParser>) => Promise<{
36
+ results: PackageHooksResult[];
37
+ '.meta': {
38
+ hooks: string[];
39
+ };
40
+ }>;
41
+ readonly prettyPrint: {
42
+ query: (r: PackageHooksResult) => string;
43
+ full: (r: PackageHooksResult) => string;
44
+ };
45
+ readonly info: {
46
+ readonly name: "Package Hooks";
47
+ readonly tags: readonly [LintingRuleTag.CmdCheck, LintingRuleTag.Bug, LintingRuleTag.Usability];
48
+ readonly certainty: LintingRuleCertainty.BestEffort;
49
+ readonly description: "Checks `.onLoad`, `.onAttach`, `.onDetach`, and `.Last.lib`: argument lists, attaching packages, output other than `packageStartupMessage()`, `installed.packages()`, misplaced `library.dynam()` calls, and the obsolete `.First.lib`. Follows calls into the package's own functions.";
50
+ readonly defaultConfig: () => {
51
+ startupMessageFunctions: string[];
52
+ allowedOutput: string[];
53
+ unsafeCalls: string[];
54
+ followCalls: true;
55
+ };
56
+ };
57
+ };
@@ -0,0 +1,165 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PACKAGE_HOOKS = void 0;
4
+ const linter_format_1 = require("../../linter-format");
5
+ const flowr_search_builder_1 = require("../../../search/flowr-search-builder");
6
+ const linter_tags_1 = require("../../linter-tags");
7
+ const range_1 = require("../../../util/range");
8
+ const identifier_1 = require("../../../dataflow/environments/identifier");
9
+ const vertex_1 = require("../../../dataflow/graph/vertex");
10
+ const query_fn_props_1 = require("../../../dataflow/environments/query-fn-props");
11
+ const built_in_props_1 = require("../../../dataflow/environments/built-in-props");
12
+ const r_function_definition_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-function-definition");
13
+ const r_function_call_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
14
+ const r_if_then_else_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-if-then-else");
15
+ const r_while_loop_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-while-loop");
16
+ const r_for_loop_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-for-loop");
17
+ const r_repeat_loop_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop");
18
+ const model_1 = require("../../../r-bridge/lang-4.x/ast/model/model");
19
+ const function_semantics_1 = require("../../../dataflow/fn/function-semantics");
20
+ const flowr_namespace_file_1 = require("../../../project/plugins/file-plugins/files/flowr-namespace-file");
21
+ const cmd_check_util_1 = require("./cmd-check-util");
22
+ /** the hooks R calls as the package is loaded or attached */
23
+ const StartupHooks = new Set(['.onLoad', '.onAttach', '.First.lib']);
24
+ /** the hooks R calls as the package is detached */
25
+ const DetachHooks = new Set(['.onDetach', '.Last.lib']);
26
+ /** the calls that belong into another hook: where they are wrong and where they belong */
27
+ const MisplacedCalls = {
28
+ 'library.dynam': { in: ['.onAttach'], instead: '.onLoad' },
29
+ 'library.dynam.unload': { in: ['.onDetach', '.Last.lib'], instead: '.onUnload' }
30
+ };
31
+ /** the constructs whose body may or may not run */
32
+ function isConditional(node) {
33
+ return r_if_then_else_1.RIfThenElse.is(node) || r_while_loop_1.RWhileLoop.is(node) || r_for_loop_1.RForLoop.is(node) || r_repeat_loop_1.RRepeatLoop.is(node) || r_function_call_1.RFunctionCall.isNamed(node, 'switch') || r_function_call_1.RFunctionCall.isNamed(node, 'tryCatch');
34
+ }
35
+ /**
36
+ * Every call made within the given definition and, if asked, within the package functions it calls (transitively).
37
+ * Of a function the hook calls, only the calls it makes in any case count: one guarded by an `if` (an option
38
+ * asking for verbose output, say) is no output of the hook.
39
+ */
40
+ function reachedCalls(def, df, idMap, follow) {
41
+ const result = [];
42
+ const visited = new Set([def.info.id]);
43
+ const work = [{ def }];
44
+ for (let item = work.pop(); item !== undefined; item = work.pop()) {
45
+ const { via } = item;
46
+ let conditional = 0;
47
+ model_1.RNode.visitAst(item.def.body, node => {
48
+ if (via !== undefined && (isConditional(node) || r_function_definition_1.RFunctionDefinition.is(node))) {
49
+ conditional++;
50
+ }
51
+ const vertex = df.graph.getVertex(node.info.id);
52
+ if (!vertex_1.DfgVertex.isFunctionCall(vertex) || conditional > 0) {
53
+ return false;
54
+ }
55
+ result.push({ id: node.info.id, name: identifier_1.Identifier.getName(vertex.name), via });
56
+ for (const callee of follow ? (0, cmd_check_util_1.calledDefinitions)(df.graph, node.info.id, idMap) : []) {
57
+ if (!visited.has(callee.info.id)) {
58
+ visited.add(callee.info.id);
59
+ work.push({ def: callee, via: via ?? node.info.id });
60
+ }
61
+ }
62
+ return false;
63
+ }, node => {
64
+ if (via !== undefined && (isConditional(node) || r_function_definition_1.RFunctionDefinition.is(node))) {
65
+ conditional--;
66
+ }
67
+ });
68
+ }
69
+ return result;
70
+ }
71
+ /** whether the call writes to a resource it is handed (`cat(x, file = f)`, `writeLines(x, con)`) rather than to the console */
72
+ function writesToResource(id, df, sig) {
73
+ const vertex = df.graph.getVertex(id);
74
+ const resources = sig?.filter(([, p]) => (p & built_in_props_1.ArgProp.Resource) !== 0).map(([n]) => n) ?? [];
75
+ if (!vertex_1.DfgVertex.isFunctionCall(vertex) || resources.length === 0) {
76
+ return false;
77
+ }
78
+ const bound = function_semantics_1.FunctionSemantics.call.match.toSpec(vertex.args, Object.fromEntries((sig ?? []).map(([n]) => [n, n])));
79
+ return resources.some(r => (bound.get(r)?.length ?? 0) > 0);
80
+ }
81
+ /** whether the call states an argument named `name` */
82
+ function hasNamedArgument(id, df, name) {
83
+ const vertex = df.graph.getVertex(id);
84
+ return vertex_1.DfgVertex.isFunctionCall(vertex) && vertex.args.some(a => a !== r_function_call_1.EmptyArgument && a.name === name);
85
+ }
86
+ /**
87
+ * Port of the `R CMD check` notes on package hooks (`checking R code for possible problems`, from
88
+ * `tools:::.check_package_code_startup_functions` and `tools:::.check_package_code_unload_functions`).
89
+ */
90
+ exports.PACKAGE_HOOKS = {
91
+ createSearch: () => flowr_search_builder_1.Q.from([]),
92
+ processSearchResult: async (_elements, config, data) => {
93
+ const df = await data.dataflow();
94
+ const ast = await data.normalize();
95
+ const idMap = ast.idMap;
96
+ const pkg = (0, cmd_check_util_1.packageInfo)(data.inspectContext());
97
+ const hooks = (0, cmd_check_util_1.topLevelDefinitions)(ast, n => StartupHooks.has(n) || DetachHooks.has(n))
98
+ .filter(h => pkg.isPackageCode(h.def.info.file));
99
+ const results = [];
100
+ const startupMessages = new Set(config.startupMessageFunctions);
101
+ const allowedOutput = new Set(config.allowedOutput);
102
+ const unsafe = new Set(config.unsafeCalls);
103
+ for (const { name: hook, def } of hooks) {
104
+ const report = (issue, message, id = def.info.id, call, certain = true) => results.push({
105
+ ...(0, cmd_check_util_1.at)(idMap.get(id) ?? def, certain),
106
+ hook,
107
+ issue,
108
+ ...(call ? { call } : {}),
109
+ message
110
+ });
111
+ if (hook === '.First.lib') {
112
+ report('obsolete', '.First.lib is obsolete and will not be used in R >= 3.0.0, use .onLoad or .onAttach instead');
113
+ }
114
+ else if (hook === '.Last.lib' && pkg.namespace !== undefined && (0, flowr_namespace_file_1.isExportedInInfo)(hook, pkg.namespace) === false) {
115
+ report('unexported', '.Last.lib will not be used unless it is exported, use .onDetach or .onUnload instead');
116
+ }
117
+ const formals = (0, cmd_check_util_1.formalNames)(def);
118
+ if (StartupHooks.has(hook) && !formals.includes('...') && (formals.length !== 2 || !formals[0].startsWith('lib') || !formals[1].startsWith('pkg'))) {
119
+ report('arguments', `${hook} has the argument list (${formals.join(', ')}) but package startup functions should have two arguments with names starting with 'lib' and 'pkg', respectively`);
120
+ }
121
+ else if (DetachHooks.has(hook) && !formals.includes('...') && (formals.length !== 1 || !formals[0].startsWith('lib'))) {
122
+ report('arguments', `${hook} has the argument list (${formals.join(', ')}) but package detach functions should have one argument with a name starting with 'lib'`);
123
+ }
124
+ for (const { id, name, via } of reachedCalls(def, df, idMap, config.followCalls)) {
125
+ const through = via === undefined ? '' : ` (through the call at ${range_1.SourceLocation.format(range_1.SourceLocation.fromNode(idMap.get(via)))})`;
126
+ const at = via ?? id;
127
+ const misplaced = MisplacedCalls[name];
128
+ if (misplaced?.in.includes(hook)) {
129
+ report('misplaced-call', `${hook} should not call ${name}, which belongs into ${misplaced.instead}${through}`, at, name, via === undefined);
130
+ continue;
131
+ }
132
+ if (!StartupHooks.has(hook)) {
133
+ continue;
134
+ }
135
+ const props = (0, query_fn_props_1.callFnProps)(id, df);
136
+ if (unsafe.has(name)) {
137
+ report('unsafe-call', `Package startup functions should not call ${name}${through}`, at, name, via === undefined);
138
+ }
139
+ else if (built_in_props_1.CallProps.hasAny(props, built_in_props_1.SemanticCallTag.AttachesPackage) && !hasNamedArgument(id, df, 'help')) {
140
+ report('search-path', `Package startup functions should not change the search path, but ${hook} calls ${name}${through}`, at, name, via === undefined);
141
+ }
142
+ else if (startupMessages.has(name) ? hook === '.onLoad' : built_in_props_1.CallProps.hasAny(props, built_in_props_1.SemanticCallTag.Prints) && !allowedOutput.has(name) && !writesToResource(id, df, props?.sig)) {
143
+ report('output', hook === '.onLoad' && startupMessages.has(name)
144
+ ? `.onLoad should not print startup messages with ${name}, use .onAttach instead${through}`
145
+ : `Package startup functions should use ${config.startupMessageFunctions[0] ?? 'packageStartupMessage'} to generate messages, but ${hook} calls ${name}${through}`, at, name, via === undefined);
146
+ }
147
+ }
148
+ }
149
+ return { results, '.meta': { hooks: hooks.map(h => h.name) } };
150
+ },
151
+ prettyPrint: (0, cmd_check_util_1.printer)(r => `${r.hook}: ${r.issue}${r.call ? ` (${r.call})` : ''}`),
152
+ info: {
153
+ name: 'Package Hooks',
154
+ tags: [linter_tags_1.LintingRuleTag.CmdCheck, linter_tags_1.LintingRuleTag.Bug, linter_tags_1.LintingRuleTag.Usability],
155
+ certainty: linter_format_1.LintingRuleCertainty.BestEffort,
156
+ description: 'Checks `.onLoad`, `.onAttach`, `.onDetach`, and `.Last.lib`: argument lists, attaching packages, output other than `packageStartupMessage()`, `installed.packages()`, misplaced `library.dynam()` calls, and the obsolete `.First.lib`. Follows calls into the package\'s own functions.',
157
+ defaultConfig: () => ({
158
+ startupMessageFunctions: ['packageStartupMessage'],
159
+ allowedOutput: ['warning'],
160
+ unsafeCalls: ['installed.packages'],
161
+ followCalls: true
162
+ })
163
+ }
164
+ };
165
+ //# sourceMappingURL=package-hooks.js.map
@@ -0,0 +1,49 @@
1
+ import { LintingRuleCertainty } from '../../linter-format';
2
+ import type { MergeableRecord } from '../../../util/objects';
3
+ import { LintingRuleTag } from '../../linter-tags';
4
+ import type { ReadonlyFlowrAnalysisProvider } from '../../../project/flowr-analyzer';
5
+ import type { ParentInformation } from '../../../r-bridge/lang-4.x/ast/model/processing/decorate';
6
+ import { type FileResult } from './file-checks';
7
+ /** what is wrong with a package file, named after the `R CMD check` finding it corresponds to */
8
+ export type PackageMetafilesKind = 'empty-index' | 'empty-demo-index' | 'undocumented-demo' | 'missing-demo' | 'citation-syntax' | 'citation-entry-type' | 'citation-missing-field' | 'citation-location' | 'citation-superseded' | 'relative-link';
9
+ export type PackageMetafilesResult = FileResult<PackageMetafilesKind>;
10
+ export interface PackageMetafilesConfig extends MergeableRecord {
11
+ /** check the `INDEX` and the `demo/00Index` of the package (default `true`) */
12
+ readonly index: boolean;
13
+ /** check `inst/CITATION` (its syntax, entry types and required fields) and the location of other CITATION files (default `true`) */
14
+ readonly citation: boolean;
15
+ /** report the citation functions superseded by a newer one, which `R CMD check` accepts (default `true`) */
16
+ readonly superseded: boolean;
17
+ /** check that the relative links of the README, NEWS and vignettes point to files of the package (default `true`) */
18
+ readonly relativeLinks: boolean;
19
+ }
20
+ export interface PackageMetafilesMetadata extends MergeableRecord {
21
+ /** the package files whose content was inspected */
22
+ readonly checkedFiles: number;
23
+ }
24
+ /** Port of the `R CMD check` notes on `INDEX`, `demo/00Index`, `inst/CITATION`, CITATION locations, and relative links of README, NEWS and vignettes. */
25
+ export declare const PACKAGE_METAFILES: {
26
+ readonly createSearch: () => import("../../../search/flowr-search-builder").FlowrSearchBuilder<"from", [], ParentInformation, import("../../../search/flowr-search").FlowrSearchElements<ParentInformation, import("../../../search/flowr-search").FlowrSearchElement<ParentInformation>[]>>;
27
+ readonly processSearchResult: (_elements: import("../../../search/flowr-search").FlowrSearchElements<ParentInformation, import("../../../search/flowr-search").FlowrSearchElement<ParentInformation>[]>, config: PackageMetafilesConfig, data: ReadonlyFlowrAnalysisProvider<import("../../..").KnownParser>) => {
28
+ results: FileResult<PackageMetafilesKind>[];
29
+ '.meta': {
30
+ checkedFiles: number;
31
+ };
32
+ };
33
+ readonly prettyPrint: {
34
+ readonly query: (result: PackageMetafilesResult) => string;
35
+ readonly full: (result: PackageMetafilesResult) => string;
36
+ };
37
+ readonly info: {
38
+ readonly name: "Package Metafiles";
39
+ readonly tags: readonly [LintingRuleTag.CmdCheck, LintingRuleTag.Robustness];
40
+ readonly certainty: LintingRuleCertainty.BestEffort;
41
+ readonly description: "Checks the demo index, `INDEX`, `inst/CITATION`, and relative links in README, NEWS, and vignettes.";
42
+ readonly defaultConfig: () => {
43
+ index: true;
44
+ citation: true;
45
+ superseded: true;
46
+ relativeLinks: true;
47
+ };
48
+ };
49
+ };