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

Remove excessive line breaks between top-level expressions #1239

Merged
merged 17 commits into from
Dec 4, 2024

Conversation

IndrajeetPatil
Copy link
Collaborator

Partly related to #1238, but kind of veered away from it during implementation. Opening for an early feedback.

library(styler)
styler::cache_deactivate()
#> Deactivated cache.

# Example-1 --------------------------------

"f <- function() NULL






g <- function() NULL" -> code

style_text(text = code)
#> f <- function() NULL
#> 
#> 
#> g <- function() NULL

# Example-2 --------------------------------

"while (TRUE) {
  print('hello')
}







for (i in 1:10) {
  print(i)
}" -> code

style_text(text = code)
#> while (TRUE) {
#>   print("hello")
#> }
#> 
#> 
#> for (i in 1:10) {
#>   print(i)
#> }

# Example-3 --------------------------------

"#' @param x A numeric vector
#' @return bla bla bla
f <- function(x) NULL







#' @param y A numeric vector
#' @return bla bla bla
g <- function(y) NULL" -> code

style_text(text = code)
#> #' @param x A numeric vector
#> #' @return bla bla bla
#> f <- function(x) NULL
#> 
#> 
#> #' @param y A numeric vector
#> #' @return bla bla bla
#> g <- function(y) NULL

Created on 2024-11-28 with reprex v2.1.1

#' @param pd_flat A flat parse table.
#' @param allowed_blank_lines The maximum number of allowed blank lines between code elements. Default is `2L`.
#' @keywords internal
reduce_extra_blank_lines_between_scopes <- function(pd_flat, allowed_blank_lines = 2L) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Style guide recommends one line breaks, but only for function calls. But that itself felt quite aggressive, given the huge numbers of changes in test outputs.

2L nicely aligns with Python and feels "natural" as well.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Lets limit to two blank lines as towards the style guide and decide later if we'll go all the way to one line break. Also, can you please apply the 2L limit to strict = TRUE only?

Copy link
Contributor

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

  • ✔️cache_applying: 184ms -> 183ms [-2.51%, +1.68%]
  • ✔️cache_recording: 556ms -> 555ms [-0.85%, +0.53%]
  • ✔️without_cache: 1.05s -> 1.05s [-1.56%, +2.38%]

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

Copy link
Contributor

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

  • ✔️cache_applying: 155ms -> 155ms [-2.77%, +2.92%]
  • ✔️cache_recording: 518ms -> 523ms [-0.17%, +1.93%]
  • ✔️without_cache: 993ms -> 1s [-0.22%, +1.79%]

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

@IndrajeetPatil IndrajeetPatil changed the title [WIP] Remove excessive line breaks between scopes Remove excessive line breaks between scopes Nov 30, 2024
R/rules-line-breaks.R Outdated Show resolved Hide resolved
R/rules-line-breaks.R Outdated Show resolved Hide resolved
@IndrajeetPatil IndrajeetPatil changed the title Remove excessive line breaks between scopes Remove excessive line breaks between top-level expressions Nov 30, 2024
Copy link
Contributor

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

  • ✔️cache_applying: 142ms -> 141ms [-1.06%, +0.44%]
  • ✔️cache_recording: 496ms -> 498ms [-0.01%, +0.89%]
  • ❗🐌without_cache: 952ms -> 961ms [+0.33%, +1.68%]

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

Copy link
Contributor

github-actions bot commented Dec 1, 2024

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

  • ✔️cache_applying: 160ms -> 158ms [-4.36%, +2.17%]
  • ✔️cache_recording: 518ms -> 523ms [-0.33%, +2.29%]
  • ✔️without_cache: 1000ms -> 1.01s [-0.07%, +1.92%]

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

@IndrajeetPatil
Copy link
Collaborator Author

@lorenzwalthert I am not fully sold on the testing strategy here. Instead of tweaking the existing tests, I think I should create a new folder for "line breaks and top-level expressions" and add all new test cases there.

WDYT?

@lorenzwalthert
Copy link
Collaborator

lorenzwalthert commented Dec 2, 2024

@lorenzwalthert I am not fully sold on the testing strategy here. Instead of tweaking the existing tests, I think I should create a new folder for "line breaks and top-level expressions" and add all new test cases there.

Right... Yes, you could crate a new folder if you want. Also, I renamed the transformer (again) to make its name more consistent with existing names of line break related transformes.

Copy link
Contributor

github-actions bot commented Dec 2, 2024

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

  • ✔️cache_applying: 152ms -> 151ms [-2.42%, +1.93%]
  • ✔️cache_recording: 516ms -> 521ms [-0.22%, +1.84%]
  • ✔️without_cache: 985ms -> 990ms [-0.18%, +1.23%]

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

Copy link
Contributor

github-actions bot commented Dec 3, 2024

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

  • ✔️cache_applying: 184ms -> 186ms [-1.91%, +4.4%]
  • ❗🐌cache_recording: 534ms -> 542ms [+0.05%, +2.93%]
  • ✔️without_cache: 1.05s -> 1.06s [-0.11%, +2.02%]

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

Copy link
Collaborator

@lorenzwalthert lorenzwalthert left a comment

Choose a reason for hiding this comment

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

Thanks a lot @IndrajeetPatil 🥳

@IndrajeetPatil IndrajeetPatil merged commit 2f1cc9b into main Dec 4, 2024
18 checks passed
@IndrajeetPatil IndrajeetPatil deleted the rm-line-breaks-between-funs branch December 4, 2024 13:18
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