Skip to content

Commit 6fc09a9

Browse files
committed
Use expect_no_lint() instead of expect_lint(., NULL).
1 parent 552668b commit 6fc09a9

10 files changed

+146
-162
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-semicolon_linter.R

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ test_that("Lint all semicolons", {
44
comp_msg <- rex::rex("Replace compound semicolons by a newline.")
55

66
# No semicolon
7-
expect_lint("", NULL, linter)
8-
expect_lint("a <- 1", NULL, linter)
9-
expect_lint("function() {a <- 1}", NULL, linter)
10-
expect_lint("a <- \"foo;bar\"", NULL, linter)
11-
expect_lint("function() {a <- \"foo;bar\"}", NULL, linter)
12-
expect_lint("a <- FALSE # ok; cool!", NULL, linter)
13-
expect_lint("function() {\na <- FALSE # ok; cool!\n}", NULL, linter)
7+
expect_no_lint("", linter)
8+
expect_no_lint("a <- 1", linter)
9+
expect_no_lint("function() {a <- 1}", linter)
10+
expect_no_lint("a <- \"foo;bar\"", linter)
11+
expect_no_lint("function() {a <- \"foo;bar\"}", linter)
12+
expect_no_lint("a <- FALSE # ok; cool!", linter)
13+
expect_no_lint("function() {\na <- FALSE # ok; cool!\n}", linter)
1414

1515
# Trailing semicolons
1616
expect_lint(
@@ -80,19 +80,19 @@ test_that("Lint all semicolons", {
8080

8181
test_that("Compound semicolons only", {
8282
linter <- semicolon_linter(allow_trailing = TRUE)
83-
expect_lint("a <- 1;", NULL, linter)
84-
expect_lint("function(){a <- 1;}", NULL, linter)
85-
expect_lint("a <- 1; \n", NULL, linter)
86-
expect_lint("function(){a <- 1; \n}", NULL, linter)
83+
expect_no_lint("a <- 1;", linter)
84+
expect_no_lint("function(){a <- 1;}", linter)
85+
expect_no_lint("a <- 1; \n", linter)
86+
expect_no_lint("function(){a <- 1; \n}", linter)
8787
})
8888

8989

9090
test_that("Trailing semicolons only", {
9191
linter <- semicolon_linter(allow_compound = TRUE)
92-
expect_lint("a <- 1;b <- 2", NULL, linter)
93-
expect_lint("function() {a <- 1;b <- 2}\n", NULL, linter)
94-
expect_lint("f <-\n 1 ;f <- 1.23", NULL, linter)
95-
expect_lint("function(){\nf <-\n 1 ;f <- 1.23\n}", NULL, linter)
92+
expect_no_lint("a <- 1;b <- 2", linter)
93+
expect_no_lint("function() {a <- 1;b <- 2}\n", linter)
94+
expect_no_lint("f <-\n 1 ;f <- 1.23", linter)
95+
expect_no_lint("function(){\nf <-\n 1 ;f <- 1.23\n}", linter)
9696
})
9797

9898

tests/testthat/test-sort_linter.R

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

4-
expect_lint("order(y)", NULL, linter)
4+
expect_no_lint("order(y)", linter)
55

6-
expect_lint("y[order(x)]", NULL, linter)
6+
expect_no_lint("y[order(x)]", linter)
77

88
# If another function is intercalated, don't fail
9-
expect_lint("x[c(order(x))]", NULL, linter)
9+
expect_no_lint("x[c(order(x))]", linter)
1010

11-
expect_lint("x[order(y, x)]", NULL, linter)
12-
expect_lint("x[order(x, y)]", NULL, linter)
11+
expect_no_lint("x[order(y, x)]", linter)
12+
expect_no_lint("x[order(x, y)]", linter)
1313
# pretty sure this never makes sense, but test anyway
14-
expect_lint("x[order(y, na.last = x)]", NULL, linter)
14+
expect_no_lint("x[order(y, na.last = x)]", linter)
1515
})
1616

1717

@@ -89,17 +89,17 @@ test_that("sort_linter skips usages calling sort arguments", {
8989
linter <- sort_linter()
9090

9191
# any arguments to sort --> not compatible
92-
expect_lint("sort(x, decreasing = TRUE) == x", NULL, linter)
93-
expect_lint("sort(x, na.last = TRUE) != x", NULL, linter)
94-
expect_lint("sort(x, method_arg = TRUE) == x", NULL, linter)
92+
expect_no_lint("sort(x, decreasing = TRUE) == x", linter)
93+
expect_no_lint("sort(x, na.last = TRUE) != x", linter)
94+
expect_no_lint("sort(x, method_arg = TRUE) == x", linter)
9595
})
9696

9797
test_that("sort_linter skips when inputs don't match", {
9898
linter <- sort_linter()
9999

100-
expect_lint("sort(x) == y", NULL, linter)
101-
expect_lint("sort(x) == foo(x)", NULL, linter)
102-
expect_lint("sort(foo(x)) == x", NULL, linter)
100+
expect_no_lint("sort(x) == y", linter)
101+
expect_no_lint("sort(x) == foo(x)", linter)
102+
expect_no_lint("sort(foo(x)) == x", linter)
103103
})
104104

105105
test_that("sort_linter blocks simple disallowed usages", {

tests/testthat/test-spaces_left_parentheses_linter.R

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

4-
expect_lint("blah", NULL, linter)
5-
expect_lint("print(blah)", NULL, linter)
6-
expect_lint("base::print(blah)", NULL, linter)
7-
expect_lint("base::print(blah, fun(1))", NULL, linter)
8-
expect_lint("blah <- function(blah) { }", NULL, linter)
4+
expect_no_lint("blah", linter)
5+
expect_no_lint("print(blah)", linter)
6+
expect_no_lint("base::print(blah)", linter)
7+
expect_no_lint("base::print(blah, fun(1))", linter)
8+
expect_no_lint("blah <- function(blah) { }", linter)
99

10-
expect_lint("(1 + 1)", NULL, linter)
11-
expect_lint("(1 + 1)", NULL, linter)
12-
expect_lint("( (1 + 1) )", NULL, linter)
13-
expect_lint("if (blah) { }", NULL, linter)
14-
expect_lint("for (i in j) { }", NULL, linter)
15-
expect_lint("1 * (1 + 1)", NULL, linter)
16-
expect_lint("!(1 == 1)", NULL, linter)
17-
expect_lint("(2 - 1):(3 - 1)", NULL, linter)
18-
expect_lint("c(1, 2, 3)[(2 - 1)]", NULL, linter)
19-
expect_lint("list(1, 2, 3)[[(2 - 1)]]", NULL, linter)
20-
expect_lint("range(10)[(2 - 1):(10 - 1)]", NULL, linter)
21-
expect_lint("function(){function(){}}()()", NULL, linter)
22-
expect_lint("c(function(){})[1]()", NULL, linter)
10+
expect_no_lint("(1 + 1)", linter)
11+
expect_no_lint("(1 + 1)", linter)
12+
expect_no_lint("( (1 + 1) )", linter)
13+
expect_no_lint("if (blah) { }", linter)
14+
expect_no_lint("for (i in j) { }", linter)
15+
expect_no_lint("1 * (1 + 1)", linter)
16+
expect_no_lint("!(1 == 1)", linter)
17+
expect_no_lint("(2 - 1):(3 - 1)", linter)
18+
expect_no_lint("c(1, 2, 3)[(2 - 1)]", linter)
19+
expect_no_lint("list(1, 2, 3)[[(2 - 1)]]", linter)
20+
expect_no_lint("range(10)[(2 - 1):(10 - 1)]", linter)
21+
expect_no_lint("function(){function(){}}()()", linter)
22+
expect_no_lint("c(function(){})[1]()", linter)
2323

24-
expect_lint("\"test <- function(x) { if(1 + 1) 'hi' }\"", NULL, linter)
25-
expect_lint("res <- c((mat - 1L) %*% combs + 1L)", NULL, linter)
26-
expect_lint("if (!(foo && bar || baz)) { foo }", NULL, linter)
27-
expect_lint("x^(y + z)", NULL, linter)
28-
expect_lint("x**(y + z)", NULL, linter)
29-
expect_lint("a <- -(b)", NULL, linter)
24+
expect_no_lint("\"test <- function(x) { if(1 + 1) 'hi' }\"", linter)
25+
expect_no_lint("res <- c((mat - 1L) %*% combs + 1L)", linter)
26+
expect_no_lint("if (!(foo && bar || baz)) { foo }", linter)
27+
expect_no_lint("x^(y + z)", linter)
28+
expect_no_lint("x**(y + z)", linter)
29+
expect_no_lint("a <- -(b)", linter)
3030

31-
expect_lint("(3^(3 + 2))", NULL, linter)
32-
expect_lint("-(!!!symb)", NULL, linter)
31+
expect_no_lint("(3^(3 + 2))", linter)
32+
expect_no_lint("-(!!!symb)", linter)
3333

34-
expect_lint("'[[<-.data.frame'(object, y)", NULL, linter)
35-
expect_lint("object@data@get('input')", NULL, linter)
36-
expect_lint("x <- ~(. + y)", NULL, linter)
34+
expect_no_lint("'[[<-.data.frame'(object, y)", linter)
35+
expect_no_lint("object@data@get('input')", linter)
36+
expect_no_lint("x <- ~(. + y)", linter)
3737
# the internal newline is required to trigger the lint
38-
expect_lint("if (x > 1)\n x <- x[-(i)]", NULL, linter)
38+
expect_no_lint("if (x > 1)\n x <- x[-(i)]", linter)
3939
# these don't violate the linter, even if they are strange coding practice
40-
expect_lint("for (ii in 1:10) next()", NULL, linter)
41-
expect_lint("for (ii in 1:10) break()", NULL, linter)
40+
expect_no_lint("for (ii in 1:10) next()", linter)
41+
expect_no_lint("for (ii in 1:10) break()", linter)
4242
})
4343

4444
test_that("spaces_left_parentheses_linter blocks disallowed usages", {

tests/testthat/test-trailing_blank_lines_linter.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
test_that("trailing_blank_lines_linter doesn't block allowed usages", {
22
linter <- trailing_blank_lines_linter()
33

4-
expect_lint("blah", NULL, linter)
5-
expect_lint("blah <- 1 ", NULL, linter)
6-
expect_lint("blah <- 1\nblah", NULL, linter)
7-
expect_lint("blah <- 1\nblah\n \n blah", NULL, linter)
4+
expect_no_lint("blah", linter)
5+
expect_no_lint("blah <- 1 ", linter)
6+
expect_no_lint("blah <- 1\nblah", linter)
7+
expect_no_lint("blah <- 1\nblah\n \n blah", linter)
88

99
tmp <- withr::local_tempfile(lines = "lm(y ~ x)")
10-
expect_lint(file = tmp, checks = NULL, linters = linter)
10+
expect_no_lint(file = tmp, linters = linter)
1111
})
1212

1313
test_that("trailing_blank_lines_linter detects disallowed usages", {

tests/testthat/test-trailing_whitespace_linter.R

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ test_that("returns the correct linting", {
22
linter <- trailing_whitespace_linter()
33
lint_msg <- rex::rex("Remove trailing whitespace.")
44

5-
expect_lint("blah", NULL, linter)
5+
expect_no_lint("blah", linter)
66

77
expect_lint(
88
"blah <- 1 ",
@@ -35,9 +35,8 @@ test_that("also handles completely empty lines per allow_empty_lines argument",
3535
trailing_whitespace_linter(allow_empty_lines = TRUE)
3636
)
3737

38-
expect_lint(
38+
expect_no_lint(
3939
"blah <- 1\n \n'hi'\na <- 2",
40-
NULL,
4140
trailing_whitespace_linter(allow_empty_lines = TRUE)
4241
)
4342
})
@@ -46,7 +45,7 @@ test_that("also handles trailing whitespace in string constants", {
4645
linter <- trailing_whitespace_linter()
4746
lint_msg <- rex::rex("Remove trailing whitespace.")
4847

49-
expect_lint("blah <- ' \n \n'", NULL, linter)
48+
expect_no_lint("blah <- ' \n \n'", linter)
5049
# Don't exclude past the end of string
5150
expect_lint(
5251
"blah <- ' \n \n' ",

0 commit comments

Comments
 (0)