Skip to content

Commit 0c802aa

Browse files
if comment is involved, move indent down
1 parent 08f9ec1 commit 0c802aa

File tree

4 files changed

+53
-14
lines changed

4 files changed

+53
-14
lines changed

R/rules-indention.R

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,17 @@ indent_eq_sub <- function(pd,
5858
if (!any(eq_sub)) {
5959
return(pd)
6060
}
61-
has_line_break <- pd$lag_newlines > 0
62-
indent_indices <- lag(eq_sub, default = FALSE) & has_line_break
61+
has_line_break <- pd$lag_newlines > 0 | pd$token == "COMMENT"
62+
indent_indices <- which(lag(eq_sub, default = FALSE) & has_line_break)
63+
if (any(pd$token[indent_indices] == "COMMENT")) {
64+
indent_indices <- purrr::map_int(indent_indices, function(idx) {
65+
if (pd$token[idx] == "COMMENT") {
66+
next_non_comment(pd, idx)
67+
} else {
68+
idx
69+
}
70+
})
71+
}
6372
pd$indent[indent_indices] <- pd$indent[indent_indices] + indent_by
6473
pd
6574
}

tests/testthat/indention_operators/eq_sub_complex_tokens-in.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,10 @@ call(a =
66
5,
77
b
88
)
9+
10+
c(
11+
a =
12+
1,
13+
b = # comment here
14+
2
15+
)

tests/testthat/indention_operators/eq_sub_complex_tokens-in_tree

Lines changed: 28 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/indention_operators/eq_sub_complex_tokens-out.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,10 @@ call(
99
5,
1010
b
1111
)
12+
13+
c(
14+
a =
15+
1,
16+
b = # comment here
17+
2
18+
)

0 commit comments

Comments
 (0)