Skip to content

Commit 4fb9797

Browse files
remove blank lines after comments and commas
1 parent acfd9a4 commit 4fb9797

File tree

5 files changed

+17
-10
lines changed

5 files changed

+17
-10
lines changed

R/rules-line-break.R

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,13 @@ set_line_break_before_curly_opening <- function(pd) {
9090
}
9191

9292

93-
set_line_break_around_comma <- function(pd) {
93+
set_line_break_around_comma <- function(pd, strict) {
9494
comma_with_line_break_that_can_be_removed_before <-
9595
(pd$token == "','") &
9696
(pd$lag_newlines > 0) &
9797
(pd$token_before != "COMMENT") &
9898
(lag(pd$token) != "'['")
99+
99100
pd$lag_newlines[comma_with_line_break_that_can_be_removed_before] <- 0L
100101
pd$lag_newlines[lag(comma_with_line_break_that_can_be_removed_before)] <- 1L
101102
pd
@@ -267,9 +268,17 @@ set_line_break_before_closing_call <- function(pd, except_token_before) {
267268

268269
#' @rdname set_line_break_if_call_is_multi_line
269270
#' @keywords internal
270-
remove_line_break_in_empty_fun_call <- function(pd) {
271-
if (is_function_call(pd) && nrow(pd) == 3) {
272-
pd$lag_newlines[3] <- 0L
271+
remove_line_break_in_fun_call <- function(pd, strict) {
272+
if (is_function_call(pd)) {
273+
# no blank lines within function calls
274+
if (strict) {
275+
pd$lag_newlines[lag(pd$token == "','") & pd$lag_newlines > 1] <- 1L
276+
277+
pd$lag_newlines[lag(pd$token == "COMMENT") & pd$lag_newlines > 0] <- 1L
278+
}
279+
if (nrow(pd) == 3) {
280+
pd$lag_newlines[3] <- 0L
281+
}
273282
}
274283
pd
275284
}

R/style-guides.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ tidyverse_style <- function(scope = "tokens",
139139
except_token_before = "COMMENT"
140140
)
141141
},
142-
remove_line_break_in_empty_fun_call,
142+
purrr::partial(remove_line_break_in_fun_call, strict = strict),
143143
add_line_break_after_pipe = if (strict) add_line_break_after_pipe,
144144
set_linebreak_after_ggplot2_plus = if (strict) set_linebreak_after_ggplot2_plus
145145
)

man/set_line_break_if_call_is_multi_line.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/line_breaks_fun_call/blank-strict-out.R

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ call(
44

55
call(
66
# comment
7-
87
1
98
)
109

1110
call(
1211
x = 2,
1312
1,
14-
1513
"w"
1614
)

tests/testthat/test-line_breaks_fun_call.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ test_that("blank lines in function calls are removed for strict = TRUE", {
1919

2020
expect_warning(test_collection("line_breaks_fun_call",
2121
"blank-non-strict",
22-
transformer = style_text
22+
transformer = style_text, strict = FALSE
2323
), NA)
2424
})
2525

0 commit comments

Comments
 (0)