-
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
Improve message for seq_linter()
#1475
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
R/seq_linter.R
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried this, but doesn't seem to work. 🤕
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh i see, i had missed that dot_expr2
was used twice. so introduced dot_expr3
instead
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)