Skip to contents

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=.

Usage

consecutive_assertion_linter()

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()
)