You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've noticed that when a variable is being used in a function without assignment, we can expect that object_usage_linter can detect it. For instance variable bar here:
foo <- function() {
# bar gets tagged with object_usage_linter
if (bar == "5") return(TRUE)
return(FALSE)
}
However, if we declare this variable after usage, either independently or as a name within an iterator, the object_usage_linter no longer thinks it is an issue.
foo <- function() {
# bar doesn't get tagged with object_usage_linter
if (bar == "5") return(TRUE)
bar <- "1"
return(FALSE)
}
foo <- function(test_vec) {
# bar doesn't get tagged with object_usage_linter
if (bar == "5") return(TRUE)
for (bar in test_vec) next
return(FALSE)
}
I have all linters on and I can't seem to get something that would flag variable usage before declaration. Would it be possible to build something that does this?
The text was updated successfully, but these errors were encountered:
This is doable in principle using static code analysis and assuming well behaved R code. However, object_usage_linter() wraps codetools::checkUsage, so that would be a better place for this enhancement.
I've noticed that when a variable is being used in a function without assignment, we can expect that
object_usage_linter
can detect it. For instance variablebar
here:However, if we declare this variable after usage, either independently or as a name within an iterator, the
object_usage_linter
no longer thinks it is an issue.I have all linters on and I can't seem to get something that would flag variable usage before declaration. Would it be possible to build something that does this?
The text was updated successfully, but these errors were encountered: