Skip to content

indent deeply-nested EQ_FORMALS correctly #546

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,32 @@
[definition for aligned function calls](https://styler.r-lib.org/articles/detect-alignment.html)
(#537).

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

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

## Minor improvements and fixes

* brace expressions in function calls are formatted in a less compact way. This
improves the formatting of `tryCatch()` in many cases (#543).

* escape characters in roxygen code examples are now correctly escaped (#512).
* Brace expressions in function calls are formatted in a less compact way to
improve readability. Typical use case: `tryCatch()` (#543).

* style selection Addin now preserves line break when the last line selected is
* Arguments in function declarations in a context which is indented multiple
times should now be correct. This typically affects `R6::R6Class()` (#546).

* Escape characters in roxygen code examples are now correctly escaped (#512).

* Style selection Addin now preserves line break when the last line selected is
an entire line (#520).

* style file Addin can now properly handle cancelling (#511).
* Style file Addin can now properly handle cancelling (#511).

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

* advice for contributors in `CONTRIBUTING.md` was updated (#508).
* Advice for contributors in `CONTRIBUTING.md` was updated (#508).

## Adaption

Expand Down
10 changes: 8 additions & 2 deletions R/visit.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ context_to_terminals <- function(pd_nested,
}

pd_transformed <- context_towards_terminals(
pd_nested, outer_lag_newlines, outer_indent, outer_spaces, outer_indention_refs
pd_nested,
outer_lag_newlines, outer_indent,
outer_spaces, outer_indention_refs
)

pd_transformed$child <- pmap(
Expand Down Expand Up @@ -110,7 +112,11 @@ context_towards_terminals <- function(pd_nested,
outer_indent,
outer_spaces,
outer_indention_refs) {
pd_nested$indent <- pd_nested$indent + outer_indent
pd_nested$indent <- pd_nested$indent + ifelse(
is.na(pd_nested$indention_ref_pos_id),
outer_indent,
0
)
ref_pos_id_is_na <- !is.na(pd_nested$indention_ref_pos_id)
pd_nested$indention_ref_pos_id[!ref_pos_id_is_na] <- outer_indention_refs
pd_nested$lag_newlines[1] <- pd_nested$lag_newlines[1] + outer_lag_newlines
Expand Down
24 changes: 24 additions & 0 deletions tests/testthat/indention_operators/eq_sub_complex_indention-in.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,27 @@ call(a =
5,
b
)

# multiple nested levels
{
v <- function(x =
122,
y) {
}
}


{
v <- function(x = 122,
y) {
}
}

MyClass <- R6::R6Class(
"MyClass",
public = list(initialize = function(my_arg,
my_named_arg = 1) {
return(invisible())
}
),
)
138 changes: 113 additions & 25 deletions tests/testthat/indention_operators/eq_sub_complex_indention-in_tree

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions tests/testthat/indention_operators/eq_sub_complex_indention-out.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,27 @@ call(a =
5,
b
)

# multiple nested levels
{
v <- function(x =
122,
y) {
}
}


{
v <- function(x = 122,
y) {
}
}

MyClass <- R6::R6Class(
"MyClass",
public = list(initialize = function(my_arg,
my_named_arg = 1) {
return(invisible())
}
),
)