Skip to content

Commit dfe2255

Browse files
mcolMichaelChirico
authored andcommitted
Use expect_no_lint() instead of expect_lint(., NULL). (r-lib#2950)
Co-authored-by: Michael Chirico <[email protected]>
1 parent a321e59 commit dfe2255

File tree

5 files changed

+53
-55
lines changed

5 files changed

+53
-55
lines changed

tests/testthat/test-namespace_linter.R

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
test_that("namespace_linter skips allowed usages", {
22
linter <- namespace_linter()
33

4-
expect_lint("stats::sd", NULL, linter)
5-
expect_lint("stats::sd(c(1,2,3))", NULL, linter)
6-
expect_lint('"stats"::sd(c(1,2,3))', NULL, linter)
7-
expect_lint('stats::"sd"(c(1,2,3))', NULL, linter)
8-
expect_lint("stats::`sd`(c(1,2,3))", NULL, linter)
4+
expect_no_lint("stats::sd", linter)
5+
expect_no_lint("stats::sd(c(1,2,3))", linter)
6+
expect_no_lint('"stats"::sd(c(1,2,3))', linter)
7+
expect_no_lint('stats::"sd"(c(1,2,3))', linter)
8+
expect_no_lint("stats::`sd`(c(1,2,3))", linter)
99

10-
expect_lint("datasets::mtcars", NULL, linter)
11-
expect_lint("stats:::print.formula", NULL, linter)
12-
expect_lint('"stats":::print.formula', NULL, linter)
10+
expect_no_lint("datasets::mtcars", linter)
11+
expect_no_lint("stats:::print.formula", linter)
12+
expect_no_lint('"stats":::print.formula', linter)
1313
})
1414

1515
test_that("namespace_linter respects check_exports and check_nonexports arguments", {
16-
expect_lint("stats::ssd(c(1,2,3))", NULL, namespace_linter(check_exports = FALSE))
17-
expect_lint("stats:::ssd(c(1,2,3))", NULL, namespace_linter(check_nonexports = FALSE))
18-
expect_lint("stats:::ssd(c(1,2,3))", NULL, namespace_linter(check_exports = FALSE, check_nonexports = FALSE))
16+
expect_no_lint("stats::ssd(c(1,2,3))", namespace_linter(check_exports = FALSE))
17+
expect_no_lint("stats:::ssd(c(1,2,3))", namespace_linter(check_nonexports = FALSE))
18+
expect_no_lint("stats:::ssd(c(1,2,3))", namespace_linter(check_exports = FALSE, check_nonexports = FALSE))
1919
})
2020

2121
test_that("namespace_linter can work with backticked symbols", {
2222
skip_if_not_installed("rlang")
2323
linter <- namespace_linter()
2424

25-
expect_lint("rlang::`%||%`", NULL, linter)
26-
expect_lint("rlang::`%||%`()", NULL, linter)
25+
expect_no_lint("rlang::`%||%`", linter)
26+
expect_no_lint("rlang::`%||%`()", linter)
2727

28-
expect_lint("rlang::'%||%'", NULL, linter)
29-
expect_lint("rlang::'%||%'()", NULL, linter)
30-
expect_lint('rlang::"%||%"', NULL, linter)
31-
expect_lint('rlang::"%||%"()', NULL, linter)
28+
expect_no_lint("rlang::'%||%'", linter)
29+
expect_no_lint("rlang::'%||%'()", linter)
30+
expect_no_lint('rlang::"%||%"', linter)
31+
expect_no_lint('rlang::"%||%"()', linter)
3232

3333
expect_lint("rlang::`%>%`", "'%>%' is not exported from {rlang}.", linter)
3434
expect_lint("rlang::'%>%'()", "'%>%' is not exported from {rlang}.", linter)

tests/testthat/test-redundant_ifelse_linter.R

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
test_that("redundant_ifelse_linter skips allowed usages", {
22
linter <- redundant_ifelse_linter()
33

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

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)
1111
})
1212

1313
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
111111
test_that("allow10 works as intended", {
112112
linter <- redundant_ifelse_linter(allow10 = TRUE)
113113

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

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

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

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)
125125
})
126126

127127
test_that("ifelse(missing = ) gives correct lints", {
128128
linter <- redundant_ifelse_linter()
129129

130130
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)
133133

134134
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)
137137

138138
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)
141141

142142
# 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)
146146
})
147147

148148
test_that("lints vectorize", {

tests/testthat/test-which_grepl_linter.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
test_that("which_grepl_linter skips allowed usages", {
22
# this _could_ be combined as p1|p2, but often it's cleaner to read this way
3-
expect_lint("which(grepl(p1, x) | grepl(p2, x))", NULL, which_grepl_linter())
3+
expect_no_lint("which(grepl(p1, x) | grepl(p2, x))", which_grepl_linter())
44
})
55

66
test_that("which_grepl_linter blocks simple disallowed usages", {

tests/testthat/test-whitespace_linter.R

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
test_that("whitespace_linter skips allowed usages", {
22
linter <- whitespace_linter()
33

4-
expect_lint("blah", NULL, linter)
5-
expect_lint(" blah", NULL, linter)
6-
expect_lint(" blah", NULL, linter)
7-
expect_lint("#\tblah", NULL, linter)
4+
expect_no_lint("blah", linter)
5+
expect_no_lint(" blah", linter)
6+
expect_no_lint(" blah", linter)
7+
expect_no_lint("#\tblah", linter)
88
})
99

1010
test_that("whitespace_linter skips allowed tab usages inside strings", {
1111
linter <- whitespace_linter()
1212

13-
expect_lint(
13+
expect_no_lint(
1414
'lint_msg <- "dont flag tabs if\tthey are inside a string."',
15-
NULL,
1615
linter
1716
)
1817

19-
expect_lint(
18+
expect_no_lint(
2019
'lint_msg <- "dont flag tabs if\n\tthey are inside multiline strings."',
21-
NULL,
2220
linter
2321
)
2422
})

tests/testthat/test-yoda_test_linter.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
test_that("yoda_test_linter skips allowed usages", {
22
linter <- yoda_test_linter()
33

4-
expect_lint("expect_equal(x, 2)", NULL, linter)
4+
expect_no_lint("expect_equal(x, 2)", linter)
55
# namespace qualification doesn't matter
6-
expect_lint("testthat::expect_identical(x, 'a')", NULL, linter)
6+
expect_no_lint("testthat::expect_identical(x, 'a')", linter)
77
# two variables can't be distinguished which is expected/actual (without
88
# playing quixotic games trying to parse that out from variable names)
9-
expect_lint("expect_equal(x, y)", NULL, linter)
9+
expect_no_lint("expect_equal(x, y)", linter)
1010
})
1111

1212
test_that("yoda_test_linter blocks simple disallowed usages", {
@@ -24,8 +24,8 @@ test_that("yoda_test_linter ignores strings in $ expressions", {
2424
linter <- yoda_test_linter()
2525

2626
# the "key" here shows up at the same level of the parse tree as plain "key" normally would
27-
expect_lint('expect_equal(x$"key", 2)', NULL, linter)
28-
expect_lint('expect_equal(x@"key", 2)', NULL, linter)
27+
expect_no_lint('expect_equal(x$"key", 2)', linter)
28+
expect_no_lint('expect_equal(x@"key", 2)', linter)
2929
})
3030

3131
# if we only inspect the first argument & ignore context, get false positives
@@ -34,7 +34,7 @@ local({
3434
linter <- yoda_test_linter()
3535
patrick::with_parameters_test_that(
3636
"yoda_test_linter ignores usage in pipelines",
37-
expect_lint(sprintf("foo() %s expect_identical(2)", pipe), NULL, linter),
37+
expect_no_lint(sprintf("foo() %s expect_identical(2)", pipe), linter),
3838
pipe = pipes,
3939
.test_name = names(pipes)
4040
)

0 commit comments

Comments
 (0)