Skip to content

Commit 319a165

Browse files
implementing exception for function call line break
1 parent ebff2a4 commit 319a165

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

R/rules-line_break.R

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ add_line_break_after_pipe <- function(pd) {
5252

5353
#' Set line break for multi-line function calls
5454
#' @param pd A parse table.
55-
#' @param except_token A character vector with tokens before "'('" that do not
55+
#' @param except_token_after A character vector with tokens after "'('" that do
56+
#' not cause a line break after "'('".
57+
#' @param except_text_before A character vector with texts before "'('" that do
58+
#' not cause a line break after "'('".
5659
#' @name set_line_break_if_call_is_multi_line
5760
#' @importFrom rlang seq2
5861
NULL
@@ -61,12 +64,17 @@ NULL
6164
#' opening parenthesis.
6265
set_line_break_after_opening_if_call_is_multi_line <-
6366
function(pd,
64-
except_token = NULL) {
67+
except_token_after = NULL,
68+
except_text_before = NULL) {
6569
if (!is_function_call(pd)) return(pd)
6670
npd <- nrow(pd)
6771
is_multi_line <- any(pd$lag_newlines[seq2(3, npd - 1)] > 0)
6872
if (!is_multi_line) return(pd)
69-
exception_pos <- which(pd$token %in% except_token)
73+
exception_pos <- c(
74+
which(pd$token %in% except_token_after),
75+
ifelse(pd$child[[1]]$text[1] %in% except_text_before, 3L, NA)
76+
)
77+
pd$lag_newlines[3] <- 0L
7078
pd$lag_newlines[setdiff(3, exception_pos)] <- 1L
7179
pd
7280
}

R/style_guides.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ tidyverse_style <- function(scope = "tokens",
7575
add_line_break_before_curly_closing,
7676
partial(
7777
set_line_break_after_opening_if_call_is_multi_line,
78-
except_token = "COMMENT"
78+
except_token_after = "COMMENT",
79+
except_text_before = c("switch", "ifelse", "if_else")
7980
),
8081
set_line_break_before_closing_if_call_is_multi_line,
8182
remove_line_break_in_empty_fun_call,

man/set_line_break_if_call_is_multi_line.Rd

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

0 commit comments

Comments
 (0)