Skip to content

Commit 3dcf923

Browse files
eq sub:
if on second line, move key also there if on first line, leave it, might be intentional
1 parent 897cafd commit 3dcf923

File tree

4 files changed

+87
-0
lines changed

4 files changed

+87
-0
lines changed

R/rules-line-breaks.R

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,21 @@ set_line_break_around_comma_and_or <- function(pd, strict) {
119119

120120
pd$lag_newlines[comma_with_line_break_that_can_be_removed_before] <- 0L
121121
pd$lag_newlines[lag(comma_with_line_break_that_can_be_removed_before)] <- 1L
122+
123+
comma_with_line_break_that_can_be_moved_two_tokens_left <- which(
124+
(pd$token == "EQ_SUB") &
125+
(pd$lag_newlines > 0) &
126+
(pd$token_before != "COMMENT") &
127+
(lag(pd$token) != "'['")
128+
)
129+
130+
pd$lag_newlines[comma_with_line_break_that_can_be_moved_two_tokens_left] <- 0L
131+
token_before <- map_int(
132+
comma_with_line_break_that_can_be_moved_two_tokens_left,
133+
previous_non_comment,
134+
pd = pd
135+
)
136+
pd$lag_newlines[token_before] <- 1L
122137
pd
123138
}
124139

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
c(x = 2)
2+
3+
c(x =
4+
2)
5+
6+
c(
7+
x = 2)
8+
9+
c(x
10+
= 2)
11+
12+
c(x = 2, a
13+
=
14+
1)
15+
16+
17+
c(x = 2, a
18+
= # stuff
19+
1)
20+
21+
22+
c(b=4, x # comment
23+
= 2)
24+
25+
26+
c(x =# comment
27+
2, c=)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
c(x = 2)
2+
3+
c(
4+
x =
5+
2
6+
)
7+
8+
c(
9+
x = 2
10+
)
11+
12+
c(
13+
x = 2
14+
)
15+
16+
c(
17+
x = 2,
18+
a =
19+
1
20+
)
21+
22+
23+
c(
24+
x = 2,
25+
a = # stuff
26+
1
27+
)
28+
29+
30+
c(
31+
b = 4, x # comment
32+
= 2
33+
)
34+
35+
36+
c(
37+
x = # comment
38+
2, c =
39+
)

tests/testthat/test-line_breaks_and_other.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,9 @@ test_that("drop redundant line breaks in assignments", {
6262
transformer = style_text, scope = I(c("line_breaks", "tokens"))
6363
), NA)
6464
})
65+
66+
test_that("line is correctly broken around = ", {
67+
expect_warning(test_collection("line_breaks_and_other", "around-eq-sub",
68+
transformer = style_text
69+
), NA)
70+
})

0 commit comments

Comments
 (0)