-
Notifications
You must be signed in to change notification settings - Fork 185
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
unnecessary_lambda_linter() misses '!' when suggesting removing a lambda #2742
Comments
Is Even so, would |
Indeed that usage should be changed to I also saw it hitting on I think you're right moving the |
Indeed: lint(text = "sapply(x, function(xi) -foo(xi))", linters = unnecessary_lambda_linter())
# <text>:1:11: warning: [unnecessary_lambda_linter] Pass foo directly as a symbol to sapply() instead of wrapping it in an unnecessary anonymous function. For example, prefer lapply(DF, sum) to lapply(DF, function(x) sum(x)).
# sapply(x, function(xi) -foo(xi))
# ^~~~~~~~~~~~~~~~~~~~~ Still |
I would suspect this is only a problem when the unary operations dispatch to different implementations within the loop (say the inner function can return different types with different negation semantics and the sapply() unifies the types) I'd keep it as a feature unless a real life false positive pops up. |
Right, exactly. At a minimum, we need to fix the lint message, which is incorrect in this case. |
We could do
sapply(x, Negate(all.equal), y)
, I think, but that's hardly a strict improvement.The text was updated successfully, but these errors were encountered: