r-lib / styler

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

R6 methods don't allow double-indented formals? #1136

Open MichaelChirico opened 1 year ago

MichaelChirico commented 1 year ago

The following should be allowed (ref: https://style.tidyverse.org/functions.html#long-lines-1 doesn't mention R6):

R6Class("MyClass",
  public = list(
    param = NULL,
    initialize = function(
        my_long_parameter = getOption("default_long_parameter", 1)) {
      self$param <- my_long_parameter
    }
  )
)

But it's currently re-styled (style_text() output):

R6Class("MyClass",
  public = list(
    param = NULL,
    initialize = function(my_long_parameter = getOption("default_long_parameter", 1)) {
      self$param <- my_long_parameter
    }
  )
)

Which of course creates an over-full line.

lorenzwalthert commented 1 year ago

Right… but I think in your example, you only put one level of indention. Shouldn’t it be

R6Class("MyClass",
  public = list(
    param = NULL,
    initialize = function(
        my_long_parameter = getOption("default_long_parameter", 1)) {
      self$param <- my_long_parameter
    }
  )
)
MichaelChirico commented 1 year ago

ah yes, my mistake. edited in the description

lorenzwalthert commented 1 year ago

Seems like detection of double indention is based on the absolute indention of the formals, instead of the relative...