Skip to content

Add exception in unnecessary_nesting_linter() for paired stop()/warning() branches #2325

@MichaelChirico

Description

@MichaelChirico

Hopefully the to-be-squashed commit 35ab376 survives as a reference for the implementation.

The description of the issue is as follows:

if (A) {
  stop("A is bad!")
} else {
  warning("!A is worrying, but not catastrophic!")
}

Is a common pattern that could in principle be unnested:

if (A) {
  stop("A is bad!")
}
warning("!A is worrying, but not catastrophic!")

But this format is a bit more awkward / doesn't leverage the clear if/else structure to make it clear what's happening.

We should do the following:

  1. Decide when exactly this reasoning applies. The example above is very clear, but what about if there's intervening code before/after warning() in the latter branch?
  2. Decide how to expose this to users. In principle there could be two parameters to this function [1] "exit" calls like stop()/q() that are guaranteed to terminate a branch [2] "signal" calls that can be "companion" calls to an "exit call", e.g. warning()

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