Skip to content

Commit c23f533

Browse files
Merge pull request #915 from lorenzwalthert/issue-909
respect `indent_by` when curly brace is added
2 parents fd466c1 + 3d45bbc commit c23f533

File tree

6 files changed

+81
-1
lines changed

6 files changed

+81
-1
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
* Preserve trailing blank line in roxygen examples to simplify concatenation of
4848
examples (#880).
4949
* added guarantee that styled code is parsable (#892).
50+
* `indenty_by` is now also respected when curly braces are added to an if
51+
statement by {styler} (#915).
5052
* An error is now thrown on styling if input unicode characters can't be
5153
correctly parsed for Windows and R < 4.2 (#883).
5254
* styling of text does not error anymore when the R option `OutDec` is set to

R/style-guides.R

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,12 @@ tidyverse_style <- function(scope = "tokens",
169169
resolve_semicolon = resolve_semicolon,
170170
add_brackets_in_pipe = add_brackets_in_pipe,
171171
wrap_if_else_while_for_fun_multi_line_in_curly =
172-
if (strict) wrap_if_else_while_for_fun_multi_line_in_curly
172+
if (strict) {
173+
purrr::partial(
174+
wrap_if_else_while_for_fun_multi_line_in_curly,
175+
indent_by = indent_by
176+
)
177+
}
173178
)
174179
}
175180

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
value <- 5
3+
if (value > 0)
4+
print(value)
5+
6+
7+
8+
if (value > 0) {
9+
print(value)
10+
}

tests/testthat/indention_curly_brackets/custom-in_tree

Lines changed: 45 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
value <- 5
3+
if (value > 0) {
4+
print(value)
5+
}
6+
7+
8+
9+
if (value > 0) {
10+
print(value)
11+
}

tests/testthat/test-indention_curly.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ test_that("indention with multi-line curley and round is correct", {
2222
), NA)
2323
})
2424

25+
test_that("custom indention for curly braces is corretct ", {
26+
expect_warning(test_collection("indention_curly_brackets",
27+
"custom",
28+
transformer = style_text, indent_by = 4
29+
), NA)
30+
})
31+
2532

2633

2734
test_that(paste(

0 commit comments

Comments
 (0)