Skip to content

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

Merged
merged 8 commits into from
Aug 23, 2017

Conversation

lorenzwalthert
Copy link
Collaborator

Removes function update_indention_ref_fun_call() from style_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 .

@lorenzwalthert lorenzwalthert force-pushed the no_reindention_calls branch 2 times, most recently from 278001c to 4c5a13c Compare August 22, 2017 18:10
@lorenzwalthert lorenzwalthert changed the title No reindention calls Don't reindent function calls Aug 22, 2017
@lorenzwalthert lorenzwalthert requested a review from krlmlr August 22, 2017 18:10
Copy link
Member

@krlmlr krlmlr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks!

except_token = NULL) {
if (!is_function_call(pd)) return(pd)
npd <- nrow(pd)
if (npd == 3) {
Copy link
Member

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?

Copy link
Collaborator Author

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.

Copy link
Member

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)

Copy link
Collaborator Author

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.

Copy link
Member

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.

Copy link
Collaborator Author

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)
Copy link
Member

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope.

)
)
1,
2, c(
Copy link
Member

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?

Copy link
Collaborator Author

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

}
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exept -> except

except_token = NULL) {
if (!is_function_call(pd)) return(pd)
npd <- nrow(pd)
if (npd == 3) {
Copy link
Member

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.

@codecov
Copy link

codecov bot commented Aug 23, 2017

Codecov Report

Merging #149 into master will decrease coverage by 1.82%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
R/rules-spacing.R 95.16% <ø> (ø) ⬆️
R/style_guides.R 97.46% <100%> (+0.2%) ⬆️
R/rules-line_break.R 100% <100%> (ø) ⬆️
R/reindent.R 63.04% <0%> (-36.96%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update db6d4b1...ae7c748. Read the comment docs.

@lorenzwalthert lorenzwalthert merged commit 5868c21 into r-lib:master Aug 23, 2017
krlmlr added a commit that referenced this pull request Aug 24, 2017
- 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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants