-
Notifications
You must be signed in to change notification settings - Fork 186
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 parameters for if_switch_linter() to optionally skip lints on "complex" if/else usage #2413
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2413 +/- ##
=======================================
Coverage 98.55% 98.55%
=======================================
Files 126 126
Lines 5735 5762 +27
=======================================
+ Hits 5652 5679 +27
Misses 83 83 ☔ View full report in Codecov by Sentry. |
Should this lint |
Interesting... possibly? I would wait for user request though, WDYT? |
I feel the linter should enforce some consistency. |
OK, let me double-check how this should work as I'm second-guessing myself trying to wrap my head around it. # always lint if/else if/else if usage
# never lint switch()
if_switch_linter(max_branch_lines = 0, max_branch_expr = 0)
# only lint if/else if/else if of "low" complexity
# also lint switch() of "high" complexity
if_switch_linter(max_branch_lines = 2, max_branch_expr = 3) i.e. these parameters require using |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as outdated.
This comment was marked as outdated.
Looks good, I would make some of the tests "unbalanced" in terms of lines/exprs per branch to ensure the largest/most complex branch dictates behavior. AFAICT there is no such test for |
IIUC those are https://github.com/r-lib/lintr/pull/2413/files#diff-5a5a1de0b476f8f7c4ffcfbf4f4307c8cdfbbfa85367eccf61060e48e433c9e5R337-R340 and https://github.com/r-lib/lintr/pull/2413/files#diff-5a5a1de0b476f8f7c4ffcfbf4f4307c8cdfbbfa85367eccf61060e48e433c9e5R361-R364
No, adding now |
In those tests, all switch branches have the same complexity (loc & expr count). That's what I meant by "balanced". I'd add something like switch(x,
a = 1
b = {
2
3
4; 5; 6
},
c = {
7
}
) to the mix
|
…into if-switch-complexity
Thanks for clarifying, added some tests unbalanced across branches |
Closes #2322