Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
This PR makes
return()
statements going to a new line and hence closes #473. They are already always on a new line with the current implementation oftidyverse_style()
, the only exception occurs in conjunction with a conditional statement, as described in #473. For this reason, the rule to be implemented is not a line break rule. Because all line break rules do separate expressions that could also go on one line like{1}
orx %>% y()
but the requirements for #473 are different. Implementing as a line break rule leads to a lot of headake as described in #473 because it had to be as follows:return()
.return()
and then remove the line break right at thereturn
token. However, findingreturn()
might be non-trivial because you can also almost always haveCOMMENT
tokens in the parse table.This results in a lot of code and additional complexity (I tried it). Instead, we modify the behavior of
wrap_if_else_multi_line_in_curly()
(renamed) to always wrap the if statement in curly braces when it containsreturn()
. In addition, this approach lets us easily wrap for and while loop statement into braces too, using akey_token
that indicates for each of the cases (if, for, while loop) which tokens helps identifying the expression to wrap into curly braces (ignoring comments). Apart from this, this PR is unfortunately convoluted with some clean-up, documentation improvement and re-location of function declarations between files. Hence, this PR closes #286.This PR also includes the renaming of
wrap_if_else_while_for_multi_line_in_curly)
in the tidyverse style guide, which some people might rely on because it is the output of an exported function.