Repository navigation
Improve message for seq_linter() - #1475
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
| "%s:%s is likely to be wrong in the empty edge case. Use %s() instead.", | ||
| dot_expr1, dot_expr2, replacement | ||
| if (length(replacement) > 0L) { | ||
| lint_message <- ifelse(replacement == "seq_len", |
There was a problem hiding this comment.
i think we can avoid the nested ifelse by setting dot_expr2 = "..." for the seq_along() branch:
dot_expr2[replacement == "seq_along"] <- "..."
lint_message <- ifelse(
grepl("seq", dot_expr1, fixed = TRUE),
...
)There was a problem hiding this comment.
Tried this, but doesn't seem to work. 🤕
There was a problem hiding this comment.
Feel free to push into the PR if you can get it to work. Maybe I missed something.
There was a problem hiding this comment.
Btw, this is the second time we have talked about avoiding nested ifelse().
I am wondering if we should introduce a new linter to cover such cases?
Providing a concrete alternative in lint message will be difficult, though.
There was a problem hiding this comment.
I am wondering if we should introduce a new linter to cover such cases?
There's already lintr::nested_ifelse_linter(), it's just not a default linter
Providing a concrete alternative in lint message will be difficult, though.
There's no requirement to do so. The message can suggest alternatives but doesn't need to be concrete. That's one of the main differences vs. styler, in fact -- styler generally has to be a bit more conservative & shouldn't touch code unless there's a clear, specific improvement, whereas lintr can call out code that can be improved without doing the improvement.
There was a problem hiding this comment.
oh i see, i had missed that dot_expr2 was used twice. so introduced dot_expr3 instead
There was a problem hiding this comment.
There's already lintr::nested_ifelse_linter(), it's just not a default linter
Oh, missed that completely! Good to know.
introduced dot_expr3 instead
Thanks for simplifying. Much more readable now!
There was a problem hiding this comment.
Okay, I went through the docs and the code, but I don't see any explanation for why this is not a default linter.
I think it should be.
E.g., in a PR like the current, we wouldn't even have to rely on its usage being caught by manual code review; the linter GHA itself would notify the contributor about the added lint.
|
Great stuff! Agree on the message format. Looks way better. |
Closes #1471
TODO:
Refactor code(I am not sure if the nestedifelse()can be avoided)Created on 2022-07-26 by the reprex package (v2.0.1)