Skip to content

no line breaks after pipe if comment is next token #160

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 1 commit into from
Aug 27, 2017
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 @@ -44,7 +44,7 @@ remove_line_break_before_round_closing <- function(pd) {

#' @importFrom rlang seq2
add_line_break_after_pipe <- function(pd) {
is_special <- pd$token %in% c("SPECIAL-PIPE")
is_special <- pd$token == c("SPECIAL-PIPE") & pd$token_after != "COMMENT"
pd$lag_newlines[lag(is_special)] <- 1L
pd
}
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/line_breaks_and_other/pipe_and_comment-in.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1:10 %>% # sum
sum()
15 changes: 15 additions & 0 deletions tests/testthat/line_breaks_and_other/pipe_and_comment-in_tree

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

2 changes: 2 additions & 0 deletions tests/testthat/line_breaks_and_other/pipe_and_comment-out.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1:10 %>% # sum
sum()
5 changes: 5 additions & 0 deletions tests/testthat/test-line_breaks_and_other.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,8 @@ test_that("adding and removing line breaks", {
transformer = style_text), NA)
})

test_that("no line break after %>% if next token is comment", {
expect_warning(test_collection("line_breaks_and_other", "pipe_and",
transformer = style_text), NA)
})