Skip to content

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

@MichaelChirico

Description

@MichaelChirico

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.

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