-
Notifications
You must be signed in to change notification settings - Fork 187
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
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. |
R/unnecessary_nesting_linter.R
Outdated
# 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LOG should not be default, and probably we should have an arg for configuration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not 100% sure yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
won't lint -- only the terminal call is examined
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So
if (A) {
stop()
} else {
warning()
do()
}
Would lint?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm just wondering how intuitive the exception logic is.
R/unnecessary_nesting_linter.R
Outdated
# 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not 100% sure yet.
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: |
R/unnecessary_nesting_linter.R
Outdated
or self::IF | ||
or self::WHILE | ||
or self::REPEAT | ||
or self::expr/SYMBOL_FUNCTION_CALL[text() = 'switch'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parameterize the list of allowed functions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those discussed in #2326 come to mind.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's follow up in #2334, removed the exception for switch()
for now.
Part of #884