Skip to content

New argument for implicit_assignment_linter allowing lazy assignment #2016

@MichaelChirico

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature request or enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions