-
Notifications
You must be signed in to change notification settings - Fork 73
Don't reindent function calls #149
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
Don't reindent function calls #149
Conversation
278001c
to
4c5a13c
Compare
4c5a13c
to
01256e7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thanks!
R/rules-line_break.R
Outdated
except_token = NULL) { | ||
if (!is_function_call(pd)) return(pd) | ||
npd <- nrow(pd) | ||
if (npd == 3) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this shortcut important?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because seq2(3, npd - 1)
would throw an error otherwise. npd = 3
is the case of empty function calls likecall()
. Just making sure there this does not happen:
call(
)
We could circumvent that using seq2(3, npd)
instead, can't actually remember why I did not do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rlang::seq2(3, 2)
#> integer(0)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uups, no error then, sorry. Buth by dropping the if condition, we cannot solve the problem because if npd = 3
, and
call(
)
we want to remove the line break before the closing parent, which we can't using seq2(a, b)
with a>b
. Also, my suggestion to use seq(3, npd)
does not make sense since
call(2
)
would then be classified as multi-line, which I think does not make sense. We should not take the closing parenthesis into account. What do you think? Not sure whether there is another way to do that then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks clearer to me to remove the shortcut and add a separate rule to remove new lines for empty calls. This new rule seems to be very low priority.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, sure.
new = ( | ||
2 | ||
) | ||
) # FIXME: Add line break between parens (#125) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need this FIXME?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope.
) | ||
) | ||
1, | ||
2, c( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We seem to need a rule that requires a newline before multi-line function arguments. Do we have a self-contained writeup for the new function call rules? Maybe open a PR to the tidystyle repo so that it's not lost?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, we don't have such a rule yet. So if I understand you correctly, you think
call(
2,
3, c(
2,
3
))
Should be styled as
call(
3,
3,
c(
very_long_such,
that_we_cant_put_it_on_one_line
)
)
If we can't put the whole sub-expression c(...)
on one line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
R/rules-line_break.R
Outdated
} | ||
is_multi_line <- any(pd$lag_newlines[seq2(3, npd - 1)] > 0) | ||
if (!is_multi_line) return(pd) | ||
exeption_pos <- which(pd$token %in% except_token) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exept -> except
R/rules-line_break.R
Outdated
except_token = NULL) { | ||
if (!is_function_call(pd)) return(pd) | ||
npd <- nrow(pd) | ||
if (npd == 3) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks clearer to me to remove the shortcut and add a separate rule to remove new lines for empty calls. This new rule seems to be very low priority.
2b7df99
to
cd805de
Compare
Codecov Report
@@ Coverage Diff @@
## master #149 +/- ##
==========================================
- Coverage 87.68% 85.86% -1.83%
==========================================
Files 19 19
Lines 755 778 +23
==========================================
+ Hits 662 668 +6
- Misses 93 110 +17
Continue to review full report at Codecov.
|
- Vignette on customizing styler (#145). - No line break after `switch()` and friends (#152). - Remove flat relicts completely (#151). - Don't reindent function calls and break line correctly for multi-line calls (#149). - Set space between "=" and "," (#150). - Make R CMD Check perfect (#148). - Adding tests for exception handling with invalid parse data (#139). - Fix indention by checking for all potential triggers (#142). - Fix un-indention (#135). - Support wide characters (#130). - No spaces around :, :: and :::. - Redesigning the API (#123). - Solve eq_sub indention in general (#125). - Minor refactorings. - Re-indent token-dependent (#119). - Supporting more indention patterns. - Allow raw indention. - Definitively fixing eol issue with comments. - Infrastructure. - Flattening out the parse table. - New rule: no space after ! -> !!! for tidyeval. - Fix spacing around '{'. - Don't drop tokens! Fixes #101. - EOL spaces in empty comments (and in general) (#98). - mal-indention in conditional statement due to wrong specification of indent_without_paren) (#95). - Complicated indentions based on arithmetic and special operators (#96). - indention interaction on with assignment operator and other operators (#97).
Removes function
update_indention_ref_fun_call()
fromstyle_tidyverse()
and adds functions to (1) add line break after opening brace of function calls if the call is multi-line and (2) adds a line break before closing brace if the call is multi-line. Closes #134 .