Skip to content

Commit e63eab4

Browse files
Merge pull request #975 from r-lib/issue-975
Break line if indention is odd (in some cases).
2 parents a3b69e4 + a7f94ea commit e63eab4

File tree

5 files changed

+52
-0
lines changed

5 files changed

+52
-0
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ editor_options:
2323

2424
- There is now always one line break after `{` and before `#` (#916).
2525

26+
- Line breaks may be added to function calls to ensure indention symmetry for
27+
round braces (#975).
28+
2629
- the cache is also invalidated on changing the stylerignore markers (#932).
2730

2831
- `{` is not put on a new line after `=` and in `function() {` for some edge

R/rules-line-breaks.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,11 @@ set_line_break_after_opening_if_call_is_multi_line <- function(pd,
311311
return(pd)
312312
}
313313
break_pos <- find_line_break_position_in_multiline_call(pd)
314+
idx_nested <- next_non_comment(pd, 2)
315+
nested_call <- is_function_call(pd$child[[idx_nested]])
316+
if (pd_is_multi_line(pd$child[[idx_nested]]) && sum(pd$lag_newlines) > 0) {
317+
break_pos <- c(break_pos, idx_nested)
318+
}
314319
}
315320
exception_pos <- c(
316321
which(pd$token %in% except_token_after),
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
test_that(key(
2+
s),x = 1)
3+
4+
test_that(key(
5+
s),
6+
x = 1
7+
)
8+
9+
10+
test_that(key(
11+
s),x = 1
12+
)
13+
14+
15+
test_that(
16+
key(s),x = 1)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
test_that(key(
2+
s
3+
), x = 1)
4+
5+
test_that(
6+
key(
7+
s
8+
),
9+
x = 1
10+
)
11+
12+
13+
test_that(key(
14+
s
15+
), x = 1)
16+
17+
18+
test_that(
19+
key(s),
20+
x = 1
21+
)

tests/testthat/test-line_breaks_fun_call.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,10 @@ test_that("line breaks work with exceptions", {
5555
transformer = style_text
5656
), NA)
5757
})
58+
59+
test_that("line breaks work with exceptions", {
60+
expect_warning(test_collection("line_breaks_fun_call",
61+
"unindent",
62+
transformer = style_text
63+
), NA)
64+
})

0 commit comments

Comments
 (0)