Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep at most one empty line at the end of each example #880

Merged
merged 3 commits into from
Dec 24, 2021
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 NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
detected (#881).
* Add vignette on distributing style guide (#846, #861).
* ensure a trailing blank line also if the input is cached (#867).
* Preserve trailing blank line in roxygen examples to simplify concatenation of examples (#880).
* Fix argument name `filetype` in Example for `style_dir()` (#855).
* An error is now thrown on styling if input unicode characters can't be
correctly parsed for Windows and R < 4.2 (#883).
Expand Down
10 changes: 8 additions & 2 deletions R/roxygen-examples.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ style_roxygen_example_snippet <- function(code_snippet,
mask <- decomposed$mask
}
code_snippet <- post_parse_roxygen(code_snippet)
append_empty <- !is_dont &&
length(code_snippet) > 1L &&
last(code_snippet) == ""

cache_is_active <- cache_is_activated()
is_cached <- is_cached(
Expand All @@ -116,10 +119,13 @@ style_roxygen_example_snippet <- function(code_snippet,
parse_transform_serialize_r(transformers,
base_indention = base_indention, warn_empty = FALSE
)
} else {
code_snippet <- ensure_last_n_empty(code_snippet, n = 0)
}

code_snippet <- ensure_last_n_empty(
code_snippet,
n = ifelse(append_empty, 1L, 0L)
)

if (!is_cached && cache_is_active) {
cache_write(
code_snippet, transformers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ create_style_guide <- function(initialize = default_style_guide_attributes,
#' op<- pd_flat$token %in% "}"
#' }
#' op <-pd_flat$token %in% "'['"
#' }
#' \donttest{
#' op <- pd_flat$token %in% "']'"
#' }
Expand All @@ -74,4 +73,5 @@ create_style_guide <- function(initialize = default_style_guide_attributes,
#' }
#' \donttest{
#' op <- pd_flat$token %in%"]"
#' }
NULL

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

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#' }
#' # before this comment is a left-over space
#' another_function <- function() NULL
#'
#' @examples
#' my_fun <- function() {
#' print("hello world!")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#' this
#'
#' mey
#' @examples
#' 2 + 1
#'
NULL


#' this
#'
#' mey
#' @examples
#' 2 + 1
#'
#'
#'
#'
#'
#'
#'
NULL


#' this
#'
#' mey
#' @examples
#' 2 + 1
NULL

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#' this
#'
#' mey
#' @examples
#' 2 + 1
#'
NULL


#' this
#'
#' mey
#' @examples
#' 2 + 1
#'
NULL


#' this
#'
#' mey
#' @examples
#' 2 + 1
NULL
5 changes: 5 additions & 0 deletions tests/testthat/test-roxygen-examples-complete.R
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,9 @@ test_that("analogous to test-roxygen-examples-complete", {
"roxygen-examples-complete", "^25",
transformer = style_text
), NA)

expect_warning(test_collection(
"roxygen-examples-complete", "^26",
transformer = style_text
), NA)
})