Skip to content
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

Only remove excessive line breaks in assignments #809

Merged
merged 2 commits into from Jun 9, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Expand Up @@ -59,6 +59,8 @@
code header anymore. This can be handy when the code can't be parsed, e.g.
within a learnr tutorial (#790).
* `#>` is recognized as an output marker and no space is added after `#` (#771).
* multi-expressions containing multiple assignments no longer remove line breaks
if they are not causing blank lines (#809).
* R code chunks in nested non-R chunks in R markdown don't yield an error
anymore when document is styled, chunks are still not styled (#788, #794).
* `cache_activate()` and `cache_deactivate()` now respect the R
Expand Down
2 changes: 1 addition & 1 deletion R/rules-line-breaks.R
Expand Up @@ -201,7 +201,7 @@ add_line_break_after_pipe <- function(pd) {
set_line_break_after_assignment <- function(pd) {
is_assignment <- lag(pd$token, default = FALSE) %in% c("LEFT_ASSIGN", "EQ_ASSIGN")
if (any(is_assignment)) {
pd$lag_newlines[is_assignment] <- min(1L, pd$lag_newlines[is_assignment])
pd$lag_newlines[is_assignment] <- pmin(1L, pd$lag_newlines[is_assignment])
}
pd
}
Expand Down
16 changes: 16 additions & 0 deletions tests/testthat/line_breaks_and_other/assignment-in.R
Expand Up @@ -22,3 +22,19 @@ x =

# comment
3



ImportantDataFrame$ImportantColumn1 <-
ImportantDataFrame$ImportantColumn2 <-
ComplicatedFunction(ImportantDataFrame$InputColumn)


ImportantDataFrame$ImportantColumn1 <-
ImportantDataFrame$ImportantColumn2 <- ComplicatedFunction(ImportantDataFrame$InputColumn)



ImportantDataFrame$ImportantColumn1 <-

ImportantDataFrame$ImportantColumn2 <- ComplicatedFunction(ImportantDataFrame$InputColumn)
83 changes: 76 additions & 7 deletions tests/testthat/line_breaks_and_other/assignment-in_tree

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

15 changes: 15 additions & 0 deletions tests/testthat/line_breaks_and_other/assignment-out.R
Expand Up @@ -21,3 +21,18 @@ x <- 3
x <-
# comment
3



ImportantDataFrame$ImportantColumn1 <-
ImportantDataFrame$ImportantColumn2 <-
ComplicatedFunction(ImportantDataFrame$InputColumn)


ImportantDataFrame$ImportantColumn1 <-
ImportantDataFrame$ImportantColumn2 <- ComplicatedFunction(ImportantDataFrame$InputColumn)



ImportantDataFrame$ImportantColumn1 <-
ImportantDataFrame$ImportantColumn2 <- ComplicatedFunction(ImportantDataFrame$InputColumn)