Skip to content

Properly handle lambda function bodies in unnecessary_nesting_linter() #2748

@salim-b

Description

@salim-b

Compare

code <- "foo <- function(x) {
  x + 1
}"
writeLines(code)
#> foo <- function(x) {
#>   x + 1
#> }
lintr::lint(
    text = code,
    linters = lintr::unnecessary_nesting_linter()
)
#> ℹ No lints found.

Created on 2025-02-13 with reprex v2.1.1

vs.

code <- "foo <- \\(x) {
  x + 1
}"
writeLines(code)
#> foo <- \(x) {
#>   x + 1
#> }
lintr::lint(
    text = code,
    linters = lintr::unnecessary_nesting_linter()
)
#> <text>:1:13: warning: [unnecessary_nesting_linter] Reduce the nesting of this statement by removing the braces {}.
#> foo <- \(x) {
#>             ^

Created on 2025-02-13 with reprex v2.1.1

Linting this case should be the responsibility of #2240, instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions