Skip to content

Commit ff81659

Browse files
since styler does not correctly unindent for }) (see r-lib/styler#485), we simply don't permit this
1 parent a10f44e commit ff81659

File tree

6 files changed

+48
-10
lines changed

6 files changed

+48
-10
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: styler.mlr
22
Title: Third-party Style Guide For 'mlr'
3-
Version: 0.0.4
3+
Version: 0.0.4.9000
44
Authors@R:
55
person(given = "Lorenz",
66
family = "Walthert",

R/core.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,12 @@ mlr_style = function(scope = "tokens",
115115
# remove_line_breaks_in_fun_dec =
116116
# if (strict) remove_line_breaks_in_fun_dec,
117117
# set_line_break_around_curly_curly = styler:::set_line_break_around_curly_curly,
118-
# set_line_break_before_closing_call = if (strict) {
119-
# partial(
120-
# styler:::set_line_break_before_closing_call,
121-
# except_token_before = "COMMENT"
122-
# )
123-
# },
118+
set_line_break_before_closing_call = if (strict) {
119+
partial(
120+
set_line_break_before_closing_call,
121+
except_token_before = "COMMENT"
122+
)
123+
},
124124
# set_line_break_after_opening_if_call_is_multi_line = if (strict) {
125125
# partial(
126126
# styler:::set_line_break_after_opening_if_call_is_multi_line,

R/rules-line-break.R

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,25 @@ style_line_break_around_curly = function(strict, pd) {
5454
}
5555
pd
5656
}
57+
58+
#' Like [styler:::set_line_break_before_closing_call()] but only adding a line
59+
#' break if multi-line function call **and** the token before the closing brace
60+
#' is a curly brace (otherwise indention does not work nicely).
61+
#' @keywords internal
62+
set_line_break_before_closing_call = function(pd, except_token_before) {
63+
if (!styler:::is_function_call(pd) && !styler:::is_subset_expr(pd)) {
64+
return(pd)
65+
}
66+
67+
npd = nrow(pd)
68+
is_multi_line = any(pd$lag_newlines[rlang::seq2(3L, npd - 1L)] > 0)
69+
if (!is_multi_line) {
70+
exception = which(pd$token_before %in% except_token_before)
71+
pd$lag_newlines[setdiff(npd, exception)] = 0L
72+
return(pd)
73+
} else if (pd$token_before[npd] == "'}'") {
74+
pd$lag_newlines[npd] = 1L
75+
}
76+
77+
pd
78+
}

man/set_line_break_before_closing_call.Rd

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

tests/testthat/core/braces-out.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
list(
22
x = list(
33
f <- function() {
4-
})
4+
}
5+
)
56
)
67

78

tests/testthat/core/fun-calls-out.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ call(x,
22
y = 2)
33

44

5-
call(x = 33, "fjk"
6-
)
5+
call(x = 33, "fjk")
76

87

98
call(

0 commit comments

Comments
 (0)