|
1 | 1 | test_that("redundant_ifelse_linter skips allowed usages", { |
2 | 2 | linter <- redundant_ifelse_linter() |
3 | 3 |
|
4 | | - expect_lint("ifelse(x > 5, 0, 2)", NULL, linter) |
5 | | - expect_lint("ifelse(x > 5, TRUE, NA)", NULL, linter) |
6 | | - expect_lint("ifelse(x > 5, FALSE, NA)", NULL, linter) |
7 | | - expect_lint("ifelse(x > 5, TRUE, TRUE)", NULL, linter) |
| 4 | + expect_no_lint("ifelse(x > 5, 0, 2)", linter) |
| 5 | + expect_no_lint("ifelse(x > 5, TRUE, NA)", linter) |
| 6 | + expect_no_lint("ifelse(x > 5, FALSE, NA)", linter) |
| 7 | + expect_no_lint("ifelse(x > 5, TRUE, TRUE)", linter) |
8 | 8 |
|
9 | | - expect_lint("ifelse(x > 5, 0L, 2L)", NULL, linter) |
10 | | - expect_lint("ifelse(x > 5, 0L, 10L)", NULL, linter) |
| 9 | + expect_no_lint("ifelse(x > 5, 0L, 2L)", linter) |
| 10 | + expect_no_lint("ifelse(x > 5, 0L, 10L)", linter) |
11 | 11 | }) |
12 | 12 |
|
13 | 13 | test_that("redundant_ifelse_linter blocks simple disallowed usages", { |
@@ -111,38 +111,38 @@ test_that("redundant_ifelse_linter blocks usages equivalent to as.numeric, optio |
111 | 111 | test_that("allow10 works as intended", { |
112 | 112 | linter <- redundant_ifelse_linter(allow10 = TRUE) |
113 | 113 |
|
114 | | - expect_lint("ifelse(x > 5, 1L, 0L)", NULL, linter) |
115 | | - expect_lint("ifelse(x > 5, 0L, 1L)", NULL, linter) |
| 114 | + expect_no_lint("ifelse(x > 5, 1L, 0L)", linter) |
| 115 | + expect_no_lint("ifelse(x > 5, 0L, 1L)", linter) |
116 | 116 |
|
117 | | - expect_lint("ifelse(x > 5, 1, 0)", NULL, linter) |
118 | | - expect_lint("ifelse(x > 5, 0, 1)", NULL, linter) |
| 117 | + expect_no_lint("ifelse(x > 5, 1, 0)", linter) |
| 118 | + expect_no_lint("ifelse(x > 5, 0, 1)", linter) |
119 | 119 |
|
120 | | - expect_lint("dplyr::if_else(x > 5, 1L, 0L)", NULL, linter) |
121 | | - expect_lint("data.table::fifelse(x > 5, 0L, 1L)", NULL, linter) |
| 120 | + expect_no_lint("dplyr::if_else(x > 5, 1L, 0L)", linter) |
| 121 | + expect_no_lint("data.table::fifelse(x > 5, 0L, 1L)", linter) |
122 | 122 |
|
123 | | - expect_lint("if_else(x > 5, 1, 0)", NULL, linter) |
124 | | - expect_lint("fifelse(x > 5, 0, 1)", NULL, linter) |
| 123 | + expect_no_lint("if_else(x > 5, 1, 0)", linter) |
| 124 | + expect_no_lint("fifelse(x > 5, 0, 1)", linter) |
125 | 125 | }) |
126 | 126 |
|
127 | 127 | test_that("ifelse(missing = ) gives correct lints", { |
128 | 128 | linter <- redundant_ifelse_linter() |
129 | 129 |
|
130 | 130 | expect_lint("if_else(x > 5, TRUE, FALSE, NA)", rex::rex("Just use the logical condition"), linter) |
131 | | - expect_lint("if_else(x > 5, TRUE, FALSE, TRUE)", NULL, linter) |
132 | | - expect_lint("if_else(x > 5, TRUE, FALSE, 5L)", NULL, linter) |
| 131 | + expect_no_lint("if_else(x > 5, TRUE, FALSE, TRUE)", linter) |
| 132 | + expect_no_lint("if_else(x > 5, TRUE, FALSE, 5L)", linter) |
133 | 133 |
|
134 | 134 | expect_lint("if_else(x > 5, 1L, 0L, NA_integer_)", rex::rex("Prefer as.integer(x)"), linter) |
135 | | - expect_lint("if_else(x > 5, 1L, 0L, 2L)", NULL, linter) |
136 | | - expect_lint("if_else(x > 5, 1L, 0L, 5)", NULL, linter) |
| 135 | + expect_no_lint("if_else(x > 5, 1L, 0L, 2L)", linter) |
| 136 | + expect_no_lint("if_else(x > 5, 1L, 0L, 5)", linter) |
137 | 137 |
|
138 | 138 | expect_lint("if_else(x > 5, 1, 0, NA_real_)", rex::rex("Prefer as.numeric(x)"), linter) |
139 | | - expect_lint("if_else(x > 5, 1, 0, 2)", NULL, linter) |
140 | | - expect_lint("if_else(x > 5, 1, 0, '5')", NULL, linter) |
| 139 | + expect_no_lint("if_else(x > 5, 1, 0, 2)", linter) |
| 140 | + expect_no_lint("if_else(x > 5, 1, 0, '5')", linter) |
141 | 141 |
|
142 | 142 | # TRUE/FALSE must be found in yes/no, not missing= |
143 | | - expect_lint("if_else(x > 5, 'a', TRUE, FALSE)", NULL, linter) |
144 | | - expect_lint("if_else(x > 5, 'a', 0L, 1L)", NULL, linter) |
145 | | - expect_lint("if_else(x > 5, 'a', 1, 0)", NULL, linter) |
| 143 | + expect_no_lint("if_else(x > 5, 'a', TRUE, FALSE)", linter) |
| 144 | + expect_no_lint("if_else(x > 5, 'a', 0L, 1L)", linter) |
| 145 | + expect_no_lint("if_else(x > 5, 'a', 1, 0)", linter) |
146 | 146 | }) |
147 | 147 |
|
148 | 148 | test_that("lints vectorize", { |
|
0 commit comments