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

Remove leading blank lines when strict = TRUE #1056

Merged
merged 22 commits into from
Dec 26, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
cf8feae
Update transform-files.R
IndrajeetPatil Nov 8, 2022
75544d0
get started
IndrajeetPatil Nov 9, 2022
21ab4e8
pre-commit
github-actions[bot] Nov 9, 2022
89fd790
minor
IndrajeetPatil Nov 9, 2022
b37d847
add `is_roxygen_code_example` parameter
IndrajeetPatil Nov 10, 2022
d89f51d
fix regression
IndrajeetPatil Nov 10, 2022
7ea5656
comment out for now
IndrajeetPatil Nov 10, 2022
4fe3083
pre-commit
github-actions[bot] Nov 10, 2022
74eee56
Update tests-cache-require-serial.R
IndrajeetPatil Nov 10, 2022
5065352
Update R/transform-files.R
IndrajeetPatil Nov 10, 2022
a6f346e
simplify if statement
IndrajeetPatil Nov 10, 2022
aa282b1
pre-commit
github-actions[bot] Nov 10, 2022
b2cb5f2
Merge branch '1014_rm_leading_blank_line' of https://github.com/r-lib…
IndrajeetPatil Nov 10, 2022
6750556
Update .Rbuildignore
IndrajeetPatil Nov 10, 2022
0af4be5
pre-commit
github-actions[bot] Nov 10, 2022
4f29805
Merge branch 'main' into 1014_rm_leading_blank_line
IndrajeetPatil Nov 19, 2022
bcb62e5
Merge branch 'main' into 1014_rm_leading_blank_line
IndrajeetPatil Nov 23, 2022
697bf76
don't comment out failing tests
IndrajeetPatil Dec 10, 2022
617c70d
Merge branch 'main' into 1014_rm_leading_blank_line
IndrajeetPatil Dec 10, 2022
26be437
ensure that line breaks ony removed for top of file
lorenzwalthert Dec 24, 2022
e177051
Merge branch 'main' into 1014_rm_leading_blank_line
lorenzwalthert Dec 24, 2022
e143717
Merge branch 'main' into 1014_rm_leading_blank_line
IndrajeetPatil Dec 24, 2022
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
3 changes: 1 addition & 2 deletions R/roxygen-examples.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ style_roxygen_code_example_segment <- function(one_dont,
}
dont_seqs <- find_dont_seqs(one_dont)
split_segments <- split_roxygen_segments(one_dont, unlist(dont_seqs))
is_dont <-
seq2(1L, length(split_segments$separated)) %in% split_segments$selectors
is_dont <- seq2(1L, length(split_segments$separated)) %in% split_segments$selectors

map2(split_segments$separated, is_dont,
style_roxygen_example_snippet,
Expand Down
5 changes: 4 additions & 1 deletion R/transform-block.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ parse_transform_serialize_r_block <- function(pd_nested,
) %>%
unlist(use.names = FALSE)
}
c(rep("", start_line - 1L), serialized_transformed_text)
c(
rep("", if (start_line == 0L) start_line else start_line - 1L),
IndrajeetPatil marked this conversation as resolved.
Show resolved Hide resolved
serialized_transformed_text
)
}

#' Find the groups of expressions that should be processed together
Expand Down
13 changes: 10 additions & 3 deletions R/transform-files.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ transform_file <- function(path,
message_after_if_changed = " *",
...,
dry) {
char_after_path <- nchar(message_before) + nchar(path) + 1
max_char_after_message_path <- nchar(message_before) + max_char_path + 1
char_after_path <- nchar(message_before) + nchar(path) + 1L
max_char_after_message_path <- nchar(message_before) + max_char_path + 1L
n_spaces_before_message_after <-
max_char_after_message_path - char_after_path
if (!getOption("styler.quiet", FALSE)) {
Expand Down Expand Up @@ -256,14 +256,21 @@ parse_transform_serialize_r <- function(text,
transformers
)

strict <- transformers$more_specs_style_guide$strict
pd_split <- unname(split(pd_nested, pd_nested$block))
pd_blank <- find_blank_lines_to_next_block(pd_nested)

start_line <- if (strict) {
1L # FIXME: should be 0L for roxygen examples
IndrajeetPatil marked this conversation as resolved.
Show resolved Hide resolved
} else {
pd_blank[[i]]
}

text_out <- vector("list", length(pd_split))
for (i in seq_along(pd_split)) {
text_out[[i]] <- parse_transform_serialize_r_block(
pd_split[[i]],
pd_blank[[i]],
start_line = start_line,
transformers = transformers,
base_indention = base_indention
)
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/curly-curly/mixed-out.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

## ............................................................................
## line breaks ####
# not inserting line breaks
Expand Down
12 changes: 4 additions & 8 deletions tests/testthat/escaping/basic-escape-out.R
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
#' things
#'
#' @examples
#' call("\\.")
#' @examples call("\\.")
NULL


#' things
#'
#' @examples
#' call("\n")
#' @examples call("\n")
NULL

#' things
#'
#' @examples
#' call("\n")
#' @examples call("\n")
#' ano("\\.", further = X)
NULL


#' things
#'
#' @examples
#' call("\n")
#' @examples call("\n")
#' ano("\\.", further = X)
NULL

Expand Down
1 change: 0 additions & 1 deletion tests/testthat/indention_curly_brackets/custom-out.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

value <- 5
if (value > 0) {
print(value)
Expand Down

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
@@ -1,4 +1,3 @@

c(a |> b())

c(a + b |> c())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


test_that("hi there", {
I(am(a(package(x))))
})
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


test_that("hi there", {
I(am(a(package(x))))
})
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


test_that("hi there", {
I(am(a(package(x))))
})
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


test_that("hi there", {
I(am(a(package(x))))
})
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


test_that("hi there", {
I(am(a(package(x))))
})
6 changes: 2 additions & 4 deletions tests/testthat/roxygen-examples-complete/10-styler-r-ui-out.R
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ prettify_pkg <- function(transformers,
#' @param text A character vector with text to style.
#' @inheritParams style_pkg
#' @family stylers
#' @examples
#' style_text("call( 1)")
#' @examples style_text("call( 1)")
#' style_text("1 + 1", strict = FALSE)
#' style_text("a%>%b", scope = "spaces")
#' style_text("a%>%b; a", scope = "line_breaks")
Expand Down Expand Up @@ -199,8 +198,7 @@ prettify_any <- function(transformers,
#' @inheritSection transform_files Value
#' @inheritSection style_pkg Warning
#' @inheritSection style_pkg Roundtrip Validation
#' @examples
#' # the following is identical but the former is more convenient:
#' @examples # the following is identical but the former is more convenient:
#' file <- tempfile("styler", fileext = ".R")
#' xfun::write_utf8("1++1", file)
#' style_file(file, style = tidyverse_style, strict = TRUE)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@

#' Create a style guide
#'
#' @param reindention A list of parameters for regex re-indention, most
#' conveniently constructed using [specify_reindention()].
#' @examples
#' set_line_break_before_crly_opening <- function(pd_flat) {
#' @examples set_line_break_before_crly_opening <- function(pd_flat) {
#' op <- pd_flat$token %in% "'{'"
#' pd_flat$lag_newlines[op] <- 1L
#' pd_flat
Expand Down Expand Up @@ -51,8 +49,7 @@ create_style_guide <- function(initialize = default_style_guide_attributes,
#'
#' @param reindention A list of parameters for regex re-indention, most
#' conveniently constructed using [specify_reindention()].
#' @examples
#' set_line_break_before_crly_opening <- function(pd_flat) {
#' @examples set_line_break_before_crly_opening <- function(pd_flat) {
#' op <- pd_flat$token %in% "'{'"
#' pd_flat$lag_newlines[op] <- 1L
#' pd_flat
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@

#' Create a style guide
#'
#' @param reindention A list of parameters for regex re-indention, most
#' conveniently constructed using [specify_reindention()].
#' @examples
#' set_line_break_before_crly_opening <- function(pd_flat) {
#' @examples set_line_break_before_crly_opening <- function(pd_flat) {
#' op <- pd_flat$token %in% "'{'"
#' pd_flat$lag_newlines[op] <- 1L
#' pd_flat
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@

#' Create a style guide
#'
#' @param reindention A list of parameters for regex re-indention, most
#' conveniently constructed using [specify_reindention()].
#' @examples
#' # empty
#' @examples # empty
#'
#'
#' # two
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#' Hi
#'
#' x
#' @examples
#' a %>%
#' @examples a %>%
#' x(b = 3) %>%
#' ff()
#' \dontrun{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#' Do stuff
#'
#' Some things we do
#' @examples
#' g()
#' @examples g()
#' \dontrun{
#' f(x)
#' }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#' @examples
#' my_fun <- function() {
#' @examples my_fun <- function() {
#' print("hello world!")
#' }
#' # before this comment is a left-over space
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#' Data frame and Tables Pretty Formatting
#'
#' @examples
#' c("\nA \\nyellow \\\nline", "yellow")
#' @examples c("\nA \\nyellow \\\nline", "yellow")
#' c("\ A \\ nyellow \\\ nline", "yellow")
#' \dontrun{
#' c("\nA \\nyellow \\\nline", "yellow")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
#' Performs various substitutions in all `.R` files in a package
#' (code and tests).
#' Carefully examine the results after running this function!
#' @examples
#' style_pkg(style = tidyverse_style, strict = TRUE)
#' @examples style_pkg(style = tidyverse_style, strict = TRUE)
#' style_pkg(
#' scope = "line_breaks",
#' math_token_spacing = specify_math_token_spacing(zero = "'+'")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
#' @family some
#' @examplesIf TRUE
#' c()
#' @examples
#' x <- 2
#' @examples x <- 2
#' @importFrom purrr partial
#' @export
x <- 3
Expand All @@ -14,8 +13,7 @@ x <- 3
#'
#' Style code according to the bli blauuu2 guide.
#' @family not
#' @examples
#' x <- 2
#' @examples x <- 2
#' @examplesIf TRUE
#' c()
#' @export
Expand Down
Loading