Learn R Programming

lintr (version 3.1.2)

consecutive_assertion_linter: Force consecutive calls to assertions into just one when possible

Description

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

Arguments

Tags

consistency, readability, style

See Also

linters for a complete list of linters available in lintr.

Examples

Run this code
# will produce lints
lint(
  text = "stopifnot(x); stopifnot(y)",
  linters = consecutive_assertion_linter()
)

lint(
  text = "assert_that(x); assert_that(y)",
  linters = consecutive_assertion_linter()
)

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

Run the code above in your browser using DataLab