Skip to content

Commit 9c5d883

Browse files
Merge pull request #645 from lorenzwalthert/issue-627
- No more than one line break between pipes (#627).
2 parents 9ec6687 + 3cc0d9d commit 9c5d883

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

R/rules-line-break.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,10 @@ remove_line_breaks_in_fun_dec <- function(pd) {
182182

183183
#' @importFrom rlang seq2
184184
add_line_break_after_pipe <- function(pd) {
185-
is_pipe <- pd$token == c("SPECIAL-PIPE") & pd$token_after != "COMMENT"
186-
if (sum(is_pipe) > 1 &&
185+
is_pipe <- pd$token == c("SPECIAL-PIPE")
186+
pd$lag_newlines[lag(is_pipe) & pd$lag_newlines > 1] <- 1L
187+
188+
if (sum(is_pipe & pd$token_after != "COMMENT") > 1 &&
187189
!(next_terminal(pd, vars = "token_before")$token_before %in% c("'('", "EQ_SUB", "','"))) {
188190
pd$lag_newlines[lag(is_pipe)] <- 1L
189191
}

tests/testthat/indention_operators/pipe_simple-in.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,14 @@ c() %>%
55
g_out()
66

77
a <- function(jon_the_pipe) {}
8+
9+
x %>%
10+
11+
# break
12+
call()
13+
14+
15+
y %>%
16+
17+
18+
call() # mor

tests/testthat/indention_operators/pipe_simple-out.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,11 @@ a %>%
55
g_out()
66

77
a <- function(jon_the_pipe) {}
8+
9+
x %>%
10+
# break
11+
call()
12+
13+
14+
y %>%
15+
call() # mor

tests/testthat/line_breaks_and_other/pipe-line-breaks-out.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ fun(
8282

8383
# FIXME closing brace could go on ntext line. Alternative: remove lin breaks completely.
8484
blew(x %>%
85-
8685
c(), y = 2)
8786

8887
# FIXME closing brace could go on ntext line. Alternative: move c() up.

0 commit comments

Comments
 (0)