Skip to content
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

No line break after switch and friends #152

Merged
merged 2 commits into from
Aug 24, 2017

Conversation

lorenzwalthert
Copy link
Collaborator

As requested in krlmlr/rlang#1 (comment), it is now possible to not break the line in function calls where the text of the function is in except_text_before. I.e.

switch(x, 
  z, 
  y
)

Will not be turned into

switch(
  x, 
  z, 
  y
)

Since there is no such rule in the tidyverse style guide yet, I suggest opening an issue or PR before merging this.
Also, I am not sure whether the names of the functions should be an argument to tidyverse_style(). For now, they are not. case_when() might also be such a function that should be treated as an exception.

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.

Looks good. Could you please update the rlang pull request?

@lorenzwalthert
Copy link
Collaborator Author

Sure. Should I submit an issue to the tidyverse style guide?

@krlmlr
Copy link
Member

krlmlr commented Aug 23, 2017

Yes, please.

@codecov
Copy link

codecov bot commented Aug 23, 2017

Codecov Report

Merging #152 into master will increase coverage by 0.09%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #152      +/-   ##
==========================================
+ Coverage   85.86%   85.95%   +0.09%     
==========================================
  Files          19       19              
  Lines         778      783       +5     
==========================================
+ Hits          668      673       +5     
  Misses        110      110
Impacted Files Coverage Δ
R/rules-line_break.R 100% <100%> (ø) ⬆️
R/style_guides.R 97.5% <100%> (+0.03%) ⬆️

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 5868c21...319a165. Read the comment docs.

@lorenzwalthert
Copy link
Collaborator Author

Do you think the text tokens be arguments in tidyverse_style as outlined above?

@@ -75,7 +75,8 @@ tidyverse_style <- function(scope = "tokens",
add_line_break_before_curly_closing,
partial(
set_line_break_after_opening_if_call_is_multi_line,
except_token = "COMMENT"
except_token_after = "COMMENT",
except_text_before = c("switch", "ifelse", "if_else")
Copy link
Member

Choose a reason for hiding this comment

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

Maybe expose an argument to tidyverse_style() that allows adding more exceptions?

Copy link
Member

Choose a reason for hiding this comment

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

(Basically answering "yes" to your earlier question, if I understood correctly.)

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, what how does that relate to tidyverse/style#39? It seems to be about named arguments according to the answer there, and not to function names anyways.

Copy link
Member

Choose a reason for hiding this comment

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

Let's merge this the way it is now and discuss rules that involve named/unnamed arguments separately.

@@ -75,7 +75,8 @@ tidyverse_style <- function(scope = "tokens",
add_line_break_before_curly_closing,
partial(
set_line_break_after_opening_if_call_is_multi_line,
except_token = "COMMENT"
except_token_after = "COMMENT",
Copy link
Member

Choose a reason for hiding this comment

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

Side note: I'm not sure about the scope argument to this function, maybe scope should be an argument of the top-level style_() functions? The default values of the arguments to this function here are useful, we can easily change that later.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Well you can do style_text("a <- 3", scope = "tokens"), so it is a top-level argument trough ...

Copy link
Member

Choose a reason for hiding this comment

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

We can keep it for now and decide later.

@krlmlr krlmlr merged commit 1b2573e into r-lib:master Aug 24, 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).
@lorenzwalthert lorenzwalthert deleted the no_reindention_calls branch September 17, 2017 20:58
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