Skip to content

New argument for implicit_assignment_linter allowing lazy assignment #2016

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
MichaelChirico opened this issue Jul 24, 2023 · 2 comments · Fixed by #2140
Closed

New argument for implicit_assignment_linter allowing lazy assignment #2016

MichaelChirico opened this issue Jul 24, 2023 · 2 comments · Fixed by #2140
Labels
feature a feature request or enhancement
Milestone

Comments

@MichaelChirico
Copy link
Collaborator

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.

@MichaelChirico MichaelChirico added the feature a feature request or enhancement label Jul 24, 2023
@AshesITR
Copy link
Collaborator

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

@MichaelChirico
Copy link
Collaborator Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants