-
Notifications
You must be signed in to change notification settings - Fork 188
Avoid implicit assignments in expectations #1879
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
Codecov Report
@@ Coverage Diff @@
## main #1879 +/- ##
=======================================
Coverage 98.84% 98.84%
=======================================
Files 112 112
Lines 4857 4857
=======================================
Hits 4801 4801
Misses 56 56 Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
I haven't touched the tests for deprecated functions, which also contains some implicit assignment lints. TBH, I think we should |
The new warning appearing in tests is unrelated to the current PR. I have created an issue to track this: #1905. |
@AshesITR This is ready for a review, btw. Tagging just in case you missed the original review request during the holidays. |
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.
Looks good. Just wondering if we should commit to the brace-syntax from magrittr or grab the result in an extra supressWarnings()
for the xml_nodes_to_lints()
tests.
The former would not be compatible with the native pipe once we drop support for R versions without it.
Bumping the minimum needed R version to 4.1 should be many years away, so that's not too worrisome. That said, the brace syntax is not too straightforward to reason about, and so maybe it's better to avoid it. Thus, I have removed the brace-syntax, and have instead used temp variables for the tests in question. |
@@ -92,10 +92,19 @@ test_that("load_cache returns an empty environment if reading cache file fails", | |||
cache_f1 <- file.path(d1, fhash(f1)) | |||
writeLines(character(), cache_f1) | |||
|
|||
expect_warning(e2 <- lintr:::load_cache(file = f1, path = d1), "Could not load cache file") | |||
expect_warning( | |||
{ |
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 found myself ready to suggest nesting the expectations instead & then remembered that's basically what we just undid by removing magrittr
:)
Someday we'll depend on R>4.1 & then we can use |>
....
In the meantime, there may be some cases where 2-nesting looks fine:
expect_warning(
expect_identical(ls(lintr:::load_cache(file = f1, path = d1), character()),
"Could not load cache file",
fixed = TRUE
)
up to you whether / which cases you agree
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.
TBH, I personally prefer to keep each expectation separate. Nested expectations are much harder to reason about.
Closes #1820