Skip to content
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

Adds expect_that() to undesirable functions linter #1377

Closed
wants to merge 13 commits into from
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@
+ No longer lints undesirable symbols if they are used as names in `$` extractions (#1050, @AshesITR)
+ Added more explanation why certain functions might be undesirable and what alternatives to use;
ditto for `undesirable_operator_linter()` (#1133, #1146, #1159, @AshesITR)
+ Added `testthat::expect_that()`, which has been deprecated since the 3rd edition of `{testthat}`
package (#1377, @patilindrajeets)
* `assignment_linter()` (#915, @MichaelChirico)
+ Right assignments are now linted by default (`->` and `->>`)
+ New argument `allow_cascading_assign` (`TRUE` by default) toggles whether to lint `<<-` and `->>`
Expand Down
2 changes: 1 addition & 1 deletion R/expect_identical_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#' 1. A named argument is set (e.g. `ignore_attr` or `tolerance`)
#' 2. Comparison is made to an explicit decimal, e.g.
#' `expect_equal(x, 1.0)` (implicitly setting `tolerance`)
#' 3. `...` is passed (wrapper functions whcih might set
#' 3. `...` is passed (wrapper functions which might set
#' arguments such as `ignore_attr` or `tolerance`)
#'
#' @evalRd rd_tags("expect_identical_linter")
Expand Down
10 changes: 10 additions & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ default_linters <- modify_defaults(
#' * [debugonce()] is only useful for interactive debugging. It should be removed.
#' * [detach()] modifies the global search path. Detaching environments from the search path is rarely necessary in
#' production code.
#' * [testthat::expect_that()] is an old style of writing tests that is no
#' longer encouraged, and is deprecated in the 3rd edition of {testthat}
#' package. Use specific expect_ functions, e.g. [testthat::expect_equal()] or
#' [testthat::expect_s3_class()], instead.
#' * [ifelse()] isn't type stable. Use an `if`/`else` block for scalar logic, or use
#' `dplyr::if_else()`/`data.table::fifelse()` for type stable vectorized logic.
#' * [.libPaths()] permanently modifies the library location. Use [withr::with_libpaths()] for a temporary change
Expand Down Expand Up @@ -106,6 +110,11 @@ all_undesirable_functions <- modify_defaults(
"debugonce" = "It is only useful for interactive debugging. It should be removed.",
"detach" = paste("It modifies the global search path. Detaching environments from the search path",
"is rarely necessary in production code."),
"expect_that" = paste("testthat::expect_that() is an old style of writing tests",
"that is no longer encouraged, and is deprecated",
"in the 3rd edition of {testthat} package.",
"Use specific expect_ functions, e.g. testthat::expect_equal() or",
"testthat::expect_s3_class(), instead."),
"ifelse" = paste("It isn't type stable. Use an `if`/`else` block for scalar logic, or use",
"dplyr::if_else()/data.table::fifelse() for type stable vectorized logic."),
".libPaths" = paste("It permanently modifies the library location. Use withr::with_libpaths()",
Expand Down Expand Up @@ -147,6 +156,7 @@ default_undesirable_functions <- all_undesirable_functions[names(all_undesirable
"debugcall",
"debugonce",
"detach",
"expect_that",
".libPaths",
"library",
"mapply",
Expand Down
4 changes: 4 additions & 0 deletions man/default_undesirable_functions.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/expect_identical_linter.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testthat/test-undesirable_function_linter.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
test_that("linter returns correct linting", {
test_that("linter returns correct linting for undesirable functions", {
linter <- undesirable_function_linter(fun = c("return" = NA, "log10" = "use log()"))
msg_return <- "Function \"return\" is undesirable.$"
msg_log10 <- "Function \"log10\" is undesirable. As an alternative, use log\\(\\)."
Expand Down