-
Notifications
You must be signed in to change notification settings - Fork 186
New linter for if(x == TRUE)
and if(x == FALSE)
#1500
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
Comments
|
Thank you for your reply and for explaining the details. I am assuming something similar to what shellcheck detects for single quotes.
|
Agreed that these should lint: library(lintr)
lint(text = "if (x == TRUE) 1L",
linters = linters_with_tags(tags = NULL))
lint(text = "if (x == FALSE) 0L",
linters = linters_with_tags(tags = NULL)) Created on 2022-08-26 with reprex v2.0.2 |
FWIW, we have a linter for this already (slated for upstreaming eventually). Any ==TRUE/FALSE expression is linted. One tougher case is data.table subsetting, where the overloading of the DT[is_treatment == TRUE]
# WRONG, not equivalent
DT[is_treatment]
# correct -- data.table uses () to signal "not a join"
DT[(is_treatment)] |
Nice! Should this get the "google-linter" label then? |
up to OP -- originally the requested linter is slightly different. but if this format is satisfactory they ok |
if(isTRUE(x))
and if(isFALSE(x))
if(x == TRUE)
and if(x == FALSE)
I think it would be great if it were implemented. |
@MichaelChirico Not sure how much it would be to port this over from Google, but, for now, marking this for |
That's fine, I don't think there's any rush for 3.0.2. Porting is mostly tedium to switch internal idioms to match lintr style, and more importantly reviewer bandwidth. |
It may be useful for beginners if this is pointed out by lintr, since it may be more appropriate to rewrite
if(x == TRUE) {...}
as followsThe text was updated successfully, but these errors were encountered: