Skip to content

unnecessary_lambda_linter() gets confused by indexing in lambda function #2231

Closed

Description

@Bisaloo
lintr::lint(
  text = "lapply(l, function(x) rle(x)$values)",
  linters = lintr::unnecessary_lambda_linter()
)
#> <text>:1:11: warning: [unnecessary_lambda_linter] Pass rle directly as a symbol to lapply() instead of wrapping it in an unnecessary anonymous function. For example, prefer lapply(DF, sum) to lapply(DF, function(x) sum(x)).
#> lapply(l, function(x) rle(x)$values)
#>           ^~~~~~~~~~~~~~~~~~~~~~~~

lintr::lint(
  text = "lapply(l, function(x) rle(x)[['values']])",
  linters = lintr::unnecessary_lambda_linter()
)
#> <text>:1:11: warning: [unnecessary_lambda_linter] Pass rle directly as a symbol to lapply() instead of wrapping it in an unnecessary anonymous function. For example, prefer lapply(DF, sum) to lapply(DF, function(x) sum(x)).
#> lapply(l, function(x) rle(x)[['values']])
#>           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Created on 2023-10-06 with reprex v2.0.2

I believe these are valid cases and shouldn't create lints

Activity

  1. MichaelChirico commented on Oct 6, 2023

    @MichaelChirico
    Collaborator

    nice find, thanks

  2. added this to the 3.1.1 milestone on Oct 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    false-positivecode that shouldn't lint, but doesregressioncode that used to work, but now doesn't

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions