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

Adapt to single indent semantics in style guide #1235

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

krlmlr
Copy link
Member

@krlmlr krlmlr commented Oct 19, 2024

https://style.tidyverse.org/functions.html#multi-line-function-definitions

It's merely a start, doesn't capture all edge cases yet.

Doesn't conflict with #1137 except for the currently last commit that would be easy to do later on.

CC @MichaelChirico.

@krlmlr krlmlr changed the title f single indent Adapt to single indent semantics in style guide Oct 19, 2024
Copy link
Contributor

This is how benchmark results would change (along with a 95% confidence interval in relative change) if 8b9a4a0 is merged into main:

  • ✔️cache_applying: 166ms -> 168ms [-2.56%, +5.29%]
  • ✔️cache_recording: 521ms -> 520ms [-0.83%, +0.42%]
  • ✔️without_cache: 998ms -> 996ms [-1.16%, +0.57%]

Further explanation regarding interpretation and methodology can be found in the documentation.

Copy link
Collaborator

@IndrajeetPatil IndrajeetPatil left a comment

Choose a reason for hiding this comment

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

The changes look good from my end. If you want, you can also add tests for anonymous function and nested function cases for a good measure.

library(styler)

"purrr::map(vec, function(
    x
) NULL)" -> code1

style_text(code1)
#> purrr::map(vec, function(
#>   x
#> ) {
#>   NULL
#> })

"function(
    x,
    f = function(
    x
    ) (x)^2
) NULL" -> code2

style_text(code2)
#> function(
#>   x,
#>   f = function(
#>     x
#>   ) {
#>     (x)^2
#>   }
#> ) {
#>   NULL
#> }

Created on 2024-10-23 with reprex v2.1.1


Outside the scope of the current PR, but this looks a bit off:

function(
  x,
  y) {
  NULL
}

compared to

function(
  x,
  y
) {
  NULL
}

I don't know if the style guide has changed its opinion on supporting the latter in the latest round of updates, though.

@MichaelChirico
Copy link
Contributor

Oh, just realized I'm cc'd. test output LGTM. I might like some cases with comments, especially comments in weird places like

f = function(
a
# comment
= 1
) { a }

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.

3 participants