Require usage of expect_null(x)
over expect_equal(x, NULL)
and similar
usages.
Details
testthat::expect_null()
exists specifically for testing for NULL
objects.
testthat::expect_equal()
, testthat::expect_identical()
, and
testthat::expect_true()
can also be used for such tests,
but it is better to use the tailored function instead.
See also
linters for a complete list of linters available in lintr.
Examples
# will produce lints
lint(
text = "expect_equal(x, NULL)",
linters = expect_null_linter()
)
#> ::warning file=<text>,line=1,col=1::file=<text>,line=1,col=1,[expect_null_linter] expect_null(x) is better than expect_equal(x, NULL)
lint(
text = "expect_identical(x, NULL)",
linters = expect_null_linter()
)
#> ::warning file=<text>,line=1,col=1::file=<text>,line=1,col=1,[expect_null_linter] expect_null(x) is better than expect_identical(x, NULL)
lint(
text = "expect_true(is.null(x))",
linters = expect_null_linter()
)
#> ::warning file=<text>,line=1,col=1::file=<text>,line=1,col=1,[expect_null_linter] expect_null(x) is better than expect_true(is.null(x))
# okay
lint(
text = "expect_null(x)",
linters = expect_null_linter()
)