Skip to content

Commit acf936b

Browse files
within functioncall, token_after is a nest and not a terminal -> token_after is NA
1 parent 38dc65a commit acf936b

File tree

5 files changed

+439
-378
lines changed

5 files changed

+439
-378
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
anymore for one level deep (not more yet, see #889), as this can change
3131
outcome of the code (#876).
3232
* rules that add tokens don't break stylerignore sequences anymore (#891).
33+
* Function calls containing `+` should no longer give any error on styling when
34+
there are comments and line breaks under certain circumstances (#905).
3335
* Add vignette on distributing style guide (#846, #861).
3436
* Alignment detection respects stylerignore (#850).
3537
* `Warning: Unknown or uninitialised column:` was fixed (#885).

R/rules-line-breaks.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ set_linebreak_after_ggplot2_plus <- function(pd) {
349349
is_plus_or_comment_after_plus_before_fun_call <-
350350
lag(is_plus_raw, next_non_comment - first_plus - 1, default = FALSE) &
351351
(pd$token_after == "SYMBOL_FUNCTION_CALL" | pd$token_after == "SYMBOL_PACKAGE")
352-
if (any(is_plus_or_comment_after_plus_before_fun_call)) {
352+
if (any(is_plus_or_comment_after_plus_before_fun_call, na.rm = TRUE)) {
353353
gg_call <- pd$child[[previous_non_comment(pd, first_plus)]]$child[[1]]
354354
if (!is.null(gg_call) && isTRUE(gg_call$text[gg_call$token == "SYMBOL_FUNCTION_CALL"] == "ggplot")) {
355355
plus_without_comment_after <- setdiff(

tests/testthat/line_breaks_and_other/ggplot2-in.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,13 @@ g()[2] + x[1]
3939

4040
# don't do anything on unary + and function call
4141
+sin(x)
42+
43+
# within function call
44+
qqjflk(
45+
log(y + 1) +
46+
# sqrt(x1) +
47+
sqrt(x2) +
48+
# sqrt(x3) +
49+
x4 +
50+
sqrt(x5)
51+
)

0 commit comments

Comments
 (0)