diff --git a/NEWS.md b/NEWS.md index 2e2c75d2..c892e970 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # roxygen2 (development version) +* All tags warn now if you only provide whitespace (#1228). + * Add support for inheriting 'note' fields via `@inherit pkg::fun note` (@pat-s, #1218) * Problems with the first tag in each block are now reported with the diff --git a/R/tag-parser.R b/R/tag-parser.R index 2e0a13b5..b5bc5e00 100644 --- a/R/tag-parser.R +++ b/R/tag-parser.R @@ -17,7 +17,7 @@ NULL #' @export #' @rdname tag_parsers tag_value <- function(x) { - if (x$raw == "") { + if (str_trim(x$raw) == "") { roxy_tag_warning(x, "requires a value") } else if (!rdComplete(x$raw, is_code = FALSE)) { roxy_tag_warning(x, "mismatched braces or quotes") @@ -30,7 +30,7 @@ tag_value <- function(x) { #' @export #' @rdname tag_parsers tag_inherit <- function(x) { - if (x$raw == "") { + if (str_trim(x$raw) == "") { roxy_tag_warning(x, "requires a value") } else if (!rdComplete(x$raw, is_code = FALSE)) { roxy_tag_warning(x, "mismatched braces or quotes") @@ -64,7 +64,7 @@ tag_inherit <- function(x) { #' @export #' @rdname tag_parsers tag_name <- function(x) { - if (x$raw == "") { + if (str_trim(x$raw) == "") { roxy_tag_warning(x, "requires a name") } else if (!rdComplete(x$raw, is_code = FALSE)) { roxy_tag_warning(x, "mismatched braces or quotes") @@ -161,7 +161,7 @@ tag_toggle <- function(x) { #' @export #' @rdname tag_parsers tag_code <- function(x) { - if (x$raw == "") { + if (str_trim(x$raw) == "") { roxy_tag_warning(x, "requires a value") } else { tryCatch({ @@ -178,7 +178,7 @@ tag_code <- function(x) { #' @export #' @rdname tag_parsers tag_examples <- function(x) { - if (x$raw == "") { + if (str_trim(x$raw) == "") { return(roxy_tag_warning(x, "requires a value")) } @@ -193,6 +193,10 @@ tag_examples <- function(x) { #' @export #' @rdname tag_parsers tag_markdown <- function(x) { + if (str_trim(x$raw) == "") { + return(roxy_tag_warning(x, "requires a value")) + } + x$val <- markdown_if_active(x$raw, x) x } @@ -200,7 +204,7 @@ tag_markdown <- function(x) { #' @export #' @rdname tag_parsers tag_markdown_with_sections <- function(x) { - if (x$raw == "") { + if (str_trim(x$raw) == "") { return(roxy_tag_warning(x, "requires a value")) } diff --git a/tests/testthat/test-tag-parser.R b/tests/testthat/test-tag-parser.R new file mode 100644 index 00000000..978f96d0 --- /dev/null +++ b/tests/testthat/test-tag-parser.R @@ -0,0 +1,18 @@ +test_that("tags containing only whitespace generate warning", { + tag <- roxy_tag("foo", " ") + + expect_parse_failure <- function(code) { + expect_warning(out <- code, "requires") + expect_null(out) + } + + expect_parse_failure(tag_value(tag)) + expect_parse_failure(tag_inherit(tag)) + expect_parse_failure(tag_name(tag)) + expect_parse_failure(tag_two_part(tag)) + expect_parse_failure(tag_name_description(tag)) + expect_parse_failure(tag_code(tag)) + expect_parse_failure(tag_examples(tag)) + expect_parse_failure(tag_markdown(tag)) + expect_parse_failure(tag_markdown_with_sections(tag)) +})