Skip to content

New argument for implicit_assignment_linter allowing lazy assignment #2016

Closed

Description

@MichaelChirico

Related but I'm not sure it's the same as #2015.

Another type of violation to implicit_assignment_linter() that I find a bit awkward to refactor looks like:

if (rare_condition1 && rare_condition2 && foo(key <- val)) {
  bar(key)
}

Lazy assignment means it's rare that key is actually assigned, so this refactor is wasteful:

key <- val
if (rare_condition1 && rare_condition2 && foo(key)) {
  bar(key)
}

The version that seems preferred gets close to an unnecessary_nested_if() violation:

if (rare_condition1 && rare_condition2) {
  key <- val
  if (foo(key)) {
    bar(key)
  }
}

This increases the indentation vs. the original version; this problem gets worse (possibly combinatorially) if there's more than one such assignment in the same if() condition.

IINM this is a subset of #2015, but still could be used in different situations. Again there's no such carveout in the style guide, so this usage should be disallowed by default.

Activity

  1. added
    feature
    on Jul 24, 2023
  2. AshesITR commented on Jul 27, 2023

    @AshesITR
    Collaborator

    Wasteful in the sense that key can't be gc() ed immediately after the if branch?

  3. MichaelChirico commented on Jul 27, 2023

    @MichaelChirico
    CollaboratorAuthor

    more importantly we could have key <- costly_call() that can be avoided

  4. added this to the 3.1.1 milestone on Aug 22, 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

    feature

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions