diff --git a/NEWS.md b/NEWS.md index 125839a46..aaebb00b5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -35,7 +35,8 @@ auto-save edits in general (Code -> Saving -> Auto-Save), e.g. on idle editor or focus loss, so this feature becomes less relevant. (#631). - blank lines in function calls and headers are now removed, for the former only - when there are no comments before or after the blank line (#629, #630, #635). + when there are no comments before or after the blank line (#629, #630, #635, + #723). - speed improvements: ~10% when cache is activated because transformers are not captured as character anymore (#679), ~3% in low-level optimization (#691). 7% by requiring magrittr 2.0 (#681), ~8% by dropping unused transformers diff --git a/R/rules-line-breaks.R b/R/rules-line-breaks.R index ef9eed84e..9accf76d3 100644 --- a/R/rules-line-breaks.R +++ b/R/rules-line-breaks.R @@ -173,7 +173,7 @@ remove_line_break_before_round_closing_after_curly <- function(pd) { remove_line_breaks_in_fun_dec <- function(pd) { if (is_function_dec(pd)) { - round_after <- pd$token == "')'" & pd$token_before != "COMMENT" + round_after <- (pd$token == "')'" | pd$token_before == "'('") & pd$token_before != "COMMENT" pd$lag_newlines[pd$lag_newlines > 1L] <- 1L pd$lag_newlines[round_after] <- 0L } diff --git a/tests/testthat/fun_dec/line_break_fun_dec-in.R b/tests/testthat/fun_dec/line_break_fun_dec-in.R index a72d9d215..4bf36e4ac 100644 --- a/tests/testthat/fun_dec/line_break_fun_dec-in.R +++ b/tests/testthat/fun_dec/line_break_fun_dec-in.R @@ -33,3 +33,16 @@ a <- function(x, y) { x - 1 } + + +a <- function( + x, + y) { + x - 1 +} + +a <- function( # + x, + y) { + x - 1 +} diff --git a/tests/testthat/fun_dec/line_break_fun_dec-in_tree b/tests/testthat/fun_dec/line_break_fun_dec-in_tree index 7ffbd33fd..4c1378941 100644 --- a/tests/testthat/fun_dec/line_break_fun_dec-in_tree +++ b/tests/testthat/fun_dec/line_break_fun_dec-in_tree @@ -102,24 +102,67 @@ ROOT (token: short_text [lag_newlines/spaces] {pos_id}) ¦ ¦ °--expr: 1 [0/0] {97} ¦ ¦ °--NUM_CONST: 1 [0/0] {96} ¦ °--'}': } [1/0] {98} - °--expr: a <- [2/0] {99} - ¦--expr: a [0/1] {101} - ¦ °--SYMBOL: a [0/0] {100} - ¦--LEFT_ASSIGN: <- [0/1] {102} - °--expr: funct [0/0] {103} - ¦--FUNCTION: funct [0/0] {104} - ¦--'(': ( [0/0] {105} - ¦--SYMBOL_FORMALS: x [0/0] {106} - ¦--',': , [0/14] {107} - ¦--SYMBOL_FORMALS: y [2/0] {108} - ¦--')': ) [0/1] {109} - °--expr: { + ¦--expr: a <- [2/0] {99} + ¦ ¦--expr: a [0/1] {101} + ¦ ¦ °--SYMBOL: a [0/0] {100} + ¦ ¦--LEFT_ASSIGN: <- [0/1] {102} + ¦ °--expr: funct [0/0] {103} + ¦ ¦--FUNCTION: funct [0/0] {104} + ¦ ¦--'(': ( [0/0] {105} + ¦ ¦--SYMBOL_FORMALS: x [0/0] {106} + ¦ ¦--',': , [0/14] {107} + ¦ ¦--SYMBOL_FORMALS: y [2/0] {108} + ¦ ¦--')': ) [0/1] {109} + ¦ °--expr: { x [0/0] {110} - ¦--'{': { [0/2] {111} - ¦--expr: x - 1 [1/0] {112} - ¦ ¦--expr: x [0/1] {114} - ¦ ¦ °--SYMBOL: x [0/0] {113} - ¦ ¦--'-': - [0/1] {115} - ¦ °--expr: 1 [0/0] {117} - ¦ °--NUM_CONST: 1 [0/0] {116} - °--'}': } [1/0] {118} + ¦ ¦--'{': { [0/2] {111} + ¦ ¦--expr: x - 1 [1/0] {112} + ¦ ¦ ¦--expr: x [0/1] {114} + ¦ ¦ ¦ °--SYMBOL: x [0/0] {113} + ¦ ¦ ¦--'-': - [0/1] {115} + ¦ ¦ °--expr: 1 [0/0] {117} + ¦ ¦ °--NUM_CONST: 1 [0/0] {116} + ¦ °--'}': } [1/0] {118} + ¦--expr: a <- [3/0] {119} + ¦ ¦--expr: a [0/1] {121} + ¦ ¦ °--SYMBOL: a [0/0] {120} + ¦ ¦--LEFT_ASSIGN: <- [0/1] {122} + ¦ °--expr: funct [0/0] {123} + ¦ ¦--FUNCTION: funct [0/0] {124} + ¦ ¦--'(': ( [0/14] {125} + ¦ ¦--SYMBOL_FORMALS: x [1/0] {126} + ¦ ¦--',': , [0/14] {127} + ¦ ¦--SYMBOL_FORMALS: y [1/0] {128} + ¦ ¦--')': ) [0/1] {129} + ¦ °--expr: { + x [0/0] {130} + ¦ ¦--'{': { [0/2] {131} + ¦ ¦--expr: x - 1 [1/0] {132} + ¦ ¦ ¦--expr: x [0/1] {134} + ¦ ¦ ¦ °--SYMBOL: x [0/0] {133} + ¦ ¦ ¦--'-': - [0/1] {135} + ¦ ¦ °--expr: 1 [0/0] {137} + ¦ ¦ °--NUM_CONST: 1 [0/0] {136} + ¦ °--'}': } [1/0] {138} + °--expr: a <- [2/0] {139} + ¦--expr: a [0/1] {141} + ¦ °--SYMBOL: a [0/0] {140} + ¦--LEFT_ASSIGN: <- [0/1] {142} + °--expr: funct [0/0] {143} + ¦--FUNCTION: funct [0/0] {144} + ¦--'(': ( [0/1] {145} + ¦--COMMENT: # [0/2] {146} + ¦--SYMBOL_FORMALS: x [1/0] {147} + ¦--',': , [0/2] {148} + ¦--SYMBOL_FORMALS: y [1/0] {149} + ¦--')': ) [0/1] {150} + °--expr: { + x [0/0] {151} + ¦--'{': { [0/2] {152} + ¦--expr: x - 1 [1/0] {153} + ¦ ¦--expr: x [0/1] {155} + ¦ ¦ °--SYMBOL: x [0/0] {154} + ¦ ¦--'-': - [0/1] {156} + ¦ °--expr: 1 [0/0] {158} + ¦ °--NUM_CONST: 1 [0/0] {157} + °--'}': } [1/0] {159} diff --git a/tests/testthat/fun_dec/line_break_fun_dec-out.R b/tests/testthat/fun_dec/line_break_fun_dec-out.R index 42f87027c..81aff8516 100644 --- a/tests/testthat/fun_dec/line_break_fun_dec-out.R +++ b/tests/testthat/fun_dec/line_break_fun_dec-out.R @@ -32,3 +32,15 @@ a <- function(x, y) { x - 1 } + + +a <- function(x, + y) { + x - 1 +} + +a <- function( # + x, + y) { + x - 1 +}