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
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ default_language_version:

repos:
- repo: https://github.com/lorenzwalthert/precommit
rev: b2a735b
rev: v0.2.2.9015
hooks:
- id: style-files
args: ['--ignore-start="^# styler: on$"', '--ignore-stop="^# styler: off$"']
Expand Down Expand Up @@ -84,7 +84,7 @@ repos:
tests/testthat/.*\.R(md)?
)$
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
rev: v4.2.0
hooks:
- id: check-added-large-files
args: ['--maxkb=200']
Expand All @@ -99,7 +99,7 @@ repos:
tests/testthat/reference-objects/.*|
)$
- repo: https://github.com/lorenzwalthert/gitignore-tidy
rev: d3e947d61fba8c6adde2707d3baa6ae36b989d5b
rev: 9dd648a2cbce0c0ce09255695b63ea4823699bec
hooks:
- id: tidy-gitignore
- repo: local
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
* If there are only empty lines in a code chunk, they are all removed (#936).
* `{` is not put on a new line after `=` and in `function() {` for some edge
cases (#939).
* Parsing of {roxygen2} example comments now also works for edge cases when
there is no literal code immediately following after the end of the example
section (#940).


# styler 1.7.0

Expand Down
5 changes: 4 additions & 1 deletion R/roxygen-examples-find.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ identify_start_to_stop_of_roxygen_examples_from_text <- function(text) {
if (length(starts) < 1L) {
return(integer())
}
stop_candidates <- grep("(^[^#]|^#'[\\s\t]*@)", text, perl = TRUE)
stop_candidates <- which(or(
grepl("(^[^#]|^#'[\\s\t]*@)", text, perl = TRUE),
grepl("^ *\t*$", text) & grepl("^#' *", lead(text))
))
stops <- map(starts, match_stop_to_start, stop_candidates) %>%
flatten_int()
if (length(stops) < 1L) {
Expand Down
2 changes: 1 addition & 1 deletion R/roxygen-examples.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#' @importFrom purrr map flatten_chr
#' @keywords internal
style_roxygen_code_example <- function(example, transformers, base_indention) {
example <- split(example, cumsum(grepl("^#' *@examples", example))) # TODO can this handle @examples 1
example <- split(example, cumsum(grepl("^#' *@examples", example)))
purrr::map(
example, style_roxygen_code_example_one,
transformers = transformers, base_indention = base_indention
Expand Down
6 changes: 3 additions & 3 deletions R/transform-files.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ make_transformer <- function(transformers,
) %>%
when(
include_roxygen_examples ~
parse_transform_serialize_roxygen(.,
transformers = transformers, base_indention = base_indention
),
parse_transform_serialize_roxygen(.,
transformers = transformers, base_indention = base_indention
),
~.
)
if (should_use_cache) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,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,13 @@
#' This
#'
#'
#' is stuff
#'
#' @examples
#' 1+1


#' nolint start
#' @examplesIf long_condition_line
#' 32 / 3
#' nolint end
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#' This
#'
#'
#' is stuff
#'
#' @examples
#' 1 + 1
#'

#' nolint start
#' @examplesIf long_condition_line
#' 32 / 3
#' nolint end
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 @@ -136,4 +136,9 @@ test_that("analogous to test-roxygen-examples-complete", {
"roxygen-examples-complete", "^26",
transformer = style_text
), NA)

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