@eagleoutice/flowr 2.16.3 → 2.16.5

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 (148) hide show
  1. package/README.md +14 -14
  2. package/cli/repl/core.js +13 -2
  3. package/cli/repl/parser/slice-query-parser.d.ts +21 -5
  4. package/cli/repl/parser/slice-query-parser.js +33 -13
  5. package/core/steps/all/static-slicing/10-reconstruct.d.ts +2 -2
  6. package/dataflow/environments/built-in.d.ts +2 -0
  7. package/dataflow/environments/built-in.js +10 -2
  8. package/dataflow/environments/data-masking-functions.js +2 -1
  9. package/dataflow/environments/default-builtin-config.d.ts +31 -5
  10. package/dataflow/environments/default-builtin-config.js +12 -15
  11. package/dataflow/environments/query-fn-props.js +2 -1
  12. package/dataflow/eval/resolve/alias-tracking.js +5 -2
  13. package/dataflow/eval/resolve/node-value.js +1 -1
  14. package/dataflow/eval/resolve/resolve-argument.js +2 -0
  15. package/dataflow/eval/resolve/resolve-strings.d.ts +10 -0
  16. package/dataflow/eval/resolve/resolve-strings.js +79 -12
  17. package/dataflow/eval/resolve/resolve.js +2 -6
  18. package/dataflow/extractor.js +11 -4
  19. package/dataflow/graph/applied-arguments.d.ts +5 -0
  20. package/dataflow/graph/applied-arguments.js +17 -0
  21. package/dataflow/graph/df-helper.js +2 -2
  22. package/dataflow/graph/graph.d.ts +5 -0
  23. package/dataflow/graph/graph.js +5 -0
  24. package/dataflow/info.js +8 -1
  25. package/dataflow/internal/linker.js +35 -13
  26. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.d.ts +9 -1
  27. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +32 -12
  28. package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +8 -1
  29. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +7 -4
  30. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +11 -1
  31. package/dataflow/internal/process/functions/call/named-call-handling.js +4 -2
  32. package/dataflow/internal/process/functions/call/quoted.js +3 -3
  33. package/dataflow/internal/program-order.js +7 -1
  34. package/dataflow/processor.d.ts +2 -0
  35. package/documentation/doc-util/doc-query.d.ts +1 -1
  36. package/documentation/doc-util/doc-query.js +3 -1
  37. package/documentation/doc-util/doc-timings.js +3 -2
  38. package/documentation/doc-util/doc-types.js +4 -0
  39. package/documentation/wiki-create-linting-rules.js +1 -1
  40. package/documentation/wiki-linter.d.ts +14 -0
  41. package/documentation/wiki-linter.js +341 -126
  42. package/linter/linter-executor.js +7 -0
  43. package/linter/linter-rules.d.ts +47 -47
  44. package/linter/rules/absolute-path.d.ts +1 -1
  45. package/linter/rules/absolute-path.js +6 -4
  46. package/linter/rules/cmd-check/call-arguments.d.ts +1 -1
  47. package/linter/rules/cmd-check/call-arguments.js +10 -5
  48. package/linter/rules/cmd-check/compiled-code.d.ts +1 -1
  49. package/linter/rules/cmd-check/compiled-code.js +1 -1
  50. package/linter/rules/cmd-check/conformance.d.ts +5 -1
  51. package/linter/rules/cmd-check/conformance.js +64 -64
  52. package/linter/rules/cmd-check/description-metadata.d.ts +1 -1
  53. package/linter/rules/cmd-check/description-metadata.js +1 -1
  54. package/linter/rules/cmd-check/documentation-mismatch.d.ts +6 -0
  55. package/linter/rules/cmd-check/foreign-function-calls.d.ts +1 -1
  56. package/linter/rules/cmd-check/foreign-function-calls.js +1 -1
  57. package/linter/rules/cmd-check/namespace-tampering.d.ts +1 -1
  58. package/linter/rules/cmd-check/namespace-tampering.js +1 -1
  59. package/linter/rules/cmd-check/non-ascii-code.d.ts +1 -1
  60. package/linter/rules/cmd-check/non-ascii-code.js +1 -1
  61. package/linter/rules/cmd-check/package-data.d.ts +3 -1
  62. package/linter/rules/cmd-check/package-data.js +1 -1
  63. package/linter/rules/cmd-check/package-hooks.d.ts +2 -2
  64. package/linter/rules/cmd-check/package-hooks.js +13 -5
  65. package/linter/rules/cmd-check/package-metafiles.d.ts +1 -1
  66. package/linter/rules/cmd-check/package-metafiles.js +1 -1
  67. package/linter/rules/cmd-check/package-structure.d.ts +1 -1
  68. package/linter/rules/cmd-check/package-structure.js +1 -1
  69. package/linter/rules/cmd-check/rd-files.d.ts +17 -1
  70. package/linter/rules/cmd-check/rd-files.js +1 -1
  71. package/linter/rules/cmd-check/true-false-abbreviation.d.ts +1 -1
  72. package/linter/rules/cmd-check/true-false-abbreviation.js +1 -1
  73. package/linter/rules/dataframe-access-validation.d.ts +1 -1
  74. package/linter/rules/dataframe-access-validation.js +1 -1
  75. package/linter/rules/dead-code.d.ts +4 -4
  76. package/linter/rules/dead-code.js +19 -4
  77. package/linter/rules/deprecated-functions.d.ts +1 -1
  78. package/linter/rules/deprecated-functions.js +1 -1
  79. package/linter/rules/file-path-validity.d.ts +6 -2
  80. package/linter/rules/file-path-validity.js +7 -3
  81. package/linter/rules/namespace-access.d.ts +3 -3
  82. package/linter/rules/namespace-access.js +12 -3
  83. package/linter/rules/naming-convention.d.ts +1 -1
  84. package/linter/rules/naming-convention.js +1 -1
  85. package/linter/rules/network-functions.d.ts +1 -1
  86. package/linter/rules/network-functions.js +1 -1
  87. package/linter/rules/no-leaked-credentials.d.ts +1 -1
  88. package/linter/rules/no-leaked-credentials.js +1 -1
  89. package/linter/rules/problematic-inputs.d.ts +2 -2
  90. package/linter/rules/problematic-inputs.js +4 -4
  91. package/linter/rules/roxygen-arguments.d.ts +2 -2
  92. package/linter/rules/roxygen-arguments.js +2 -2
  93. package/linter/rules/seeded-randomness.d.ts +2 -2
  94. package/linter/rules/seeded-randomness.js +2 -2
  95. package/linter/rules/software-has-license.d.ts +2 -2
  96. package/linter/rules/software-has-license.js +2 -2
  97. package/linter/rules/software-has-tests.d.ts +2 -2
  98. package/linter/rules/software-has-tests.js +2 -2
  99. package/linter/rules/stop-with-call-arg.d.ts +3 -3
  100. package/linter/rules/stop-with-call-arg.js +22 -5
  101. package/linter/rules/syntactically-valid.d.ts +1 -1
  102. package/linter/rules/syntactically-valid.js +1 -1
  103. package/linter/rules/unclosed-connection.d.ts +2 -2
  104. package/linter/rules/unclosed-connection.js +2 -2
  105. package/linter/rules/undefined-symbol.d.ts +1 -1
  106. package/linter/rules/undefined-symbol.js +27 -4
  107. package/linter/rules/unescaped-arguments.d.ts +1 -1
  108. package/linter/rules/unescaped-arguments.js +1 -1
  109. package/linter/rules/unused-definition.d.ts +1 -1
  110. package/linter/rules/unused-definition.js +21 -2
  111. package/linter/rules/unused-import.d.ts +1 -1
  112. package/linter/rules/unused-import.js +1 -1
  113. package/linter/rules/useless-loop.d.ts +1 -1
  114. package/linter/rules/useless-loop.js +1 -1
  115. package/package.json +1 -1
  116. package/project/context/flowr-analyzer-environment-context.d.ts +1 -1
  117. package/project/context/flowr-analyzer-environment-context.js +2 -1
  118. package/project/context/flowr-analyzer-files-context.js +12 -11
  119. package/project/dependency-version-space.js +4 -6
  120. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.d.ts +2 -0
  121. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +9 -8
  122. package/project/plugins/file-plugins/flowr-analyzer-test-file-plugin.js +1 -1
  123. package/project/plugins/file-plugins/flowr-analyzer-vignette-file-plugin.js +1 -1
  124. package/queries/catalog/dependencies-query/data-flow.d.ts +2 -0
  125. package/queries/catalog/dependencies-query/data-flow.js +6 -0
  126. package/queries/catalog/dependencies-query/dependencies-query-executor.js +31 -0
  127. package/queries/catalog/dependencies-query/dependencies-query-format.d.ts +5 -0
  128. package/queries/catalog/dependencies-query/implicit-echo.js +29 -30
  129. package/queries/catalog/dependencies-query/plot-objects.js +6 -2
  130. package/queries/catalog/dice-query/dice-query-format.d.ts +1 -1
  131. package/queries/catalog/dice-query/dice-query-format.js +1 -1
  132. package/queries/catalog/slice-query-options.d.ts +3 -3
  133. package/queries/catalog/slice-query-options.js +1 -1
  134. package/queries/catalog/static-slice-query/static-slice-query-executor.js +12 -1
  135. package/queries/catalog/static-slice-query/static-slice-query-format.d.ts +7 -1
  136. package/queries/catalog/static-slice-query/static-slice-query-format.js +4 -2
  137. package/queries/query.d.ts +2 -2
  138. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-normalize.js +19 -56
  139. package/reconstruct/inline/source-inline-map.d.ts +1 -1
  140. package/reconstruct/inline/source-inline-map.js +5 -3
  141. package/reconstruct/reconstruct.d.ts +8 -1
  142. package/reconstruct/reconstruct.js +12 -3
  143. package/slicing/static/removal-slice.d.ts +19 -0
  144. package/slicing/static/removal-slice.js +165 -0
  145. package/slicing/static/static-slicer.js +10 -5
  146. package/util/text/playground-link.d.ts +24 -1
  147. package/util/text/playground-link.js +16 -1
  148. package/util/version.js +2 -2
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.WikiLinter = void 0;
6
+ exports.WikiLinter = exports.LintingRuleExamples = void 0;
7
7
  const r_string_1 = require("../r-bridge/lang-4.x/ast/model/nodes/r-string");
