Skip to content

Commit f7b835a

Browse files
Merge pull request #92 from lorenzwalthert/speedup
curly braces don't move a line up if previous token is comment
2 parents 879b473 + 57ff203 commit f7b835a

File tree

6 files changed

+31
-2
lines changed

6 files changed

+31
-2
lines changed

R/rules-line_break.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# A { should never go on its own line
22
remove_line_break_before_curly_opening <- function(pd) {
3-
rm_break <- pd$token_after == "'{'"
3+
rm_break <- (pd$token_after == "'{'") & (pd$token != "COMMENT")
44
pd$lag_newlines[lag(rm_break)] <- 0L
55
pd
66
}

tests/testthat/indention_operators/while_for_if_without_curly-in_tree

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
a <- function(x) # this is a comment and the bracket below should not be moved one line up after the comment.
2+
{
3+
x
4+
}

tests/testthat/line_breaks_and_other/edge_comment_and_curly-in_tree

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
a <- function(x) # this is a comment and the bracket below should not be moved one line up after the comment.
2+
{
3+
x
4+
}

tests/testthat/test-line_breaks_and_other.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ test_that("line breaks involing curly brackets", {
1111
transformer = style_text), NA)
1212
})
1313

14+
test_that("line breaks involing curly brackets", {
15+
expect_warning(test_collection("line_breaks_and_other", "edge_comment_and_curly",
16+
transformer = style_text), NA)
17+
})
18+
1419
test_that("adding and removing line breaks", {
1520
expect_warning(test_collection("line_breaks_and_other", "if",
1621
transformer = style_text), NA)

0 commit comments

Comments
 (0)