From 0ce719aa10d7ffca5e35b0e2b021f5bab9c1154d Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Thu, 16 Jun 2022 00:19:34 +0200 Subject: [PATCH] comments never follow after { on the same line or with multiple lines inbetween. --- NEWS.md | 2 ++ R/rules-line-breaks.R | 2 +- tests/testthat/indention_multiple/overall-out.R | 3 ++- tests/testthat/line_breaks_and_other/curly-in.R | 10 ++++++++++ tests/testthat/line_breaks_and_other/curly-out.R | 8 ++++++++ 5 files changed, 23 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index 23cd088ca..91cb4d34c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -19,6 +19,8 @@ editor_options: - If there are only empty lines in a code chunk, they are all removed (#936). +- There is now always one line break after `{` and before `#` (#916). + - the cache is also invalidated on changing the stylerignore markers (#932). - `{` is not put on a new line after `=` and in `function() {` for some edge diff --git a/R/rules-line-breaks.R b/R/rules-line-breaks.R index 499300e9d..40d3c42a4 100644 --- a/R/rules-line-breaks.R +++ b/R/rules-line-breaks.R @@ -144,7 +144,7 @@ set_line_break_around_comma_and_or <- function(pd, strict) { style_line_break_around_curly <- function(strict, pd) { if (is_curly_expr(pd) && nrow(pd) > 2) { closing_before <- pd$token == "'}'" - opening_before <- (pd$token == "'{'") & (pd$token_after != "COMMENT") + opening_before <- (pd$token == "'{'") to_break <- lag(opening_before, default = FALSE) | closing_before len_to_break <- sum(to_break) pd$lag_newlines[to_break] <- ifelse(rep(strict, len_to_break), diff --git a/tests/testthat/indention_multiple/overall-out.R b/tests/testthat/indention_multiple/overall-out.R index 4db2b90fc..ef2b5dd16 100644 --- a/tests/testthat/indention_multiple/overall-out.R +++ b/tests/testthat/indention_multiple/overall-out.R @@ -8,7 +8,8 @@ a <- function(x) { 22 + 1 )) if (x > 10) { - for (x in 22) { # FIXME in operator only to be surrounded by one space. What about %in%? + for (x in 22) { + # FIXME in operator only to be surrounded by one space. What about %in%? prin(x) } } diff --git a/tests/testthat/line_breaks_and_other/curly-in.R b/tests/testthat/line_breaks_and_other/curly-in.R index fada7e486..9f44b5716 100644 --- a/tests/testthat/line_breaks_and_other/curly-in.R +++ b/tests/testthat/line_breaks_and_other/curly-in.R @@ -31,3 +31,13 @@ test_that("I am here", { a_test(x) } ) + +test_that( + desc = "bla", + code = { + + + + # comment + expect_equal(1 + 1, 2) + }) diff --git a/tests/testthat/line_breaks_and_other/curly-out.R b/tests/testthat/line_breaks_and_other/curly-out.R index 6f1f53272..c55508290 100644 --- a/tests/testthat/line_breaks_and_other/curly-out.R +++ b/tests/testthat/line_breaks_and_other/curly-out.R @@ -30,3 +30,11 @@ if (1 > 3) { test_that("I am here", { a_test(x) }) + +test_that( + desc = "bla", + code = { + # comment + expect_equal(1 + 1, 2) + } +)