8
8
  const doc_auto_gen_1 = require("./doc-util/doc-auto-gen");
9
9
  const doc_files_1 = require("./doc-util/doc-files");
@@ -11,6 +11,7 @@ const conformance_1 = require("../linter/rules/cmd-check/conformance");
11
11
  const linter_rules_1 = require("../linter/linter-rules");
12
12
  const doc_code_1 = require("./doc-util/doc-code");
13
13
  const doc_query_1 = require("./doc-util/doc-query");
14
+ const retriever_1 = require("../r-bridge/retriever");
14
15
  const doc_types_1 = require("./doc-util/doc-types");
15
16
  const path_1 = __importDefault(require("path"));
16
17
  const assert_1 = require("../util/assert");
@@ -26,15 +27,25 @@ const doc_maker_1 = require("./wiki-mk/doc-maker");
26
27
  const flowr_analyzer_context_1 = require("../project/context/flowr-analyzer-context");
27
28
  const config_1 = require("../config");
28
29
  const documentedContext = new flowr_analyzer_context_1.FlowrAnalyzerContext(config_1.FlowrConfig.default());
29
- const SpecialTagColors = {
30
+ /** one color per role of a tag: the kind of issue, R CMD check, quick fixes, the status of a rule, and every other aspect */
31
+ const TagColors = {
30
32
  [linter_tags_1.LintingRuleTag.Bug]: 'red',
31
- [linter_tags_1.LintingRuleTag.Security]: 'orange',
32
33
  [linter_tags_1.LintingRuleTag.Smell]: 'yellow',
33
- [linter_tags_1.LintingRuleTag.QuickFix]: 'lightgray'
34
+ [linter_tags_1.LintingRuleTag.Style]: 'blue',
35
+ [linter_tags_1.LintingRuleTag.CmdCheck]: 'blueviolet',
36
+ [linter_tags_1.LintingRuleTag.QuickFix]: 'brightgreen',
37
+ [linter_tags_1.LintingRuleTag.Experimental]: 'lightgrey'
34
38
  };
35
- function makeTagBadge(name, info) {
39
+ const AspectColor = 'teal';
40
+ const ConformancePageName = 'R CMD check Conformance';
41
+ const ConformancePage = `${doc_files_1.FlowrWikiBaseRef}/${ConformancePageName.replaceAll(' ', '-')}`;
42
+ /** text as a part of a shields.io badge url */
43
+ const shield = (text) => encodeURIComponent(text.replaceAll('-', '--').replaceAll('_', '__'));
44
+ function makeTagBadge(name, info, message, href = `${doc_files_1.FlowrWikiBaseRef}/Linter#${name}`) {
36
45
  const doc = (0, doc_types_1.getDocumentationForType)('LintingRuleTag::' + name, info, '', { fuzzy: true }).replaceAll('\n', ' ');
37
- return (0, html_hover_over_1.textWithTooltip)(`<a href='#${name}'>![` + name + '](https://img.shields.io/badge/' + name.toLowerCase() + `-${SpecialTagColors[name] ?? 'teal'}) </a>`, doc);
46
+ const color = TagColors[name] ?? AspectColor;
47
+ const badge = message === undefined ? `${shield(name)}-${color}` : `${shield(name)}-${shield(message)}-${color}`;
48
+ return (0, html_hover_over_1.textWithTooltip)(`<a href='${href}'>![${name}${message === undefined ? '' : ` ${message}`}](https://img.shields.io/badge/${badge}) </a>`, doc);
38
49
  }
39
50
  function getPageNameForLintingRule(name) {
40
51
  // convert file-path-validity to 'Linting Rule: File Path Validity'
@@ -229,110 +240,259 @@ See [here](${(0, doc_types_1.getTypePathLink)({ filePath: report.source.fileName
229
240
  }
230
241
  return result;
231
242
  }
232
- function registerRules(knownParser, tagTypes, format = 'short') {
233
- const ruleExplanations = new Map();
234
- rule(knownParser, 'deprecated-functions', 'DeprecatedFunctionsConfig', 'DEPRECATED_FUNCTIONS', 'lint-deprecated-functions', `
243
+ const ExampleDescription = 'Package: pkg\nVersion: 1.0\nTitle: A Package\nLicense: MIT\n';
244
+ const ExampleRoot = '/pkg';
245
+ /** what the wiki shows for each linting rule: its configuration and implementation types, its tests, and an example with findings */
246
+ exports.LintingRuleExamples = {
247
+ 'deprecated-functions': {
248
+ configType: 'DeprecatedFunctionsConfig', ruleType: 'DEPRECATED_FUNCTIONS', testfile: 'lint-deprecated-functions',
249
+ example: `
235
250
  first <- data.frame(x = c(1, 2, 3), y = c(1, 2, 3))
236
251
  second <- data.frame(x = c(1, 3, 2), y = c(1, 3, 2))
237
252
  dplyr::all_equal(first, second)
238
- `, tagTypes);
239
- rule(knownParser, 'network-functions', 'NetworkFunctionsConfig', 'NETWORK_FUNCTIONS', 'lint-network-functions', `
253
+
254
+ library(ggplot2)
255
+ theme(panel.grid = element_line(size = 1))
256
+ `
257
+ },
258
+ 'network-functions': {
259
+ configType: 'NetworkFunctionsConfig', ruleType: 'NETWORK_FUNCTIONS', testfile: 'lint-network-functions',
260
+ example: `
240
261
  read.csv("https://example.com/data.csv")
241
262
  download.file("https://foo.bar")
242
- `, tagTypes);
243
- rule(knownParser, 'file-path-validity', 'FilePathValidityConfig', 'FILE_PATH_VALIDITY', 'lint-file-path-validity', `
244
- my_data <- read.csv("C:/Users/me/Documents/My R Scripts/Reproducible.csv")
245
- `, tagTypes);
246
- rule(knownParser, 'absolute-file-paths', 'AbsoluteFilePathConfig', 'ABSOLUTE_PATH', 'lint-absolute-path', `
247
- read.csv("C:/Users/me/Documents/My R Scripts/Reproducible.csv")
248
- `, tagTypes);
249
- rule(knownParser, 'unused-definitions', 'UnusedDefinitionConfig', 'UNUSED_DEFINITION', 'lint-unused-definition', `
263
+ `
264
+ },
265
+ 'file-path-validity': {
266
+ configType: 'FilePathValidityConfig', ruleType: 'FILE_PATH_VALIDITY', testfile: 'lint-file-path-validity',
267
+ example: { code: 'survey <- read.csv("data/Survey.csv")', files: { 'R/survey.csv': 'id,value\n1,2\n' } }
268
+ },
269
+ 'absolute-file-paths': {
270
+ configType: 'AbsoluteFilePathConfig', ruleType: 'ABSOLUTE_PATH', testfile: 'lint-absolute-path',
271
+ example: 'read.csv("/home/me/project/data/survey.csv")',
272
+ config: { useAsWd: '/home/me/project' }
273
+ },
274
+ 'unused-definitions': {
275
+ configType: 'UnusedDefinitionConfig', ruleType: 'UNUSED_DEFINITION', testfile: 'lint-unused-definition',
276
+ example: `
250
277
  x <- 42
251
278
  y <- 3
252
279
  print(x)
253
- `, tagTypes);
254
- rule(knownParser, 'seeded-randomness', 'SeededRandomnessConfig', 'SEEDED_RANDOMNESS', 'lint-seeded-randomness', 'runif(1)', tagTypes);
255
- rule(knownParser, 'naming-convention', 'NamingConventionConfig', 'NAMING_CONVENTION', 'lint-naming-convention', `
256
- myVar <- 42
257
- print(myVar)
258
- `, tagTypes);
259
- rule(knownParser, 'dataframe-access-validation', 'DataFrameAccessValidationConfig', 'DATA_FRAME_ACCESS_VALIDATION', 'lint-dataframe-access-validation', `
280
+ `
281
+ },
282
+ 'seeded-randomness': {
283
+ configType: 'SeededRandomnessConfig', ruleType: 'SEEDED_RANDOMNESS', testfile: 'lint-seeded-randomness',
284
+ example: 'runif(1)'
285
+ },
286
+ 'naming-convention': {
287
+ configType: 'NamingConventionConfig', ruleType: 'NAMING_CONVENTION', testfile: 'lint-naming-convention',
288
+ example: `
289
+ testVar <- 5
290
+ testVarTwo <- 5
291
+ other_var <- 5
292
+ `
293
+ },
294
+ 'dataframe-access-validation': {
295
+ configType: 'DataFrameAccessValidationConfig', ruleType: 'DATA_FRAME_ACCESS_VALIDATION', testfile: 'lint-dataframe-access-validation',
296
+ example: `
260
297
  df <- data.frame(id = 1:5, name = 6:10)
261
298
  df[6, "value"]
262
- `, tagTypes);
263
- rule(knownParser, 'dead-code', 'DeadCodeConfig', 'DEAD_CODE', 'lint-dead-code', 'if(TRUE) 1 else 2', tagTypes);
264
- rule(knownParser, 'useless-loop', 'UselessLoopConfig', 'USELESS_LOOP', 'lint-useless-loop', 'for(i in c(1)) { print(i) }', tagTypes);
265
- rule(knownParser, 'stop-call', 'StopWithCallConfig', 'STOP_WITH_CALL_ARG', 'lint-stop-call', 'stop(42)', tagTypes);
266
- rule(knownParser, 'roxygen-arguments', 'RoxygenArgsConfig', 'ROXYGEN_ARGS', 'lint-roxygen-arguments', '#\' A function with two parameters, but only only one documented\n#\' @param a A variable\nf = function(a, b){return a;}', tagTypes);
267
- rule(knownParser, 'problematic-inputs', 'ProblematicInputsConfig', 'PROBLEMATIC_INPUTS', 'lint-problematic-inputs', `
299
+ `
300
+ },
301
+ 'dead-code': {
302
+ configType: 'DeadCodeConfig', ruleType: 'DEAD_CODE', testfile: 'lint-dead-code',
303
+ example: `
304
+ f <- function(x) {
305
+ return(x)
306
+ print("never reached")
307
+ }
308
+ if(TRUE) 1 else 2
309
+ `
310
+ },
311
+ 'useless-loop': {
312
+ configType: 'UselessLoopConfig', ruleType: 'USELESS_LOOP', testfile: 'lint-useless-loop',
313
+ example: 'for(i in c(1)) { print(i) }'
314
+ },
315
+ 'stop-call': {
316
+ configType: 'StopWithCallConfig', ruleType: 'STOP_WITH_CALL_ARG', testfile: 'lint-stop-call',
317
+ example: 'f <- function(x) stop(x)'
318
+ },
319
+ 'roxygen-arguments': {
320
+ configType: 'RoxygenArgsConfig', ruleType: 'ROXYGEN_ARGS', testfile: 'lint-roxygen-arguments',
321
+ example: '#\' A function with two parameters, but only only one documented\n#\' @param a A variable\nf = function(a, b){return a;}'
322
+ },
323
+ 'problematic-inputs': {
324
+ configType: 'ProblematicInputsConfig', ruleType: 'PROBLEMATIC_INPUTS', testfile: 'lint-problematic-inputs',
325
+ example: `
268
326
  function(x) {
269
327
  eval(x)
270
328
  }
271
- `, tagTypes);
272
- rule(knownParser, 'software-has-license', 'SoftwareHasLicenseConfig', 'SOFTWARE_HAS_LICENSE', 'lint-software-has-license', 'cat("a project without a license")', tagTypes);
273
- rule(knownParser, 'software-has-tests', 'SoftwareHasTestsConfig', 'SOFTWARE_HAS_TESTS', 'lint-software-has-tests', 'cat("hello")', tagTypes);
274
- rule(knownParser, 'no-leaked-credentials', 'NoLeakedCredentialsConfig', 'NO_LEAKED_CREDENTIALS', 'lint-no-leaked-credentials', 'password <- "s3cr3t"', tagTypes);
275
- rule(knownParser, 'undefined-symbol', 'UndefinedSymbolConfig', 'UNDEFINED_SYMBOL', 'lint-undefined-symbol', 'undefined_helper(42)', tagTypes);
276
- rule(knownParser, 'syntactically-valid', 'SyntacticallyValidConfig', 'SYNTACTICALLY_VALID', 'lint-syntactically-valid', 'x <- c(1, 2', tagTypes);
277
- rule(knownParser, 'unclosed-connection', 'UnclosedConnectionConfig', 'UNCLOSED_CONNECTION', 'lint-unclosed-connection', 'con <- file("data.csv")\nreadLines(con)', tagTypes);
278
- rule(knownParser, 'unused-import', 'UnusedImportConfig', 'UNUSED_IMPORT', 'lint-unused-import', 'library(stats)\nprint("no stats function is used")', tagTypes);
279
- rule(knownParser, 'unescaped-arguments', 'UnescapedArgumentsConfig', 'UNESCAPED_ARGUMENTS', 'lint-unescaped-arguments', 'function(dir) {\n\tsystem(paste0("ls ", dir))\n}', tagTypes);
280
- rule(knownParser, 'namespace-access', 'NamespaceAccessConfig', 'NAMESPACE_ACCESS', 'lint-namespace-access', 'dplyr:::filter(df, x > 1)', tagTypes);
281
- rule(knownParser, 'description-metadata', 'DescriptionMetadataConfig', 'DESCRIPTION_METADATA', 'cmd-check/lint-description-metadata', 'cat("a package with a malformed DESCRIPTION")', tagTypes);
282
- rule(knownParser, 'documentation-mismatch', 'DocumentationMismatchConfig', 'DOCUMENTATION_MISMATCH', 'cmd-check/lint-documentation-mismatch', 'f <- function(x, y) x + y', tagTypes);
283
- rule(knownParser, 'non-ascii-code', 'NonAsciiCodeConfig', 'NON_ASCII_CODE', 'cmd-check/lint-non-ascii-code', 'escaped <- function() message("Gr\\u00fc\\u00dfe")\nliteral <- function() message("Gr\u00fc\u00dfe")', tagTypes);
284
- rule(knownParser, 'class-string-comparison', 'ClassStringComparisonConfig', 'CLASS_STRING_COMPARISON', 'cmd-check/lint-class-string-comparison', 'f <- function(x) if(class(x) == "data.frame") nrow(x) else length(x)', tagTypes);
285
- rule(knownParser, 'true-false-abbreviation', 'TrueFalseAbbreviationConfig', 'TRUE_FALSE_ABBREVIATION', 'cmd-check/lint-true-false-abbreviation', 'f <- function(x) mean(x, na.rm = T)', tagTypes);
286
- rule(knownParser, 'bogus-return', 'BogusReturnConfig', 'BOGUS_RETURN', 'cmd-check/lint-bogus-return', 'f <- function(x) {\n\tif(is.null(x)) return\n\tx + 1\n}', tagTypes);
287
- rule(knownParser, 'package-hooks', 'PackageHooksConfig', 'PACKAGE_HOOKS', 'cmd-check/lint-package-hooks', '.onLoad <- function(libname, pkgname) {\n\tlibrary(stats)\n\tcat("Welcome!")\n}', tagTypes);
288
- rule(knownParser, 'global-environment-modification', 'GlobalEnvironmentModificationConfig', 'GLOBAL_ENVIRONMENT_MODIFICATION', 'cmd-check/lint-global-environment-modification', 'cache <- function(v) assign("cached", v, envir = globalenv())\ncount <- function() counter <<- counter + 1', tagTypes);
289
- rule(knownParser, 'namespace-tampering', 'NamespaceTamperingConfig', 'NAMESPACE_TAMPERING', 'cmd-check/lint-namespace-tampering', 'patch <- function() assignInNamespace("mean", function(x, ...) 42, "base")', tagTypes);
290
- rule(knownParser, 's3-method-consistency', 'S3MethodConsistencyConfig', 'S3_METHOD_CONSISTENCY', 'cmd-check/lint-s-three-method-consistency', 'print.myclass <- function(obj) cat("myclass")\n`size<-` <- function(x, v) { attr(x, "size") <- v; x }', tagTypes);
291
- rule(knownParser, 'foreign-function-calls', 'ForeignFunctionCallsConfig', 'FOREIGN_FUNCTION_CALLS', 'cmd-check/lint-foreign-function-calls', 'f <- function(x) .Call("C_mean", x)', tagTypes);
292
- rule(knownParser, 'dependency-declaration', 'DependencyDeclarationConfig', 'DEPENDENCY_DECLARATION', 'cmd-check/lint-dependency-declaration', 'f <- function(df) {\n\tlibrary(dplyr)\n\ttidyr::drop_na(df)\n}', tagTypes);
293
- rule(knownParser, 'call-arguments', 'CallArgumentsConfig', 'CALL_ARGUMENTS', 'cmd-check/lint-call-arguments', 'scale_by <- function(x, factor) x * factor\nf <- function(x) scale_by(x, fact = 2, center = TRUE)', tagTypes);
294
- rule(knownParser, 'package-structure', 'PackageStructureConfig', 'PACKAGE_STRUCTURE', 'cmd-check/lint-package-structure', 'f <- function() 1', tagTypes);
295
- rule(knownParser, 'compiled-code', 'CompiledCodeConfig', 'COMPILED_CODE', 'cmd-check/lint-compiled-code', 'f <- function(x) .Call("C_f", x)', tagTypes);
296
- rule(knownParser, 'package-metafiles', 'PackageMetafilesConfig', 'PACKAGE_METAFILES', 'cmd-check/lint-package-metafiles', 'f <- function() 1', tagTypes);
297
- rule(knownParser, 'rd-files', 'RdFilesConfig', 'RD_FILES', 'cmd-check/lint-rd-files', 'f <- function() 1', tagTypes);
298
- rule(knownParser, 'package-data', 'PackageDataConfig', 'PACKAGE_DATA', 'cmd-check/lint-package-data', 'f <- function() 1', tagTypes);
299
- rule(knownParser, 'package-runtime', 'PackageRuntimeConfig', 'PACKAGE_RUNTIME', 'cmd-check/lint-package-runtime', 'f <- function() library(pkg)', tagTypes);
300
- function rule(parser, name, configType, ruleType, testfile, example, types) {
329
+ `
330
+ },
331
+ 'software-has-license': {
332
+ configType: 'SoftwareHasLicenseConfig', ruleType: 'SOFTWARE_HAS_LICENSE', testfile: 'lint-software-has-license',
333
+ example: 'cat("a project without a license")'
334
+ },
335
+ 'software-has-tests': {
336
+ configType: 'SoftwareHasTestsConfig', ruleType: 'SOFTWARE_HAS_TESTS', testfile: 'lint-software-has-tests',
337
+ example: 'cat("hello")'
338
+ },
339
+ 'no-leaked-credentials': {
340
+ configType: 'NoLeakedCredentialsConfig', ruleType: 'NO_LEAKED_CREDENTIALS', testfile: 'lint-no-leaked-credentials',
341
+ example: 'password <- "s3cr3t"'
342
+ },
343
+ 'undefined-symbol': {
344
+ configType: 'UndefinedSymbolConfig', ruleType: 'UNDEFINED_SYMBOL', testfile: 'lint-undefined-symbol',
345
+ example: 'undefined_helper(42)'
346
+ },
347
+ 'syntactically-valid': {
348
+ configType: 'SyntacticallyValidConfig', ruleType: 'SYNTACTICALLY_VALID', testfile: 'lint-syntactically-valid',
349
+ example: 'x <- c(1, 2'
350
+ },
351
+ 'unclosed-connection': {
352
+ configType: 'UnclosedConnectionConfig', ruleType: 'UNCLOSED_CONNECTION', testfile: 'lint-unclosed-connection',
353
+ example: 'con <- file("data.csv")\nreadLines(con)'
354
+ },
355
+ 'unused-import': {
356
+ configType: 'UnusedImportConfig', ruleType: 'UNUSED_IMPORT', testfile: 'lint-unused-import',
357
+ example: 'library(stats)\nprint("no stats function is used")'
358
+ },
359
+ 'unescaped-arguments': {
360
+ configType: 'UnescapedArgumentsConfig', ruleType: 'UNESCAPED_ARGUMENTS', testfile: 'lint-unescaped-arguments',
361
+ example: 'function(dir) {\n\tsystem(paste0("ls ", dir))\n}'
362
+ },
363
+ 'namespace-access': {
364
+ configType: 'NamespaceAccessConfig', ruleType: 'NAMESPACE_ACCESS', testfile: 'lint-namespace-access',
365
+ example: 'dplyr:::filter(df, x > 1)'
366
+ },
367
+ 'description-metadata': {
368
+ configType: 'DescriptionMetadataConfig', ruleType: 'DESCRIPTION_METADATA', testfile: 'cmd-check/lint-description-metadata',
369
+ example: { code: 'x <- 1', files: { DESCRIPTION: 'Package: pkg\nVersion: 1.0\nTitle: A Package\nLicense: GPL-3 + file LICENSE\n' } }
370
+ },
371
+ 'documentation-mismatch': {
372
+ configType: 'DocumentationMismatchConfig', ruleType: 'DOCUMENTATION_MISMATCH', testfile: 'cmd-check/lint-documentation-mismatch',
373
+ example: { code: 'f <- function(x, y) x + y', files: { DESCRIPTION: ExampleDescription, 'NAMESPACE': 'export(f)\n', 'man/f.Rd': '\\name{f}\n\\alias{f}\n\\title{Add}\n\\usage{f(x)}\n\\arguments{\\item{x}{a number}}\n' } }
374
+ },
375
+ 'non-ascii-code': {
376
+ configType: 'NonAsciiCodeConfig', ruleType: 'NON_ASCII_CODE', testfile: 'cmd-check/lint-non-ascii-code',
377
+ example: 'escaped <- function() message("Gr\\u00fc\\u00dfe")\nliteral <- function() message("Gr\u00fc\u00dfe")'
378
+ },
379
+ 'class-string-comparison': {
380
+ configType: 'ClassStringComparisonConfig', ruleType: 'CLASS_STRING_COMPARISON', testfile: 'cmd-check/lint-class-string-comparison',
381
+ example: 'f <- function(x) if(class(x) == "data.frame") nrow(x) else length(x)'
382
+ },
383
+ 'true-false-abbreviation': {
384
+ configType: 'TrueFalseAbbreviationConfig', ruleType: 'TRUE_FALSE_ABBREVIATION', testfile: 'cmd-check/lint-true-false-abbreviation',
385
+ example: 'f <- function(x) mean(x, na.rm = T)'
386
+ },
387
+ 'bogus-return': {
388
+ configType: 'BogusReturnConfig', ruleType: 'BOGUS_RETURN', testfile: 'cmd-check/lint-bogus-return',
389
+ example: 'f <- function(x) {\n\tif(is.null(x)) return\n\tx + 1\n}'
390
+ },
391
+ 'package-hooks': {
392
+ configType: 'PackageHooksConfig', ruleType: 'PACKAGE_HOOKS', testfile: 'cmd-check/lint-package-hooks',
393
+ example: '.onLoad <- function(libname, pkgname) {\n\tlibrary(stats)\n\tcat("Loading")\n}\n.onAttach <- function(libname, pkgname) message("Welcome!")'
394
+ },
395
+ 'global-environment-modification': {
396
+ configType: 'GlobalEnvironmentModificationConfig', ruleType: 'GLOBAL_ENVIRONMENT_MODIFICATION', testfile: 'cmd-check/lint-global-environment-modification',
397
+ example: 'cache <- function(v) assign("cached", v, envir = globalenv())\ncount <- function() counter <<- counter + 1'
398
+ },
399
+ 'namespace-tampering': {
400
+ configType: 'NamespaceTamperingConfig', ruleType: 'NAMESPACE_TAMPERING', testfile: 'cmd-check/lint-namespace-tampering',
401
+ example: 'patch <- function() assignInNamespace("mean", function(x, ...) 42, "base")'
402
+ },
403
+ 's3-method-consistency': {
404
+ configType: 'S3MethodConsistencyConfig', ruleType: 'S3_METHOD_CONSISTENCY', testfile: 'cmd-check/lint-s-three-method-consistency',
405
+ example: 'print.myclass <- function(obj) cat("myclass")\n`size<-` <- function(x, v) { attr(x, "size") <- v; x }'
406
+ },
407
+ 'foreign-function-calls': {
408
+ configType: 'ForeignFunctionCallsConfig', ruleType: 'FOREIGN_FUNCTION_CALLS', testfile: 'cmd-check/lint-foreign-function-calls',
409
+ example: 'f <- function(x) .Call("C_mean", x)'
410
+ },
411
+ 'dependency-declaration': {
412
+ configType: 'DependencyDeclarationConfig', ruleType: 'DEPENDENCY_DECLARATION', testfile: 'cmd-check/lint-dependency-declaration',
413
+ example: { code: 'f <- function(df) {\n\tlibrary(dplyr)\n\ttidyr::drop_na(df)\n}', files: { DESCRIPTION: ExampleDescription } }
414
+ },
415
+ 'call-arguments': {
416
+ configType: 'CallArgumentsConfig', ruleType: 'CALL_ARGUMENTS', testfile: 'cmd-check/lint-call-arguments',
417
+ example: 'scale_by <- function(x, factor) x * factor\nf <- function(x) scale_by(x, fact = 2, center = TRUE)'
418
+ },
419
+ 'package-structure': {
420
+ configType: 'PackageStructureConfig', ruleType: 'PACKAGE_STRUCTURE', testfile: 'cmd-check/lint-package-structure',
421
+ example: { code: 'f <- function() 1', files: { DESCRIPTION: ExampleDescription, 'R/a:b.R': 'g <- function() 2\n' } }
422
+ },
423
+ 'compiled-code': {
424
+ configType: 'CompiledCodeConfig', ruleType: 'COMPILED_CODE', testfile: 'cmd-check/lint-compiled-code',
425
+ example: { code: 'f <- function(x) .Call("C_f", x)', files: { DESCRIPTION: ExampleDescription, 'NAMESPACE': 'useDynLib(pkg)\nexport(f)\n', 'src/Makevars': 'PKG_CXXFLAGS = -O3 -Wall -fPIC\n' } }
426
+ },
427
+ 'package-metafiles': {
428
+ configType: 'PackageMetafilesConfig', ruleType: 'PACKAGE_METAFILES', testfile: 'cmd-check/lint-package-metafiles',
429
+ example: { code: 'f <- function() 1', files: { DESCRIPTION: ExampleDescription, 'demo/a.R': 'f()\n', 'demo/b.R': 'f() + 1\n', 'demo/00Index': 'a A first demo\n' } }
430
+ },
431
+ 'rd-files': {
432
+ configType: 'RdFilesConfig', ruleType: 'RD_FILES', testfile: 'cmd-check/lint-rd-files',
433
+ example: { code: 'f <- function(x) x', files: { DESCRIPTION: ExampleDescription, 'man/f.Rd': '\\name{f}\n\\alias{f}\n\\title{F}\n\\description{D}\n\\details{\n a \\foo{x}}\n' } }
434
+ },
435
+ 'package-data': {
436
+ configType: 'PackageDataConfig', ruleType: 'PACKAGE_DATA', testfile: 'cmd-check/lint-package-data',
437
+ example: { code: 'f <- function() 1', files: { DESCRIPTION: ExampleDescription, 'data/notes.md': 'what the data means\n' } }
438
+ },
439
+ 'package-runtime': {
440
+ configType: 'PackageRuntimeConfig', ruleType: 'PACKAGE_RUNTIME', testfile: 'cmd-check/lint-package-runtime',
441
+ example: { code: 'f <- function() 1', files: { DESCRIPTION: ExampleDescription, 'NAMESPACE': 'export(f)\nexport(g)\n' } }
442
+ }
443
+ };
444
+ /** the kinds of issue a rule finds, each rule carries at most one */
445
+ const RuleKinds = [
446
+ [linter_tags_1.LintingRuleTag.Bug, 'Bugs'],
447
+ [linter_tags_1.LintingRuleTag.Smell, 'Smells'],
448
+ [linter_tags_1.LintingRuleTag.Style, 'Style']
449
+ ];
450
+ /** the tags of a rule as the wiki shows them: its kind, R CMD check, quick fixes, then the aspects by name */
451
+ function sortedTags(tags) {
452
+ const rank = (t) => RuleKinds.some(([k]) => k === t) ? 0 : t === linter_tags_1.LintingRuleTag.CmdCheck ? 1 : t === linter_tags_1.LintingRuleTag.QuickFix ? 2 : 3;
453
+ return tags.toSorted((a, b) => rank(a) - rank(b) || a.localeCompare(b));
454
+ }
455
+ /** one table per kind of rule, the rules without a kind check the files of a package */
456
+ function rulesOverview(info) {
457
+ const names = Object.keys(linter_rules_1.LintingRules).toSorted((a, b) => linter_rules_1.LintingRules[a].info.name.localeCompare(linter_rules_1.LintingRules[b].info.name));
458
+ const kindOf = (name) => RuleKinds.find(([k]) => linter_rules_1.LintingRules[name].info.tags.includes(k))?.[0];
459
+ const row = (name) => {
460
+ const rule = linter_rules_1.LintingRules[name].info;
461
+ const finds = rule.description.split(/\.\s+(?=[A-Z`])/)[0].replace(/^Finds /, '').replace(/\.$/, '');
462
+ const badges = sortedTags(rule.tags).filter(t => !RuleKinds.some(([k]) => k === t)).map(t => makeTagBadge(t, info));
463
+ /* the steps are text, a badge naming them grows with them and squeezes the others */
464
+ const step = (n) => `[${n}](${ConformancePage}#cmd-check-${n})`;
465
+ const steps = cmdCheckRuns(name).map(r => r.from === r.to ? step(r.from) : `${step(r.from)}–${step(r.to)}`).join(', ');
466
+ return `| [${rule.name}](${doc_files_1.FlowrWikiBaseRef}/${encodeURIComponent(getPageNameForLintingRule(name))}) | ${finds.replaceAll('|', '\\|')}${steps === '' ? '' : `<br><sub>R CMD check ${steps}</sub>`} | ${badges.join(' ')} |`;
467
+ };
468
+ const groups = [...RuleKinds.map(([kind, title]) => [title, names.filter(n => kindOf(n) === kind)]), ['Package Files', names.filter(n => kindOf(n) === undefined)]];
469
+ const anchor = (title) => `rules-${title.toLowerCase().replaceAll(' ', '-')}`;
470
+ const toc = groups.map(([title, rules]) => `[${title}](#${anchor(title)}) (${rules.length})`).join(', ');
471
+ return `${toc}\n\n` + groups
472
+ .map(([title, rules]) => `${(0, doc_structure_1.section)(title, 3, anchor(title))}
473
+
474
+ | Rule | Finds | Tags |
475
+ | :-- | :-- | :-- |
476
+ ${rules.map(row).join('\n')}`).join('\n\n');
477
+ }
478
+ function registerRules(knownParser, tagTypes) {
479
+ const ruleExplanations = new Map();
480
+ for (const [name, { configType, ruleType, testfile, example, config }] of Object.entries(exports.LintingRuleExamples)) {
481
+ rule(knownParser, name, configType, ruleType, testfile, example, config, tagTypes);
482
+ }
483
+ function rule(parser, name, configType, ruleType, testfile, example, config, types) {
301
484
  const rule = linter_rules_1.LintingRules[name];
302
- const tags = rule.info.tags.toSorted((a, b) => {
303
- // sort but specials first
304
- if (a === b) {
305
- return 0;
306
- }
307
- if (SpecialTagColors[a] && SpecialTagColors[b]) {
308
- return SpecialTagColors[b].localeCompare(SpecialTagColors[a]);
309
- }
310
- else if (SpecialTagColors[a]) {
311
- return -1;
312
- }
313
- else if (SpecialTagColors[b]) {
314
- return 1;
315
- }
316
- return a.localeCompare(b);
317
- }).map(t => makeTagBadge(t, types)).join(' ');
485
+ const tags = sortedTags(rule.info.tags).map(t => t === linter_tags_1.LintingRuleTag.CmdCheck ? cmdCheckBadge(name, types) : makeTagBadge(t, types)).join(' ');
318
486
  const certaintyDoc = (0, doc_types_1.getDocumentationForType)(`LintingRuleCertainty::${rule.info.certainty}`, types, '', { fuzzy: true }).replaceAll('\n', ' ');
319
487
  const certaintyText = `\`${(0, html_hover_over_1.textWithTooltip)(rule.info.certainty, certaintyDoc)}\``;
320
- if (format === 'short') {
321
- ruleExplanations.set(name, () => Promise.resolve(`
322
- **[${rule.info.name}](${doc_files_1.FlowrWikiBaseRef}/${encodeURIComponent(getPageNameForLintingRule(name))}):** ${rule.info.description} [see ${(0, doc_types_1.shortLinkFile)(ruleType, types)}]\\
323
- ${tags}${cmdCheckStepsOf(name, false) === '' ? '' : `\\\n\t${cmdCheckStepsOf(name, false)}`}
324
-
325
- `.trim()));
326
- }
327
- else {
328
- ruleExplanations.set(name, async () => `
488
+ ruleExplanations.set(name, async () => `
329
489
 
330
490
  ${(0, doc_auto_gen_1.autoGenHeader)({ filename: module.filename, purpose: 'linter' })}
331
491
  ${(0, doc_structure_1.section)(rule.info.name + `&emsp;<sup>[<a href="${doc_files_1.FlowrWikiBaseRef}/Linter">overview</a>]</sup>`, 2, name)}
332
492
 
333
493
  ${tags}
334
494
 
335
- ${cmdCheckStepsOf(name, true)}
495
+ ${cmdCheckStepsOf(name)}
336
496
 
337
497
  This rule is a ${certaintyText} rule.
338
498
 
@@ -345,32 +505,85 @@ _This linting rule is implemented in ${(0, doc_types_1.shortLinkFile)(ruleType,
345
505
  Linting rules can be configured by passing a configuration object to the linter query as shown in the example below.
346
506
  The \`${name}\` rule accepts the following configuration options:
347
507
 
348
- ${Object.keys(linter_rules_1.LintingRules[name].info.defaultConfig(documentedContext)).sort().map(key => `- ${(0, doc_types_1.shortLink)(`${configType}:::${key}`, types)}\\\n${(0, doc_types_1.getDocumentationForType)(`${configType}::${key}`, types)}`).join('\n')}
508
+ ${Object.keys(linter_rules_1.LintingRules[name].info.defaultConfig(documentedContext)).sort().map(key => `- ${(0, doc_types_1.shortLink)(`${configType}:::${key}`, types)}\\\n${(0, doc_types_1.getDocumentationForType)(`${configType}::${key}`, types)}${cmdCheckStepsOfOption(name, key)}`).join('\n')}
349
509
 
350
510
  ### Examples
351
511
 
352
- ${(0, doc_code_1.codeBlock)('r', example)}
512
+ ${typeof example === 'string' ? (0, doc_code_1.codeBlock)('r', example) : `A project with the code \`R/code.R\`:\n\n${(0, doc_code_1.codeBlock)('r', example.code)}\n\nand the files\n\n${Object.entries(example.files).map(([file, content]) => `\`${file}\`:\n\n${(0, doc_code_1.codeBlock)(file.endsWith('.R') ? 'r' : 'text', content.trimEnd())}`).join('\n\n')}`}
353
513
 
354
514
  The linting query can be used to run this rule on the above example:
355
515
 
356
- ${await (0, doc_query_1.showQuery)(parser, example, [{ type: 'linter', rules: [{ name, config: {} }] }], { collapseQuery: true })}
516
+ ${await exampleQuery(parser, name, example, config)}
357
517
 
358
518
  ${rule.info.tags.includes(linter_tags_1.LintingRuleTag.CmdCheck) ? `More examples are the test cases in ${(0, doc_files_1.linkFlowRSourceFile)(`test/functionality/linter/${testfile}.test.ts`)}.` : buildSamplesFromLinterTestCases(parser, `${testfile}.test.ts`)}
359
519
 
360
520
  `.trim());
361
- }
362
521
  }
363
522
  return ruleExplanations;
364
523
  }
524
+ /** runs the linter query on a rule's wiki example, refusing an example that shows no finding or an error */
525
+ async function exampleQuery(parser, name, example, config = {}) {
526
+ const queries = [{ type: 'linter', rules: [{ name, config: config }] }];
527
+ const shown = typeof example === 'string' ? await (0, doc_query_1.showQuery)(parser, example, queries, { collapseQuery: true })
528
+ : await (0, doc_query_1.showQuery)(parser, `${retriever_1.fileProtocol}${ExampleRoot}/R/code.R`, queries, {
529
+ collapseQuery: true,
530
+ files: [['R/code.R', example.code], ...Object.entries(example.files)].map(([file, content]) => ({ name: `${ExampleRoot}/${file}`, content }))
531
+ });
532
+ if (shown.includes('_no findings_') || shown.includes('Error during execution of rule') || shown.includes('rules failed to execute')) {
533
+ throw new Error(`the wiki example of ${name} must show a finding: ${shown}`);
534
+ }
535
+ return shown;
536
+ }
365
537
  const ConformanceSymbol = {
366
538
  [conformance_1.ConformanceLevel.Full]: '🟩',
367
539
  [conformance_1.ConformanceLevel.Static]: '🔷',
368
540
  [conformance_1.ConformanceLevel.Partial]: '🔶'
369
541
  };
370
- /** the R CMD check steps a rule covers, as links into the conformance table */
371
- function cmdCheckStepsOf(name, withCoverage) {
542
+ /** the R CMD check steps a rule covers, consecutive steps joined into one run */
543
+ function cmdCheckRuns(name) {
544
+ const runs = [];
545
+ for (const e of (0, conformance_1.numberedConformance)().filter(e => e.rules.includes(name))) {
546
+ const last = runs.at(-1);
547
+ if (last !== undefined && last.to + 1 === e.number) {
548
+ last.to = e.number;
549
+ }
550
+ else {
551
+ runs.push({ from: e.number, to: e.number });
552
+ }
553
+ }
554
+ return runs;
555
+ }
556
+ /** the cmd-check badge, naming the R CMD check steps the rule covers */
557
+ function cmdCheckBadge(name, info) {
558
+ const steps = cmdCheckRuns(name).map(r => r.from === r.to ? `${r.from}` : `${r.from}–${r.to}`).join(', ');
559
+ return steps === '' ? makeTagBadge(linter_tags_1.LintingRuleTag.CmdCheck, info) : makeTagBadge(linter_tags_1.LintingRuleTag.CmdCheck, info, steps, `${ConformancePage}`);
560
+ }
561
+ const MoreThanCmdCheck = '⭐';
562
+ /** how much of a step flowR covers, starred when it reports more */
563
+ function cmdCheckCoverage(e) {
564
+ return `${ConformanceSymbol[e.level]}${e.adds === undefined ? '' : MoreThanCmdCheck}`;
565
+ }
566
+ /** what flowR adds to a step and what it leaves out */
567
+ function cmdCheckNote(e) {
568
+ return [e.adds === undefined ? undefined : `${MoreThanCmdCheck} also ${e.adds}`, e.note].filter(n => n !== undefined).join('<br>').replaceAll('|', '\\|');
569
+ }
570
+ /** an R CMD check step, linked to its code in R's `check.R` and its section in R Packages */
571
+ function cmdCheckStep(e) {
572
+ return `[${e.check.replaceAll('|', '\\|')}](${conformance_1.CmdCheckSource}#L${e.line}) ([book](${conformance_1.RPackagesCmdCheck}#${e.book}))`;
573
+ }
574
+ /** links to the R CMD check steps that `option` of rule `name` tunes */
575
+ function cmdCheckStepsOfOption(name, option) {
576
+ const steps = (0, conformance_1.numberedConformance)().filter(e => e.options?.includes(`${name}.${option}`));
577
+ return steps.length === 0 ? '' : `\\\n_R CMD check ${steps.map(e => `[#${e.number}](${ConformancePage}#cmd-check-${e.number} "checking ${e.check.replaceAll('"', '\'')}")`).join(', ')}_`;
578
+ }
579
+ /** the R CMD check steps a rule covers, each linked to the code of R that performs it */
580
+ function cmdCheckStepsOf(name) {
372
581
  const steps = (0, conformance_1.numberedConformance)().filter(e => e.rules.includes(name));
373
- return steps.length === 0 ? '' : `R CMD check: ${steps.map(e => `[#${e.number}](${doc_files_1.FlowrWikiBaseRef}/Linter#cmd-check-${e.number})${withCoverage ? ` ${ConformanceSymbol[e.level]}` : ''}`).join(', ')}`;
582
+ return steps.length === 0 ? '' : `This rule ports the following steps of \`R CMD check\` (see the [conformance table](${ConformancePage}) for the legend):
583
+
584
+ | # | Step | Coverage | Note |
585
+ |---|------|:--------:|------|
586
+ ${steps.map(e => `| [${e.number}](${ConformancePage}#cmd-check-${e.number}) | ${cmdCheckStep(e)} | ${cmdCheckCoverage(e)} | ${cmdCheckNote(e)} |`).join('\n')}`;
374
587
  }
375
588
  function getAllLintingRulesWithTag(tag) {
376
589
  return Object.entries(linter_rules_1.LintingRules).filter(([_, rule]) => rule.info.tags.includes(tag)).map(([name]) => name);
@@ -382,7 +595,6 @@ function linkToRule(name) {
382
595
  return `[${name}](${doc_files_1.FlowrWikiBaseRef}/${encodeURIComponent(getPageNameForLintingRule(name).replaceAll(' ', '-'))})`;
383
596
  }
384
597
  async function getTextMainPage(knownParser, tagTypes, ctx) {
385
- const rules = registerRules(knownParser, tagTypes.info);
386
598
  return `
387
599
  This page describes the flowR linter, which is a tool that utilizes flowR's dataflow analysis to find common issues in R scripts. The linter can currently be used through the linter ${ctx.linkPage('wiki/Query API', 'query')}.
388
600
  Some rules also draw on the ${ctx.linkPage('wiki/Signature Database', 'signature database')}.
@@ -409,36 +621,11 @@ ${(0, doc_structure_1.block)({
409
621
  content: `If you want to add a new linting rule, see ${ctx.linkPage('wiki/Create Linting Rules')}.`
410
622
  })}
411
623
 
412
- The following linting rules are available:
624
+ The following linting rules are available, grouped by the kind of issue they find.
625
+ Badges link to the [tags](#tags), steps of \`R CMD check\` to the [conformance page](${ConformancePage}).
413
626
 
414
- ${await (async () => {
415
- let result = '';
416
- for (const k of Object.keys(linter_rules_1.LintingRules).sort()) {
417
- const rule = rules.get(k);
418
- (0, assert_1.guard)(rule !== undefined, `Linting rule ${k} is not documented!`);
419
- result += '\n\n' + await rule();
420
- }
421
- return result;
422
- })()}
627
+ ${rulesOverview(tagTypes.info)}
423
628
 
424
- ${(0, doc_structure_1.section)('R CMD check Conformance', 2, 'r-cmd-check-conformance')}
425
-
426
- Rules tagged ${makeTagBadge(linter_tags_1.LintingRuleTag.CmdCheck, tagTypes.info)} port \`R CMD check\` (R 4.6.1, see [Writing R Extensions](${conformance_1.WritingRExtensionsCmdCheck}) and [R Packages](${conformance_1.RPackagesCmdCheck})).
427
- They run by default only for packages (config option \`linter.disabledTags\`).
428
- Below are all steps of \`R CMD check\`, numbered by us (R itself prints them as \`* checking ...\`), each linked to its code in [R's \`check.R\`](${conformance_1.CmdCheckSource}) and its section in R Packages.
429
-
430
- | | Coverage |
431
- | :-: | :-- |
432
- | ${ConformanceSymbol.full} | everything the step reports |
433
- | ${ConformanceSymbol.static} | what can be decided without building, installing, or running the package |
434
- | ${ConformanceSymbol.partial} | part of what the step reports |
435
-
436
- ${conformance_1.CmdCheckConformance.map(({ area }) => `${(0, doc_structure_1.section)(area, 3)}
437
-
438
- | # | Step (\`checking ...\`) | | Rules | Note |
439
- | --: | :-- | :-: | :-- | :-- |
440
- ${(0, conformance_1.numberedConformance)().filter(e => e.area === area).map(e => `| <a id="cmd-check-${e.number}"></a>${e.number} | [${e.check.replaceAll('|', '\\|')}](${conformance_1.CmdCheckSource}#L${e.line}) ([book](${conformance_1.RPackagesCmdCheck}#${e.book})) | ${ConformanceSymbol[e.level]} | ${e.rules.map(r => linkToRule(r)).join(', ')} | ${(e.note ?? '').replaceAll('|', '\\|')} |`).join('\n')}`).join('\n\n')}
441
-
442
629
  ${(0, doc_structure_1.section)('Quick Fixes', 2, 'quick-fixes')}
443
630
 
444
631
  Rules tagged ${makeTagBadge(linter_tags_1.LintingRuleTag.QuickFix, tagTypes.info)} attach a ${(0, doc_types_1.shortLink)('LintQuickFix', tagTypes.info)} to their results,
@@ -479,10 +666,37 @@ ${(0, doc_structure_1.section)('Result Certainty', 3, 'result-certainty')}
479
666
  | ---------------- | :---------- |
480
667
  ${Object.entries(linter_format_1.LintingResultCertainty).map(([name, certainty]) => `| <a id="${certainty}"></a> \`${certainty}\` | ${(0, doc_types_1.getDocumentationForType)('LintingResultCertainty::' + name, tagTypes.info).replaceAll('\n', ' ')} |`).join('\n')}
481
668
 
669
+ ${(0, doc_structure_1.section)('R CMD check', 2, 'r-cmd-check')}
670
+
671
+ Rules tagged ${makeTagBadge(linter_tags_1.LintingRuleTag.CmdCheck, tagTypes.info)} port \`R CMD check\`, they run by default only for packages (config option \`linter.disabledTags\`).
672
+ The [R CMD check conformance](${ConformancePage}) page lists every step of \`R CMD check\`, the rules covering it, and how far they go.
673
+
482
674
  `.trim();
483
675
  }
676
+ /** the page listing every step of R CMD check and the rules covering it */
677
+ function getConformancePage(tagTypes) {
678
+ return `${(0, doc_auto_gen_1.autoGenHeader)({ filename: module.filename, purpose: 'linter' })}
679
+
680
+ Rules tagged ${makeTagBadge(linter_tags_1.LintingRuleTag.CmdCheck, tagTypes.info)} port \`R CMD check\` (R 4.6.1, see [Writing R Extensions](${conformance_1.WritingRExtensionsCmdCheck}) and [R Packages](${conformance_1.RPackagesCmdCheck})).
681
+ They run by default only for packages (config option \`linter.disabledTags\`), see the [linter](${doc_files_1.FlowrWikiBaseRef}/Linter) for all rules.
682
+ Below are all steps of \`R CMD check\`, numbered by us (R itself prints them as \`* checking ...\`), each linked to its code in [R's \`check.R\`](${conformance_1.CmdCheckSource}) and its section in R Packages.
683
+
684
+ | | Coverage |
685
+ | :-: | :-- |
686
+ | ${ConformanceSymbol.full} | everything the step reports |
687
+ | ${ConformanceSymbol.static} | what can be decided without building, installing, or running the package |
688
+ | ${ConformanceSymbol.partial} | part of what the step reports |
689
+ | ${MoreThanCmdCheck} | flowR reports more than the step, the note says what |
690
+
691
+ ${conformance_1.CmdCheckConformance.map(({ area }) => `${(0, doc_structure_1.section)(area, 3)}
692
+
693
+ | # | Step (\`checking ...\`) | | Rules | Note |
694
+ | --: | :-- | :-: | :-- | :-- |
695
+ ${(0, conformance_1.numberedConformance)().filter(e => e.area === area).map(e => `| <a id="cmd-check-${e.number}"></a>${e.number} | ${cmdCheckStep(e)} | ${cmdCheckCoverage(e)} | ${e.rules.map(r => linkToRule(r)).join(', ')} | ${cmdCheckNote(e)} |`).join('\n')}`).join('\n\n')}
696
+ `;
697
+ }
484
698
  async function getRulesPages(knownParser, tagTypes) {
485
- const rules = registerRules(knownParser, tagTypes.info, 'long');
699
+ const rules = registerRules(knownParser, tagTypes.info);
486
700
  const result = {};
487
701
  for (const [name, rule] of rules) {
488
702
  const filepath = path_1.default.join('wiki', `${getPageNameForLintingRule(name)}.md`);
@@ -498,7 +712,8 @@ async function getTexts(parser, ctx) {
498
712
  });
499
713
  return {
500
714
  'main': await getTextMainPage(parser, tagTypes, ctx),
501
- ...await getRulesPages(parser, tagTypes)
715
+ ...await getRulesPages(parser, tagTypes),
716
+ [path_1.default.join('wiki', `${ConformancePageName}.md`)]: getConformancePage(tagTypes)
502
717
  };
503
718
  }
504
719
  /**
@@ -22,6 +22,11 @@ function withoutUntrustedRegexes(ruleName, config) {
22
22
  }
23
23
  return Object.fromEntries(Object.entries(config).filter(([k]) => !keys.includes(k)));
24
24
  }
25
+ /** the finding with the file it is in, which a rule pointing at a node of the program leaves to that node */
26
+ function locatedIn(found, idMap) {
27
+ const file = found.loc[4] ?? idMap.get([found.involvedId ?? []].flat()[0])?.info.file;
28
+ return file === found.loc[4] ? found : { ...found, loc: [found.loc[0], found.loc[1], found.loc[2], found.loc[3], file] };
29
+ }
25
30
  /**
26
31
  * Executes a specific linting rule on the given analysis provider input.
27
32
  */
@@ -36,8 +41,10 @@ async function executeLintingRule(ruleName, input, lintingRuleConfig) {
36
41
  const processStart = Date.now();
37
42
  const result = await rule.processSearchResult(searchResult, fullConfig, input);
38
43
  const processTime = Date.now() - processStart;
44
+ const { idMap } = await input.normalize();
39
45
  return {
40
46
  ...result,
47
+ results: result.results.map(found => locatedIn(found, idMap)),
41
48
  '.meta': {
42
49
  ...(result['.meta'] ?? {}),
43
50
  searchTimeMs: searchTime,