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

View source: R/consecutive_assertion_linter.R

consecutive_assertion_linterR Documentation

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

Tags

consistency, readability, style

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

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


lintr documentation built on May 29, 2024, 11:31 a.m.