Skip to content

Commit 990a031

Browse files
Merge pull request #1035 from r-lib/issue-984
Fix alignment detection for one column, mixed named/unnamed
2 parents 305644b + d24fcfa commit 990a031

File tree

4 files changed

+79
-1
lines changed

4 files changed

+79
-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) == 1L || 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+
)

0 commit comments

Comments
 (0)