Skip to content

New argument for implicit_assignment_linter to skip "scoped" usages #2015

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 · 1 comment · Fixed by #2171
Closed

New argument for implicit_assignment_linter to skip "scoped" usages #2015

MichaelChirico opened this issue Jul 24, 2023 · 1 comment · Fixed by #2171
Labels
feature a feature request or enhancement
Milestone

Comments

@MichaelChirico
Copy link
Collaborator

I sometimes find the following type of usage to be appropriate for "implicit" assignment:

if (any(idx <- x > 0)) {
  stop("Found positive entries: [", toString(which(idx)), "]")
}

The object idx is not used outside the branch, so I think it can be distracting to define it in the "main" body of the function. I believe @IndrajeetPatil has a cite on this being good practice in some contexts too.

It would be nice to allow this sort of implicit assignment, defined by the object of assignment is (1) inside if and (2) only referenced inside that if's parent <expr>.

This argument (let's say allow_scoped_if_assignment) would be FALSE by default since the style guide does not consider this exception.

@MichaelChirico
Copy link
Collaborator Author

One question is whether foo(x <- 1) should be linted if x is not referenced anywhere else in the code. I think yes (esp. since this is a common mistake where = was intended), but it will make implementation a bit harder.

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.

1 participant