-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implementation of breaking long function calls #118
Comments
Your "simple rule" sounds good. It appears that we see the entire function call at the same level in the nested parse data -- we could look at I suggest we leave this open for now. |
On a related note, I am also not sure about how closing brackets and pipes should interact, i.e. call(b,
c, d) %>%
x()
# vs.
call(
b, c, d
) %>%
x |
I am not sure whether I understand you correctly, but I think we don't need to use break_line_after_opening_if_call_is_multiline <- function(pd) {
npd <- nrow(pd)
if (npd < 2) return(pd)
if (all(is.na(pd$token_before[2]))) return(pd)
is_call <- pd$token_before[2] == "SYMBOL_FUNCTION_CALL"
if (!is_call) return(pd)
if (npd == 3) {
pd$lag_newlines[3] <- 0L
return(pd)
}
comments <- which(pd$token == "COMMENT")
is_multi_line <- any(pd$lag_newlines[3:(npd - 1)] > 0)
if (!is_multi_line) return(pd)
pd$lag_newlines[setdiff(3, comments)] <- 1L
pd
}
Note that it only adds line breaks after the opening parenthesis, not before the closing parenthesis. It could be easily extended though (or put in a seperate rule). |
Closing parens and pipes: I like the second version better, but maybe it should be b %>%
call(
c, d
) %>%
x (I'm not suggesting to do anything about it in styler.) Looking at |
Closing in favor of #125. |
The tidyverse style guide states that long function calls are not compliant with the style guide:
It also states that multiple arguments can remain on the same line if they are related.
I am not sure how to implement that and how strictly we should use it. A simple rule would be to add a line break after
(
, and leaving everything until)
untouched in terms of line breaks and putting the closing)
on a new line. Also, I think this should be a transformer that is only used ifstrict = TRUE
since I think its one of the rules in the style guide that is not consistently obeyed by many people. @krlmlr maybe you can advise on that.The text was updated successfully, but these errors were encountered: