Skip to content

Commit

Permalink
stricter requirements in doc generation (#1024)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelChirico authored Mar 29, 2022
1 parent 2d25025 commit 2309d0e
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions R/linter_tags.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,13 @@ available_linters <- function(packages = "lintr") {
rd_tags <- function(linter_name) {
linters <- available_linters()
tags <- platform_independent_sort(linters[["tags"]][[match(linter_name, linters[["linter"]])]])
if (length(tags) == 0L) {
stop("tags are required, but found none for ", linter_name)
}

c(
"\\section{Tags}{",
if (length(tags)) {
paste0("\\link[=", tags, "_linters]{", tags, "}", collapse = ", ")
} else {
"No tags are given."
},
paste0("\\link[=", tags, "_linters]{", tags, "}", collapse = ", "),
"}"
)
}
Expand All @@ -115,20 +114,17 @@ rd_linters <- function(tag_name) {
function(tag_list) tag_name %in% tag_list,
logical(1L)
)])
if (length(tagged) == 0L) {
stop("No linters found associated with tag ", tag_name)
}

c(
"\\section{Linters}{",
if (length(tagged)) {
c(
paste0("The following linters are tagged with '", tag_name, "':"),
"\\itemize{",
paste0("\\item{\\code{\\link{", tagged, "}}}"),
"}"
)
} else {
paste0("No linters are tagged with '", tag_name, "'.")
},
"}"
paste0("The following linters are tagged with '", tag_name, "':"),
"\\itemize{",
paste0("\\item{\\code{\\link{", tagged, "}}}"),
"}", # itemize
"}" # section
)
}

Expand All @@ -137,18 +133,21 @@ rd_linters <- function(tag_name) {
#' @noRd
rd_taglist <- function() {
linters <- available_linters()

tag_table <- table(unlist(linters[["tags"]]))
tags <- platform_independent_sort(unique(unlist(linters[["tags"]])))
# re-order
tag_table <- tag_table[tags]

c(
"\\section{Tags}{",
"The following tags exist:",
"\\itemize{",
vapply(tags, function(tag) {
n_linters <- sum(vapply(linters[["tags"]], function(tags) tag %in% tags, logical(1L)))
paste0("\\item{\\link[=", tag, "_linters]{", tag, "} (", n_linters, " linters)}")
paste0("\\item{\\link[=", tag, "_linters]{", tag, "} (", tag_table[[tag]], " linters)}")
}, character(1L)),
"}", # itemize
"}" # section
"}" # section
)
}

Expand Down

0 comments on commit 2309d0e

Please sign in to comment.