r-lib / styler

Non-invasive pretty printing of R code
https://styler.r-lib.org
Other
713 stars 70 forks source link

Add newline after standalone closing parenthesis with comma? #1133

Closed krlmlr closed 9 months ago

krlmlr commented 1 year ago

I'm confused by the following behavior:

styler::style_text("
list(
  c(
    a
  ), c(
    b
  )
)
")
#> list(
#>   c(
#>     a
#>   ), c(
#>     b
#>   )
#> )

Created on 2023-06-15 with reprex v2.0.2

Should styler add a newline here? What's a precise description of the rules to be applied here?

lorenzwalthert commented 1 year ago

I think if there is a line break, it won’t remove it, so think the behavior works for both cases. Maybe we can also add an argument to tidyverse_style() to enforce adding one.

krlmlr commented 1 year ago

I wonder if there are legitimate cases where a line break is not desired here.

MichaelChirico commented 1 year ago

Adding a newline for cases like this tends to create a lot of wasted whitespace.

I might choose to add a newline myself, but styler's defaults should be non-invasive -- unless there's a specific rule, don't do anything.

If there's a gap in the style guide, the fix should start from there:

https://github.com/tidyverse/style/issues