Skip to content

Commit dd1ccdd

Browse files
Merge pull request #546 from lorenzwalthert/no-linebreak-with-eq-formals
- indent deeply-nested EQ_FORMALS correctly (#546).
2 parents 8bd7267 + 08382a8 commit dd1ccdd

File tree

5 files changed

+181
-36
lines changed

5 files changed

+181
-36
lines changed

NEWS.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,32 @@
1616
[definition for aligned function calls](https://styler.r-lib.org/articles/detect-alignment.html)
1717
(#537).
1818

19-
* curlyl-curly (`{{`) syntactic sugar introduced with rlang 0.4.0 is now
19+
* curly-curly (`{{`) syntactic sugar introduced with rlang 0.4.0 is now
2020
explicitly handled, as opposed previously where it was just treated as two
21-
consequtive curly braces (#528).
21+
consecutive curly braces (#528).
2222

2323
* `style_pkg()`, `style_dir()` and the Addins can now style `.Rprofile`, and
2424
hidden files are now also styled (#530).
2525

2626
## Minor improvements and fixes
2727

28-
* brace expressions in function calls are formatted in a less compact way. This
29-
improves the formatting of `tryCatch()` in many cases (#543).
30-
31-
* escape characters in roxygen code examples are now correctly escaped (#512).
28+
* Brace expressions in function calls are formatted in a less compact way to
29+
improve readability. Typical use case: `tryCatch()` (#543).
3230

33-
* style selection Addin now preserves line break when the last line selected is
31+
* Arguments in function declarations in a context which is indented multiple
32+
times should now be correct. This typically affects `R6::R6Class()` (#546).
33+
34+
* Escape characters in roxygen code examples are now correctly escaped (#512).
35+
36+
* Style selection Addin now preserves line break when the last line selected is
3437
an entire line (#520).
3538

36-
* style file Addin can now properly handle cancelling (#511).
39+
* Style file Addin can now properly handle cancelling (#511).
3740

3841
* The body of a multi-line function declaration is now indented correctly for
3942
`strict = FALSE` and also wrapped in curly braces for `strict = TRUE` (#536).
4043

41-
* advice for contributors in `CONTRIBUTING.md` was updated (#508).
44+
* Advice for contributors in `CONTRIBUTING.md` was updated (#508).
4245

4346
## Adaption
4447

R/visit.R

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ context_to_terminals <- function(pd_nested,
7474
}
7575

7676
pd_transformed <- context_towards_terminals(
77-
pd_nested, outer_lag_newlines, outer_indent, outer_spaces, outer_indention_refs
77+
pd_nested,
78+
outer_lag_newlines, outer_indent,
79+
outer_spaces, outer_indention_refs
7880
)
7981

8082
pd_transformed$child <- pmap(
@@ -110,7 +112,11 @@ context_towards_terminals <- function(pd_nested,
110112
outer_indent,
111113
outer_spaces,
112114
outer_indention_refs) {
113-
pd_nested$indent <- pd_nested$indent + outer_indent
115+
pd_nested$indent <- pd_nested$indent + ifelse(
116+
is.na(pd_nested$indention_ref_pos_id),
117+
outer_indent,
118+
0
119+
)
114120
ref_pos_id_is_na <- !is.na(pd_nested$indention_ref_pos_id)
115121
pd_nested$indention_ref_pos_id[!ref_pos_id_is_na] <- outer_indention_refs
116122
pd_nested$lag_newlines[1] <- pd_nested$lag_newlines[1] + outer_lag_newlines

tests/testthat/indention_operators/eq_sub_complex_indention-in.R

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,27 @@ call(a =
66
5,
77
b
88
)
9+
10+
# multiple nested levels
11+
{
12+
v <- function(x =
13+
122,
14+
y) {
15+
}
16+
}
17+
18+
19+
{
20+
v <- function(x = 122,
21+
y) {
22+
}
23+
}
24+
25+
MyClass <- R6::R6Class(
26+
"MyClass",
27+
public = list(initialize = function(my_arg,
28+
my_named_arg = 1) {
29+
return(invisible())
30+
}
31+
),
32+
)

tests/testthat/indention_operators/eq_sub_complex_indention-in_tree

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

tests/testthat/indention_operators/eq_sub_complex_indention-out.R

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,27 @@ call(a =
66
5,
77
b
88
)
9+
10+
# multiple nested levels
11+
{
12+
v <- function(x =
13+
122,
14+
y) {
15+
}
16+
}
17+
18+
19+
{
20+
v <- function(x = 122,
21+
y) {
22+
}
23+
}
24+
25+
MyClass <- R6::R6Class(
26+
"MyClass",
27+
public = list(initialize = function(my_arg,
28+
my_named_arg = 1) {
29+
return(invisible())
30+
}
31+
),
32+
)

0 commit comments

Comments
 (0)