@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,621 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RD_FILES = 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 r_function_call_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
9
+ const r_argument_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
10
+ const r_symbol_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol");
11
+ const r_string_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-string");
12
+ const r_binary_op_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-binary-op");
13
+ const arrays_1 = require("../../../util/collections/arrays");
14
+ const identifier_1 = require("../../../dataflow/environments/identifier");
15
+ const r_base_packages_1 = require("../../../util/r-base-packages");
16
+ const flowr_rd_file_1 = require("../../../project/plugins/file-plugins/files/flowr-rd-file");
17
+ const cmd_check_util_1 = require("./cmd-check-util");
18
+ const package_files_1 = require("./package-files");
19
+ const package_code_1 = require("./package-code");
20
+ const file_checks_1 = require("./file-checks");
21
+ /** A map from each of the space-separated names of the keys to the value. */
22
+ const table = (spec) => new Map(Object.entries(spec).flatMap(([names, v]) => names.split(' ').map(n => [n, v])));
23
+ const words = (names) => new Set(names.split(' '));
24
+ /** the standard keywords of R (`KEYWORDS.db`) */
25
+ const StandardKeywords = ('algebra aplot arith array attribute Basics category character chron classes classif cluster color complex connection data database datagen '
26
+ + 'datasets debugging design device distribution documentation dplot dynamic environment error file Graphics graphs hplot htest interface internal IO iplot iteration '
27
+ + 'list loess logic manip MASS math Mathematics methods misc models multivariate NA neural nonlinear nonparametric optimize package print programming Programming '
28
+ + 'regression robust smooth spatial Statistics survey survival symbolmath sysdata tree ts univar utilities').split(' ');
29
+ /** the URL schemes registered with IANA that Rd pages commonly use */
30
+ const UrlSchemes = words('http https ftp ftps sftp mailto file git ssh svn rsync irc news nntp telnet tel sms data urn doi javascript ldap gopher imap geo magnet xmpp sip webcal ws wss about');
31
+ /** R's system macros (`share/Rd/macros/system.Rd`) */
32
+ const SystemMacros = 'CRANpkg PR sspace packageTitle packageDescription packageAuthor packageMaintainer packageDESCRIPTION packageIndices doi LaTeX proglang I manual bibcitep bibcitet bibshow bibinfo';
33
+ /** the argument modes of the Rd and system macros, see {@link scanRd} */
34
+ const Macros = new Map(Object.entries({
35
+ t: 'title concept description arguments value details note author references seealso format source link linkS4class linkS4methods file env pkg var command option emph strong bold cite acronym abbr dfn sQuote dQuote itemize enumerate describe CRANpkg PR packageTitle packageDescription packageAuthor packageMaintainer packageDESCRIPTION packageIndices doi proglang I bibcitep bibcitet bibshow',
36
+ v: 'name alias keyword encoding docType Rdversion RdOpts preformatted verb samp kbd email url out dontrun',
37
+ r: 'usage examples code special Sexpr donttest dontshow testonly dontdiff',
38
+ tt: 'section subsection enc if tabular manual',
39
+ '': 'cr tab dots ldots R sspace LaTeX',
40
+ vt: 'href',
41
+ vv: 'method S3method S4method newcommand renewcommand',
42
+ vV: 'eqn deqn figure',
43
+ ttt: 'ifelse bibinfo'
44
+ }).flatMap(([modes, names]) => names.split(' ').map(n => [n, modes])));
45
+ const ItemModes = table({ 'arguments value describe': 'tt', 'itemize enumerate': '' });
46
+ /** the sections `prepare_Rd` knows, and the macros that may stand next to them */
47
+ const SectionNames = words('title name alias concept keyword encoding description usage arguments format details value section note author source references seealso examples');
48
+ const ExtraSections = words('docType Rdversion RdOpts newcommand renewcommand Sexpr');
49
+ const UniqueSections = 'description usage arguments format details value references source seealso examples author encoding'.split(' ');
50
+ const DocTypes = words('data package methods class import');
51
+ const IfFormats = words('latex example text html TRUE FALSE');
52
+ const PlainContent = 'describe enumerate itemize bold cite command dfn emph kbd Sexpr special strong var verb abbr acronym env file option pkg samp sQuote dQuote';
53
+ const ExampleWrappers = 'dontrun donttest dontdiff dontshow testonly';
54
+ const LinkMacros = 'link linkS4class linkS4methods';
55
+ const LinkSuffix = { linkS4class: '-class', linkS4methods: '-methods' };
56
+ const NameRules = [
57
+ { test: /[!|@]/, level: 5, text: '\\name should not contain !, | or @' },
58
+ { test: /[^\x20-\x7e]/, level: -1, text: '\\name should only contain printable ASCII characters' }
59
+ ];
60
+ const EmailPattern = /^[A-Za-z0-9.!#$%&'*+/=?^_`{|}~-]+@[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?(?:\.[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?)*$/;
61
+ const Always = Number.POSITIVE_INFINITY;
62
+ const arg = (m, i) => m.args[i] ?? [];
63
+ const isMacro = (n) => n.type === 'macro';
64
+ const sectionsOf = (nodes, name) => nodes.filter((n) => isMacro(n) && n.name === name);
65
+ /** the raw text of the text nodes, macros skipped */
66
+ const plain = (nodes) => nodes.map(n => n.type === 'text' ? n.text : n.type === 'group' ? plain(n.children) : '').join('');
67
+ /** the source form of a node list, as `.Rd_deparse` gives it */
68
+ const deparse = (nodes) => nodes.map(n => n.type === 'text' ? n.text : n.type === 'group' ? `{${deparse(n.children)}}` : `\\${n.name}${n.args.map(a => `{${deparse(a)}}`).join('')}`).join('');
69
+ /** whether the nodes hold no text at all, as `prepare_Rd` decides what an empty section is */
70
+ const isBlank = (nodes) => nodes.every(n => n.type === 'text' ? !/\S/.test(n.text) : n.type === 'group' ? isBlank(n.children) : Macros.has(n.name) && n.args.every(isBlank));
71
+ const unescape = (s) => s.replace(/\\([\\%{}])/g, '$1');
72
+ /** The checks of `tools::checkRd` and the structure checks of `prepare_Rd`, run on one scanned page. */
73
+ class RdChecker {
74
+ scan;
75
+ settings;
76
+ diags = [];
77
+ links = [];
78
+ hasText = false;
79
+ inEnc2 = false;
80
+ defEnc;
81
+ constructor(scan, settings) {
82
+ this.scan = scan;
83
+ this.settings = settings;
84
+ this.defEnc = settings.defEnc;
85
+ }
86
+ warn(at, level, kind, text) {
87
+ this.diags.push({ line: this.scan.lineOf(at), level, kind, text });
88
+ }
89
+ known(name) {
90
+ return this.settings.macros.has(name) || this.settings.lenient;
91
+ }
92
+ contentOf = (m, tag) => m.args.forEach(a => this.content(a, m.name, tag));
93
+ withText = (h) => (m, tag) => {
94
+ h(m, tag);
95
+ this.hasText = true;
96
+ };
97
+ inline = this.withText(this.contentOf);
98
+ /** what a macro in text does: `early` before the macros the package defines, `late` after them */
99
+ blocks = {
100
+ early: table({
101
+ [PlainContent]: this.contentOf,
102
+ 'code preformatted': m => this.code(arg(m, 0), m.name),
103
+ [LinkMacros]: m => this.link(m),
104
+ email: this.withText(m => [unescape(plain(arg(m, 0))).trim()].filter(a => a !== '' && !EmailPattern.test(a)).forEach(a => this.warn(m.at, 7, 'rd-markup', `Invalid email address: ${a}`))),
105
+ url: this.withText(m => this.url(m)),
106
+ 'cr newcommand renewcommand out': () => undefined
107
+ }),
108
+ known: words('dots ldots R'),
109
+ late: table({
110
+ 'method S3method S4method': m => this.warn(m.at, 7, 'rd-markup', `Tag \\${m.name} not valid outside a code block`),
111
+ enc: (m, tag) => {
112
+ this.content(arg(m, 0), 'enc', tag);
113
+ const saved = this.defEnc;
114
+ [this.defEnc, this.inEnc2] = [false, true];
115
+ this.content(arg(m, 1), 'enc', tag);
116
+ [this.defEnc, this.inEnc2] = [saved, false];
117
+ },
118
+ 'eqn deqn figure': (m, tag) => {
119
+ this.contentOf(m, tag);
120
+ const options = plain(arg(m, 1));
121
+ if (options.startsWith('options: ') && /(height|width) *= *['"]?[0-9]+%/.test(options)) {
122
+ this.warn(m.at, -1, 'rd-markup', 'height/width attributes should be in pixels');
123
+ }
124
+ },
125
+ tabular: m => this.tabular(m),
126
+ subsection: this.withText(m => this.section(m, false)),
127
+ 'if ifelse': (m, tag) => {
128
+ const formats = plain(arg(m, 0)).split(',').map(s => s.trim()).filter(f => f !== '' && !IfFormats.has(f));
129
+ if (formats.length > 0) {
130
+ this.warn(m.at, 7, 'rd-markup', `Unrecognized format: ${formats.join(' ')}`);
131
+ }
132
+ m.args.slice(1).forEach(a => this.content(a, m.name, tag));
133
+ },
134
+ href: (m, tag) => {
135
+ this.url(m);
136
+ this.content(arg(m, 1), m.name, tag);
137
+ }
138
+ }),
139
+ fallback: (m) => this.warn(m.at, 7, 'rd-markup', `Tag \\${m.name} not recognized`)
140
+ };
141
+ /** what a macro in a code block does, the tag being the code block */
142
+ codes = {
143
+ early: table({ 'var special': (m, tag) => this.code(arg(m, 0), tag) }),
144
+ known: words('dots R newcommand renewcommand Sexpr'),
145
+ late: table({
146
+ ldots: this.withText(m => this.warn(m.at, -3, 'rd-markup', 'Tag \\ldots is invalid in a code block')),
147
+ [LinkMacros]: m => this.link(m),
148
+ 'method S3method S4method': (m, tag) => tag === 'usage' ? m.args.forEach(a => this.content(a, m.name, tag)) : this.warn(m.at, 7, 'rd-markup', `Tag \\${m.name} is only valid in \\usage`),
149
+ [ExampleWrappers]: (m, tag) => tag === 'examples' ? this.code(arg(m, 0), tag) : this.warn(m.at, 7, 'rd-markup', `Tag \\${m.name} is only valid in \\examples`)
150
+ }),
151
+ fallback: this.withText((m, tag) => this.warn(m.at, 7, 'rd-markup', `Tag \\${m.name} is invalid in a \\${tag} block`))
152
+ };
153
+ dispatch(m, tag, { early, known, late, fallback }, inline) {
154
+ (early.get(m.name) ?? (known.has(m.name) || this.known(m.name) ? inline : late.get(m.name)) ?? fallback)(m, tag);
155
+ }
156
+ sections(nodes) {
157
+ nodes.filter(n => n.type === 'text' && /\S/.test(n.text)).forEach(n => this.warn(n.at, Always, 'rd-structure', 'All text must be in a section'));
158
+ const macros = nodes.filter(isMacro);
159
+ const named = (name) => macros.filter(m => m.name === name);
160
+ const structure = (m, text) => m && this.warn(m.at, Always, 'rd-structure', text);
161
+ structure(named('Rdversion')[1], 'Only one \\Rdversion declaration is allowed');
162
+ macros.filter(m => !SectionNames.has(m.name) && !ExtraSections.has(m.name) && !this.known(m.name)).forEach(m => structure(m, `unexpected macro '\\${m.name}'`));
163
+ structure(named('docType')[1], 'Multiple \\docType sections are not supported');
164
+ const docTypes = named('docType').map(d => [d, plain(arg(d, 0)).trim()]);
165
+ docTypes.filter(([, t]) => !DocTypes.has(t)).forEach(([d, t]) => structure(d, `docType '${t}' is unrecognized`));
166
+ const docType = docTypes[0]?.[1] ?? '';
167
+ const dropped = new Set(UniqueSections.flatMap(tag => named(tag).slice(1)));
168
+ dropped.forEach(m => structure(m, `Only one \\${m.name} section is allowed: the first will be used`));
169
+ this.defEnc ||= named('encoding').length > 0;
170
+ const [names, titles] = [named('name'), named('title')];
171
+ if (names.length !== 1 || titles.length !== 1) {
172
+ this.warn(0, Always, 'rd-structure', 'Sections \\title, and \\name must exist and be unique in Rd files');
173
+ return { nameAt: 0, docType };
174
+ }
175
+ const [nameMacro, nameNodes] = [names[0], arg(names[0], 0)];
176
+ const name = unescape(plain(nameNodes)).trim();
177
+ if (name === '' || name.includes('\\') || nameNodes.some(n => n.type !== 'text')) {
178
+ structure(nameMacro, '\\name must only contain simple text');
179
+ return { nameAt: nameMacro.at, docType };
180
+ }
181
+ NameRules.filter(r => r.test.test(name)).forEach(r => this.warn(nameMacro.at, r.level, 'rd-markup', r.text));
182
+ macros.filter(m => SectionNames.has(m.name) && !dropped.has(m)).forEach(m => this.section(m, true));
183
+ return { name, nameAt: nameMacro.at, docType };
184
+ }
185
+ section(m, top) {
186
+ const titled = m.name === 'section' || m.name === 'subsection';
187
+ const [title, content] = titled ? [arg(m, 0), arg(m, 1)] : [[], arg(m, 0)];
188
+ const tagTitle = titled ? `'${plain(title).trim()}'` : `\\${m.name}`;
189
+ if (top && isBlank(content)) {
190
+ this.warn(m.at, Always, 'rd-empty-section', `Dropping empty section ${tagTitle}`);
191
+ return;
192
+ }
193
+ this.content(title, m.name, m.name);
194
+ this.hasText = false;
195
+ if (m.name === 'usage' || m.name === 'examples') {
196
+ this.code(content, m.name);
197
+ }
198
+ else {
199
+ this.content(content, m.name, m.name);
200
+ }
201
+ if (!this.hasText) {
202
+ this.warn(m.at, 3, 'rd-empty-section', `Empty section ${tagTitle}`);
203
+ }
204
+ const rd = deparse(titled ? title : content);
205
+ if ((titled || m.name === 'title') && /[^.]\.\s*$/.test(rd) && !/(etc|et\s+al)\.\s*$/.test(rd)) {
206
+ this.warn(m.at, -5, 'rd-markup', `\\${m.name}${titled ? ' name' : ''} should not end in a period`);
207
+ }
208
+ }
209
+ text(n) {
210
+ if (!/\S/.test(n.text)) {
211
+ return;
212
+ }
213
+ this.hasText = true;
214
+ if ((this.inEnc2 || !this.defEnc) && /\P{ASCII}/u.test(n.text)) {
215
+ this.warn(n.at, -1, 'rd-encoding', `Non-ASCII contents ${this.inEnc2 ? 'in second part of \\enc' : 'without declared encoding'}: '${n.text.trim()}'`);
216
+ }
217
+ const specials = n.mode === 't' ? [...n.text.matchAll(/(?:^|[^\\])(\\[#$&_^~])/g)].map(m => m[1]) : [];
218
+ if (specials.length > 0) {
219
+ this.warn(n.at, -1, 'rd-markup', `Escaped LaTeX specials: ${specials.join(' ')}`);
220
+ }
221
+ }
222
+ /** walks text; `cell` takes the macros of a table row first, and makes even blank groups lost braces */
223
+ content(nodes, blocktag, sectionTag, cell) {
224
+ nodes.forEach((n, i) => {
225
+ if (n.type === 'text') {
226
+ this.text(n);
227
+ }
228
+ else if (n.type === 'group') {
229
+ if (cell !== undefined || !isBlank(n.children)) {
230
+ this.lostBraces(n, nodes.slice(0, i), blocktag, sectionTag);
231
+ }
232
+ this.content(n.children, blocktag, sectionTag);
233
+ }
234
+ else if (cell?.(n)) {
235
+ return;
236
+ }
237
+ else if (n.name === 'item') {
238
+ if (ItemModes.get(blocktag) === 'tt' && arg(n, 0).every(l => l.type === 'text' && !/\S/.test(l.text))) {
239
+ this.warn(n.at, 5, 'rd-markup', `\\item in \\${blocktag} must have non-empty label`);
240
+ }
241
+ n.args.forEach(a => this.content(a, 'item', sectionTag));
242
+ }
243
+ else {
244
+ this.dispatch(n, sectionTag, this.blocks, this.inline);
245
+ }
246
+ });
247
+ }
248
+ lostBraces(group, pre, blocktag, sectionTag) {
249
+ const tagOf = (n) => n.type === 'text' ? (/^\s*$/.test(n.text) ? 'BLANK' : 'TEXT') : n.type === 'group' ? 'LIST' : `\\${n.name}`;
250
+ const pretags = pre.map(tagOf);
251
+ const pretag = pretags.filter(t => t !== 'BLANK').pop();
252
+ if (pretag === undefined) {
253
+ return;
254
+ }
255
+ const [preblock, last, tags] = [pre[pre.length - 1], pretags[pretags.length - 1], group.children.map(tagOf)];
256
+ const separated = last === 'BLANK' || (last === 'TEXT' && preblock.type === 'text' && !/([A-Za-z0-9]|\\[!-/:-@[-`{-~]|[\])])$/.test(preblock.text));
257
+ const ignore = (tags.length === 1 && tags[0].startsWith('\\') && separated) || ((blocktag === 'itemize' || blocktag === 'enumerate') && pretag === '\\item')
258
+ || pretag === '\\tab' || ((sectionTag === 'source' || sectionTag === 'references') && (separated || pretag === '\\cr'));
259
+ if (!ignore) {
260
+ this.warn(group.at, -1, 'rd-lost-braces', `Lost braces${separated && tags.length === 1 && tags[0] === 'TEXT' ? '; missing escapes or markup?' : ''}`);
261
+ }
262
+ }
263
+ link(m) {
264
+ this.content(arg(m, 0), m.name, m.name);
265
+ const text = plain(arg(m, 0)).trim();
266
+ const option = m.option?.trim() ?? '';
267
+ const colon = option.indexOf(':');
268
+ const [topic, pkg] = option === '' ? [text + (LinkSuffix[m.name] ?? ''), undefined]
269
+ : option.startsWith('=') ? [option.slice(1), undefined]
270
+ : colon >= 0 ? [option.slice(colon + 1), option.slice(0, colon)] : [text, option];
271
+ this.links.push({ line: this.scan.lineOf(m.at), topic, pkg, shown: option === '' ? `\\${m.name}{${text}}` : `\\${m.name}[${option}]{${text}}` });
272
+ }
273
+ url(m) {
274
+ const url = unescape(plain(arg(m, 0))).replace(/\s+/g, '');
275
+ const scheme = /^([A-Za-z][A-Za-z0-9+.-]*):/.exec(url)?.[1].toLowerCase();
276
+ if (scheme !== undefined && (!UrlSchemes.has(scheme) || (scheme === 'mailto' && !EmailPattern.test(url.slice('mailto:'.length))))) {
277
+ this.warn(m.at, 7, 'rd-markup', `Invalid URL: ${url}`);
278
+ }
279
+ }
280
+ code(nodes, blocktag) {
281
+ for (const n of nodes) {
282
+ if (n.type === 'text') {
283
+ this.text(n);
284
+ }
285
+ else if (n.type === 'group') {
286
+ this.code(n.children, blocktag);
287
+ }
288
+ else {
289
+ this.dispatch(n, blocktag, this.codes, this.withText(() => undefined));
290
+ }
291
+ }
292
+ }
293
+ tabular(table) {
294
+ this.hasText = true;
295
+ const format = arg(table, 0);
296
+ const content = [...arg(table, 1)];
297
+ const spec = plain(format).trim();
298
+ if (format.length !== 1 || format[0].type !== 'text') {
299
+ this.warn(table.at, 7, 'rd-markup', '\\tabular format must be simple text');
300
+ }
301
+ if (!/^[lcr]*$/.test(spec)) {
302
+ this.warn(table.at, 7, 'rd-markup', `Unrecognized \\tabular format: ${spec}`);
303
+ }
304
+ const lastCr = content.map(n => isMacro(n) && n.name === 'cr').lastIndexOf(true);
305
+ if (lastCr >= 0 && isBlank(content.slice(lastCr + 1))) {
306
+ content.splice(lastCr, 1);
307
+ }
308
+ const len = spec.length;
309
+ let [col, row] = [1, 1];
310
+ const check = () => col !== len && this.warn(table.at, col > len ? 7 : -2, 'rd-markup', `Only ${len} ${len === 1 ? 'column' : 'columns'} allowed in this table (row ${row} has ${col})`);
311
+ this.content(content, 'tabular', 'tabular', n => {
312
+ if (n.name === 'cr') {
313
+ check();
314
+ [row, col] = [row + 1, 1];
315
+ }
316
+ col += n.name === 'tab' ? 1 : 0;
317
+ return n.name === 'cr' || n.name === 'tab';
318
+ });
319
+ check();
320
+ }
321
+ }
322
+ /** Scans and checks one Rd page. */
323
+ function checkPage(file, src, settings) {
324
+ const macros = new Map([...settings.macros, ...[...(0, flowr_rd_file_1.parseRdMacros)(src)].map(([n, m]) => [n, m.params])]);
325
+ const scan = (0, flowr_rd_file_1.scanRd)(src, {
326
+ lenient: settings.lenient,
327
+ specOf: (name, parent) => name === 'item' ? ItemModes.get(parent ?? '') : Macros.get(name) ?? (macros.has(name) ? 't'.repeat(macros.get(name) ?? 0) : undefined)
328
+ });
329
+ const checker = new RdChecker(scan, { ...settings, macros });
330
+ const diags = scan.problems.map(p => ({ line: scan.lineOf(p.at), level: Always, kind: p.kind === 'syntax' ? 'rd-syntax' : 'rd-unknown-macro', text: p.text }));
331
+ const info = diags.some(d => d.kind === 'rd-syntax') ? { nameAt: 0, docType: '' } : checker.sections(scan.nodes);
332
+ diags.push(...checker.diags);
333
+ const aliases = sectionsOf(scan.nodes, 'alias').map(a => unescape(plain(arg(a, 0))).trim()).filter(a => a !== '');
334
+ const keywords = sectionsOf(scan.nodes, 'keyword').map(k => ({ keyword: plain(arg(k, 0)).trim(), line: scan.lineOf(k.at) }));
335
+ return { file, src, scan, diags, aliases, keywords, base: file.slice(file.lastIndexOf('/') + 1), name: info.name, nameLine: scan.lineOf(info.nameAt), docType: info.docType, links: checker.links };
336
+ }
337
+ const section = (p, name) => sectionsOf(p.scan.nodes, name)[0];
338
+ const items = (m) => sectionsOf(m?.args[0] ?? [], 'item');
339
+ const hasKeyword = (p, keywords) => p.keywords.some(k => keywords.includes(k.keyword));
340
+ const BoilerplateKeywords = ['~kwd1', '~kwd2', '~~ other possible keyword(s) ~~'];
341
+ /** the unedited content `prompt()` and `package.skeleton()` generate, by section: a test on the deparsed body and its node count */
342
+ const Boilerplate = [
343
+ ['title', rd => rd.trim().startsWith('A Capitalized Title')],
344
+ ['details', (rd, n) => rd.includes('If necessary, more details than the description above') || (n <= 11 && rd.includes('~~ An overview of how to use the package'))],
345
+ ['references', rd => rd.replace(/\s+/g, ' ').includes('Literature or other references for background information')],
346
+ ['seealso', (rd, n) => n <= 5 && rd.includes('Optional links to other man pages')],
347
+ ['examples', rd => rd.includes('Optional simple examples of the most important functions')]
348
+ ];
349
+ /** `checking Rd contents`: missing descriptions and values, argument items without text, and generated boilerplate */
350
+ function contents(p, { config }) {
351
+ const found = [];
352
+ const add = (kind, line, text) => found.push([kind, line, text]);
353
+ const internal = hasKeyword(p, ['internal']);
354
+ const line = (m) => p.scan.lineOf(m.at);
355
+ if (p.docType !== 'package' && isBlank(section(p, 'description')?.args[0] ?? [])) {
356
+ add('rd-missing-description', 1, `Rd files without \\description: '${p.base}'`);
357
+ }
358
+ const args = items(section(p, 'arguments')).filter(i => i.args.length === 2);
359
+ for (const item of internal ? [] : args.filter(i => isBlank(i.args[1]) && !isBlank(i.args[0]))) {
360
+ plain(item.args[0]).split(',').map(s => s.trim()).filter(a => a !== '').forEach(a => add('rd-undocumented-argument', line(item), `Argument items with no description in Rd file '${p.base}': '${a}'`));
361
+ }
362
+ const boilerplate = (l, what) => add('rd-boilerplate', l, `Auto-generated content requiring editing in Rd file '${p.base}': ${what}`);
363
+ for (const [name, test] of Boilerplate) {
364
+ const m = section(p, name);
365
+ if (m !== undefined && test(deparse(arg(m, 0)), arg(m, 0).length)) {
366
+ boilerplate(line(m), `\\${name}`);
367
+ }
368
+ }
369
+ for (const item of args) {
370
+ const label = plain(item.args[0]).trim();
371
+ if (deparse(item.args[1]).trim() === `~~Describe \\code{${label}} here~~`) {
372
+ boilerplate(line(item), `\\arguments: ${label}`);
373
+ }
374
+ }
375
+ p.keywords.filter(k => BoilerplateKeywords.includes(k.keyword)).forEach(k => boilerplate(k.line, `\\keyword: ${k.keyword}`));
376
+ const usage = section(p, 'usage');
377
+ if (config.requireValue && !internal && p.docType === '' && !hasKeyword(p, ['aplot', 'hplot', 'device', 'dynamic']) && usage !== undefined
378
+ && !isBlank(arg(usage, 0)) && section(p, 'value') === undefined && !deparse(arg(usage, 0)).includes('\\special')) {
379
+ add('rd-missing-value', line(usage), `Rd files without \\value: '${p.base}'`);
380
+ }
381
+ return found;
382
+ }
383
+ /** `checking Rd line widths`: the code lines as the PDF manual sets them */
384
+ function lineWidths(p, { config }) {
385
+ return [['usage', config.usageWidth], ['examples', config.examplesWidth]].flatMap(([tag, limit]) => {
386
+ const span = section(p, tag)?.spans[0];
387
+ const lines = span === undefined ? [] : p.scan.text.slice(...span).split('\n');
388
+ return lines.map((l, i) => [p.scan.lineOf(span?.[0] ?? 0) + i, unescape(l).replace(/\\l?dots/g, '...').trimEnd()]).filter(([, t]) => t.length > limit)
389
+ .map(([line, t]) => ['rd-line-width', line, `Rd file '${p.base}': \\${tag} lines wider than ${limit} characters (${t.length}): ${t.length > 140 ? `${t.slice(0, 140)}... [TRUNCATED]` : t.trim()}`]);
390
+ });
391
+ }
392
+ /** the `\bibcitep`/`\bibcitet` keys a page cites but never shows with `\bibshow` */
393
+ function bibentries(p) {
394
+ const events = [];
395
+ const visit = (nodes) => nodes.forEach(n => {
396
+ if (n.type === 'group') {
397
+ visit(n.children);
398
+ }
399
+ else if (isMacro(n)) {
400
+ if (n.name.startsWith('bibci') || n.name === 'bibshow') {
401
+ events.push({ name: n.name, keys: plain(arg(n, 0)).split(',').map(k => k.trim()).filter(k => k !== ''), line: p.scan.lineOf(n.at) });
402
+ }
403
+ n.args.forEach(visit);
404
+ }
405
+ });
406
+ visit(p.scan.nodes);
407
+ let [cited, cache, shown, first] = [[], [], [], 0];
408
+ for (const e of events) {
409
+ if (e.name !== 'bibshow') {
410
+ [cited, cache, first] = [(0, arrays_1.uniqueArrayMerge)(cited, e.keys), (0, arrays_1.uniqueArrayMerge)(cache, e.keys), first || e.line];
411
+ }
412
+ else if (e.keys.length === 0) {
413
+ cited = [];
414
+ }
415
+ else {
416
+ shown = (0, arrays_1.uniqueArrayMerge)(shown, e.keys.includes('*') ? [...e.keys.filter(k => k !== '*'), ...cache] : e.keys);
417
+ }
418
+ }
419
+ const missing = cited.filter(k => !shown.includes(k));
420
+ return missing.length > 0 ? [['rd-bibentry', first, `Bibentries cited but not shown in Rd file '${p.base}': ${missing.map(k => `'${k}'`).join(', ')}`]] : [];
421
+ }
422
+ /** the S3 methods a `\usage` calls by their full name rather than with `\method` */
423
+ function s3Names(p, { methods }) {
424
+ const found = [];
425
+ const visit = (nodes) => nodes.forEach(n => {
426
+ const call = n.type === 'text' ? /^\s*([A-Za-z.][A-Za-z0-9._]*)\s*\(/.exec(n.text)?.[1] : undefined;
427
+ if (call !== undefined && methods.has(call)) {
428
+ found.push(['rd-s3-method-name', p.scan.lineOf(n.at), `S3 methods shown with full name in Rd file '${p.base}': '${call}'`]);
429
+ }
430
+ visit(n.type === 'group' ? n.children : isMacro(n) && ExampleWrappers.includes(n.name) ? arg(n, 0) : []);
431
+ });
432
+ visit(section(p, 'usage')?.args[0] ?? []);
433
+ return found;
434
+ }
435
+ /** a tree-sitter error node, searched without recursion deeper than the tree */
436
+ function firstErrorRow(root) {
437
+ const stack = [root];
438
+ for (let node = stack.pop(); node !== undefined; node = stack.pop()) {
439
+ if (node.isError || node.isMissing) {
440
+ return node.startPosition.row;
441
+ }
442
+ stack.push(...node.children.slice().reverse());
443
+ }
444
+ return undefined;
445
+ }
446
+ /** the file argument of the functions that write one: its name and its position among the unnamed arguments */
447
+ const FileWriters = new Map([
448
+ ['file', 1, 'write.csv write.csv2 write.table saveRDS write dput dump'], ['file', -1, 'save cat'], ['file', 0, 'save.image sink pdf postscript'], ['filename', 0, 'png jpeg bmp tiff svg cairo_pdf'],
449
+ ['con', 1, 'writeLines'], ['', 0, 'file.create'], ['path', 0, 'dir.create'], ['destfile', 1, 'download.file'], ['path', 1, 'write_rds']
450
+ ].flatMap(([name, at, fns]) => fns.split(' ').map(fn => [fn, [name, at]])));
451
+ const HarmlessPaths = words(' /dev/null nul');
452
+ /** `checking examples`: what running the `\examples` of a page would complain about or leave behind */
453
+ function examples(p, { data }) {
454
+ const ex = (0, package_code_1.rdExamples)(p.src);
455
+ if (ex === undefined || !/\S/.test(ex.code) || p.diags.some(d => d.kind === 'rd-syntax')) {
456
+ return [];
457
+ }
458
+ const at = (row) => ex.lineOffset + row;
459
+ const tree = data.parseStandalone(ex.code);
460
+ const errorRow = tree.rootNode.hasError ? firstErrorRow(tree.rootNode) : undefined;
461
+ if (errorRow !== undefined) {
462
+ return [['rd-example-syntax', at(errorRow), `Running examples in '${p.file}' failed: the example code does not parse (unexpected code at line ${at(errorRow)})`]];
463
+ }
464
+ const ast = data.normalizeStandalone(ex.code);
465
+ const nodes = (0, cmd_check_util_1.projectNodes)(ast);
466
+ const found = [];
467
+ const lineOf = (n) => at((range_1.SourceLocation.fromNode(n)?.[0] ?? 1) - 1);
468
+ const assigned = (node) => {
469
+ const parent = node.info.parent === undefined ? undefined : ast.idMap.get(node.info.parent);
470
+ return (r_argument_1.RArgument.is(parent) && parent.name === node) || (r_binary_op_1.RBinaryOp.is(parent) && parent.lhs === node && ['<-', '=', '<<-'].includes(parent.operator));
471
+ };
472
+ let [setwds, restores] = [0, false];
473
+ for (const node of nodes) {
474
+ const symbol = r_symbol_1.RSymbol.is(node) ? identifier_1.Identifier.getName(node.content) : undefined;
475
+ if ((symbol === 'T' || symbol === 'F') && !assigned(node)) {
476
+ found.push(['rd-example-abbreviation', lineOf(node), `Examples use '${symbol}' instead of '${symbol === 'T' ? 'TRUE' : 'FALSE'}'`]);
477
+ }
478
+ if (!r_function_call_1.RFunctionCall.isNamed(node)) {
479
+ continue;
480
+ }
481
+ const name = identifier_1.Identifier.getName(node.functionName.content);
482
+ if (name === 'q' || name === 'quit') {
483
+ found.push(['rd-example-quit', lineOf(node), `Examples call ${name}(), which ends the R session`]);
484
+ }
485
+ setwds += name === 'setwd' ? 1 : 0;
486
+ restores ||= ['on.exit', 'with_dir', 'withr::with_dir'].includes(name);
487
+ const [argName, position] = FileWriters.get(name) ?? ['', -1];
488
+ const args = node.arguments.filter(r_argument_1.RArgument.isNotEmpty);
489
+ const value = ((argName === '' ? undefined : args.find(a => a.name?.content === argName)) ?? args.filter(a => a.name === undefined)[position])?.value;
490
+ if (r_string_1.RString.is(value) && !HarmlessPaths.has(value.content.str)) {
491
+ found.push(['rd-example-file', lineOf(node), `Examples write to '${value.content.str}', which is not below tempdir(); the file is left behind`]);
492
+ }
493
+ }
494
+ if (setwds === 1 && !restores) {
495
+ const call = nodes.find(n => r_function_call_1.RFunctionCall.isNamed(n, 'setwd'));
496
+ found.push(['rd-example-setwd', call === undefined ? at(0) : lineOf(call), 'Examples change the working directory with setwd() and never restore it']);
497
+ }
498
+ return found;
499
+ }
500
+ /** the checks run on each page, in order, with the configuration that enables them */
501
+ const PageChecks = [
502
+ [c => c.parse, (p, { config }) => p.diags.filter(d => d.level >= config.minLevel).map(d => [d.kind, d.line, `${p.base}:${d.line}: ${d.text}`])],
503
+ [c => c.parse && c.bibentries, bibentries],
504
+ [c => c.lineWidths, lineWidths],
505
+ [c => c.contents, contents],
506
+ [c => c.standardKeywords, (p, { config }) => p.keywords.filter(k => k.keyword !== '' && !config.keywords.includes(k.keyword) && !BoilerplateKeywords.slice(0, 2).includes(k.keyword))
507
+ .map(k => ['rd-keyword', k.line, `Rd file '${p.base}': keyword '${k.keyword}' is not one of the standard keywords`])],
508
+ [c => c.docStyle, s3Names],
509
+ [c => c.examples, examples]
510
+ ];
511
+ /** the pages grouped by `key`, only the groups of more than one */
512
+ function shared(items, key) {
513
+ const m = new Map();
514
+ items.forEach(i => m.set(key(i), [...m.get(key(i)) ?? [], i]));
515
+ return [...m].filter(([, g]) => g.length > 1);
516
+ }
517
+ /** `checking Rd metadata`: names and aliases that more than one page uses, and the package aliases */
518
+ function checkMetadata(pages, pkg, add) {
519
+ const named = pages.filter(p => p.name !== undefined);
520
+ for (const [name, ps] of shared(named, p => p.name ?? '')) {
521
+ ps.slice(1).forEach(p => add('rd-duplicate-name', p.file, `Rd files with duplicated name '${name}': ${ps.map(x => x.base).join(', ')}`, p.nameLine));
522
+ }
523
+ for (const [alias, ps] of shared(pages.flatMap(p => p.aliases.map(a => [a, p])), ([a]) => a)) {
524
+ ps.slice(1).forEach(([, p]) => add('rd-duplicate-alias', p.file, `Rd files with duplicated alias '${alias}': ${ps.map(([, x]) => x.base).join(', ')}`, 1));
525
+ }
526
+ named.filter(p => p.aliases.length === 0).forEach(p => add('rd-missing-alias', p.file, `Rd files without \\alias: '${p.base}'`, 1));
527
+ const own = `${pkg}-package`;
528
+ const all = pages.flatMap(p => p.aliases.filter(a => a.endsWith('-package')).map(a => [a, p]));
529
+ const hasOwn = all.some(([a]) => a === own);
530
+ all.filter(([a]) => !(hasOwn && a.toLowerCase() === own.toLowerCase())).forEach(([a, p]) => add('rd-package-alias', p.file, `Invalid package aliases in Rd file '${p.base}': '${a}'`, 1));
531
+ for (const [lower, ps] of shared(named, p => p.name?.toLowerCase() ?? '')) {
532
+ if (new Set(ps.map(p => p.name)).size > 1) {
533
+ ps.forEach(p => add('rd-name-case', p.file, `Rd files whose name differs only by case ('${lower}'): ${ps.map(x => `'${x.name}'`).join(', ')}`, p.nameLine));
534
+ }
535
+ }
536
+ }
537
+ /** `checking Rd cross-references`: where each link of the pages points */
538
+ function checkCrossReferences(pages, ctx, info, uncertain, add) {
539
+ const own = new Set(pages.flatMap(p => p.aliases));
540
+ const linked = new Set([...info.declared.get('Depends') ?? [], ...info.declared.get('Imports') ?? []]);
541
+ const declared = new Set(cmd_check_util_1.DependencyFields.flatMap(f => info.declared.get(f) ?? []));
542
+ const sigdb = ctx.deps.hasSignatureDatabase();
543
+ const reported = new Set();
544
+ for (const page of pages) {
545
+ for (const { pkg, topic, line, shown } of page.links) {
546
+ const checkable = uncertain && /^[A-Za-z.][A-Za-z0-9._]*$/.test(topic);
547
+ const exporters = ctx.deps.packagesExporting(topic);
548
+ let missing = false;
549
+ if (pkg === undefined) {
550
+ missing = checkable && sigdb && !own.has(topic) && (0, r_base_packages_1.baseRExportOwner)(topic) === undefined && !exporters.some(p => linked.has(p));
551
+ }
552
+ else if (pkg !== info.name && !(0, r_base_packages_1.isBaseRPackage)(pkg) && !declared.has(pkg)) {
553
+ if (!reported.has(pkg)) {
554
+ reported.add(pkg);
555
+ add('rd-undeclared-package', page.file, `Undeclared package '${pkg}' in Rd xrefs`, line);
556
+ }
557
+ }
558
+ else if (pkg !== info.name && checkable) {
559
+ const owner = (0, r_base_packages_1.baseRExportOwner)(topic);
560
+ missing = (0, r_base_packages_1.isBaseRPackage)(pkg) ? owner !== undefined && owner !== pkg
561
+ : sigdb && ctx.deps.signatureSources().some(s => s.has(pkg)) && exporters.length > 0 && !exporters.includes(pkg);
562
+ }
563
+ if (missing) {
564
+ add('rd-missing-link', page.file, `Missing link(s) in Rd file '${page.base}': '${shown}'`, line, linter_format_1.LintingResultCertainty.Uncertain);
565
+ }
566
+ }
567
+ }
568
+ }
569
+ /** the Rd macros of the package: R's system macros, those of `man/macros`, and the configured ones */
570
+ function packageMacros(files, extra) {
571
+ const defined = files.entries.filter(e => !e.isDirectory && /^man\/macros\/[^/]+\.[Rr]d$/.test(e.relative))
572
+ .flatMap(e => [...(0, flowr_rd_file_1.parseRdMacros)(files.read(e.relative) ?? '')].map(([n, m]) => [n, m.params]));
573
+ return new Map([...SystemMacros.split(' ').map(m => [m, 0]), ...defined, ...extra.map(m => [m.replace(/^\\/, ''), 0])]);
574
+ }
575
+ /** Port of the Rd checks of `R CMD check`, run on the `man/*.Rd` sources. */
576
+ exports.RD_FILES = {
577
+ createSearch: () => flowr_search_builder_1.Q.from([]),
578
+ processSearchResult: (_elements, config, data) => {
579
+ const ctx = data.inspectContext();
580
+ const info = (0, cmd_check_util_1.packageInfo)(ctx);
581
+ const files = (0, package_files_1.packageFiles)(ctx, info.name);
582
+ if (files === undefined) {
583
+ return { results: [], '.meta': { checkedFiles: 0 } };
584
+ }
585
+ const { results, add } = (0, file_checks_1.fileFindings)(files);
586
+ const description = info.description?.content();
587
+ const has = (field) => (description?.get(field)?.length ?? 0) > 0;
588
+ const settings = { defEnc: has('Encoding'), macros: packageMacros(files, config.extraMacros), lenient: has('RdMacros') || config.extraMacros.length > 0 };
589
+ const pages = files.entries.filter(e => !e.isDirectory && /^man\/([^/]+\/)?[^/]+\.[Rr]d$/.test(e.relative) && !e.relative.startsWith('man/macros/'))
590
+ .flatMap(e => [files.read(e.relative)].filter(src => src !== undefined).map(src => checkPage(e.relative, src, settings)));
591
+ const methods = new Set([...info.namespace?.exportS3Generics ?? []].flatMap(([generic, classes]) => classes.map(c => `${generic}.${c}`)));
592
+ const env = { config, data, methods };
593
+ for (const page of pages) {
594
+ PageChecks.filter(([on]) => on(config)).forEach(([, run]) => run(page, env).forEach(([kind, line, message]) => add(kind, page.file, message, line)));
595
+ }
596
+ const news = files.read('inst/NEWS.Rd');
597
+ if (config.parse && news !== undefined) {
598
+ checkPage('inst/NEWS.Rd', news, { ...settings, defEnc: true }).diags.filter(d => (d.kind === 'rd-syntax' || d.kind === 'rd-unknown-macro') && d.level >= config.minLevel)
599
+ .forEach(d => add(d.kind, 'inst/NEWS.Rd', `NEWS.Rd:${d.line}: ${d.text}`, d.line));
600
+ }
601
+ if (config.metadata) {
602
+ checkMetadata(pages, info.name, add);
603
+ }
604
+ if (config.crossReferences) {
605
+ checkCrossReferences(pages, ctx, info, config.uncertainLinks, add);
606
+ }
607
+ return { results, '.meta': { checkedFiles: pages.length } };
608
+ },
609
+ prettyPrint: {
610
+ [linter_format_1.LintingPrettyPrintContext.Query]: result => `${result.kind} in ${result.file} at ${range_1.SourceLocation.format(result.loc)}`,
611
+ [linter_format_1.LintingPrettyPrintContext.Full]: result => `${result.message} (at ${range_1.SourceLocation.format(result.loc)})`
612
+ },
613
+ info: {
614
+ name: 'Rd Files',
615
+ tags: [linter_tags_1.LintingRuleTag.CmdCheck, linter_tags_1.LintingRuleTag.Robustness],
616
+ certainty: linter_format_1.LintingRuleCertainty.BestEffort,
617
+ description: 'Checks the Rd files: syntax, unknown macros, required and duplicated sections, metadata, cross-references, line widths, contents, and the example code.',
618
+ defaultConfig: () => ({ parse: true, minLevel: -1, metadata: true, crossReferences: true, uncertainLinks: true, lineWidths: true, usageWidth: 90, examplesWidth: 100, contents: true, requireValue: false, standardKeywords: false, keywords: StandardKeywords, docStyle: true, bibentries: true, examples: true, extraMacros: [] })
619
+ }
620
+ };
621
+ //# sourceMappingURL=rd-files.js.map