-
Notifications
You must be signed in to change notification settings - Fork 186
extend assignment_linter for other operators #928
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
Conversation
@AshesITR PTAL at the test failure. Looks odd to me. For now I just removed the test. At HEAD,
vs. in this PR it's
What's puzzling is the test is checking that exactly the new value of lintr/tests/testthat/test-expect_lint.R Line 28 in 6f55ef5
So I'm second guessing if there's a reason for that? I can't think of any. And
There's this comment in the original PR:
|
tests/testthat/test-expect_lint.R
Outdated
expect_failure(expect_lint("a=1", list(ranges = list(c(2L, 2L))), linter)) | ||
expect_success(expect_lint("a=1", list(ranges = list(c(2L, 2L))), linter)) |
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.
What was the original failure?
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.
Error: check #1: ranges NULL did not match list(c(2L, 2L))
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.
So that seems like a way of documenting the bug we just fixed 😆
Feel free to remove the test.
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.
Despite not really knowing the purpose of the test I'm still a bit loath to remove it 😆
I changed it to use a different linter that gives NULL
for ranges
ah poop. git is hard. |
c774fd2
to
a647042
Compare
R/assignment_linter.R
Outdated
# always block = (NB: the parser differentiates EQ_ASSIGN, EQ_SUB, and EQ_FORMALS) | ||
"//EQ_ASSIGN", | ||
# -> and ->> are both 'RIGHT_ASSIGN' | ||
if (!allow_right_assign) "//RIGHT_ASSIGN" else if (!allow_cascading_assign) "//RIGHT_ASSIGN[text() = '->>']", | ||
# <-, :=, and <<- are all 'LEFT_ASSIGN'; check the text if blocking <<- |
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.
Shouldn't we lint :=
as well?
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.
We'd have to write special logic to handle correct rlang
and data.table
usages. Don't think it's worth it (most people don't know that :=
can be used for "regular" assignment and it's explicitly not mentioned in the R documentation).
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.
Agreed. Maybe worth mentioning here why we chose not to lint :=
?
Looks mostly good, just a few finishing touches needed. |
NEWS.md
Outdated
@@ -88,6 +88,7 @@ function calls. (#850, #851, @renkun-ken) | |||
* `lintr` now uses the 3rd edition of `testthat` (@MichaelChirico, #910) | |||
* `lintr` is adopting a new set of linters provided as part of Google's extension to the tidyverse style guide (#884, @michaelchirico) | |||
+ `expect_null_linter()` Require usage of `expect_null(x)` over `expect_equal(x, NULL)` and similar | |||
* `assignment_linter()` now blocks right assignment (`->` and `->>`) and gains two arguments. `allow_cascading_assign` (`TRUE` by default) toggles whether to block `<<-` and `->>`; `allow_right_assign` toggles whether to block `->` and `->>` (#915, @michaelchirico) |
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.
block --> lint
R/assignment_linter.R
Outdated
# always block = (NB: the parser differentiates EQ_ASSIGN, EQ_SUB, and EQ_FORMALS) | ||
"//EQ_ASSIGN", | ||
# -> and ->> are both 'RIGHT_ASSIGN' | ||
if (!allow_right_assign) "//RIGHT_ASSIGN" else if (!allow_cascading_assign) "//RIGHT_ASSIGN[text() = '->>']", | ||
# <-, :=, and <<- are all 'LEFT_ASSIGN'; check the text if blocking <<- |
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.
Agreed. Maybe worth mentioning here why we chose not to lint :=
?
Closes #915