r-lib / styler

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

Disagreement with styler and lintr about long lines. Rstudio gives a better format #1192

Closed maikol-solis closed 3 months ago

maikol-solis commented 3 months ago

Hi!

I have this problem. Suppose you have this long line in your code:

value <- my_function(arg0 = 0, arg1 = 1, arg2 = 2, arg3 = 3, arg4 = 4, arg5 = 5, arg6 = 6, arg7 = 7)

Checking it with styler, returns the unmodified string.

styler::style_text("value <- my_function(arg0 = 0, arg1 = 1, arg2 = 2, arg3 = 3, arg4 = 4, arg5 = 5, arg6 = 6, arg7 = 7)")
value <- my_function(arg0 = 0, arg1 = 1, arg2 = 2, arg3 = 3, arg4 = 4, arg5 = 5, arg6 = 6, arg7 = 7)

However, lintr is complaining about the length of the line

[line_length_linter]: Lines should not be more than 80 characters. This line is 100 characters. 

In my opinion, Rstudio gives a better format:

value <-
  my_function(
    arg0 = 0,
    arg1 = 1,
    arg2 = 2,
    arg3 = 3,
    arg4 = 4,
    arg5 = 5,
    arg6 = 6,
    arg7 = 7
  )

What can I do to make styler behave like Rstudio in this case?

Best.

IndrajeetPatil commented 3 months ago

Closing in favour of #247

If you want to avoid the lint, you can change the length limit in the lintr config:

library(lintr)

lint(
  text = "value <- my_function(arg0 = 0, arg1 = 1, arg2 = 2, arg3 = 3, arg4 = 4, arg5 = 5, arg6 = 6, arg7 = 7)",
  linters = line_length_linter(120L)
)

Created on 2024-04-20 with reprex v2.1.0

maikol-solis commented 3 months ago

Thanks for the tip.