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

Single-indent multi-line function definitions #2830

Open
d-morrison opened this issue Mar 10, 2025 · 3 comments
Open

Single-indent multi-line function definitions #2830

d-morrison opened this issue Mar 10, 2025 · 3 comments

Comments

@d-morrison
Copy link

The "Good" "Single-indent" example of "Multi-line function definitions" from the tidyverse style guide (https://style.tidyverse.org/functions.html#multi-line-function-definitions) currently generates a lint from indentation_linter:

code <-
'long_function_name <- function(
    a = "a long argument",
    b = "another argument",
    c = "another long argument"
) {
  # As usual code is indented by two spaces.
}'
cat(code)
#> long_function_name <- function(
#>     a = "a long argument",
#>     b = "another argument",
#>     c = "another long argument"
#> ) {
#>   # As usual code is indented by two spaces.
#> }
lintr::lint(code)
#> <text>:2:4: style: [indentation_linter] Indentation should be 2 spaces but is 4 spaces.
#>     a = "a long argument",
#>   ~^

Created on 2025-03-10 with reprex v2.1.1

This occurs both with v3.2.0 from CRAN and commit a2b8d6f from GitHub.

In contrast, moving ) { onto the line of the last argument produces no lint:

code <-
'long_function_name <- function(
    a = "a long argument",
    b = "another argument",
    c = "another long argument") {
  # As usual code is indented by two spaces.
}'
cat(code)
#> long_function_name <- function(
#>     a = "a long argument",
#>     b = "another argument",
#>     c = "another long argument") {
#>   # As usual code is indented by two spaces.
#> }
lintr::lint(code)
#> ℹ No lints found.

Created on 2025-03-10 with reprex v2.1.1

@AshesITR
Copy link
Collaborator

AshesITR commented Mar 11, 2025

Double indentation for argument lists was removed from the tidyverse guide. So to me the first example is expected default behavior?

@d-morrison
Copy link
Author

Ah - I didn't realize that those indents had gotten doubled when I set up the reprex (they are un-doubled in the style guide).
I think "Reindent lines" (Ctrl-I) in RStudio still adds the double-indent (c.f. rstudio/rstudio#10752 and rstudio/rstudio#11101).

If double-indentation has been removed from the style guide, should the second example above also throw a lint? It also has double indentation, but currently no lint is thrown. Here's a slightly clearer version:

code <-
'
long_function_name <- function(
    a = "a long argument",
    b = "another argument",
    c = "another long argument") {
  # As usual code is indented by two spaces.
}
'
cat(code)
#> 
#> long_function_name <- function(
#>     a = "a long argument",
#>     b = "another argument",
#>     c = "another long argument") {
#>   # As usual code is indented by two spaces.
#> }
lintr::lint(code)
#> ℹ No lints found.

Created on 2025-03-11 with reprex v2.1.1

@AshesITR
Copy link
Collaborator

Yes I agree that could lint.
IMO it's not an indentation lint though, I think the lint should land on ) which should be on a new line since the corresponding ( is last-on-line.

WDYT, @MichaelChirico and @IndrajeetPatil?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants