Force consecutive calls to assertions into just one when possible
Source:R/consecutive_assertion_linter.R
consecutive_assertion_linter.Rd
stopifnot()
accepts any number of tests, so sequences like
stopifnot(x); stopifnot(y)
are redundant. Ditto for tests using
assertthat::assert_that()
without specifying msg=
.
See also
linters for a complete list of linters available in lintr.
Examples
# will produce lints
lint(
text = "stopifnot(x); stopifnot(y)",
linters = consecutive_assertion_linter()
)
#> ::warning file=<text>,line=1,col=1::file=<text>,line=1,col=1,[consecutive_assertion_linter] Unify consecutive calls to stopifnot().
lint(
text = "assert_that(x); assert_that(y)",
linters = consecutive_assertion_linter()
)
#> ::warning file=<text>,line=1,col=1::file=<text>,line=1,col=1,[consecutive_assertion_linter] Unify consecutive calls to assert_that().
# okay
lint(
text = "stopifnot(x, y)",
linters = consecutive_assertion_linter()
)
lint(
text = 'assert_that(x, msg = "Bad x!"); assert_that(y)',
linters = consecutive_assertion_linter()
)