Repository navigation
New unnecessary_nesting_linter - #2302
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2302 +/- ##
=======================================
Coverage 99.40% 99.40%
=======================================
Files 122 123 +1
Lines 5523 5584 +61
=======================================
+ Hits 5490 5551 +61
Misses 33 33 ☔ View full report in Codecov by Sentry. |
| # NB: print() is intentionally excluded since its usage is usually a mistake (?print_linter) | ||
| signal_calls <- c( | ||
| exit_calls, | ||
| "warning", "warn", "message", "cat", "LOG", "stopifnot" |
There was a problem hiding this comment.
LOG should not be default, and probably we should have an arg for configuration.
There was a problem hiding this comment.
yep... left it in here as a reminder to discuss what sort of parameterization we should build in here, WDYT?
allow_signal_calls = c("warning", "message", "cat", "stopifnot")?
There was a problem hiding this comment.
So, just to understand this: These functions explicitly allow a parallel branch in if statements with a single control-flow breaking statement?
There was a problem hiding this comment.
Right... they're allowed to pair with "exit" clauses, but can't cause a lint by themselves -- nested code using them can't always be unnested. IOW they can remove a lint, but not cause a lint.
There was a problem hiding this comment.
won't lint -- only the terminal call is examined
There was a problem hiding this comment.
So
if (A) {
stop()
} else {
warning()
do()
}Would lint?
There was a problem hiding this comment.
Of course, one could always disable this behavior (and always force unnesting if possibe) by passing e.g. character() to the argument accepting a vector of calls.
There was a problem hiding this comment.
I'm just wondering how intuitive the exception logic is.
| # NB: print() is intentionally excluded since its usage is usually a mistake (?print_linter) | ||
| signal_calls <- c( | ||
| exit_calls, | ||
| "warning", "warn", "message", "cat", "LOG", "stopifnot" |
SGTM. Should default to not linting (so |
|
I think the exceptions need some additional thought. Two options:
Which do you prefer? |
let's go with one, I'm for making these PRs as sleek as possible in general: |
| or self::IF | ||
| or self::WHILE | ||
| or self::REPEAT | ||
| or self::expr/SYMBOL_FUNCTION_CALL[text() = 'switch'] |
There was a problem hiding this comment.
Parameterize the list of allowed functions?
There was a problem hiding this comment.
Have something specific in mind? Per the comment, switch() is included here as a control flow which happens to be a function, so it's treated the same as if/for/while/repeat.
There was a problem hiding this comment.
Let's follow up in #2334, removed the exception for switch() for now.
Part of #884