Skip to content

Commit d31ee93

Browse files
Merge pull request #822 from lorenzwalthert/issue-821
- Don't break line around comments (#822).
2 parents 2744f76 + 0b06017 commit d31ee93

File tree

8 files changed

+99
-28
lines changed

8 files changed

+99
-28
lines changed

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# styler 1.5.1.9000 (Development version)
2+
3+
* Don't break line before comments in pipes (#822).
4+
15
# styler 1.5.1
26

37
## Alignment detection

R/rules-line-breaks.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ add_line_break_after_pipe <- function(pd) {
193193

194194
if (sum(is_pipe & pd$token_after != "COMMENT") > 1 &&
195195
!(next_terminal(pd, vars = "token_before")$token_before %in% c("'('", "EQ_SUB", "','"))) {
196-
pd$lag_newlines[lag(is_pipe)] <- 1L
196+
pd$lag_newlines[lag(is_pipe) & pd$token != "COMMENT"] <- 1L
197197
}
198198
pd
199199
}

tests/testthat/line_breaks_and_other/base-pipe-line-breaks-in.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,8 @@ blew(y = 2, x |>
8181

8282

8383
{a |> c() +1}
84+
85+
b |>
86+
f() |> # never move comment to next line as it can be styler: off or nolint
87+
k() |>
88+
x()

tests/testthat/line_breaks_and_other/base-pipe-line-breaks-in_tree

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

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,8 @@ blew(y = 2, x |>
8888
{
8989
a |> c() + 1
9090
}
91+
92+
b |>
93+
f() |> # never move comment to next line as it can be styler: off or nolint
94+
k() |>
95+
x()

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,9 @@ blew(y = 2, x %>%
8383

8484

8585
{a %>% c +1}
86+
87+
88+
b %>%
89+
f() %>% # never move comment to next line as it can be styler: off or nolint
90+
k() %>%
91+
x()

tests/testthat/line_breaks_and_other/pipe-line-breaks-in_tree

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

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,9 @@ blew(y = 2, x %>%
9292
{
9393
a %>% c() + 1
9494
}
95+
96+
97+
b %>%
98+
f() %>% # never move comment to next line as it can be styler: off or nolint
99+
k() %>%
100+
x()

0 commit comments

Comments
 (0)