Skip to content

Commit b86e324

Browse files
detect unaligned columns when there is only one column and not all arguments are named
1 parent c6b978b commit b86e324

File tree

5 files changed

+101
-1
lines changed

5 files changed

+101
-1
lines changed

R/detect-alignment.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ token_is_on_aligned_line <- function(pd_flat) {
107107
# over columns.
108108
n_cols <- map_int(pd_by_line, ~ sum(.x$token == "','"))
109109
previous_line <- current_col <- 0L
110-
start_eval <- if (alignment_col1_all_named(pd_by_line)) {
110+
# if all col1 are named or there is at max 1 column,
111+
# start at column 1, else start at column 2
112+
start_eval <- if (max(n_cols) == 1 || alignment_col1_all_named(pd_by_line)) {
111113
1L
112114
} else {
113115
2L
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
foo(
2+
img,
3+
pkg = "abc",
4+
color = "lmn",
5+
font = "xyz"
6+
)
7+
8+
9+
foo(
10+
img, #
11+
pkg = "abc",
12+
color = "lmn",
13+
font = "xyz"
14+
)

tests/testthat/alignment/one-col-some-named-in_tree

Lines changed: 48 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
foo(
2+
img,
3+
pkg = "abc",
4+
color = "lmn",
5+
font = "xyz"
6+
)
7+
8+
9+
foo(
10+
img, #
11+
pkg = "abc",
12+
color = "lmn",
13+
font = "xyz"
14+
)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
a[[b]]
2+
3+
4+
a[[
5+
2
6+
]
7+
]
8+
9+
a[[
10+
2
11+
]]
12+
13+
14+
a[[
15+
2
16+
]]
17+
18+
19+
a[[
20+
2
21+
] #
22+
]

0 commit comments

Comments
 (0)