expect_not_linter: Require usage of 'expect_false(x)' over 'expect_true(!x)'

expect_not_linterR Documentation

Require usage of expect_false(x) over expect_true(!x)

Description

testthat::expect_false() exists specifically for testing that an output is FALSE. testthat::expect_true() can also be used for such tests by negating the output, but it is better to use the tailored function instead. The reverse is also true – use expect_false(A) instead of expect_true(!A).

Usage

expect_not_linter()

Tags

best_practices, package_development, pkg_testthat, readability

See Also

linters for a complete list of linters available in lintr.

Examples

# will produce lints
lint(
  text = "expect_true(!x)",
  linters = expect_not_linter()
)

# okay
lint(
  text = "expect_false(x)",
  linters = expect_not_linter()
)


jimhester/lintr documentation built on April 24, 2024, 8:21 a.m.