Block usages like !(x == y) where a direct relational operator is appropriate
Source:R/comparison_negation_linter.R
comparison_negation_linter.Rd
!(x == y)
is more readably expressed as x != y
. The same is true of
other negations of simple comparisons like !(x > y)
and !(x <= y)
.
See also
linters for a complete list of linters available in lintr.
Examples
# will produce lints
lint(
text = "!x == 2",
linters = comparison_negation_linter()
)
#> <text>:1:1: warning: [comparison_negation_linter] Use x != y, not !(x == y).
#> !x == 2
#> ^~~~~~~
lint(
text = "!(x > 2)",
linters = comparison_negation_linter()
)
#> <text>:1:1: warning: [comparison_negation_linter] Use x <= y, not !(x > y).
#> !(x > 2)
#> ^~~~~~~~
# okay
lint(
text = "!(x == 2 & y > 2)",
linters = comparison_negation_linter()
)
#> ℹ No lints found.
lint(
text = "!(x & y)",
linters = comparison_negation_linter()
)
#> ℹ No lints found.
lint(
text = "x != 2",
linters = comparison_negation_linter()
)
#> ℹ No lints found.