-
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 allow_implicit_else argument for return_linter #2321
Conversation
The linter should probably be made configurable. I can see Also, the message implies explicit returns. Should be reworded to be agnostic of the return style if possible. |
Right, that's why I'm thinking it may be best to subsume into
Not seeing the connection with R6, could you elaborate? |
For implicit returns, the lint could also be desired because the implicit NULL might surprise. Regarding R6: Foo <- R6::R6Class(
"Foo",
public = list(
initialize = function(x) {
self$x <- x
},
x = NULL
)
) Shouldn't lint. |
I think for implicit return style it could also be a good feature to lint terminal Suggestion: |
what is the lint for the implicit return case? that |
Implemented under |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2321 +/- ##
=======================================
Coverage 99.10% 99.10%
=======================================
Files 125 125
Lines 5671 5689 +18
=======================================
+ Hits 5620 5638 +18
Misses 51 51 ☔ View full report in Codecov by Sentry. |
I think there is still a bug in the marking in the new functionality. foo <- function(x, y = 3) {
if(x) {
return(x)
}
} with And in this case there are two separate lints for the foo <- function(x, y = 3) {
if(x) {
x
}
} Would it be ok if I add some test cases? |
@AshesITR unfortunately, I don't understand how this parameter should be understood in implicit style. Can you give an example that should be linted without this parameter but not? I actually found the idea of @MichaelChirico with the different types with gradations of explicitness very elegant |
Thanks @MEO265, arbitrary nesting is now handled in #2362 and adapted here -- your example now catches 3 lints (two missing |
NB this is based against #2362 for now. That means we don't get GHA... |
…plicit_else_return
return_functions = NULL, | ||
except = NULL) { | ||
return_style <- match.arg(return_style) | ||
|
||
if (!allow_implicit_else || return_style == "explicit") { | ||
except_xpath <- glue("parent::expr[not( | ||
preceding-sibling::expr/SYMBOL[{ xp_text_in_table(union(special_funs, except)) }] |
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 was a bit worried about the preceding-sibling::expr
and parent::expr
here in the context of =
or ->
assignment. Added a test for the former; the latter is not relevant I think, because of operator precedence:
function() {
...
} -> .onLoad
Does not work as "intended" -- it actually parses like:
function() ( foo <- { } )
So right-assignment of a function would actually have to look like:
(function() {
...
}) -> .onLoad
That seems pretty unlikely to me, so ignoring it for now unless there's a user request.
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 do see a handful of such assignments, looks like exclusively in the package {symbol.equation.gpt}, but I'm happy to ignore them, e.g.
Part of #884
With this, all of the internal linters we plan to "upstream" are now filed on the tracker 🎉