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

Fix line break around comma #479

Merged
merged 1 commit into from
Mar 9, 2019
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
2 changes: 1 addition & 1 deletion R/rules-line-break.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ set_line_break_around_comma <- function(pd) {
(pd$token_before != "COMMENT") &
(lag(pd$token) != "'['")
pd$lag_newlines[comma_with_line_break_that_can_be_removed_before] <- 0L
pd$lag_newlines[lead(comma_with_line_break_that_can_be_removed_before)] <- 1L
pd$lag_newlines[lag(comma_with_line_break_that_can_be_removed_before)] <- 1L
pd
}

Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/line_breaks_and_other/comma-in.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@ call(a,

call(a
,)

mpg %>%
summarise(avg_cty = mean(cty)
, avg_hwy = mean(hwy)
, n = n()
, n_class = n_distinct(class))
148 changes: 97 additions & 51 deletions tests/testthat/line_breaks_and_other/comma-in_tree

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

18 changes: 12 additions & 6 deletions tests/testthat/line_breaks_and_other/comma-out.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
call(
a,
b, c
b,
c
)

call(
a,
b,
a, b,
c
)

call(a, )
call(a, )

call(
a,
)
call(a, )

mpg %>%
summarise(
avg_cty = mean(cty),
avg_hwy = mean(hwy),
n = n(),
n_class = n_distinct(class)
)
3 changes: 2 additions & 1 deletion tests/testthat/strict/non_strict-out.R
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ line breaks are unfortunately split"

nested(
function_call (with),
many, first_level_args)
many,
first_level_args)

nested(
function_call (with), # a comment and
Expand Down
3 changes: 2 additions & 1 deletion tests/testthat/strict/strict-out.R
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ test <- function() {

nested(
function_call(with),
many, first_level_args
many,
first_level_args
)

nested(
Expand Down