Skip to content

Commit

Permalink
Merge pull request #793 from lorenzwalthert/issue-792
Browse files Browse the repository at this point in the history
- Remove line breaks between `}` and `else` (#792).
  • Loading branch information
lorenzwalthert committed May 6, 2021
2 parents 74f79ae + 2ca8c26 commit 2b10dfc
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 20 deletions.
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
}
}

0 comments on commit 2b10dfc

Please sign in to comment.