View source: R/yoda_test_linter.R
yoda_test_linter | R Documentation |
Yoda tests use (expected, actual)
instead of the more common (actual, expected)
.
This is not always possible to detect statically; this linter focuses on
the simple case of testing an expression against a literal value, e.g.
(1L, foo(x))
should be (foo(x), 1L)
.
yoda_test_linter()
best_practices, package_development, pkg_testthat, readability
linters for a complete list of linters available in lintr. https://en.wikipedia.org/wiki/Yoda_conditions
# will produce lints
lint(
text = "expect_equal(2, x)",
linters = yoda_test_linter()
)
lint(
text = 'expect_identical("a", x)',
linters = yoda_test_linter()
)
# okay
lint(
text = "expect_equal(x, 2)",
linters = yoda_test_linter()
)
lint(
text = 'expect_identical(x, "a")',
linters = yoda_test_linter()
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.