tidyverse / style

The tidyverse style guide for R code
https://style.tidyverse.org
Other
293 stars 100 forks source link

Formating of function arguments behaviour changes if `indent_by` is not `2` #211

Closed averissimo closed 7 months ago

averissimo commented 7 months ago

Problem: Changing indent_by configuration doesn't implement the same styling guides (on "Double-indent")

It changes the style to "Function-indent" (reference)

Reproducible code:

foo_2 <- "foo <- function(
    bar) {
  NULL
}"

foo_4 <- "foo <- function(
        bar) {
    NULL
}"

styler::style_text(foo_2)
#> foo <- function(
#>     bar) {
#>   NULL
#> }
styler::style_text(foo_4, indent_by = 4L)
#> foo <- function(bar) {
#>     NULL
#> }
styler::style_text(foo_4, transformers = styler::tidyverse_style(indent_by = 4))
#> foo <- function(bar) {
#>     NULL
#> }

testthat::expect_identical(
    foo_2 |> 
        styler::style_text(transformers = styler::tidyverse_style(indent_by = 2L)) |> 
        as.character() |> 
        paste(collapse = "\n", sep = ""),
    foo_2
)

testthat::expect_identical(
    foo_4 |> 
        styler::style_text(transformers = styler::tidyverse_style(indent_by = 4)) |> 
        as.character() |> 
        paste(collapse = "\n", sep = ""),
    foo_4
)
#> Error: paste(...) not identical to `foo_4`.
#> 1/1 mismatches
#> x[1]: "foo <- function(bar) {\n    NULL\n}"
#> y[1]: "foo <- function(\n        bar) {\n    NULL\n}"

Created on 2024-02-14 with reprex v2.1.0

lorenzwalthert commented 7 months ago

I think this should be transferred to r-lib/styler.

averissimo commented 7 months ago

Ah sorry. You're right.