Skip to content

Commit e7d6644

Browse files
extend rule to cover edge case and update docs / add example.
1 parent b76ca0d commit e7d6644

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

R/indent.R

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,11 @@ needs_indention <- function(pd,
192192
#'
193193
#' * there is no multi-line token between the trigger and the first line break.
194194
#' * there is no other token between the potential trigger and the first line
195-
#' break that is going to cause indention.
196-
#'
195+
#' break that is going to cause indention. Note that such an other trigger
196+
#' only causes indention if there is a line break after that other token, not
197+
#' otherwise. See 'Details' for an example where there is such an other
198+
#' trigger, but since the next token is on the same line as the other trigger,
199+
#' no indention is caused by that other trigger.
197200
#' @param pd A parse table.
198201
#' @param potential_trigger_pos the index of the token in the parse table
199202
#' for which it should be checked whether it should trigger indention.
@@ -203,6 +206,8 @@ needs_indention <- function(pd,
203206
#' @return `TRUE` if indention is needed, `FALSE` otherwise.
204207
#' @importFrom rlang seq2
205208
#' @keywords internal
209+
#' @examples
210+
#' style_text("call(named = c, \nnamed = b)", strict = FALSE)
206211
needs_indention_one <- function(pd,
207212
potential_trigger_pos,
208213
other_trigger_tokens) {
@@ -219,9 +224,14 @@ needs_indention_one <- function(pd,
219224
potential_trigger_pos
220225
)
221226

222-
other_trigger_on_same_line <-
223-
pd$token[remaining_row_idx_between_trigger_and_line_break] %in%
224-
other_trigger_tokens
227+
other_trigger_on_same_line <- (
228+
pd$token[remaining_row_idx_between_trigger_and_line_break] %in%
229+
other_trigger_tokens
230+
) & (
231+
pd$lag_newlines[remaining_row_idx_between_trigger_and_line_break + 1L] >
232+
0L
233+
)
234+
225235

226236
!any(multi_line_token) & !any(other_trigger_on_same_line)
227237
}

man/needs_indention_one.Rd

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)