Skip to content

Commit

Permalink
Merge pull request #904 from lorenzwalthert/issue-900
Browse files Browse the repository at this point in the history
`~` should cause indention too
  • Loading branch information
lorenzwalthert authored Mar 7, 2022
2 parents b9c4ffd + 67539e3 commit b70aebe
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 3 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
there are comments and line breaks under certain circumstances (#905).
* rules that add tokens don't break stylerignore sequences anymore (#891).
* Alignment detection respects stylerignore (#850).
* `~` causes now indention, like `+`, `-`, `|` etc. (#902).
* `Warning: Unknown or uninitialised column:` was fixed (#885).
* Unaligned expressions with quoted key (e.g. `c("x" = 2)`) are now correctly
detected (#881).
Expand Down
2 changes: 1 addition & 1 deletion R/relevel.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ flatten_operators_one <- function(pd_nested) {
pd_token_left <- c(special_token, "PIPE", math_token, "'$'")
pd_token_right <- c(
special_token, "PIPE", "LEFT_ASSIGN", if (parser_version_get() > 1) "EQ_ASSIGN",
"'+'", "'-'"
"'+'", "'-'", "'~'"
)
pd_nested %>%
flatten_pd(pd_token_left, left = TRUE) %>%
Expand Down
3 changes: 2 additions & 1 deletion R/rules-indention.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ indent_op <- function(pd,
"PIPE",
"LEFT_ASSIGN",
"EQ_ASSIGN",
"'$'"
"'$'",
"'~'"
)) {
indent_indices <- compute_indent_indices(pd, token)
pd$indent[indent_indices] <- pd$indent[indent_indices] + indent_by
Expand Down
2 changes: 1 addition & 1 deletion man/update_indention.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions tests/testthat/indention_operators/tilde-in.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
y ~
x+
y


x ~
1 + (x|b)
28 changes: 28 additions & 0 deletions tests/testthat/indention_operators/tilde-in_tree

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions tests/testthat/indention_operators/tilde-out.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
y ~
x +
y


x ~
1 + (x | b)
8 changes: 8 additions & 0 deletions tests/testthat/test-indention_operators.R
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ test_that("indents eq_formals correctly with various levels of scope", {
), NA)
})

test_that("tilde causes indention and is flattened out", {
expect_warning(test_collection("indention_operators",
"tilde",
transformer = style_text
), NA)
})


test_that("overall", {
expect_warning(test_collection("indention_operators",
"overall",
Expand Down

0 comments on commit b70aebe

Please sign in to comment.