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
{{ message }}
Repository navigation
How do we exclude if from the implicit_assignment_linter? #2913
No worries. Will close. Is it worth mentioning in the docs that some functions cannot be used in except? I'm still not clear what can't be used in except from the docs.
That said I guess my feature request is to be able to disambiguate the, IMO, more problematic issues such as
fun<-function(x, y) if (y>0) "yes"else"boo"
fun(y<-3, x<--1)
#> [1] "boo"
from ones where the arguments against are more stylistic (i.e. assignment in control structure). In essence I want to be able to flag the fun example to protect colleagues whilst allowing the use of assignment in control structures to which I'm pretty ambivalent.
Is this worth a separate FR issue or is this a no go?
@MichaelChirico - Actually maybe this does want reopening? Coming back to your original comment about allow_scoped, I think the intention would be that this would work (i.e. no lints)
library(lintr)
lint(
linters=list(
implicit_assignment_linter(
except= c("if", "`if`"),
allow_scoped=TRUE)
),
text="if(a <- 1) print(a)"
)
#> <text>:1:4: warning: [implicit_assignment_linter] Avoid implicit assignments in function calls. For example, instead of `if (x <- 1L) { ... }`, write `x <- 1L; if (x) { ... }`.#> if(a <- 1) print(a)#> ^~~~~~
if is also referred to as a function in the hard coded error message within implicit_assignment_linter.
Activity
MichaelChirico commentedon Jul 31, 2025
you might want allow_scoped=TRUE
TimTaylor commentedon Jul 31, 2025
Afraid not
Seems specific to
if()(possibly others)lint( linters = list(implicit_assignment_linter(except = c("mean"), allow_scoped = T)), text="mean(a <- 1)" ) #> ℹ No lints found.MichaelChirico commentedon Jul 31, 2025
allow_scoped will skip if and only if 'a' is used inside that branch and not later on.
there's not support for your use case otherwise, you'll just want to disable the linter.
TimTaylor commentedon Jul 31, 2025
No worries. Will close. Is it worth mentioning in the docs that some functions cannot be used in
except? I'm still not clear what can't be used inexceptfrom the docs.MichaelChirico commentedon Jul 31, 2025
if is an operator, not a function, I'm not sure it's worth mentioning.
TimTaylor commentedon Jul 31, 2025
Even though a control structure I assume it still counts as a function, i.e.
That said I guess my feature request is to be able to disambiguate the, IMO, more problematic issues such as
from ones where the arguments against are more stylistic (i.e. assignment in control structure). In essence I want to be able to flag the
funexample to protect colleagues whilst allowing the use of assignment in control structures to which I'm pretty ambivalent.Is this worth a separate FR issue or is this a no go?
TimTaylor commentedon Jul 31, 2025
@MichaelChirico - Actually maybe this does want reopening? Coming back to your original comment about
allow_scoped, I think the intention would be that this would work (i.e. no lints)ifis also referred to as a function in the hard coded error message within implicit_assignment_linter.MichaelChirico commentedon Jul 31, 2025
That's right -- fixed in #2914.