
Require usage of expect_gt(x, y) over expect_true(x > y) (and similar)
Source: R/expect_comparison_linter.R
expect_comparison_linter.Rdtestthat::expect_gt(), testthat::expect_gte(), testthat::expect_lt(),
testthat::expect_lte(), and testthat::expect_equal() exist specifically
for testing comparisons between two objects. 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_true(x > y)",
linters = expect_comparison_linter()
)
#> <text>:1:1: warning: [expect_comparison_linter] expect_gt(x, y) is better than expect_true(x > y).
#> expect_true(x > y)
#> ^~~~~~~~~~~~~~~~~~
lint(
text = "expect_true(x <= y)",
linters = expect_comparison_linter()
)
#> <text>:1:1: warning: [expect_comparison_linter] expect_lte(x, y) is better than expect_true(x <= y).
#> expect_true(x <= y)
#> ^~~~~~~~~~~~~~~~~~~
lint(
text = "expect_true(x == (y == 2))",
linters = expect_comparison_linter()
)
#> <text>:1:1: warning: [expect_comparison_linter] expect_identical(x, y) is better than expect_true(x == y).
#> expect_true(x == (y == 2))
#> ^~~~~~~~~~~~~~~~~~~~~~~~~~
# okay
lint(
text = "expect_gt(x, y)",
linters = expect_comparison_linter()
)
#> ℹ No lints found.
lint(
text = "expect_lte(x, y)",
linters = expect_comparison_linter()
)
#> ℹ No lints found.
lint(
text = "expect_identical(x, y == 2)",
linters = expect_comparison_linter()
)
#> ℹ No lints found.
lint(
text = "expect_true(x < y | x > y^2)",
linters = expect_comparison_linter()
)
#> ℹ No lints found.