Skip to content

Commit 3fd90ba

Browse files
only lint the first argument of expect_true (#2408)
1 parent a716e1a commit 3fd90ba

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

NEWS.md

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
+ ignores extractions with explicit returns like `lapply(l, function(x) foo(x)$bar)` (#2258, @MichaelChirico).
6969
+ ignores calls on the RHS of operators like `lapply(l, function(x) "a" %in% names(x))` (#2310, @MichaelChirico).
7070
* `vector_logic_linter()` recognizes some cases where bitwise `&`/`|` are used correctly (#1453, @MichaelChirico).
71+
* `expect_comparison_linter()` ignores faulty usage like `expect_true(x, y > z)` (#2083, @MichaelChirico). Note that `y > z` is being passed to the `info=` argument, so this is likely a mistake.
7172

7273
### Lint accuracy fixes: removing false negatives
7374

R/expect_comparison_linter.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ expect_comparison_linter <- function() {
5353
xpath <- glue("
5454
//SYMBOL_FUNCTION_CALL[text() = 'expect_true']
5555
/parent::expr
56-
/following-sibling::expr[ {xp_or(comparator_nodes)} ]
56+
/following-sibling::expr[1][ {xp_or(comparator_nodes)} ]
5757
/parent::expr[not(SYMBOL_SUB[text() = 'info'])]
5858
")
5959

tests/testthat/test-expect_comparison_linter.R

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ test_that("expect_comparison_linter skips allowed usages", {
1111

1212
# expect_gt() and friends don't have an info= argument
1313
expect_lint("expect_true(x > y, info = 'x is bigger than y yo')", NULL, linter)
14+
15+
# expect_true() used incorrectly, and as executed the first argument is not a lint
16+
expect_lint("expect_true(is.count(n_draws), n_draws > 1)", NULL, linter)
1417
})
1518

1619
test_that("expect_comparison_linter blocks simple disallowed usages", {

0 commit comments

Comments
 (0)