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

Remove line breaks between } and else #793

Merged
merged 3 commits into from May 6, 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
1 change: 1 addition & 0 deletions NEWS.md
Expand Up @@ -49,6 +49,7 @@

## Minor changes and fixes

* line breaks between `}` and `else` are removed (#793).
* styler won't format code chunks with explicit `tidy = FALSE` in an Rmd or Rnw
code header anymore. This can be handy when the code can't be parsed, e.g.
within a learnr tutorial (#790).
Expand Down
6 changes: 6 additions & 0 deletions R/rules-line-breaks.R
Expand Up @@ -113,6 +113,12 @@ style_line_break_around_curly <- function(strict, pd) {
1L,
pmax(1L, pd$lag_newlines[to_break])
)
} else {
is_else <- pd$token == "ELSE"
if (any(pd$token_before[is_else] == "'}'")) {
pd$lag_newlines[is_else] <- 0L
pd$spaces[c(is_else, FALSE)[-1]] <- 1L
}
}
pd
}
Expand Down
10 changes: 10 additions & 0 deletions tests/testthat/indention_multiple/if_else_curly-in.R
Expand Up @@ -27,3 +27,13 @@ if (TRUE) {
4
}
}

# rather space than brace thing, but
foo <- function(x) {
if (TRUE) {
1
}
else {
2
}
}
73 changes: 53 additions & 20 deletions tests/testthat/indention_multiple/if_else_curly-in_tree

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

9 changes: 9 additions & 0 deletions tests/testthat/indention_multiple/if_else_curly-out.R
Expand Up @@ -27,3 +27,12 @@
4
}
}

# rather space than brace thing, but
foo <- function(x) {
if (TRUE) {
1
} else {
2
}
}