Skip to content

implicit_assignment_linter misses non-call assignments #2138

Closed

Description

@MichaelChirico

#2016 is not quite as relevant at the moment since assignments like this are always skipped:

lint("A && (B <- ...)\n", implicit_assignment_linter())

Activity

  1. added this to the 3.1.1 milestone on Sep 11, 2023
  2. MichaelChirico commented on Sep 11, 2023

    @MichaelChirico
    CollaboratorAuthor

    There are two existing tests that would be affected by the simplest fix:

    expect_lint("mean(x <- (y <- 1:3) + 1L)", lint_message, linter)

    The latter looks like it should be two lints to me.

    The former is tougher. Should we carve out an exception for {purrr} mappers? OTOH this is like a violation of function_return_linter() -- why have an assignment in a one-line function? If it is <<- (which is also covered by //LEFT_ASSIGN), it's more interesting, but we could still force { to be used instead:

    x <- 1
    map(
      .x = 1:4,
      .f = ~ {x <<- .x + x}
    )

    Of course, that's a brace_linter() violation now, so it would have to be:

    x <- 1
    map(
      .x = 1:4,
      .f = ~ {
        x <<- .x + x
      }
    )

    cc @IndrajeetPatil

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-negativecode that should lint, but doesn't

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions