Skip to content

Commit 1e9f254

Browse files
tilde is flattened out and causes indention like other operators
1 parent 38af4ad commit 1e9f254

File tree

7 files changed

+54
-2
lines changed

7 files changed

+54
-2
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
* rules that add tokens don't break stylerignore sequences anymore (#891).
3333
* Add vignette on distributing style guide (#846, #861).
3434
* Alignment detection respects stylerignore (#850).
35+
* `~` causes now indention, like `+`, `-`, `|` etc. (#902).
3536
* `Warning: Unknown or uninitialised column:` was fixed (#885).
3637
* Unaligned expressions with quoted key (e.g. `c("x" = 2)`) are now correctly
3738
detected (#881).

R/relevel.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ flatten_operators_one <- function(pd_nested) {
2828
pd_token_left <- c(special_token, "PIPE", math_token, "'$'")
2929
pd_token_right <- c(
3030
special_token, "PIPE", "LEFT_ASSIGN", if (parser_version_get() > 1) "EQ_ASSIGN",
31-
"'+'", "'-'"
31+
"'+'", "'-'", "'~'"
3232
)
3333
pd_nested %>%
3434
flatten_pd(pd_token_left, left = TRUE) %>%

R/rules-indention.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ indent_op <- function(pd,
3838
"PIPE",
3939
"LEFT_ASSIGN",
4040
"EQ_ASSIGN",
41-
"'$'"
41+
"'$'",
42+
"'~'"
4243
)) {
4344
indent_indices <- compute_indent_indices(pd, token)
4445
pd$indent[indent_indices] <- pd$indent[indent_indices] + indent_by
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
y ~
2+
x+
3+
y
4+
5+
6+
x ~
7+
1 + (x|b)

tests/testthat/indention_operators/tilde-in_tree

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
y ~
2+
x +
3+
y
4+
5+
6+
x ~
7+
1 + (x | b)

tests/testthat/test-indention_operators.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,14 @@ test_that("indents eq_formals correctly with various levels of scope", {
141141
), NA)
142142
})
143143

144+
test_that("tilde causes indention and is flattened out", {
145+
expect_warning(test_collection("indention_operators",
146+
"tilde",
147+
transformer = style_text
148+
), NA)
149+
})
150+
151+
144152
test_that("overall", {
145153
expect_warning(test_collection("indention_operators",
146154
"overall",

0 commit comments

Comments
 (0)