Skip to content

Single-indent multi-line function definitions #2830

@d-morrison

Description

@d-morrison

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions