Skip to content

Commit 1d299f2

Browse files
Merge pull request #629 from lorenzwalthert/issue-627
- No blank line in function calls for strict = TRUE (#629).
2 parents 9a42a40 + 720981e commit 1d299f2

11 files changed

+159
-8
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/alignment/named-out.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ call(
6363
# algorithm: aligned. human: aligned.
6464
call(
6565
x = 1, n = 33, z = "333",
66-
6766
xy = 2,
6867
)
6968

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
call(
2+
3+
4+
1
5+
)
6+
7+
call(
8+
# comment
9+
10+
1
11+
)
12+
13+
call(
14+
x = 2,
15+
1,
16+
17+
"w"
18+
)

tests/testthat/line_breaks_fun_call/blank-non-strict-in_tree

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
call(
2+
3+
4+
1
5+
)
6+
7+
call(
8+
# comment
9+
10+
1
11+
)
12+
13+
call(
14+
x = 2,
15+
1,
16+
17+
"w"
18+
)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
call(
2+
3+
4+
1
5+
)
6+
7+
call(
8+
# comment
9+
10+
1
11+
)
12+
13+
call(
14+
x = 2,
15+
1,
16+
17+
"w"
18+
)

tests/testthat/line_breaks_fun_call/blank-strict-in_tree

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
call(
2+
1
3+
)
4+
5+
call(
6+
# comment
7+
1
8+
)
9+
10+
call(
11+
x = 2,
12+
1,
13+
"w"
14+
)

0 commit comments

Comments
 (0)