Skip to content

Commit 9e6df34

Browse files
further simplify, unify helper naming
1 parent 08a861a commit 9e6df34

File tree

1 file changed

+17
-22
lines changed

1 file changed

+17
-22
lines changed

.ci/linters/rd/options_doc_check.R

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,20 @@
11
# Ensure that data.table options in code match documentation
22
check_options_documentation = function(rd_file) {
33
if (!grepl("\\name{data.table-options}", rd_file, fixed = TRUE)) return(invisible())
4-
4+
55
# Find options in R code
6-
walk_for_dt_options = function(expr) {
6+
walk_r_ast_for_options = function(expr) {
77
result = character()
88
if (is.call(expr) && length(expr) >= 2L && identical(expr[[1L]], quote(getOption)) && is.character(e2 <- expr[[2L]]) && startsWith(e2, "datatable.")) {
99
result = e2
1010
} else if (is.recursive(expr)) {
11-
result = c(result, unlist(lapply(expr, walk_for_dt_options)))
11+
result = c(result, unlist(lapply(expr, walk_r_ast_for_options)))
1212
}
1313
result
1414
}
15-
get_options_from_code = function() {
16-
list.files("R", pattern = "\\.R$", full.names = TRUE) |>
17-
lapply(\(f) lapply(parse(f), walk_for_dt_options)) |>
18-
unlist() |>
19-
unique() |>
20-
sort()
21-
}
22-
15+
2316
# Find options in documentation
24-
walk_rd = function(rd_element) {
17+
walk_rd_ast_for_options = function(rd_element) {
2518
result = character()
2619
if (!is.list(rd_element)) return(character())
2720
if (isTRUE(attr(rd_element, "Rd_tag") == "\\code") && length(rd_element) >= 1L) {
@@ -30,26 +23,28 @@ check_options_documentation = function(rd_file) {
3023
result = content
3124
}
3225
}
33-
c(result, unlist(lapply(rd_element, walk_rd)))
26+
c(result, unlist(lapply(rd_element, walk_rd_ast_for_options)))
3427
}
3528

36-
code_opts = get_options_from_code()
29+
code_opts = list.files("R", pattern = "\\.R$", full.names = TRUE) |>
30+
lapply(\(f) lapply(parse(f), walk_for_dt_options)) |>
31+
unlist() |>
32+
unique() |>
33+
setdiff("datatable.alloc")
3734
doc_opts = rd_file |>
3835
tools::parse_Rd() |>
3936
walk_rd() |>
40-
unique() |>
41-
sort()
42-
code_opts = setdiff(code_opts, "datatable.alloc")
37+
unique()
4338

4439
miss_in_doc = setdiff(code_opts, doc_opts)
4540
miss_in_code = setdiff(doc_opts, code_opts)
4641

47-
if (length(miss_in_doc) > 0 || length(miss_in_code) > 0) {
48-
if (length(miss_in_doc) > 0) {
49-
cat("Options in code but missing from docs:", paste(miss_in_doc, collapse = ", "), "\n")
42+
if (length(miss_in_doc) > 0L || length(miss_in_code) > 0L) {
43+
if (length(miss_in_doc) > 0L) {
44+
cat(sprintf("Options in code but missing from docs: %s\n", toString(miss_in_doc)))
5045
}
51-
if (length(miss_in_code) > 0) {
52-
cat("Options in docs but not in code:", paste(miss_in_code, collapse = ", "), "\n")
46+
if (length(miss_in_code) > 0L) {
47+
cat(sprintf("Options in docs but not in code: %s\n", toString(miss_in_code)))
5348
}
5449
stop("Please sync man/data.table-options.Rd with code options")
5550
}

0 commit comments

Comments
 (0)