Skip to content

Indent function declaration without curly braces correctly #202

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
Sep 18, 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
4 changes: 2 additions & 2 deletions R/modify_pd.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ indent_without_paren <- function(pd, indent_by = 2) {
#' @describeIn update_indention Is used to indent for and while statements.
indent_without_paren_for_while <- function(pd, indent_by) {
nrow <- nrow(pd)
if (!(pd$token[1] %in% c("FOR", "WHILE"))) return(pd)
if (pd$lag_newlines[nrow] == 0) return(pd)
if (!(pd$token[1] %in% c("FOR", "WHILE", "FUNCTION"))) return(pd)
if (is_curly_expr(pd$child[[nrow]])) return(pd)
pd$indent[nrow] <- indent_by
pd
}
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/indention_multiple/fun_for_new_line-in.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function()
NULL

for (i in 1:3)
{
2
}
25 changes: 25 additions & 0 deletions tests/testthat/indention_multiple/fun_for_new_line-in_tree

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

7 changes: 7 additions & 0 deletions tests/testthat/indention_multiple/fun_for_new_line-out.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function()
NULL

for (i in 1:3)
{
2
}
7 changes: 7 additions & 0 deletions tests/testthat/test-indention_multiple.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,10 @@ test_that("edge cases work", {
transformer = style_text), NA)

})

test_that("token / braces interaction works", {
expect_warning(test_collection("indention_multiple",
"fun_for_new_line",
transformer = style_text), NA)
})