Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ S3method(merge,rd_section_inherit_section)
S3method(merge,rd_section_minidesc)
S3method(merge,rd_section_param)
S3method(merge,rd_section_prop)
S3method(merge,rd_section_r6_class)
S3method(merge,rd_section_reexport)
S3method(merge,rd_section_section)
S3method(merge,rd_section_seealso)
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ See `vignette("rd-S7")` for best practices.

## Individual tags

* Tags that expect single-line input now warn when they span multiple lines, catching a common class of mistake. Affected tags: `@aliases`, `@concept`, `@encoding`, `@exportClass`, `@exportMethod`, `@exportPattern`, `@exportS3Method`, `@importFrom`, `@importClassesFrom`, `@importMethodsFrom`, `@include`, `@keywords`, `@method`, `@name`, `@order`, `@rdname`, `@S3method`, `@template`, and `@useDynLib` (#1642, #1688). This may break some existing usage, but it prevents a wide range of otherwise silent errors.
* Tags that expect single-line input now warn when they span multiple lines, catching a common class of mistake. Affected tags: `@aliases`, `@concept`, `@encoding`, `@exportClass`, `@exportMethod`, `@exportPattern`, `@exportS3Method`, `@importFrom`, `@importClassesFrom`, `@importMethodsFrom`, `@include`, `@includeRmd`, `@inheritDotParams`, `@inheritParams`, `@inheritSection`, `@keywords`, `@method`, `@name`, `@order`, `@rdname`, `@S3method`, `@template`, and `@useDynLib` (#1642, #1688). This may break some existing usage, but it prevents a wide range of otherwise silent errors.
* Reexported functions now display with `()` appended (e.g. `fun()` instead of `fun`) on the reexports page, except for infix operators like `%>%` (#1222). They also use the modern (>= 4.1.0) linking style.
* `@description` no longer errors when the markdown text starts with a heading (#1705).
* `@examples` no longer warns about unmatched braces inside raw strings, or inside strings within R comments, e.g. `# '{greeting}'` (#1492).
Expand Down
2 changes: 1 addition & 1 deletion R/rd-describe-in.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ roxy_tag_parse.roxy_tag_describeIn <- function(x) {
)
NULL
} else {
tag_two_part(x, "a topic name", "a description")
tag_two_part(x, "a topic name", "a description", multiline = TRUE)
}
}

Expand Down
2 changes: 1 addition & 1 deletion R/rd-params.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' @export
roxy_tag_parse.roxy_tag_param <- function(x) {
tag_two_part(x, "an argument name", "a description")
tag_two_part(x, "an argument name", "a description", multiline = TRUE)
}

#' @export
Expand Down
4 changes: 2 additions & 2 deletions R/rd-s4.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' @export
roxy_tag_parse.roxy_tag_field <- function(x) {
tag_two_part(x, "a field name", "a description")
tag_two_part(x, "a field name", "a description", multiline = TRUE)
}
#' @export
roxy_tag_rd.roxy_tag_field <- function(x, base_path, env) {
Expand All @@ -14,7 +14,7 @@ format.rd_section_field <- function(x, ...) {

#' @export
roxy_tag_parse.roxy_tag_slot <- function(x) {
tag_two_part(x, "a slot name", "a description")
tag_two_part(x, "a slot name", "a description", multiline = TRUE)
}
#' @export
roxy_tag_rd.roxy_tag_slot <- function(x, base_path, env) {
Expand Down
2 changes: 1 addition & 1 deletion R/rd-s7.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' @export
roxy_tag_parse.roxy_tag_prop <- function(x) {
x <- tag_two_part(x, "a property name", "a description")
x <- tag_two_part(x, "a property name", "a description", multiline = TRUE)
if (is.null(x)) {
return()
}
Expand Down
2 changes: 1 addition & 1 deletion R/rd-template.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ roxy_tag_parse.roxy_tag_template <- function(x) {

#' @export
roxy_tag_parse.roxy_tag_templateVar <- function(x) {
tag_two_part(x, "a variable name", "a value")
tag_two_part(x, "a variable name", "a value", multiline = TRUE)
}

process_templates <- function(block, base_path) {
Expand Down
11 changes: 10 additions & 1 deletion R/tag-parser.R
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,23 @@ tag_name <- function(x) {
#' @param required Is the second part required (TRUE) or can it be blank
#' (FALSE)?
#' @param markdown Should the second part be parsed as markdown?
tag_two_part <- function(x, first, second, required = TRUE, markdown = TRUE) {
tag_two_part <- function(
x,
first,
second,
required = TRUE,
markdown = TRUE,
multiline = FALSE
) {
if (trimws(x$raw) == "") {
if (!required) {
warn_roxy_tag(x, "requires {first}")
} else {
warn_roxy_tag(x, "requires two parts: {first} and {second}")
}
NULL
} else if (!multiline && warn_if_multiline(x, trimws(x$raw))) {
NULL
} else if (!rdComplete(x$raw, is_code = FALSE)) {
warn_roxy_tag(x, "has mismatched braces or quotes")
NULL
Expand Down
9 changes: 8 additions & 1 deletion man/tag_parsers.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions tests/testthat/_snaps/tag-parser.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,17 @@
x test.R:1: @test must be only 1 line long, not 3.
i The first line is "a"

# tag_two_part() warns on multi-line content by default

Code
tag <- roxy_test_tag("foo bar\nbaz")
expect_parse_failure(tag_two_part(tag, "a name", "a value"))
Output
<message/rlang_message>
Message:
x test.R:1: @test must be only 1 line long, not 2.
i The first line is "foo bar"

# tag_value() warns on multi-line content

Code
Expand Down
11 changes: 11 additions & 0 deletions tests/testthat/test-tag-parser.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,17 @@ test_that("tag_words() warns on multi-line content", {
})
})

test_that("tag_two_part() warns on multi-line content by default", {
expect_snapshot({
tag <- roxy_test_tag("foo bar\nbaz")
expect_parse_failure(tag_two_part(tag, "a name", "a value"))
})

tag <- roxy_test_tag("foo bar\nbaz")
out <- tag_two_part(tag, "a name", "a value", multiline = TRUE)
expect_equal(out$val, list(name = "foo", description = "bar\nbaz"))
})

test_that("tag_value() warns on multi-line content", {
expect_snapshot({
tag <- roxy_test_tag("a\nb")
Expand Down
Loading