diff --git a/tests/testthat/test-any_is_na_linter.R b/tests/testthat/test-any_is_na_linter.R index 398ca53cc..f65724550 100644 --- a/tests/testthat/test-any_is_na_linter.R +++ b/tests/testthat/test-any_is_na_linter.R @@ -1,17 +1,17 @@ test_that("any_is_na_linter skips allowed usages", { linter <- any_is_na_linter() - expect_lint("x <- any(y)", NULL, linter) + expect_no_lint("x <- any(y)", linter) - expect_lint("y <- is.na(z)", NULL, linter) + expect_no_lint("y <- is.na(z)", linter) # extended usage of ... arguments to any is not covered - expect_lint("any(is.na(y), b)", NULL, linter) - expect_lint("any(b, is.na(y))", NULL, linter) + expect_no_lint("any(is.na(y), b)", linter) + expect_no_lint("any(b, is.na(y))", linter) # negation shouldn't list - expect_lint("any(!is.na(x))", NULL, linter) - expect_lint("any(!is.na(foo(x)))", NULL, linter) + expect_no_lint("any(!is.na(x))", linter) + expect_no_lint("any(!is.na(foo(x)))", linter) }) test_that("any_is_na_linter blocks simple disallowed usages", { @@ -32,7 +32,7 @@ test_that("NA %in% x is also found", { expect_lint("NA %in% x", lint_message, linter) expect_lint("NA_real_ %in% x", lint_message, linter) - expect_lint("NA_not_a_sentinel_ %in% x", NULL, linter) + expect_no_lint("NA_not_a_sentinel_ %in% x", linter) }) test_that("lints vectorize", { @@ -40,12 +40,14 @@ test_that("lints vectorize", { in_message <- rex::rex("NA %in% x") expect_lint( - trim_some("{ + trim_some( + "{ any(is.na(foo(x))) any(is.na(y), na.rm = TRUE) NA %in% a NA_complex_ %in% b - }"), + }" + ), list( list(any_message, line_number = 2L), list(any_message, line_number = 3L), diff --git a/tests/testthat/test-backport_linter.R b/tests/testthat/test-backport_linter.R index 0025f4b3b..a13148ba6 100644 --- a/tests/testthat/test-backport_linter.R +++ b/tests/testthat/test-backport_linter.R @@ -7,9 +7,9 @@ test_that("backport_linter produces error when R version misspecified", { test_that("backport_linter detects backwards-incompatibility", { # default should be current R version; all of these are included on our dependency - expect_lint(".getNamespaceInfo(dir.exists(lapply(x, toTitleCase)))", NULL, backport_linter()) - expect_lint(".getNamespaceInfo(dir.exists(lapply(x, toTitleCase)))", NULL, backport_linter("release")) - expect_lint(".getNamespaceInfo(dir.exists(lapply(x, toTitleCase)))", NULL, backport_linter("devel")) + expect_no_lint(".getNamespaceInfo(dir.exists(lapply(x, toTitleCase)))", backport_linter()) + expect_no_lint(".getNamespaceInfo(dir.exists(lapply(x, toTitleCase)))", backport_linter("release")) + expect_no_lint(".getNamespaceInfo(dir.exists(lapply(x, toTitleCase)))", backport_linter("devel")) expect_lint( "numToBits(2)", @@ -61,14 +61,10 @@ test_that("backport_linter detects backwards-incompatibility", { ) # except is honored - expect_lint( - trim_some(" + expect_no_lint(trim_some(" numToBits(2) R_user_dir('mypkg') - "), - NULL, - backport_linter("3.0.0", except = c("numToBits", "R_user_dir")) - ) + "), backport_linter("3.0.0", except = c("numToBits", "R_user_dir"))) }) test_that("backport_linter generates expected warnings", { diff --git a/tests/testthat/test-class_equals_linter.R b/tests/testthat/test-class_equals_linter.R index cc4495ec3..80cecac01 100644 --- a/tests/testthat/test-class_equals_linter.R +++ b/tests/testthat/test-class_equals_linter.R @@ -1,12 +1,12 @@ test_that("class_equals_linter skips allowed usages", { linter <- class_equals_linter() - expect_lint("class(x) <- 'character'", NULL, linter) - expect_lint("class(x) = 'character'", NULL, linter) + expect_no_lint("class(x) <- 'character'", linter) + expect_no_lint("class(x) = 'character'", linter) # proper way to test exact class - expect_lint("identical(class(x), c('glue', 'character'))", NULL, linter) - expect_lint("is_lm <- inherits(x, 'lm')", NULL, linter) + expect_no_lint("identical(class(x), c('glue', 'character'))", linter) + expect_no_lint("is_lm <- inherits(x, 'lm')", linter) }) test_that("class_equals_linter blocks simple disallowed usages", { @@ -38,7 +38,7 @@ test_that("class_equals_linter blocks class(x) != 'klass'", { test_that("class_equals_linter skips usage for subsetting", { linter <- class_equals_linter() - expect_lint("class(x)[class(x) == 'foo']", NULL, linter) + expect_no_lint("class(x)[class(x) == 'foo']", linter) # but not further nesting expect_lint( diff --git a/tests/testthat/test-commas_linter.R b/tests/testthat/test-commas_linter.R index fb8a4e4f3..e1b89e9b3 100644 --- a/tests/testthat/test-commas_linter.R +++ b/tests/testthat/test-commas_linter.R @@ -3,12 +3,12 @@ test_that("returns the correct linting (with default parameters)", { msg_after <- rex::rex("Put a space after a comma.") msg_before <- rex::rex("Remove spaces before a comma.") - expect_lint("blah", NULL, linter) - expect_lint("fun(1, 1)", NULL, linter) - expect_lint("fun(1,\n 1)", NULL, linter) - expect_lint("fun(1,\n1)", NULL, linter) - expect_lint("fun(1\n,\n1)", NULL, linter) - expect_lint("fun(1\n ,\n1)", NULL, linter) + expect_no_lint("blah", linter) + expect_no_lint("fun(1, 1)", linter) + expect_no_lint("fun(1,\n 1)", linter) + expect_no_lint("fun(1,\n1)", linter) + expect_no_lint("fun(1\n,\n1)", linter) + expect_no_lint("fun(1\n ,\n1)", linter) expect_lint("fun(1\n,1)", msg_after, linter) expect_lint("fun(1,1)", msg_after, linter) @@ -25,14 +25,14 @@ test_that("returns the correct linting (with default parameters)", { linter ) - expect_lint("\"fun(1 ,1)\"", NULL, linter) - expect_lint("a[1, , 2]", NULL, linter) - expect_lint("a[1, , 2, , 3]", NULL, linter) + expect_no_lint("\"fun(1 ,1)\"", linter) + expect_no_lint("a[1, , 2]", linter) + expect_no_lint("a[1, , 2, , 3]", linter) - expect_lint("switch(op, x = foo, y = bar)", NULL, linter) - expect_lint("switch(op, x = , y = bar)", NULL, linter) - expect_lint("switch(op, \"x\" = , y = bar)", NULL, linter) - expect_lint("switch(op, x = ,\ny = bar)", NULL, linter) + expect_no_lint("switch(op, x = foo, y = bar)", linter) + expect_no_lint("switch(op, x = , y = bar)", linter) + expect_no_lint("switch(op, \"x\" = , y = bar)", linter) + expect_no_lint("switch(op, x = ,\ny = bar)", linter) expect_lint("switch(op, x = foo , y = bar)", msg_before, linter) expect_lint("switch(op, x = foo , y = bar)", msg_before, linter) @@ -67,14 +67,14 @@ test_that("returns the correct linting (with 'allow_trailing' set)", { msg_after <- rex::rex("Put a space after a comma.") msg_before <- rex::rex("Remove spaces before a comma.") - expect_lint("blah", NULL, linter) - expect_lint("fun(1, 1)", NULL, linter) - expect_lint("fun(1,\n 1)", NULL, linter) - expect_lint("fun(1,\n1)", NULL, linter) - expect_lint("fun(1\n,\n1)", NULL, linter) - expect_lint("fun(1\n ,\n1)", NULL, linter) - expect_lint("a[1,]", NULL, linter) - expect_lint("a(1,)", NULL, linter) + expect_no_lint("blah", linter) + expect_no_lint("fun(1, 1)", linter) + expect_no_lint("fun(1,\n 1)", linter) + expect_no_lint("fun(1,\n1)", linter) + expect_no_lint("fun(1\n,\n1)", linter) + expect_no_lint("fun(1\n ,\n1)", linter) + expect_no_lint("a[1,]", linter) + expect_no_lint("a(1,)", linter) expect_lint("fun(1\n,1)", msg_after, linter) expect_lint("fun(1,1)", msg_after, linter) @@ -88,15 +88,15 @@ test_that("returns the correct linting (with 'allow_trailing' set)", { linter ) - expect_lint("\"fun(1 ,1)\"", NULL, linter) - expect_lint("a[1, , 2]", NULL, linter) - expect_lint("a[1, , 2, , 3]", NULL, linter) - expect_lint("a[[1,]]", NULL, linter) + expect_no_lint("\"fun(1 ,1)\"", linter) + expect_no_lint("a[1, , 2]", linter) + expect_no_lint("a[1, , 2, , 3]", linter) + expect_no_lint("a[[1,]]", linter) - expect_lint("switch(op, x = foo, y = bar)", NULL, linter) - expect_lint("switch(op, x = , y = bar)", NULL, linter) - expect_lint("switch(op, \"x\" = , y = bar)", NULL, linter) - expect_lint("switch(op, x = ,\ny = bar)", NULL, linter) + expect_no_lint("switch(op, x = foo, y = bar)", linter) + expect_no_lint("switch(op, x = , y = bar)", linter) + expect_no_lint("switch(op, \"x\" = , y = bar)", linter) + expect_no_lint("switch(op, x = ,\ny = bar)", linter) expect_lint("switch(op, x = foo , y = bar)", msg_before, linter) expect_lint("switch(op, x = foo , y = bar)", msg_before, linter) diff --git a/tests/testthat/test-consecutive_assertion_linter.R b/tests/testthat/test-consecutive_assertion_linter.R index 5722e6d1a..e81b91e81 100644 --- a/tests/testthat/test-consecutive_assertion_linter.R +++ b/tests/testthat/test-consecutive_assertion_linter.R @@ -1,22 +1,18 @@ test_that("consecutive_assertion_linter skips allowed usages", { linter <- consecutive_assertion_linter() - expect_lint("stopifnot(x)", NULL, linter) - expect_lint("stopifnot(x, y, z)", NULL, linter) + expect_no_lint("stopifnot(x)", linter) + expect_no_lint("stopifnot(x, y, z)", linter) # intervening expression - expect_lint("stopifnot(x); y; stopifnot(z)", NULL, linter) + expect_no_lint("stopifnot(x); y; stopifnot(z)", linter) # inline or potentially with gaps don't matter - expect_lint( - trim_some(" + expect_no_lint(trim_some(" stopifnot(x) y - + stopifnot(z) - "), - NULL, - linter - ) + "), linter) }) test_that("consecutive_assertion_linter blocks simple disallowed usages", { @@ -33,7 +29,7 @@ test_that("consecutive_assertion_linter blocks simple disallowed usages", { expect_lint( trim_some(" stopifnot(x) - + stopifnot(y, z) "), lint_msg, @@ -64,15 +60,15 @@ test_that("assert_that usages are handled correctly too", { linter <- consecutive_assertion_linter() lint_msg <- rex::rex("Unify consecutive calls to assert_that().") - expect_lint("assert_that(x)", NULL, linter) - expect_lint("assertthat::assert_that(x, y, z)", NULL, linter) + expect_no_lint("assert_that(x)", linter) + expect_no_lint("assertthat::assert_that(x, y, z)", linter) # if msg= is used, can't necessarily combine lines <- trim_some(" assert_that(x, msg = 'bad x') assert_that(y, msg = 'bad y') ") - expect_lint(lines, NULL, linter) + expect_no_lint(lines, linter) # one test of inline usage expect_lint( @@ -90,14 +86,10 @@ test_that("assert_that usages are handled correctly too", { }) test_that("Mixing test functions is fine", { - expect_lint( - trim_some(" + expect_no_lint(trim_some(" assert_that(x) stopifnot(y) - "), - NULL, - consecutive_assertion_linter() - ) + "), consecutive_assertion_linter()) }) test_that("lints vectorize", { @@ -121,8 +113,7 @@ test_that("old name consecutive_stopifnot_linter() is defunct", { }) test_that("interceding = assignments aren't linted", { - expect_lint( - trim_some("{ + expect_no_lint(trim_some("{ stopifnot(A) x = 1 stopifnot(B) @@ -130,8 +121,5 @@ test_that("interceding = assignments aren't linted", { assert_that(C) z = 3 assert_that(D) - }"), - NULL, - consecutive_assertion_linter() - ) + }"), consecutive_assertion_linter()) }) diff --git a/tests/testthat/test-consecutive_mutate_linter.R b/tests/testthat/test-consecutive_mutate_linter.R index 044ad18ad..eaefc4b47 100644 --- a/tests/testthat/test-consecutive_mutate_linter.R +++ b/tests/testthat/test-consecutive_mutate_linter.R @@ -1,19 +1,19 @@ test_that("consecutive_mutate_linter skips allowed usages", { linter <- consecutive_mutate_linter() - expect_lint("DF %>% mutate(x = 1)", NULL, linter) + expect_no_lint("DF %>% mutate(x = 1)", linter) # intervening expression - expect_lint("DF %>% mutate(x = 1) %>% filter(x > 2) %>% mutate(y = 2)", NULL, linter) + expect_no_lint("DF %>% mutate(x = 1) %>% filter(x > 2) %>% mutate(y = 2)", linter) # pipeline starts with mutate() - expect_lint("mutate(DF, x = 1) %>% arrange(y) %>% mutate(z = 2)", NULL, linter) + expect_no_lint("mutate(DF, x = 1) %>% arrange(y) %>% mutate(z = 2)", linter) # new dplyr: .keep and .by arguments are ignored - expect_lint("DF %>% mutate(a = 1) %>% mutate(a = a / sum(a), .by = b)", NULL, linter) - expect_lint("DF %>% mutate(a = 1) %>% mutate(a = b, .keep = 'none')", NULL, linter) - expect_lint("DF %>% mutate(a = a / sum(a), .by = b) %>% mutate(c = 1)", NULL, linter) - expect_lint("DF %>% mutate(a = 1, .keep = 'none') %>% mutate(a = a + 1)", NULL, linter) + expect_no_lint("DF %>% mutate(a = 1) %>% mutate(a = a / sum(a), .by = b)", linter) + expect_no_lint("DF %>% mutate(a = 1) %>% mutate(a = b, .keep = 'none')", linter) + expect_no_lint("DF %>% mutate(a = a / sum(a), .by = b) %>% mutate(c = 1)", linter) + expect_no_lint("DF %>% mutate(a = 1, .keep = 'none') %>% mutate(a = a + 1)", linter) }) patrick::with_parameters_test_that( @@ -21,59 +21,38 @@ patrick::with_parameters_test_that( { linter <- consecutive_mutate_linter(invalid_backends = backend) - expect_lint( - trim_some(glue::glue(" + expect_no_lint(trim_some(glue::glue(" library({backend}) DF %>% mutate(a = a + 1) %>% mutate(b = a - 2) - ")), - NULL, - linter - ) + ")), linter) - expect_lint( - trim_some(glue::glue(" + expect_no_lint(trim_some(glue::glue(" require('{backend}') DF %>% mutate(a = a + 1) %>% mutate(b = a - 2) - ")), - NULL, - linter - ) + ")), linter) - expect_lint( - trim_some(glue(" + expect_no_lint(trim_some(glue(" conn %>% tbl({backend}::sql('SELECT 1 AS x')) %>% mutate(a = x + 1) %>% mutate(b = a + 1) - ")), - NULL, - linter - ) + ")), linter) - expect_lint( - trim_some(glue(" + expect_no_lint(trim_some(glue(" conn %>% tbl({backend}:::sql('SELECT 1 AS x')) %>% mutate(a = x + 1) %>% mutate(b = a + 1) - ")), - NULL, - linter - ) + ")), linter) - expect_lint( - trim_some(glue(" + expect_no_lint(trim_some(glue(" #' @import {backend} NULL DF %>% mutate(a = a + 1) %>% mutate(b = a - 2) - ")), - NULL, - linter - ) + ")), linter) - expect_lint( - trim_some(glue(" + expect_no_lint(trim_some(glue(" #' @importFrom {backend} sql NULL @@ -81,10 +60,7 @@ patrick::with_parameters_test_that( tbl(sql('SELECT 1 AS x')) %>% mutate(a = x + 1) %>% mutate(b = a + 1) - ")), - NULL, - linter - ) + ")), linter) }, .test_name = c("dbplyr", "custom.backend"), backend = c("dbplyr", "custom.backend") @@ -135,11 +111,11 @@ test_that("consecutive_mutate_linter blocks simple disallowed usages", { test_that("'parallel' calls are not linted", { linter <- consecutive_mutate_linter() - expect_lint("foo(mutate(DF1, x = 1), mutate(DF2, y = 2))", NULL, linter) + expect_no_lint("foo(mutate(DF1, x = 1), mutate(DF2, y = 2))", linter) - expect_lint("foo(DF1 %>% mutate(x = 1), DF2 %>% mutate(y = 2))", NULL, linter) + expect_no_lint("foo(DF1 %>% mutate(x = 1), DF2 %>% mutate(y = 2))", linter) - expect_lint("DF1 %>% mutate(x = 1) %>% inner_join(DF2 %>% mutate(y = 2))", NULL, linter) + expect_no_lint("DF1 %>% mutate(x = 1) %>% inner_join(DF2 %>% mutate(y = 2))", linter) }) test_that("native pipe is linted", { diff --git a/tests/testthat/test-duplicate_argument_linter.R b/tests/testthat/test-duplicate_argument_linter.R index 44040ab26..ccf335f03 100644 --- a/tests/testthat/test-duplicate_argument_linter.R +++ b/tests/testthat/test-duplicate_argument_linter.R @@ -1,12 +1,12 @@ test_that("duplicate_argument_linter doesn't block allowed usages", { linter <- duplicate_argument_linter() - expect_lint("fun(arg = 1)", NULL, linter) - expect_lint("fun('arg' = 1)", NULL, linter) - expect_lint("fun(`arg` = 1)", NULL, linter) - expect_lint("'fun'(arg = 1)", NULL, linter) - expect_lint("(function(x, y) x + y)(x = 1)", NULL, linter) - expect_lint("dt[i = 1]", NULL, linter) + expect_no_lint("fun(arg = 1)", linter) + expect_no_lint("fun('arg' = 1)", linter) + expect_no_lint("fun(`arg` = 1)", linter) + expect_no_lint("'fun'(arg = 1)", linter) + expect_no_lint("(function(x, y) x + y)(x = 1)", linter) + expect_no_lint("dt[i = 1]", linter) }) test_that("duplicate_argument_linter blocks disallowed usages", { @@ -36,21 +36,13 @@ test_that("duplicate_argument_linter respects except argument", { linter_list <- duplicate_argument_linter(except = "list") linter_all <- duplicate_argument_linter(except = character()) - expect_lint( - "list( + expect_no_lint("list( var = 1, var = 2 - )", - NULL, - linter_list - ) + )", linter_list) - expect_lint( - "(function(x, y) x + y)(x = 1) - list(var = 1, var = 2)", - NULL, - linter_list - ) + expect_no_lint("(function(x, y) x + y)(x = 1) + list(var = 1, var = 2)", linter_list) expect_lint( "fun(` @@ -70,35 +62,23 @@ test_that("duplicate_argument_linter respects except argument", { test_that("doesn't lint duplicated arguments in allowed functions", { linter <- duplicate_argument_linter() - expect_lint( - "x %>% + expect_no_lint("x %>% dplyr::mutate( col = a + b, col = col + d - )", - NULL, - linter - ) + )", linter) - expect_lint( - "x %>% + expect_no_lint("x %>% dplyr::transmute( col = a + b, col = col / 2.5 - )", - NULL, - linter - ) + )", linter) skip_if_not_r_version("4.1.0") - expect_lint( - "x |> + expect_no_lint("x |> dplyr::mutate( col = col |> str_replace('t', '') |> str_replace('\\\\s+$', 'xxx') - )", - NULL, - linter - ) + )", linter) }) test_that("interceding comments don't trip up logic", { diff --git a/tests/testthat/test-empty_assignment_linter.R b/tests/testthat/test-empty_assignment_linter.R index 8bf39b34a..c53ad79a6 100644 --- a/tests/testthat/test-empty_assignment_linter.R +++ b/tests/testthat/test-empty_assignment_linter.R @@ -1,9 +1,9 @@ test_that("empty_assignment_linter skips valid usage", { - expect_lint("x <- { 3 + 4 }", NULL, empty_assignment_linter()) - expect_lint("x <- if (x > 1) { 3 + 4 }", NULL, empty_assignment_linter()) + expect_no_lint("x <- { 3 + 4 }", empty_assignment_linter()) + expect_no_lint("x <- if (x > 1) { 3 + 4 }", empty_assignment_linter()) # also triggers assignment_linter - expect_lint("x = { 3 + 4 }", NULL, empty_assignment_linter()) + expect_no_lint("x = { 3 + 4 }", empty_assignment_linter()) }) test_that("empty_assignment_linter blocks disallowed usages", { diff --git a/tests/testthat/test-equals_na_linter.R b/tests/testthat/test-equals_na_linter.R index 26109e30b..6443df927 100644 --- a/tests/testthat/test-equals_na_linter.R +++ b/tests/testthat/test-equals_na_linter.R @@ -1,25 +1,25 @@ test_that("equals_na_linter skips allowed usages", { linter <- equals_na_linter() - expect_lint("blah", NULL, linter) - expect_lint(" blah", NULL, linter) - expect_lint(" blah", NULL, linter) - expect_lint("x=NA", NULL, linter) - expect_lint("x = NaN", NULL, linter) - expect_lint("x = NA_real_", NULL, linter) - expect_lint("is.na(x)", NULL, linter) - expect_lint("is.nan(x)", NULL, linter) - expect_lint("x[!is.na(x)]", NULL, linter) + expect_no_lint("blah", linter) + expect_no_lint(" blah", linter) + expect_no_lint(" blah", linter) + expect_no_lint("x=NA", linter) + expect_no_lint("x = NaN", linter) + expect_no_lint("x = NA_real_", linter) + expect_no_lint("is.na(x)", linter) + expect_no_lint("is.nan(x)", linter) + expect_no_lint("x[!is.na(x)]", linter) # equals_na_linter should ignore strings and comments - expect_lint("is.na(x) # do not flag x == NA if inside a comment", NULL, linter) - expect_lint("lint_msg <- 'do not flag x == NA if inside a string'", NULL, linter) + expect_no_lint("is.na(x) # do not flag x == NA if inside a comment", linter) + expect_no_lint("lint_msg <- 'do not flag x == NA if inside a string'", linter) # nested NAs are okay - expect_lint("x==f(1, ignore = NA)", NULL, linter) + expect_no_lint("x==f(1, ignore = NA)", linter) # this should be covered by any_is_na_linter() - expect_lint("NA %in% x", NULL, linter) + expect_no_lint("NA %in% x", linter) }) skip_if_not_installed("tibble") diff --git a/tests/testthat/test-error.R b/tests/testthat/test-error.R index 3001c8d66..8daecabd0 100644 --- a/tests/testthat/test-error.R +++ b/tests/testthat/test-error.R @@ -21,7 +21,7 @@ test_that("returns the correct linting", { expect_lint("x = ;", rex::rex("unexpected ';'"), linter) # no parsing error is expected for the equals-assignment in this code - expect_lint("purrr::partial(list, 1, ... = , 2)", NULL, linter) + expect_no_lint("purrr::partial(list, 1, ... = , 2)", linter) # trigger error with base only, and extract it to match against # what comes out from expect_lint. diff --git a/tests/testthat/test-exclusions.R b/tests/testthat/test-exclusions.R index 78140df54..c52922552 100644 --- a/tests/testthat/test-exclusions.R +++ b/tests/testthat/test-exclusions.R @@ -178,32 +178,20 @@ test_that("next-line exclusion works", { linter <- assignment_linter() # blanket exclusion works - expect_lint( - trim_some(" + expect_no_lint(trim_some(" # NLN x = 1 - "), - NULL, - linter - ) + "), linter) # specific exclusion works - expect_lint( - trim_some(" + expect_no_lint(trim_some(" # NLN: assignment_linter. x = 1 - "), - NULL, - linter - ) - expect_lint( - trim_some(" + "), linter) + expect_no_lint(trim_some(" # NLN: assignment. x = 1 - "), - NULL, - linter - ) + "), linter) expect_lint( trim_some(" # NLN: line_length_linter. diff --git a/tests/testthat/test-expect_comparison_linter.R b/tests/testthat/test-expect_comparison_linter.R index cf1a349aa..6483c3fcd 100644 --- a/tests/testthat/test-expect_comparison_linter.R +++ b/tests/testthat/test-expect_comparison_linter.R @@ -2,18 +2,18 @@ test_that("expect_comparison_linter skips allowed usages", { linter <- expect_comparison_linter() # there's no expect_ne() for this operator - expect_lint("expect_true(x != y)", NULL, linter) + expect_no_lint("expect_true(x != y)", linter) # NB: also applies to tinytest, but it's sufficient to test testthat - expect_lint("testthat::expect_true(x != y)", NULL, linter) + expect_no_lint("testthat::expect_true(x != y)", linter) # multiple comparisons are OK - expect_lint("expect_true(x > y || x > z)", NULL, linter) + expect_no_lint("expect_true(x > y || x > z)", linter) # expect_gt() and friends don't have an info= argument - expect_lint("expect_true(x > y, info = 'x is bigger than y yo')", NULL, linter) + expect_no_lint("expect_true(x > y, info = 'x is bigger than y yo')", linter) # expect_true() used incorrectly, and as executed the first argument is not a lint - expect_lint("expect_true(is.count(n_draws), n_draws > 1)", NULL, linter) + expect_no_lint("expect_true(is.count(n_draws), n_draws > 1)", linter) }) test_that("expect_comparison_linter blocks simple disallowed usages", { diff --git a/tests/testthat/test-expect_identical_linter.R b/tests/testthat/test-expect_identical_linter.R index a672acbfe..49f4e3f0e 100644 --- a/tests/testthat/test-expect_identical_linter.R +++ b/tests/testthat/test-expect_identical_linter.R @@ -2,17 +2,17 @@ test_that("expect_identical_linter skips allowed usages", { linter <- expect_identical_linter() # expect_type doesn't have an inverted version - expect_lint("expect_true(identical(x, y) || identical(y, z))", NULL, linter) + expect_no_lint("expect_true(identical(x, y) || identical(y, z))", linter) # NB: also applies to tinytest, but it's sufficient to test testthat - expect_lint("testthat::expect_true(identical(x, y) || identical(y, z))", NULL, linter) + expect_no_lint("testthat::expect_true(identical(x, y) || identical(y, z))", linter) # expect_equal calls with explicit tolerance= are OK - expect_lint("expect_equal(x, y, tolerance = 1e-6)", NULL, linter) + expect_no_lint("expect_equal(x, y, tolerance = 1e-6)", linter) # ditto if the argument is passed quoted - expect_lint("expect_equal(x, y, 'tolerance' = 1e-6)", NULL, linter) + expect_no_lint("expect_equal(x, y, 'tolerance' = 1e-6)", linter) # ditto for check.attributes = FALSE - expect_lint("expect_equal(x, y, check.attributes = FALSE)", NULL, linter) + expect_no_lint("expect_equal(x, y, check.attributes = FALSE)", linter) }) test_that("expect_identical_linter blocks simple disallowed usages", { @@ -29,14 +29,14 @@ test_that("expect_identical_linter skips cases likely testing numeric equality", linter <- expect_identical_linter() lint_msg <- rex::rex("Use expect_identical(x, y) by default; resort to expect_equal() only when needed") - expect_lint("expect_equal(x, 1.034)", NULL, linter) - expect_lint("expect_equal(x, -1.034)", NULL, linter) - expect_lint("expect_equal(x, c(-1.034))", NULL, linter) - expect_lint("expect_equal(x, -c(1.034))", NULL, linter) + expect_no_lint("expect_equal(x, 1.034)", linter) + expect_no_lint("expect_equal(x, -1.034)", linter) + expect_no_lint("expect_equal(x, c(-1.034))", linter) + expect_no_lint("expect_equal(x, -c(1.034))", linter) - expect_lint("expect_equal(x, c(1.01, 1.02))", NULL, linter) + expect_no_lint("expect_equal(x, c(1.01, 1.02))", linter) # whole numbers with explicit decimals are OK, even in mixed scenarios - expect_lint("expect_equal(x, c(1.0, 2))", NULL, linter) + expect_no_lint("expect_equal(x, c(1.0, 2))", linter) # plain numbers are still caught, however expect_lint("expect_equal(x, 1L)", lint_msg, linter) expect_lint("expect_equal(x, 1)", lint_msg, linter) @@ -49,13 +49,13 @@ test_that("expect_identical_linter skips cases likely testing numeric equality", }) test_that("expect_identical_linter skips 3e cases needing expect_equal", { - expect_lint("expect_equal(x, y, ignore_attr = 'names')", NULL, expect_identical_linter()) + expect_no_lint("expect_equal(x, y, ignore_attr = 'names')", expect_identical_linter()) }) # this arose where a helper function was wrapping expect_equal() and # some of the "allowed" arguments were being passed --> false positive test_that("expect_identical_linter skips calls using ...", { - expect_lint("expect_equal(x, y, ...)", NULL, expect_identical_linter()) + expect_no_lint("expect_equal(x, y, ...)", expect_identical_linter()) }) test_that("lints vectorize", { diff --git a/tests/testthat/test-expect_length_linter.R b/tests/testthat/test-expect_length_linter.R index 79176ab76..aa0ab2f9f 100644 --- a/tests/testthat/test-expect_length_linter.R +++ b/tests/testthat/test-expect_length_linter.R @@ -1,18 +1,18 @@ test_that("expect_length_linter skips allowed usages", { linter <- expect_length_linter() - expect_lint("expect_equal(nrow(x), 4L)", NULL, linter) + expect_no_lint("expect_equal(nrow(x), 4L)", linter) # NB: also applies to tinytest, but it's sufficient to test testthat - expect_lint("testthat::expect_equal(nrow(x), 4L)", NULL, linter) + expect_no_lint("testthat::expect_equal(nrow(x), 4L)", linter) # only check the first argument. yoda tests in the second argument will be # missed, but there are legitimate uses of length() in argument 2 - expect_lint("expect_equal(nrow(x), length(y))", NULL, linter) + expect_no_lint("expect_equal(nrow(x), length(y))", linter) # expect_length() doesn't have info= or label= arguments - expect_lint("expect_equal(length(x), n, info = 'x should have size n')", NULL, linter) - expect_lint("expect_equal(length(x), n, label = 'x size')", NULL, linter) - expect_lint("expect_equal(length(x), n, expected.label = 'target size')", NULL, linter) + expect_no_lint("expect_equal(length(x), n, info = 'x should have size n')", linter) + expect_no_lint("expect_equal(length(x), n, label = 'x size')", linter) + expect_no_lint("expect_equal(length(x), n, expected.label = 'target size')", linter) }) test_that("expect_length_linter blocks simple disallowed usages", { diff --git a/tests/testthat/test-expect_named_linter.R b/tests/testthat/test-expect_named_linter.R index 662be5a6b..84fffbd0e 100644 --- a/tests/testthat/test-expect_named_linter.R +++ b/tests/testthat/test-expect_named_linter.R @@ -2,17 +2,17 @@ test_that("expect_named_linter skips allowed usages", { linter <- expect_named_linter() # colnames(), rownames(), and dimnames() tests are not equivalent - expect_lint("expect_equal(colnames(x), 'a')", NULL, linter) - expect_lint("expect_equal(rownames(x), 'a')", NULL, linter) - expect_lint("expect_equal(dimnames(x), 'a')", NULL, linter) + expect_no_lint("expect_equal(colnames(x), 'a')", linter) + expect_no_lint("expect_equal(rownames(x), 'a')", linter) + expect_no_lint("expect_equal(dimnames(x), 'a')", linter) - expect_lint("expect_equal(nrow(x), 4L)", NULL, linter) + expect_no_lint("expect_equal(nrow(x), 4L)", linter) # NB: also applies to tinytest, but it's sufficient to test testthat - expect_lint("testthat::expect_equal(nrow(x), 4L)", NULL, linter) + expect_no_lint("testthat::expect_equal(nrow(x), 4L)", linter) # only check the first argument. yoda tests in the second argument will be # missed, but there are legitimate uses of names() in argument 2 - expect_lint("expect_equal(colnames(x), names(y))", NULL, linter) + expect_no_lint("expect_equal(colnames(x), names(y))", linter) }) test_that("expect_named_linter blocks simple disallowed usages", { diff --git a/tests/testthat/test-expect_not_linter.R b/tests/testthat/test-expect_not_linter.R index 6b17c2189..03fb72529 100644 --- a/tests/testthat/test-expect_not_linter.R +++ b/tests/testthat/test-expect_not_linter.R @@ -1,13 +1,13 @@ test_that("expect_not_linter skips allowed usages", { - expect_lint("expect_true(x)", NULL, expect_not_linter()) + expect_no_lint("expect_true(x)", expect_not_linter()) # NB: also applies to tinytest, but it's sufficient to test testthat - expect_lint("testthat::expect_true(x)", NULL, expect_not_linter()) - expect_lint("expect_false(x)", NULL, expect_not_linter()) - expect_lint("testthat::expect_false(x)", NULL, expect_not_linter()) + expect_no_lint("testthat::expect_true(x)", expect_not_linter()) + expect_no_lint("expect_false(x)", expect_not_linter()) + expect_no_lint("testthat::expect_false(x)", expect_not_linter()) # not a strict ban on ! ## (expect_false(x && y) is the same, but it's not clear which to prefer) - expect_lint("expect_true(!x || !y)", NULL, expect_not_linter()) + expect_no_lint("expect_true(!x || !y)", expect_not_linter()) }) test_that("expect_not_linter blocks simple disallowed usages", { diff --git a/tests/testthat/test-expect_null_linter.R b/tests/testthat/test-expect_null_linter.R index dc93eb400..bbfbf6f3c 100644 --- a/tests/testthat/test-expect_null_linter.R +++ b/tests/testthat/test-expect_null_linter.R @@ -3,15 +3,15 @@ test_that("expect_null_linter skips allowed usages", { # NB: this usage should be expect_false(), but this linter should # nevertheless apply (e.g. for maintainers not using expect_not_linter) - expect_lint("expect_true(!is.null(x))", NULL, linter) + expect_no_lint("expect_true(!is.null(x))", linter) # NB: also applies to tinytest, but it's sufficient to test testthat - expect_lint("testthat::expect_true(!is.null(x))", NULL, linter) + expect_no_lint("testthat::expect_true(!is.null(x))", linter) # length-0 could be NULL, but could be integer() or list(), so let it pass - expect_lint("expect_length(x, 0L)", NULL, linter) + expect_no_lint("expect_length(x, 0L)", linter) # no false positive for is.null() at the wrong positional argument - expect_lint("expect_true(x, is.null(y))", NULL, linter) + expect_no_lint("expect_true(x, is.null(y))", linter) }) test_that("expect_null_linter blocks simple disallowed usages", { diff --git a/tests/testthat/test-expect_s3_class_linter.R b/tests/testthat/test-expect_s3_class_linter.R index acdbd2686..11b0a78b1 100644 --- a/tests/testthat/test-expect_s3_class_linter.R +++ b/tests/testthat/test-expect_s3_class_linter.R @@ -2,21 +2,21 @@ test_that("expect_s3_class_linter skips allowed usages", { linter <- expect_s3_class_linter() # expect_s3_class doesn't have an inverted version - expect_lint("expect_true(!inherits(x, 'class'))", NULL, linter) + expect_no_lint("expect_true(!inherits(x, 'class'))", linter) # NB: also applies to tinytest, but it's sufficient to test testthat - expect_lint("testthat::expect_true(!inherits(x, 'class'))", NULL, linter) + expect_no_lint("testthat::expect_true(!inherits(x, 'class'))", linter) # other is. calls are not suitable for expect_s3_class in particular - expect_lint("expect_true(is.na(x))", NULL, linter) + expect_no_lint("expect_true(is.na(x))", linter) # case where expect_s3_class() *could* be used but we don't enforce - expect_lint("expect_true(is.data.table(x))", NULL, linter) + expect_no_lint("expect_true(is.data.table(x))", linter) # expect_s3_class() doesn't have info= or label= arguments - expect_lint("expect_equal(class(x), k, info = 'x should have class k')", NULL, linter) - expect_lint("expect_equal(class(x), k, label = 'x class')", NULL, linter) - expect_lint("expect_equal(class(x), k, expected.label = 'target class')", NULL, linter) - expect_lint("expect_true(is.data.frame(x), info = 'x should be a data.frame')", NULL, linter) + expect_no_lint("expect_equal(class(x), k, info = 'x should have class k')", linter) + expect_no_lint("expect_equal(class(x), k, label = 'x class')", linter) + expect_no_lint("expect_equal(class(x), k, expected.label = 'target class')", linter) + expect_no_lint("expect_true(is.data.frame(x), info = 'x should be a data.frame')", linter) }) test_that("expect_s3_class_linter blocks simple disallowed usages", { diff --git a/tests/testthat/test-expect_s4_class_linter.R b/tests/testthat/test-expect_s4_class_linter.R index 9892cabff..7ed231c09 100644 --- a/tests/testthat/test-expect_s4_class_linter.R +++ b/tests/testthat/test-expect_s4_class_linter.R @@ -2,13 +2,13 @@ test_that("expect_s4_class_linter skips allowed usages", { linter <- expect_s4_class_linter() # expect_s4_class doesn't have an inverted version - expect_lint("expect_true(!is(x, 'class'))", NULL, linter) + expect_no_lint("expect_true(!is(x, 'class'))", linter) # NB: also applies to tinytest, but it's sufficient to test testthat - expect_lint("testthat::expect_s3_class(!is(x, 'class'))", NULL, linter) + expect_no_lint("testthat::expect_s3_class(!is(x, 'class'))", linter) # expect_s4_class() doesn't have info= or label= arguments - expect_lint("expect_true(is(x, 'SpatialPoly'), info = 'x should be SpatialPoly')", NULL, linter) - expect_lint("expect_true(is(x, 'SpatialPoly'), label = 'x inheritance')", NULL, linter) + expect_no_lint("expect_true(is(x, 'SpatialPoly'), info = 'x should be SpatialPoly')", linter) + expect_no_lint("expect_true(is(x, 'SpatialPoly'), label = 'x inheritance')", linter) }) test_that("expect_s4_class blocks simple disallowed usages", { diff --git a/tests/testthat/test-expect_type_linter.R b/tests/testthat/test-expect_type_linter.R index a88ac8959..e8b04df07 100644 --- a/tests/testthat/test-expect_type_linter.R +++ b/tests/testthat/test-expect_type_linter.R @@ -2,21 +2,21 @@ test_that("expect_type_linter skips allowed usages", { linter <- expect_type_linter() # expect_type doesn't have an inverted version - expect_lint("expect_true(!is.numeric(x))", NULL, linter) + expect_no_lint("expect_true(!is.numeric(x))", linter) # NB: also applies to tinytest, but it's sufficient to test testthat - expect_lint("testthat::expect_true(!is.numeric(x))", NULL, linter) + expect_no_lint("testthat::expect_true(!is.numeric(x))", linter) # other is. calls are not suitable for expect_type in particular - expect_lint("expect_true(is.data.frame(x))", NULL, linter) + expect_no_lint("expect_true(is.data.frame(x))", linter) # expect_type(x, ...) cannot be cleanly used here: - expect_lint("expect_true(typeof(x) %in% c('builtin', 'closure'))", NULL, linter) + expect_no_lint("expect_true(typeof(x) %in% c('builtin', 'closure'))", linter) # expect_type() doesn't have info= or label= arguments - expect_lint("expect_equal(typeof(x), t, info = 'x should have type t')", NULL, linter) - expect_lint("expect_equal(typeof(x), t, label = 'x type')", NULL, linter) - expect_lint("expect_equal(typeof(x), t, expected.label = 'type')", NULL, linter) - expect_lint("expect_true(is.double(x), info = 'x should be double')", NULL, linter) + expect_no_lint("expect_equal(typeof(x), t, info = 'x should have type t')", linter) + expect_no_lint("expect_equal(typeof(x), t, label = 'x type')", linter) + expect_no_lint("expect_equal(typeof(x), t, expected.label = 'type')", linter) + expect_no_lint("expect_true(is.double(x), info = 'x should be double')", linter) }) test_that("expect_type_linter blocks simple disallowed usages", { diff --git a/tests/testthat/test-for_loop_index_linter.R b/tests/testthat/test-for_loop_index_linter.R index f138e1938..b3b48827b 100644 --- a/tests/testthat/test-for_loop_index_linter.R +++ b/tests/testthat/test-for_loop_index_linter.R @@ -1,26 +1,22 @@ test_that("for_loop_index_linter skips allowed usages", { linter <- for_loop_index_linter() - expect_lint("for (xi in x) {}", NULL, linter) + expect_no_lint("for (xi in x) {}", linter) # this is OK, so not every symbol is problematic - expect_lint("for (col in DF$col) {}", NULL, linter) - expect_lint("for (col in S4@col) {}", NULL, linter) - expect_lint("for (col in DT[, col]) {}", NULL, linter) + expect_no_lint("for (col in DF$col) {}", linter) + expect_no_lint("for (col in S4@col) {}", linter) + expect_no_lint("for (col in DT[, col]) {}", linter) # make sure symbol check is scoped - expect_lint( - trim_some(" + expect_no_lint(trim_some(" { for (i in 1:10) { 42L } i <- 7L } - "), - NULL, - linter - ) + "), linter) }) test_that("for_loop_index_linter blocks simple disallowed usages", { diff --git a/tests/testthat/test-function_argument_linter.R b/tests/testthat/test-function_argument_linter.R index 8462d4d77..beba11318 100644 --- a/tests/testthat/test-function_argument_linter.R +++ b/tests/testthat/test-function_argument_linter.R @@ -1,12 +1,12 @@ test_that("function_argument_linter skips allowed usages", { linter <- function_argument_linter() - expect_lint("function(x, y = 1, z = 2) {}", NULL, linter) - expect_lint("function(x, y, z = 1) {}", NULL, linter) + expect_no_lint("function(x, y = 1, z = 2) {}", linter) + expect_no_lint("function(x, y, z = 1) {}", linter) # ... handled correctly - expect_lint("function(x, y, z = 1, ...) {}", NULL, linter) - expect_lint("function(x, y, ..., z = 1) {}", NULL, linter) + expect_no_lint("function(x, y, z = 1, ...) {}", linter) + expect_no_lint("function(x, y, ..., z = 1) {}", linter) }) test_that("function_argument_linter blocks disallowed usages", { @@ -41,16 +41,12 @@ test_that("function_argument_linter blocks disallowed usages", { list(message = lint_msg, line_number = 4L), linter ) - expect_lint( - trim_some(" + expect_no_lint(trim_some(" function(x, y = 1, z = 2) { } - "), - NULL, - linter - ) + "), linter) }) test_that("function_argument_linter also lints lambda expressions", { @@ -60,8 +56,8 @@ test_that("function_argument_linter also lints lambda expressions", { expect_lint("\\(x, y = 1, z) {}", list(message = lint_msg, column_number = 13L), linter) expect_lint("\\(x, y = 1, z, w = 2) {}", list(message = lint_msg, column_number = 13L), linter) - expect_lint("\\(x, y = 1, z = 2) {}", NULL, linter) - expect_lint("\\(x, y, z = 1) {}", NULL, linter) + expect_no_lint("\\(x, y = 1, z = 2) {}", linter) + expect_no_lint("\\(x, y, z = 1) {}", linter) }) test_that("Use of missing() is reported in the lint message", { diff --git a/tests/testthat/test-function_return_linter.R b/tests/testthat/test-function_return_linter.R index 0a78a895f..af2855916 100644 --- a/tests/testthat/test-function_return_linter.R +++ b/tests/testthat/test-function_return_linter.R @@ -5,7 +5,7 @@ test_that("function_return_linter skips allowed usages", { return(x) } ") - expect_lint(lines_simple, NULL, function_return_linter()) + expect_no_lint(lines_simple, function_return_linter()) # arguably an expression as complicated as this should also be assigned, # but for now that's out of the scope of this linter @@ -17,7 +17,7 @@ test_that("function_return_linter skips allowed usages", { }]) } ") - expect_lint(lines_subassignment, NULL, function_return_linter()) + expect_no_lint(lines_subassignment, function_return_linter()) }) test_that("function_return_linter blocks simple disallowed usages", { diff --git a/tests/testthat/test-if_not_else_linter.R b/tests/testthat/test-if_not_else_linter.R index f63f936ff..fb05da5cc 100644 --- a/tests/testthat/test-if_not_else_linter.R +++ b/tests/testthat/test-if_not_else_linter.R @@ -2,20 +2,20 @@ test_that("if_not_else_linter skips allowed usages", { linter <- if_not_else_linter() # simple if/else statement is fine - expect_lint("if (A) x else y", NULL, linter) + expect_no_lint("if (A) x else y", linter) # not plain negation --> OK - expect_lint("if (!A || B) x else y", NULL, linter) + expect_no_lint("if (!A || B) x else y", linter) # no else clause --> OK - expect_lint("if (!A) x", NULL, linter) + expect_no_lint("if (!A) x", linter) # nested statements are also OK - expect_lint("if (!A) x else if (B) y", NULL, linter) - expect_lint("if (!A) x else if (B) y else z", NULL, linter) - expect_lint("if (A) x else if (B) y else if (!C) z", NULL, linter) + expect_no_lint("if (!A) x else if (B) y", linter) + expect_no_lint("if (!A) x else if (B) y else z", linter) + expect_no_lint("if (A) x else if (B) y else if (!C) z", linter) # ! picked up in the evaluation statements is skipped - expect_lint("if (A) !x else y", NULL, linter) - expect_lint("if (A) x else !y", NULL, linter) + expect_no_lint("if (A) !x else y", linter) + expect_no_lint("if (A) x else !y", linter) }) test_that("if_not_else_linter blocks simple disallowed usages", { @@ -33,15 +33,15 @@ patrick::with_parameters_test_that( "if_not_else_linter blocks usages in ifelse() and friends as well", { linter <- if_not_else_linter() - expect_lint(sprintf("%s(!A | B, x, y)", ifelse_fun), NULL, linter) - expect_lint(sprintf("%s(A, !x, y)", ifelse_fun), NULL, linter) + expect_no_lint(sprintf("%s(!A | B, x, y)", ifelse_fun), linter) + expect_no_lint(sprintf("%s(A, !x, y)", ifelse_fun), linter) expect_lint( sprintf("%s(!A, x, y)", ifelse_fun), sprintf("Prefer `%s[(]A, x, y[)]` to the less-readable", ifelse_fun), linter ) # particularly relevant for if_else() - expect_lint(sprintf("%s(!!A, x, y)", ifelse_fun), NULL, linter) + expect_no_lint(sprintf("%s(!!A, x, y)", ifelse_fun), linter) }, .test_name = c("ifelse", "fifelse", "if_else"), ifelse_fun = c("ifelse", "fifelse", "if_else") @@ -50,10 +50,10 @@ patrick::with_parameters_test_that( test_that("if_not_else_linter skips negated calls to is.null & similar", { linter <- if_not_else_linter() - expect_lint("if (!is.null(x)) x else y", NULL, linter) - expect_lint("if (!is.na(x)) x else y", NULL, linter) - expect_lint("if (!missing(x)) x else y", NULL, linter) - expect_lint("ifelse(!is.na(x), x, y)", NULL, linter) + expect_no_lint("if (!is.null(x)) x else y", linter) + expect_no_lint("if (!is.na(x)) x else y", linter) + expect_no_lint("if (!missing(x)) x else y", linter) + expect_no_lint("ifelse(!is.na(x), x, y)", linter) }) test_that("multiple lints are generated correctly", { @@ -81,5 +81,5 @@ test_that("exceptions= argument works", { if_not_else_linter(exceptions = character()) ) - expect_lint("if (!foo(x)) y else z", NULL, if_not_else_linter(exceptions = "foo")) + expect_no_lint("if (!foo(x)) y else z", if_not_else_linter(exceptions = "foo")) }) diff --git a/tests/testthat/test-if_switch_linter.R b/tests/testthat/test-if_switch_linter.R index e6b3e5fe5..8e5352615 100644 --- a/tests/testthat/test-if_switch_linter.R +++ b/tests/testthat/test-if_switch_linter.R @@ -2,23 +2,23 @@ test_that("if_switch_linter skips allowed usages", { linter <- if_switch_linter() # don't apply to simple if/else statements - expect_lint("if (x == 'a') 1 else 2", NULL, linter) + expect_no_lint("if (x == 'a') 1 else 2", linter) # don't apply to non-character conditions # (NB: switch _could_ be used for integral input, but this # interface is IMO a bit clunky / opaque) - expect_lint("if (x == 1) 1 else 2", NULL, linter) + expect_no_lint("if (x == 1) 1 else 2", linter) # this also has a switch equivalent, but we don't both handling such # complicated cases - expect_lint("if (x == 'a') 1 else if (x != 'b') 2 else 3", NULL, linter) + expect_no_lint("if (x == 'a') 1 else if (x != 'b') 2 else 3", linter) # multiple variables involved --> no clean change - expect_lint("if (x == 'a') 1 else if (y == 'b') 2 else 3", NULL, linter) + expect_no_lint("if (x == 'a') 1 else if (y == 'b') 2 else 3", linter) # multiple conditions --> no clean change - expect_lint("if (is.character(x) && x == 'a') 1 else if (x == 'b') 2 else 3", NULL, linter) + expect_no_lint("if (is.character(x) && x == 'a') 1 else if (x == 'b') 2 else 3", linter) # simple cases with two conditions might be more natural # without switch(); require at least three branches to trigger a lint - expect_lint("if (x == 'a') 1 else if (x == 'b') 2", NULL, linter) + expect_no_lint("if (x == 'a') 1 else if (x == 'b') 2", linter) # still no third if() clause - expect_lint("if (x == 'a') 1 else if (x == 'b') 2 else 3", NULL, linter) + expect_no_lint("if (x == 'a') 1 else if (x == 'b') 2 else 3", linter) }) test_that("if_switch_linter blocks simple disallowed usages", { @@ -43,9 +43,8 @@ test_that("if_switch_linter handles further nested if/else correctly", { # related to previous test -- if the first condition is non-`==`, the # whole if/else chain is "tainted" / non-switch()-recommended. # (technically, switch can work here, but the semantics are opaque) - expect_lint( + expect_no_lint( "if (x %in% c('a', 'e', 'f')) 1 else if (x == 'b') 2 else if (x == 'c') 3 else if (x == 'd') 4", - NULL, linter ) }) @@ -131,9 +130,9 @@ test_that("max_branch_lines= and max_branch_expressions= arguments work", { 9 } ") - expect_lint(three_per_branch_lines, NULL, max_lines2_linter) + expect_no_lint(three_per_branch_lines, max_lines2_linter) expect_lint(three_per_branch_lines, lint_msg, max_lines4_linter) - expect_lint(three_per_branch_lines, NULL, max_expr2_linter) + expect_no_lint(three_per_branch_lines, max_expr2_linter) expect_lint(three_per_branch_lines, lint_msg, max_expr4_linter) five_per_branch_lines <- trim_some(" @@ -157,10 +156,10 @@ test_that("max_branch_lines= and max_branch_expressions= arguments work", { 15 } ") - expect_lint(five_per_branch_lines, NULL, max_lines2_linter) - expect_lint(five_per_branch_lines, NULL, max_lines4_linter) - expect_lint(five_per_branch_lines, NULL, max_expr2_linter) - expect_lint(five_per_branch_lines, NULL, max_expr4_linter) + expect_no_lint(five_per_branch_lines, max_lines2_linter) + expect_no_lint(five_per_branch_lines, max_lines4_linter) + expect_no_lint(five_per_branch_lines, max_expr2_linter) + expect_no_lint(five_per_branch_lines, max_expr4_linter) five_lines_three_expr_lines <- trim_some(" if (x == 'a') { @@ -183,9 +182,9 @@ test_that("max_branch_lines= and max_branch_expressions= arguments work", { ) } ") - expect_lint(five_lines_three_expr_lines, NULL, max_lines2_linter) - expect_lint(five_lines_three_expr_lines, NULL, max_lines4_linter) - expect_lint(five_lines_three_expr_lines, NULL, max_expr2_linter) + expect_no_lint(five_lines_three_expr_lines, max_lines2_linter) + expect_no_lint(five_lines_three_expr_lines, max_lines4_linter) + expect_no_lint(five_lines_three_expr_lines, max_expr2_linter) expect_lint( five_lines_three_expr_lines, list(lint_msg, line_number = 1L), @@ -207,14 +206,14 @@ test_that("max_branch_lines= and max_branch_expressions= arguments work", { 13; 14; 15 } ") - expect_lint(five_expr_three_lines_lines, NULL, max_lines2_linter) + expect_no_lint(five_expr_three_lines_lines, max_lines2_linter) expect_lint( five_expr_three_lines_lines, list(lint_msg, line_number = 1L), max_lines4_linter ) - expect_lint(five_expr_three_lines_lines, NULL, max_expr2_linter) - expect_lint(five_expr_three_lines_lines, NULL, max_expr4_linter) + expect_no_lint(five_expr_three_lines_lines, max_expr2_linter) + expect_no_lint(five_expr_three_lines_lines, max_expr4_linter) }) test_that("max_branch_lines= and max_branch_expressions= block over-complex switch() too", { @@ -237,10 +236,10 @@ test_that("max_branch_lines= and max_branch_expressions= block over-complex swit } ) ") - expect_lint(one_per_branch_lines, NULL, max_lines2_linter) - expect_lint(one_per_branch_lines, NULL, max_lines4_linter) - expect_lint(one_per_branch_lines, NULL, max_expr2_linter) - expect_lint(one_per_branch_lines, NULL, max_expr4_linter) + expect_no_lint(one_per_branch_lines, max_lines2_linter) + expect_no_lint(one_per_branch_lines, max_lines4_linter) + expect_no_lint(one_per_branch_lines, max_expr2_linter) + expect_no_lint(one_per_branch_lines, max_expr4_linter) two_per_branch_lines <- trim_some(" switch(x, @@ -258,10 +257,10 @@ test_that("max_branch_lines= and max_branch_expressions= block over-complex swit } ) ") - expect_lint(two_per_branch_lines, NULL, max_lines2_linter) - expect_lint(two_per_branch_lines, NULL, max_lines4_linter) - expect_lint(two_per_branch_lines, NULL, max_expr2_linter) - expect_lint(two_per_branch_lines, NULL, max_expr4_linter) + expect_no_lint(two_per_branch_lines, max_lines2_linter) + expect_no_lint(two_per_branch_lines, max_lines4_linter) + expect_no_lint(two_per_branch_lines, max_expr2_linter) + expect_no_lint(two_per_branch_lines, max_expr4_linter) three_per_branch_lines <- trim_some(" switch(x, @@ -287,13 +286,13 @@ test_that("max_branch_lines= and max_branch_expressions= block over-complex swit list(lint_msg, line_number = 1L), max_lines2_linter ) - expect_lint(three_per_branch_lines, NULL, max_lines4_linter) + expect_no_lint(three_per_branch_lines, max_lines4_linter) expect_lint( three_per_branch_lines, list(lint_msg, line_number = 1L), max_expr2_linter ) - expect_lint(three_per_branch_lines, NULL, max_expr4_linter) + expect_no_lint(three_per_branch_lines, max_expr4_linter) five_per_branch_lines <- trim_some(" switch(x, @@ -353,7 +352,7 @@ test_that("max_branch_lines= and max_branch_expressions= block over-complex swit expect_lint(five_lines_three_expr_lines, lint_msg, max_lines2_linter) expect_lint(five_lines_three_expr_lines, lint_msg, max_lines4_linter) expect_lint(five_lines_three_expr_lines, lint_msg, max_expr2_linter) - expect_lint(five_lines_three_expr_lines, NULL, max_expr4_linter) + expect_no_lint(five_lines_three_expr_lines, max_expr4_linter) five_expr_three_lines_lines <- trim_some(" switch(x, @@ -375,7 +374,7 @@ test_that("max_branch_lines= and max_branch_expressions= block over-complex swit ) ") expect_lint(five_expr_three_lines_lines, lint_msg, max_lines2_linter) - expect_lint(five_expr_three_lines_lines, NULL, max_lines4_linter) + expect_no_lint(five_expr_three_lines_lines, max_lines4_linter) expect_lint(five_expr_three_lines_lines, lint_msg, max_expr2_linter) expect_lint(five_expr_three_lines_lines, lint_msg, max_expr4_linter) }) @@ -398,8 +397,7 @@ test_that("max_branch_lines= and max_branch_expressions= interact correctly", { linter ) - expect_lint( - trim_some(" + expect_no_lint(trim_some(" if (x == 'a') { foo( x1, @@ -412,13 +410,9 @@ test_that("max_branch_lines= and max_branch_expressions= interact correctly", { } else if (x == 'c') { 3 } - "), - NULL, - linter - ) + "), linter) - expect_lint( - trim_some(" + expect_no_lint(trim_some(" if (x == 'a') { 1; 2; 3; 4 } else if (x == 'b') { @@ -426,10 +420,7 @@ test_that("max_branch_lines= and max_branch_expressions= interact correctly", { } else if (x == 'c') { 6 } - "), - NULL, - linter - ) + "), linter) }) test_that("max_branch_lines= and max_branch_expressions= work for a terminal 'else' branch", { @@ -450,8 +441,8 @@ test_that("max_branch_lines= and max_branch_expressions= work for a terminal 'el 6 } ") - expect_lint(else_long_lines, NULL, max_lines2_linter) - expect_lint(else_long_lines, NULL, max_expr2_linter) + expect_no_lint(else_long_lines, max_lines2_linter) + expect_no_lint(else_long_lines, max_expr2_linter) default_long_lines <- trim_some(" switch(x, @@ -492,8 +483,8 @@ test_that("max_branch_lines= and max_branch_expressions= are guided by the most 5 } ") - expect_lint(if_else_one_branch_lines, NULL, max_lines2_linter) - expect_lint(if_else_one_branch_lines, NULL, max_expr2_linter) + expect_no_lint(if_else_one_branch_lines, max_lines2_linter) + expect_no_lint(if_else_one_branch_lines, max_expr2_linter) # lint if _any_ branch is too complex switch_one_branch_lines <- trim_some(" diff --git a/tests/testthat/test-implicit_integer_linter.R b/tests/testthat/test-implicit_integer_linter.R index c4c6fa016..650f7c196 100644 --- a/tests/testthat/test-implicit_integer_linter.R +++ b/tests/testthat/test-implicit_integer_linter.R @@ -57,8 +57,8 @@ test_that("linter returns the correct linting", { linter <- implicit_integer_linter() lint_msg <- rex::rex("Use 1L or 1.0 to avoid implicit integers.") - expect_lint("x <<- 1L", NULL, linter) - expect_lint("1.0/-Inf -> y", NULL, linter) + expect_no_lint("x <<- 1L", linter) + expect_no_lint("1.0/-Inf -> y", linter) expect_lint( "y <- 1+i", list(message = lint_msg, line_number = 1L, column_number = 7L), diff --git a/tests/testthat/test-inner_combine_linter.R b/tests/testthat/test-inner_combine_linter.R index 2f594374d..cf79b0990 100644 --- a/tests/testthat/test-inner_combine_linter.R +++ b/tests/testthat/test-inner_combine_linter.R @@ -68,13 +68,13 @@ test_that("inner_combine_linter is order-agnostic for matching arguments", { }) test_that("c() with ...length()=1 is OK", { - expect_lint("c(exp())", NULL, inner_combine_linter()) + expect_no_lint("c(exp())", inner_combine_linter()) }) skip_if_not_installed("tibble") patrick::with_parameters_test_that( "inner_combine_linter skips allowed usages:", - expect_lint(expr, NULL, inner_combine_linter()), + expect_no_lint(expr, inner_combine_linter()), .cases = tibble::tribble( ~.test_name, ~expr, "simple sin()", "x <- sin(1:10)", diff --git a/tests/testthat/test-knitr_formats.R b/tests/testthat/test-knitr_formats.R index eb3dfc5f9..08cffe126 100644 --- a/tests/testthat/test-knitr_formats.R +++ b/tests/testthat/test-knitr_formats.R @@ -131,11 +131,7 @@ test_that("it does _not_ handle brew", { }) test_that("it does _not_ error with inline \\Sexpr", { - expect_lint( - "#' text \\Sexpr{1 + 1} more text", - NULL, - default_linters - ) + expect_no_lint("#' text \\Sexpr{1 + 1} more text", default_linters) }) test_that("it does lint .Rmd or .qmd file with malformed input", { diff --git a/tests/testthat/test-length_levels_linter.R b/tests/testthat/test-length_levels_linter.R index c7b07ee18..b89c8a40b 100644 --- a/tests/testthat/test-length_levels_linter.R +++ b/tests/testthat/test-length_levels_linter.R @@ -1,5 +1,5 @@ test_that("length_levels_linter skips allowed usages", { - expect_lint("length(c(levels(x), 'a'))", NULL, length_levels_linter()) + expect_no_lint("length(c(levels(x), 'a'))", length_levels_linter()) }) test_that("length_levels_linter blocks simple disallowed usages", { diff --git a/tests/testthat/test-lengths_linter.R b/tests/testthat/test-lengths_linter.R index fbca36bd8..a330c04c2 100644 --- a/tests/testthat/test-lengths_linter.R +++ b/tests/testthat/test-lengths_linter.R @@ -1,13 +1,13 @@ test_that("lengths_linter skips allowed usages", { linter <- lengths_linter() - expect_lint("length(x)", NULL, linter) - expect_lint("function(x) length(x) + 1L", NULL, linter) - expect_lint("vapply(x, fun, integer(length(y)))", NULL, linter) - expect_lint("sapply(x, sqrt, simplify = length(x))", NULL, linter) + expect_no_lint("length(x)", linter) + expect_no_lint("function(x) length(x) + 1L", linter) + expect_no_lint("vapply(x, fun, integer(length(y)))", linter) + expect_no_lint("sapply(x, sqrt, simplify = length(x))", linter) # TODO(#1570): also throw a lint here, and for map(x, length) - expect_lint("lapply(x, length)", NULL, linter) + expect_no_lint("lapply(x, length)", linter) }) test_that("lengths_linter blocks simple disallowed base usages", { diff --git a/tests/testthat/test-line_length_linter.R b/tests/testthat/test-line_length_linter.R index 5e22fc523..2acfb92ff 100644 --- a/tests/testthat/test-line_length_linter.R +++ b/tests/testthat/test-line_length_linter.R @@ -1,8 +1,8 @@ test_that("line_length_linter skips allowed usages", { linter <- line_length_linter(80L) - expect_lint("blah", NULL, linter) - expect_lint(strrep("x", 80L), NULL, linter) + expect_no_lint("blah", linter) + expect_no_lint(strrep("x", 80L), linter) }) test_that("line_length_linter blocks disallowed usages", { @@ -37,7 +37,7 @@ test_that("line_length_linter blocks disallowed usages", { linter <- line_length_linter(20L) lint_msg <- rex::rex("Lines should not be more than 20 characters. This line is 22 characters.") - expect_lint(strrep("a", 20L), NULL, linter) + expect_no_lint(strrep("a", 20L), linter) expect_lint( strrep("a", 22L), list( diff --git a/tests/testthat/test-list_comparison_linter.R b/tests/testthat/test-list_comparison_linter.R index 6177caed1..49a6291a5 100644 --- a/tests/testthat/test-list_comparison_linter.R +++ b/tests/testthat/test-list_comparison_linter.R @@ -1,5 +1,5 @@ test_that("list_comparison_linter skips allowed usages", { - expect_lint("sapply(x, sum) > 10", NULL, list_comparison_linter()) + expect_no_lint("sapply(x, sum) > 10", list_comparison_linter()) }) local({ diff --git a/tests/testthat/test-matrix_apply_linter.R b/tests/testthat/test-matrix_apply_linter.R index 5503fb8b2..a6c66ccf9 100644 --- a/tests/testthat/test-matrix_apply_linter.R +++ b/tests/testthat/test-matrix_apply_linter.R @@ -92,5 +92,4 @@ test_that("matrix_apply_linter works with multiple lints in a single expression" ), linter ) - }) diff --git a/tests/testthat/test-missing_package_linter.R b/tests/testthat/test-missing_package_linter.R index 4b0d0165f..d3c76ea04 100644 --- a/tests/testthat/test-missing_package_linter.R +++ b/tests/testthat/test-missing_package_linter.R @@ -1,16 +1,16 @@ test_that("missing_package_linter skips allowed usages", { linter <- missing_package_linter() - expect_lint("library(stats)", NULL, linter) - expect_lint('library("stats")', NULL, linter) - expect_lint("library('stats')", NULL, linter) - expect_lint("library(`stats`)", NULL, linter) - expect_lint("library(stats, quietly)", NULL, linter) - expect_lint("library(stats, quietly = TRUE)", NULL, linter) - expect_lint("require(stats)", NULL, linter) - expect_lint("require(stats, quietly = TRUE)", NULL, linter) - expect_lint('loadNamespace("stats")', NULL, linter) - expect_lint('requireNamespace("stats")', NULL, linter) + expect_no_lint("library(stats)", linter) + expect_no_lint('library("stats")', linter) + expect_no_lint("library('stats')", linter) + expect_no_lint("library(`stats`)", linter) + expect_no_lint("library(stats, quietly)", linter) + expect_no_lint("library(stats, quietly = TRUE)", linter) + expect_no_lint("require(stats)", linter) + expect_no_lint("require(stats, quietly = TRUE)", linter) + expect_no_lint('loadNamespace("stats")', linter) + expect_no_lint('requireNamespace("stats")', linter) }) test_that("missing_package_linter blocks disallowed usages", { @@ -36,16 +36,16 @@ test_that("missing_package_linter blocks disallowed usages", { test_that("loadNamespace and requireNamespace allow plain symbols", { linter <- missing_package_linter() - expect_lint("loadNamespace(mypkg)", NULL, linter) - expect_lint("requireNamespace(mypkg)", NULL, linter) + expect_no_lint("loadNamespace(mypkg)", linter) + expect_no_lint("requireNamespace(mypkg)", linter) }) test_that("character.only=TRUE case is handled", { linter <- missing_package_linter() - expect_lint("library(statts, character.only = TRUE)", NULL, linter) - expect_lint("require(statts, character.only = TRUE)", NULL, linter) - expect_lint('library("stats", character.only = TRUE)', NULL, linter) + expect_no_lint("library(statts, character.only = TRUE)", linter) + expect_no_lint("require(statts, character.only = TRUE)", linter) + expect_no_lint('library("stats", character.only = TRUE)', linter) expect_lint( 'library("statts", character.only = TRUE)', diff --git a/tests/testthat/test-nested_ifelse_linter.R b/tests/testthat/test-nested_ifelse_linter.R index 66e6d1ff6..a5ff7123a 100644 --- a/tests/testthat/test-nested_ifelse_linter.R +++ b/tests/testthat/test-nested_ifelse_linter.R @@ -1,14 +1,14 @@ test_that("nested_ifelse_linter skips allowed usages", { linter <- nested_ifelse_linter() - expect_lint("if (TRUE) 1 else 2", NULL, linter) - expect_lint("if (TRUE) 1 else if (TRUE) 2 else 3", NULL, linter) + expect_no_lint("if (TRUE) 1 else 2", linter) + expect_no_lint("if (TRUE) 1 else if (TRUE) 2 else 3", linter) - expect_lint("ifelse(runif(10) > .2, 4, 6)", NULL, linter) + expect_no_lint("ifelse(runif(10) > .2, 4, 6)", linter) # don't block suggested alternatives - expect_lint("fcase(l1, v1, l2, v2)", NULL, linter) - expect_lint("case_when(l1 ~ v1, l2 ~ v2)", NULL, linter) + expect_no_lint("fcase(l1, v1, l2, v2)", linter) + expect_no_lint("case_when(l1 ~ v1, l2 ~ v2)", linter) }) test_that("nested_ifelse_linter blocks simple disallowed usages", { diff --git a/tests/testthat/test-nested_pipe_linter.R b/tests/testthat/test-nested_pipe_linter.R index 1e1679238..6910bd272 100644 --- a/tests/testthat/test-nested_pipe_linter.R +++ b/tests/testthat/test-nested_pipe_linter.R @@ -1,56 +1,40 @@ test_that("nested_pipe_linter skips allowed usages", { linter <- nested_pipe_linter() - expect_lint("a %>% b() %>% c()", NULL, linter) + expect_no_lint("a %>% b() %>% c()", linter) - expect_lint( - trim_some(" + expect_no_lint(trim_some(" foo <- function(x) { out <- a %>% b() return(out) } - "), - NULL, - linter - ) + "), linter) # pipes fitting on one line can be ignored - expect_lint( - "bind_rows(a %>% select(b), c %>% select(b))", - NULL, - linter - ) + expect_no_lint("bind_rows(a %>% select(b), c %>% select(b))", linter) # switch outputs are OK - expect_lint("switch(x, a = x %>% foo())", NULL, linter) + expect_no_lint("switch(x, a = x %>% foo())", linter) # final position is an output position - expect_lint("switch(x, a = x, x %>% foo())", NULL, linter) + expect_no_lint("switch(x, a = x, x %>% foo())", linter) # inline switch inputs are not linted - expect_lint( - trim_some(" + expect_no_lint(trim_some(" switch( x %>% foo(), a = x ) - "), - NULL, - linter - ) + "), linter) }) patrick::with_parameters_test_that( "allow_outer_calls defaults are ignored by default", - expect_lint( - trim_some(sprintf(outer_call, fmt = " + expect_no_lint(trim_some(sprintf(outer_call, fmt = " %s( x %%>%% foo() ) - ")), - NULL, - nested_pipe_linter() - ), + ")), nested_pipe_linter()), .test_name = c("try", "tryCatch", "withCallingHandlers"), outer_call = c("try", "tryCatch", "withCallingHandlers") ) @@ -114,16 +98,12 @@ test_that("allow_outer_calls= argument works", { nested_pipe_linter(allow_outer_calls = character()) ) - expect_lint( - trim_some(" + expect_no_lint(trim_some(" print( x %>% foo() ) - "), - NULL, - nested_pipe_linter(allow_outer_calls = "print") - ) + "), nested_pipe_linter(allow_outer_calls = "print")) }) test_that("Native pipes are handled as well", { @@ -133,11 +113,7 @@ test_that("Native pipes are handled as well", { linter_inline <- nested_pipe_linter(allow_inline = FALSE) lint_msg <- rex::rex("Don't nest pipes inside other calls.") - expect_lint( - "bind_rows(a |> select(b), c |> select(b))", - NULL, - linter - ) + expect_no_lint("bind_rows(a |> select(b), c |> select(b))", linter) expect_lint( "bind_rows(a |> select(b), c |> select(b))", list(lint_msg, lint_msg), diff --git a/tests/testthat/test-nonportable_path_linter.R b/tests/testthat/test-nonportable_path_linter.R index 9069ff938..c9fa8e3c8 100644 --- a/tests/testthat/test-nonportable_path_linter.R +++ b/tests/testthat/test-nonportable_path_linter.R @@ -8,17 +8,17 @@ test_that("nonportable_path_linter skips allowed usages", { encodeString("hello\nthere!") ) for (path in non_path_strings) { - expect_lint(single_quote(path), NULL, linter) - expect_lint(double_quote(path), NULL, linter) + expect_no_lint(single_quote(path), linter) + expect_no_lint(double_quote(path), linter) } - expect_lint("\"'/foo'\"", NULL, linter) # nested quotes + expect_no_lint("\"'/foo'\"", linter) # nested quotes # system root root_path_strings <- c("/", "~", "c:", ".") for (path in root_path_strings) { - expect_lint(single_quote(path), NULL, linter) - expect_lint(double_quote(path), NULL, linter) + expect_no_lint(single_quote(path), linter) + expect_no_lint(double_quote(path), linter) } }) @@ -53,8 +53,8 @@ test_that("nonportable_path_linter's lax argument works", { "/foo", encodeString("/a\nsdf/bar"), "/as:df/bar" ) for (path in unlikely_path_strings) { - expect_lint(single_quote(path), NULL, linter) - expect_lint(double_quote(path), NULL, linter) + expect_no_lint(single_quote(path), linter) + expect_no_lint(double_quote(path), linter) } }) diff --git a/tests/testthat/test-nrow_subset_linter.R b/tests/testthat/test-nrow_subset_linter.R index 8f1d49f24..1b07c670c 100644 --- a/tests/testthat/test-nrow_subset_linter.R +++ b/tests/testthat/test-nrow_subset_linter.R @@ -1,8 +1,8 @@ test_that("nrow_subset_linter skips allowed usage", { linter <- nrow_subset_linter() - expect_lint("nrow(foo(subset(x, y == z)))", NULL, linter) - expect_lint("with(x, sum(y == z))", NULL, linter) + expect_no_lint("nrow(foo(subset(x, y == z)))", linter) + expect_no_lint("with(x, sum(y == z))", linter) }) test_that("nrow_subset_linter blocks subset() cases", { diff --git a/tests/testthat/test-numeric_leading_zero_linter.R b/tests/testthat/test-numeric_leading_zero_linter.R index 3f362bc3a..0580cbae5 100644 --- a/tests/testthat/test-numeric_leading_zero_linter.R +++ b/tests/testthat/test-numeric_leading_zero_linter.R @@ -1,17 +1,17 @@ test_that("numeric_leading_zero_linter skips allowed usages", { linter <- numeric_leading_zero_linter() - expect_lint("a <- 0.1", NULL, linter) - expect_lint("b <- -0.2", NULL, linter) - expect_lint("c <- 3.0", NULL, linter) - expect_lint("d <- 4L", NULL, linter) - expect_lint("e <- TRUE", NULL, linter) - expect_lint("f <- 0.5e6", NULL, linter) - expect_lint("g <- 0x78", NULL, linter) - expect_lint("h <- 0.9 + 0.1i", NULL, linter) - expect_lint("h <- 0.9+0.1i", NULL, linter) - expect_lint("h <- 0.9 - 0.1i", NULL, linter) - expect_lint("i <- 2L + 3.4i", NULL, linter) + expect_no_lint("a <- 0.1", linter) + expect_no_lint("b <- -0.2", linter) + expect_no_lint("c <- 3.0", linter) + expect_no_lint("d <- 4L", linter) + expect_no_lint("e <- TRUE", linter) + expect_no_lint("f <- 0.5e6", linter) + expect_no_lint("g <- 0x78", linter) + expect_no_lint("h <- 0.9 + 0.1i", linter) + expect_no_lint("h <- 0.9+0.1i", linter) + expect_no_lint("h <- 0.9 - 0.1i", linter) + expect_no_lint("i <- 2L + 3.4i", linter) }) test_that("numeric_leading_zero_linter blocks simple disallowed usages", { diff --git a/tests/testthat/test-object_name_linter.R b/tests/testthat/test-object_name_linter.R index ad09b06c7..6dda5d600 100644 --- a/tests/testthat/test-object_name_linter.R +++ b/tests/testthat/test-object_name_linter.R @@ -1,5 +1,5 @@ test_that("default styles are linted correctly", { - linters <- list( + linters <- list( symbols_linter = object_name_linter("symbols"), CamelCase_linter = object_name_linter("CamelCase"), camelCase_linter = object_name_linter("camelCase"), diff --git a/tests/testthat/test-object_overwrite_linter.R b/tests/testthat/test-object_overwrite_linter.R index 175c4e7e8..bdf3540ef 100644 --- a/tests/testthat/test-object_overwrite_linter.R +++ b/tests/testthat/test-object_overwrite_linter.R @@ -1,13 +1,13 @@ test_that("object_overwrite_linter skips allowed usages", { linter <- object_overwrite_linter() - expect_lint("function() DT <- data.frame(a = 1)", NULL, linter) + expect_no_lint("function() DT <- data.frame(a = 1)", linter) # don't block names subassigned e.g. as columns or list elements - expect_lint("function() x$sd <- sd(rnorm(100))", NULL, linter) + expect_no_lint("function() x$sd <- sd(rnorm(100))", linter) # These virtual names are ignored to slightly reduce the search space - expect_lint("function() .__C__logical <- TRUE", NULL, linter) + expect_no_lint("function() .__C__logical <- TRUE", linter) }) test_that("object_overwrite_linter blocks simple disallowed usages", { @@ -94,32 +94,28 @@ test_that("Non-syntactic names are matched & linted (#2346)", { test_that("object_overwrite_linter skips any name assigned at the top level", { linter <- object_overwrite_linter() - expect_lint("data <- mtcars", NULL, linter) - expect_lint("sigma <- sd(rnorm(100))", NULL, linter) + expect_no_lint("data <- mtcars", linter) + expect_no_lint("sigma <- sd(rnorm(100))", linter) }) test_that("object_overwrite_linter skips argument names", { linter <- object_overwrite_linter() - expect_lint("foo <- function(data) data <- data + 1", NULL, linter) + expect_no_lint("foo <- function(data) data <- data + 1", linter) - expect_lint( - trim_some(" + expect_no_lint(trim_some(" bar <- function(a, b, c, sigma) { sigma <- a * b * c ^ sigma } - "), - NULL, - linter - ) + "), linter) }) test_that("object_overwrite_linter skips data.table assignments with :=", { - expect_lint("foo <- function() x[, title := 4]", NULL, object_overwrite_linter()) + expect_no_lint("foo <- function() x[, title := 4]", object_overwrite_linter()) }) test_that("object_overwrite_linter optionally accepts package names", { - expect_lint("function() data <- 1", NULL, object_overwrite_linter(packages = "base")) + expect_no_lint("function() data <- 1", object_overwrite_linter(packages = "base")) expect_lint( "function() lint <- TRUE", @@ -145,7 +141,7 @@ test_that("shorthand lambda is detected", { }) test_that("allow_names= works to ignore certain symbols", { - expect_lint("function() data <- 1", NULL, object_overwrite_linter(allow_names = "data")) + expect_no_lint("function() data <- 1", object_overwrite_linter(allow_names = "data")) }) test_that("lints vectorize", { diff --git a/tests/testthat/test-package_hooks_linter.R b/tests/testthat/test-package_hooks_linter.R index 883a1b0fd..f3a22953f 100644 --- a/tests/testthat/test-package_hooks_linter.R +++ b/tests/testthat/test-package_hooks_linter.R @@ -2,9 +2,9 @@ test_that("package_hooks_linter skips allowed usages of packageStartupMessage() linter <- package_hooks_linter() # allowed in .onAttach, not .onLoad - expect_lint(".onAttach <- function(lib, pkg) packageStartupMessage('hi')", NULL, linter) + expect_no_lint(".onAttach <- function(lib, pkg) packageStartupMessage('hi')", linter) # allowed in .onLoad, not .onAttach - expect_lint(".onLoad <- function(lib, pkg) library.dynam()", NULL, linter) + expect_no_lint(".onLoad <- function(lib, pkg) library.dynam()", linter) }) test_that("package_hooks_linter blocks simple disallowed usages of packageStartupMessage() & library.dynam()", { @@ -86,12 +86,12 @@ test_that("package_hooks_linter blocks simple disallowed usages of other blocked test_that("package_hooks_linter skips valid .onLoad() and .onAttach() arguments", { linter <- package_hooks_linter() - expect_lint(".onAttach <- function(lib, pkg) { }", NULL, linter) - expect_lint(".onLoad <- function(lib, pkg) { }", NULL, linter) + expect_no_lint(".onAttach <- function(lib, pkg) { }", linter) + expect_no_lint(".onLoad <- function(lib, pkg) { }", linter) # args only need to start with those characters - expect_lint(".onAttach <- function(libname, pkgpath) { }", NULL, linter) - expect_lint(".onLoad <- function(libXXXX, pkgYYYY) { }", NULL, linter) + expect_no_lint(".onAttach <- function(libname, pkgpath) { }", linter) + expect_no_lint(".onLoad <- function(libXXXX, pkgYYYY) { }", linter) }) test_that("package_hooks_linter blocks invalid .onLoad() / .onAttach() arguments", { @@ -118,8 +118,8 @@ test_that("package_hooks_linter blocks invalid .onLoad() / .onAttach() arguments test_that("package_hooks_linter skips valid namespace loading", { linter <- package_hooks_linter() - expect_lint(".onAttach <- function(lib, pkg) { requireNamespace('foo') }", NULL, linter) - expect_lint(".onLoad <- function(lib, pkg) { requireNamespace('foo') }", NULL, linter) + expect_no_lint(".onAttach <- function(lib, pkg) { requireNamespace('foo') }", linter) + expect_no_lint(".onLoad <- function(lib, pkg) { requireNamespace('foo') }", linter) }) test_that("package_hooks_linter blocks attaching namespaces", { @@ -174,11 +174,11 @@ test_that("package_hooks_linter blocks attaching namespaces", { test_that("package_hooks_linter skips valid .onDetach() and .Last.lib()", { linter <- package_hooks_linter() - expect_lint(".onDetach <- function(lib) { }", NULL, linter) - expect_lint(".onDetach <- function(libname) { }", NULL, linter) + expect_no_lint(".onDetach <- function(lib) { }", linter) + expect_no_lint(".onDetach <- function(libname) { }", linter) - expect_lint(".Last.lib <- function(lib) { }", NULL, linter) - expect_lint(".Last.lib <- function(libname) { }", NULL, linter) + expect_no_lint(".Last.lib <- function(lib) { }", linter) + expect_no_lint(".Last.lib <- function(libname) { }", linter) }) test_that("package_hooks_linter catches usage of library.dynam.unload()", { @@ -195,11 +195,7 @@ test_that("package_hooks_linter catches usage of library.dynam.unload()", { linter ) # expected usage is in .onUnload - expect_lint( - ".onUnload <- function(lib) { library.dynam.unload() }", - NULL, - linter - ) + expect_no_lint(".onUnload <- function(lib) { library.dynam.unload() }", linter) }) test_that("package_hooks_linter detects bad argument names in .onDetach()/.Last.lib()", { diff --git a/tests/testthat/test-paren_body_linter.R b/tests/testthat/test-paren_body_linter.R index dac02cae4..308066eef 100644 --- a/tests/testthat/test-paren_body_linter.R +++ b/tests/testthat/test-paren_body_linter.R @@ -10,10 +10,10 @@ testthat::test_that("paren_body_linter returns correct lints", { expect_lint("for (i in seq_along(1))test", lint_msg, linter) # A space after the closing parenthesis does not prompt a lint - expect_lint("function() test", NULL, linter) + expect_no_lint("function() test", linter) # Symbols after the closing parenthesis of a function call do not prompt a lint - expect_lint("head(mtcars)$cyl", NULL, linter) + expect_no_lint("head(mtcars)$cyl", linter) # paren_body_linter returns the correct line number expect_lint( @@ -35,10 +35,10 @@ testthat::test_that("paren_body_linter returns correct lints", { ) # paren_body_linter does not lint when the function body is defined on a new line - expect_lint("function()\n test", NULL, linter) + expect_no_lint("function()\n test", linter) # paren_body_linter does not lint comments - expect_lint("#function()test", NULL, linter) + expect_no_lint("#function()test", linter) # multiple lints on the same line expect_lint("function()if(TRUE)while(TRUE)test", list(lint_msg, lint_msg, lint_msg), linter) diff --git a/tests/testthat/test-pipe_consistency_linter.R b/tests/testthat/test-pipe_consistency_linter.R index 2197fa329..5ece252c2 100644 --- a/tests/testthat/test-pipe_consistency_linter.R +++ b/tests/testthat/test-pipe_consistency_linter.R @@ -142,7 +142,7 @@ test_that("pipe_consistency_linter works with %>% argument", { expect_lint( trim_some(" 1:3 %>% - mean() |> + mean() |> as.character() "), list(message = expected_message, line_number = 2L, column_number = 10L), diff --git a/tests/testthat/test-pipe_continuation_linter.R b/tests/testthat/test-pipe_continuation_linter.R index 89633f6b2..8dc52ff43 100644 --- a/tests/testthat/test-pipe_continuation_linter.R +++ b/tests/testthat/test-pipe_continuation_linter.R @@ -136,41 +136,41 @@ test_that("pipe-continuation linter handles native pipe", { local({ linter <- pipe_continuation_linter() .cases <- tibble::tribble( - ~code_string, ~.test_name, + ~code_string, ~.test_name, trim_some(" my_fun <- function() { a %>% b() } - "), "two on one line", + "), "two on one line", trim_some(" my_fun <- function() { a %>% b() %>% c() } - "), "three on one line", + "), "three on one line", trim_some(" with( diamonds, x %>% head(10) %>% tail(5) ) - "), "three inside with()", + "), "three inside with()", trim_some(" test_that('blah', { test_data <- diamonds %>% head(10) %>% tail(5) }) - "), "three inside test_that()", + "), "three inside test_that()", trim_some(" { x <- a %>% b %>% c y <- c %>% b %>% a } - "), "two different single-line pipelines", + "), "two different single-line pipelines", trim_some(" my_fun <- function() { a %>% b() %>% c() } - "), "at most one pipe-character per line" + "), "at most one pipe-character per line" ) patrick::with_parameters_test_that( "valid nesting is handled", diff --git a/tests/testthat/test-print_linter.R b/tests/testthat/test-print_linter.R index b39f90869..e4f553248 100644 --- a/tests/testthat/test-print_linter.R +++ b/tests/testthat/test-print_linter.R @@ -1,8 +1,8 @@ test_that("print_linter skips allowed usages", { linter <- print_linter() - expect_lint("print(x)", NULL, linter) - expect_lint("print(foo(x))", NULL, linter) + expect_no_lint("print(x)", linter) + expect_no_lint("print(foo(x))", linter) }) test_that("print_linter blocks disallowed usages", { diff --git a/tests/testthat/test-redundant_equals_linter.R b/tests/testthat/test-redundant_equals_linter.R index 541237f83..270ee0ad2 100644 --- a/tests/testthat/test-redundant_equals_linter.R +++ b/tests/testthat/test-redundant_equals_linter.R @@ -1,8 +1,8 @@ test_that("redundant_equals_linter skips allowed usages", { # comparisons to non-logical constants - expect_lint("x == 1", NULL, redundant_equals_linter()) + expect_no_lint("x == 1", redundant_equals_linter()) # comparison to TRUE as a string - expect_lint("x != 'TRUE'", NULL, redundant_equals_linter()) + expect_no_lint("x != 'TRUE'", redundant_equals_linter()) }) test_that("multiple lints return correct custom messages", { diff --git a/tests/testthat/test-regex_subset_linter.R b/tests/testthat/test-regex_subset_linter.R index 0c3e0c6e9..9ba92c84a 100644 --- a/tests/testthat/test-regex_subset_linter.R +++ b/tests/testthat/test-regex_subset_linter.R @@ -1,6 +1,6 @@ test_that("regex_subset_linter skips allowed usages", { - expect_lint("y[grepl(ptn, x)]", NULL, regex_subset_linter()) - expect_lint("x[grepl(ptn, foo(x))]", NULL, regex_subset_linter()) + expect_no_lint("y[grepl(ptn, x)]", regex_subset_linter()) + expect_no_lint("x[grepl(ptn, foo(x))]", regex_subset_linter()) }) test_that("regex_subset_linter blocks simple disallowed usages", { @@ -15,19 +15,19 @@ test_that("regex_subset_linter blocks simple disallowed usages", { test_that("regex_subset_linter skips grep/grepl subassignment", { linter <- regex_subset_linter() - expect_lint("x[grep(ptn, x)] <- ''", NULL, linter) - expect_lint("x[grepl(ptn, x)] <- ''", NULL, linter) - expect_lint("x[grep(ptn, x, perl = TRUE)] = ''", NULL, linter) - expect_lint("'' -> x[grep(ptn, x, ignore.case = TRUE)] = ''", NULL, linter) + expect_no_lint("x[grep(ptn, x)] <- ''", linter) + expect_no_lint("x[grepl(ptn, x)] <- ''", linter) + expect_no_lint("x[grep(ptn, x, perl = TRUE)] = ''", linter) + expect_no_lint("'' -> x[grep(ptn, x, ignore.case = TRUE)] = ''", linter) }) test_that("regex_subset_linter skips allowed usages for stringr equivalents", { linter <- regex_subset_linter() - expect_lint("y[str_detect(x, ptn)]", NULL, linter) - expect_lint("x[str_detect(foo(x), ptn)]", NULL, linter) - expect_lint("x[str_detect(x, ptn)] <- ''", NULL, linter) - expect_lint("x[str_detect(x, ptn)] <- ''", NULL, linter) + expect_no_lint("y[str_detect(x, ptn)]", linter) + expect_no_lint("x[str_detect(foo(x), ptn)]", linter) + expect_no_lint("x[str_detect(x, ptn)] <- ''", linter) + expect_no_lint("x[str_detect(x, ptn)] <- ''", linter) }) test_that("regex_subset_linter blocks disallowed usages for stringr equivalents", { diff --git a/tests/testthat/test-rep_len_linter.R b/tests/testthat/test-rep_len_linter.R index 34ef79aca..fe9dc8264 100644 --- a/tests/testthat/test-rep_len_linter.R +++ b/tests/testthat/test-rep_len_linter.R @@ -2,17 +2,17 @@ test_that("rep_len_linter skips allowed usages", { linter <- rep_len_linter() # only catch length.out usages - expect_lint("rep(x, y)", NULL, linter) - expect_lint("rep(1:10, 2)", NULL, linter) - expect_lint("rep(1:10, 10:1)", NULL, linter) + expect_no_lint("rep(x, y)", linter) + expect_no_lint("rep(1:10, 2)", linter) + expect_no_lint("rep(1:10, 10:1)", linter) # usage of each is not compatible with rep_len; see ?rep. - expect_lint("rep(x, each = 4, length.out = 50)", NULL, linter) + expect_no_lint("rep(x, each = 4, length.out = 50)", linter) # each is implicitly the 4th positional argument. a very strange usage # (because length.out is ignored), but doesn't hurt to catch it - expect_lint("rep(a, b, length.out = c, d)", NULL, linter) + expect_no_lint("rep(a, b, length.out = c, d)", linter) # ditto for implicit length.out= - expect_lint("rep(a, b, c, d)", NULL, linter) + expect_no_lint("rep(a, b, c, d)", linter) }) test_that("rep_len_linter blocks simple disallowed usages", { diff --git a/tests/testthat/test-repeat_linter.R b/tests/testthat/test-repeat_linter.R index 9c3cb16ee..3bc052f46 100644 --- a/tests/testthat/test-repeat_linter.R +++ b/tests/testthat/test-repeat_linter.R @@ -2,11 +2,11 @@ test_that("test repeat_linter", { linter <- repeat_linter() msg <- rex::rex("Use 'repeat' instead of 'while (TRUE)' for infinite loops.") - expect_lint("repeat { }", NULL, linter) - expect_lint("while (FALSE) { }", NULL, linter) - expect_lint("while (i < 5) { }", NULL, linter) - expect_lint("while (j < 5) TRUE", NULL, linter) - expect_lint("while (TRUE && j < 5) { ... }", NULL, linter) + expect_no_lint("repeat { }", linter) + expect_no_lint("while (FALSE) { }", linter) + expect_no_lint("while (i < 5) { }", linter) + expect_no_lint("while (j < 5) TRUE", linter) + expect_no_lint("while (TRUE && j < 5) { ... }", linter) expect_lint("while (TRUE) { }", msg, linter) expect_lint("for (i in 1:10) { while (TRUE) { if (i == 5) { break } } }", msg, linter) diff --git a/tests/testthat/test-routine_registration_linter.R b/tests/testthat/test-routine_registration_linter.R index e0bdafefa..f2bb44e7f 100644 --- a/tests/testthat/test-routine_registration_linter.R +++ b/tests/testthat/test-routine_registration_linter.R @@ -2,7 +2,7 @@ patrick::with_parameters_test_that( "lints correctly", { linter <- routine_registration_linter() - expect_lint(sprintf("%s(ROUTINE, 1)", caller), NULL, linter) + expect_no_lint(sprintf("%s(ROUTINE, 1)", caller), linter) expect_lint( sprintf("%s('ROUTINE', PACKAGE = 'foo')", caller), "Register your native code routines with useDynLib", diff --git a/tests/testthat/test-sample_int_linter.R b/tests/testthat/test-sample_int_linter.R index bf217cbee..fbf08598d 100644 --- a/tests/testthat/test-sample_int_linter.R +++ b/tests/testthat/test-sample_int_linter.R @@ -1,13 +1,13 @@ test_that("sample_int_linter skips allowed usages", { linter <- sample_int_linter() - expect_lint("sample(n, m)", NULL, linter) - expect_lint("sample(n, m, TRUE)", NULL, linter) - expect_lint("sample(n, m, prob = 1:n/n)", NULL, linter) - expect_lint("sample(foo(x), m, TRUE)", NULL, linter) - expect_lint("sample(n, replace = TRUE)", NULL, linter) + expect_no_lint("sample(n, m)", linter) + expect_no_lint("sample(n, m, TRUE)", linter) + expect_no_lint("sample(n, m, prob = 1:n/n)", linter) + expect_no_lint("sample(foo(x), m, TRUE)", linter) + expect_no_lint("sample(n, replace = TRUE)", linter) - expect_lint("sample(10:1, m)", NULL, linter) + expect_no_lint("sample(10:1, m)", linter) }) test_that("sample_int_linter blocks simple disallowed usages", { @@ -40,8 +40,8 @@ test_that("sample_int_linter blocks sample(seq(n)) and sample(seq(1, ...))", { expect_lint("sample(seq(1L, 10, by = 1L), 5)", lint_msg, linter) # lint doesn't apply when by= is used (except when set to literal 1) - expect_lint("sample(seq(1, 10, by = 2), 5)", NULL, linter) - expect_lint("sample(seq(1, 10, by = n), 5)", NULL, linter) + expect_no_lint("sample(seq(1, 10, by = 2), 5)", linter) + expect_no_lint("sample(seq(1, 10, by = n), 5)", linter) }) test_that("sample_int_linter catches literal integer/numeric in the first arg", { @@ -55,19 +55,19 @@ test_that("sample_int_linter catches literal integer/numeric in the first arg", test_that("sample_int_linter skips TRUE or FALSE in the first argument", { linter <- sample_int_linter() - expect_lint("sample(replace = TRUE, letters)", NULL, linter) - expect_lint("sample(replace = FALSE, letters)", NULL, linter) + expect_no_lint("sample(replace = TRUE, letters)", linter) + expect_no_lint("sample(replace = FALSE, letters)", linter) }) test_that("sample_int_linter skips x$sample() usage", { linter <- sample_int_linter() lint_msg <- rex::rex("sample.int(n, m, ...) is preferable to sample(n, m, ...).") - expect_lint("foo$sample(1L)", NULL, linter) - expect_lint("foo$sample(1:10)", NULL, linter) - expect_lint("foo$sample(seq_len(10L))", NULL, linter) + expect_no_lint("foo$sample(1L)", linter) + expect_no_lint("foo$sample(1:10)", linter) + expect_no_lint("foo$sample(seq_len(10L))", linter) # ditto for '@' slot extraction - expect_lint("foo@sample(1L)", NULL, linter) + expect_no_lint("foo@sample(1L)", linter) # however, base::sample qualification is still caught expect_lint("base::sample(10L)", lint_msg, linter) diff --git a/tests/testthat/test-scalar_in_linter.R b/tests/testthat/test-scalar_in_linter.R index fb3663087..fe85ba56a 100644 --- a/tests/testthat/test-scalar_in_linter.R +++ b/tests/testthat/test-scalar_in_linter.R @@ -1,16 +1,16 @@ test_that("scalar_in_linter skips allowed usages", { linter <- scalar_in_linter() - expect_lint("x %in% y", NULL, linter) - expect_lint("y %in% c('a', 'b')", NULL, linter) - expect_lint("c('a', 'b') %in% x", NULL, linter) - expect_lint("z %in% 1:3", NULL, linter) + expect_no_lint("x %in% y", linter) + expect_no_lint("y %in% c('a', 'b')", linter) + expect_no_lint("c('a', 'b') %in% x", linter) + expect_no_lint("z %in% 1:3", linter) # scalars on LHS are fine (often used as `"col" %in% names(DF)`) - expect_lint("3L %in% x", NULL, linter) + expect_no_lint("3L %in% x", linter) # this should be is.na(x), but it more directly uses the "always TRUE/FALSE, _not_ NA" # aspect of %in%, so we delegate linting here to equals_na_linter() - expect_lint("x %in% NA", NULL, linter) - expect_lint("x %in% NA_character_", NULL, linter) + expect_no_lint("x %in% NA", linter) + expect_no_lint("x %in% NA_character_", linter) }) test_that("scalar_in_linter blocks simple disallowed usages", { @@ -30,13 +30,13 @@ test_that("scalar_in_linter blocks or skips based on configuration", { # default expect_lint("x %in% 1", lint_msg, linter_default) - expect_lint("x %notin% 1", NULL, linter_default) - expect_lint("x %notin% y", NULL, linter_default) + expect_no_lint("x %notin% 1", linter_default) + expect_no_lint("x %notin% y", linter_default) # configured expect_lint("x %in% 1", lint_msg, linter_config) expect_lint("x %notin% 1", lint_msg, linter_config) - expect_lint("x %notin% y", NULL, linter_config) + expect_no_lint("x %notin% y", linter_config) }) test_that("multiple lints are generated correctly", { diff --git a/tests/testthat/test-semicolon_linter.R b/tests/testthat/test-semicolon_linter.R index 8a72da509..83f8dd9ad 100644 --- a/tests/testthat/test-semicolon_linter.R +++ b/tests/testthat/test-semicolon_linter.R @@ -4,13 +4,13 @@ test_that("Lint all semicolons", { comp_msg <- rex::rex("Replace compound semicolons by a newline.") # No semicolon - expect_lint("", NULL, linter) - expect_lint("a <- 1", NULL, linter) - expect_lint("function() {a <- 1}", NULL, linter) - expect_lint("a <- \"foo;bar\"", NULL, linter) - expect_lint("function() {a <- \"foo;bar\"}", NULL, linter) - expect_lint("a <- FALSE # ok; cool!", NULL, linter) - expect_lint("function() {\na <- FALSE # ok; cool!\n}", NULL, linter) + expect_no_lint("", linter) + expect_no_lint("a <- 1", linter) + expect_no_lint("function() {a <- 1}", linter) + expect_no_lint("a <- \"foo;bar\"", linter) + expect_no_lint("function() {a <- \"foo;bar\"}", linter) + expect_no_lint("a <- FALSE # ok; cool!", linter) + expect_no_lint("function() {\na <- FALSE # ok; cool!\n}", linter) # Trailing semicolons expect_lint( @@ -80,19 +80,19 @@ test_that("Lint all semicolons", { test_that("Compound semicolons only", { linter <- semicolon_linter(allow_trailing = TRUE) - expect_lint("a <- 1;", NULL, linter) - expect_lint("function(){a <- 1;}", NULL, linter) - expect_lint("a <- 1; \n", NULL, linter) - expect_lint("function(){a <- 1; \n}", NULL, linter) + expect_no_lint("a <- 1;", linter) + expect_no_lint("function(){a <- 1;}", linter) + expect_no_lint("a <- 1; \n", linter) + expect_no_lint("function(){a <- 1; \n}", linter) }) test_that("Trailing semicolons only", { linter <- semicolon_linter(allow_compound = TRUE) - expect_lint("a <- 1;b <- 2", NULL, linter) - expect_lint("function() {a <- 1;b <- 2}\n", NULL, linter) - expect_lint("f <-\n 1 ;f <- 1.23", NULL, linter) - expect_lint("function(){\nf <-\n 1 ;f <- 1.23\n}", NULL, linter) + expect_no_lint("a <- 1;b <- 2", linter) + expect_no_lint("function() {a <- 1;b <- 2}\n", linter) + expect_no_lint("f <-\n 1 ;f <- 1.23", linter) + expect_no_lint("function(){\nf <-\n 1 ;f <- 1.23\n}", linter) }) diff --git a/tests/testthat/test-sort_linter.R b/tests/testthat/test-sort_linter.R index 15d8ab209..b9c376da0 100644 --- a/tests/testthat/test-sort_linter.R +++ b/tests/testthat/test-sort_linter.R @@ -1,17 +1,17 @@ test_that("sort_linter skips allowed usages", { linter <- sort_linter() - expect_lint("order(y)", NULL, linter) + expect_no_lint("order(y)", linter) - expect_lint("y[order(x)]", NULL, linter) + expect_no_lint("y[order(x)]", linter) # If another function is intercalated, don't fail - expect_lint("x[c(order(x))]", NULL, linter) + expect_no_lint("x[c(order(x))]", linter) - expect_lint("x[order(y, x)]", NULL, linter) - expect_lint("x[order(x, y)]", NULL, linter) + expect_no_lint("x[order(y, x)]", linter) + expect_no_lint("x[order(x, y)]", linter) # pretty sure this never makes sense, but test anyway - expect_lint("x[order(y, na.last = x)]", NULL, linter) + expect_no_lint("x[order(y, na.last = x)]", linter) }) @@ -82,24 +82,23 @@ test_that("sort_linter works with multiple lints in a single expression", { ), linter ) - }) test_that("sort_linter skips usages calling sort arguments", { linter <- sort_linter() # any arguments to sort --> not compatible - expect_lint("sort(x, decreasing = TRUE) == x", NULL, linter) - expect_lint("sort(x, na.last = TRUE) != x", NULL, linter) - expect_lint("sort(x, method_arg = TRUE) == x", NULL, linter) + expect_no_lint("sort(x, decreasing = TRUE) == x", linter) + expect_no_lint("sort(x, na.last = TRUE) != x", linter) + expect_no_lint("sort(x, method_arg = TRUE) == x", linter) }) test_that("sort_linter skips when inputs don't match", { linter <- sort_linter() - expect_lint("sort(x) == y", NULL, linter) - expect_lint("sort(x) == foo(x)", NULL, linter) - expect_lint("sort(foo(x)) == x", NULL, linter) + expect_no_lint("sort(x) == y", linter) + expect_no_lint("sort(x) == foo(x)", linter) + expect_no_lint("sort(foo(x)) == x", linter) }) test_that("sort_linter blocks simple disallowed usages", { diff --git a/tests/testthat/test-spaces_inside_linter.R b/tests/testthat/test-spaces_inside_linter.R index ff0981ab5..f485ecf5e 100644 --- a/tests/testthat/test-spaces_inside_linter.R +++ b/tests/testthat/test-spaces_inside_linter.R @@ -1,38 +1,30 @@ test_that("spaces_inside_linter skips allowed usages", { linter <- spaces_inside_linter() - expect_lint("blah", NULL, linter) - expect_lint("print(blah)", NULL, linter) - expect_lint("base::print(blah)", NULL, linter) - expect_lint("a[, ]", NULL, linter) - expect_lint("a[1]", NULL, linter) - expect_lint("fun(\na[1]\n )", NULL, linter) - expect_lint("a(, )", NULL, linter) - expect_lint("a(,)", NULL, linter) - expect_lint("a(1)", NULL, linter) - expect_lint('"a( 1 )"', NULL, linter) + expect_no_lint("blah", linter) + expect_no_lint("print(blah)", linter) + expect_no_lint("base::print(blah)", linter) + expect_no_lint("a[, ]", linter) + expect_no_lint("a[1]", linter) + expect_no_lint("fun(\na[1]\n )", linter) + expect_no_lint("a(, )", linter) + expect_no_lint("a(,)", linter) + expect_no_lint("a(1)", linter) + expect_no_lint('"a( 1 )"', linter) # trailing comments are OK (#636) - expect_lint( - trim_some(" + expect_no_lint(trim_some(" or( #code x, y ) - "), - NULL, - linter - ) + "), linter) - expect_lint( - trim_some(" + expect_no_lint(trim_some(" fun( # this is another comment a = 42, # because 42 is always the answer b = Inf ) - "), - NULL, - linter - ) + "), linter) }) test_that("spaces_inside_linter blocks diallowed usages", { @@ -243,5 +235,5 @@ test_that("spaces_inside_linter blocks disallowed usages with a pipe", { }) test_that("terminal missing keyword arguments are OK", { - expect_lint("alist(missing_arg = )", NULL, spaces_inside_linter()) + expect_no_lint("alist(missing_arg = )", spaces_inside_linter()) }) diff --git a/tests/testthat/test-spaces_left_parentheses_linter.R b/tests/testthat/test-spaces_left_parentheses_linter.R index ce854828c..7ca16e414 100644 --- a/tests/testthat/test-spaces_left_parentheses_linter.R +++ b/tests/testthat/test-spaces_left_parentheses_linter.R @@ -1,44 +1,44 @@ test_that("spaces_left_parentheses_linter skips allowed usages", { linter <- spaces_left_parentheses_linter() - expect_lint("blah", NULL, linter) - expect_lint("print(blah)", NULL, linter) - expect_lint("base::print(blah)", NULL, linter) - expect_lint("base::print(blah, fun(1))", NULL, linter) - expect_lint("blah <- function(blah) { }", NULL, linter) + expect_no_lint("blah", linter) + expect_no_lint("print(blah)", linter) + expect_no_lint("base::print(blah)", linter) + expect_no_lint("base::print(blah, fun(1))", linter) + expect_no_lint("blah <- function(blah) { }", linter) - expect_lint("(1 + 1)", NULL, linter) - expect_lint("(1 + 1)", NULL, linter) - expect_lint("( (1 + 1) )", NULL, linter) - expect_lint("if (blah) { }", NULL, linter) - expect_lint("for (i in j) { }", NULL, linter) - expect_lint("1 * (1 + 1)", NULL, linter) - expect_lint("!(1 == 1)", NULL, linter) - expect_lint("(2 - 1):(3 - 1)", NULL, linter) - expect_lint("c(1, 2, 3)[(2 - 1)]", NULL, linter) - expect_lint("list(1, 2, 3)[[(2 - 1)]]", NULL, linter) - expect_lint("range(10)[(2 - 1):(10 - 1)]", NULL, linter) - expect_lint("function(){function(){}}()()", NULL, linter) - expect_lint("c(function(){})[1]()", NULL, linter) + expect_no_lint("(1 + 1)", linter) + expect_no_lint("(1 + 1)", linter) + expect_no_lint("( (1 + 1) )", linter) + expect_no_lint("if (blah) { }", linter) + expect_no_lint("for (i in j) { }", linter) + expect_no_lint("1 * (1 + 1)", linter) + expect_no_lint("!(1 == 1)", linter) + expect_no_lint("(2 - 1):(3 - 1)", linter) + expect_no_lint("c(1, 2, 3)[(2 - 1)]", linter) + expect_no_lint("list(1, 2, 3)[[(2 - 1)]]", linter) + expect_no_lint("range(10)[(2 - 1):(10 - 1)]", linter) + expect_no_lint("function(){function(){}}()()", linter) + expect_no_lint("c(function(){})[1]()", linter) - expect_lint("\"test <- function(x) { if(1 + 1) 'hi' }\"", NULL, linter) - expect_lint("res <- c((mat - 1L) %*% combs + 1L)", NULL, linter) - expect_lint("if (!(foo && bar || baz)) { foo }", NULL, linter) - expect_lint("x^(y + z)", NULL, linter) - expect_lint("x**(y + z)", NULL, linter) - expect_lint("a <- -(b)", NULL, linter) + expect_no_lint("\"test <- function(x) { if(1 + 1) 'hi' }\"", linter) + expect_no_lint("res <- c((mat - 1L) %*% combs + 1L)", linter) + expect_no_lint("if (!(foo && bar || baz)) { foo }", linter) + expect_no_lint("x^(y + z)", linter) + expect_no_lint("x**(y + z)", linter) + expect_no_lint("a <- -(b)", linter) - expect_lint("(3^(3 + 2))", NULL, linter) - expect_lint("-(!!!symb)", NULL, linter) + expect_no_lint("(3^(3 + 2))", linter) + expect_no_lint("-(!!!symb)", linter) - expect_lint("'[[<-.data.frame'(object, y)", NULL, linter) - expect_lint("object@data@get('input')", NULL, linter) - expect_lint("x <- ~(. + y)", NULL, linter) + expect_no_lint("'[[<-.data.frame'(object, y)", linter) + expect_no_lint("object@data@get('input')", linter) + expect_no_lint("x <- ~(. + y)", linter) # the internal newline is required to trigger the lint - expect_lint("if (x > 1)\n x <- x[-(i)]", NULL, linter) + expect_no_lint("if (x > 1)\n x <- x[-(i)]", linter) # these don't violate the linter, even if they are strange coding practice - expect_lint("for (ii in 1:10) next()", NULL, linter) - expect_lint("for (ii in 1:10) break()", NULL, linter) + expect_no_lint("for (ii in 1:10) next()", linter) + expect_no_lint("for (ii in 1:10) break()", linter) }) test_that("spaces_left_parentheses_linter blocks disallowed usages", { diff --git a/tests/testthat/test-stopifnot_all_linter.R b/tests/testthat/test-stopifnot_all_linter.R index ded0fb4b3..87b61a44c 100644 --- a/tests/testthat/test-stopifnot_all_linter.R +++ b/tests/testthat/test-stopifnot_all_linter.R @@ -1,5 +1,5 @@ test_that("stopifnot_all_linter skips allowed usages", { - expect_lint("stopifnot(all(x) || any(y))", NULL, stopifnot_all_linter()) + expect_no_lint("stopifnot(all(x) || any(y))", stopifnot_all_linter()) }) test_that("stopifnot_all_linter blocks simple disallowed usages", { diff --git a/tests/testthat/test-strings_as_factors_linter.R b/tests/testthat/test-strings_as_factors_linter.R index a45624b80..22a9b85d1 100644 --- a/tests/testthat/test-strings_as_factors_linter.R +++ b/tests/testthat/test-strings_as_factors_linter.R @@ -1,22 +1,22 @@ test_that("strings_as_factors_linter skips allowed usages", { linter <- strings_as_factors_linter() - expect_lint("data.frame(1:3)", NULL, linter) - expect_lint("data.frame(x = 1:3)", NULL, linter) + expect_no_lint("data.frame(1:3)", linter) + expect_no_lint("data.frame(x = 1:3)", linter) - expect_lint("data.frame(x = 'a', stringsAsFactors = TRUE)", NULL, linter) - expect_lint("data.frame(x = 'a', stringsAsFactors = FALSE)", NULL, linter) - expect_lint("data.frame(x = c('a', 'b'), stringsAsFactors = FALSE)", NULL, linter) + expect_no_lint("data.frame(x = 'a', stringsAsFactors = TRUE)", linter) + expect_no_lint("data.frame(x = 'a', stringsAsFactors = FALSE)", linter) + expect_no_lint("data.frame(x = c('a', 'b'), stringsAsFactors = FALSE)", linter) # strings in argument names to c() don't get linted - expect_lint("data.frame(x = c('a b' = 1L, 'b c' = 2L))", NULL, linter) + expect_no_lint("data.frame(x = c('a b' = 1L, 'b c' = 2L))", linter) # characters supplied to row.names are not affected - expect_lint("data.frame(x = 1:3, row.names = c('a', 'b', 'c'))", NULL, linter) + expect_no_lint("data.frame(x = 1:3, row.names = c('a', 'b', 'c'))", linter) # ambiguous cases passes - expect_lint("data.frame(x = c(xx, 'a'))", NULL, linter) - expect_lint("data.frame(x = c(foo(y), 'a'))", NULL, linter) + expect_no_lint("data.frame(x = c(xx, 'a'))", linter) + expect_no_lint("data.frame(x = c(foo(y), 'a'))", linter) }) test_that("strings_as_factors_linter blocks simple disallowed usages", { @@ -44,8 +44,8 @@ test_that("strings_as_factors_linters catches rep(char) usages", { expect_lint("data.frame(rep(c('a', 'b'), 10L))", lint_msg, linter) # literal char, not mixed or non-char - expect_lint("data.frame(rep(1L, 10L))", NULL, linter) - expect_lint("data.frame(rep(c(x, 'a'), 10L))", NULL, linter) + expect_no_lint("data.frame(rep(1L, 10L))", linter) + expect_no_lint("data.frame(rep(c(x, 'a'), 10L))", linter) # however, type promotion of literals is caught expect_lint("data.frame(rep(c(TRUE, 'a'), 10L))", lint_msg, linter) }) @@ -59,7 +59,7 @@ test_that("strings_as_factors_linter catches character(), as.character() usages" expect_lint("data.frame(a = as.character(x))", lint_msg, linter) # but not for row.names - expect_lint("data.frame(a = 1:10, row.names = as.character(1:10))", NULL, linter) + expect_no_lint("data.frame(a = 1:10, row.names = as.character(1:10))", linter) }) test_that("strings_as_factors_linter catches more functions with string output", { @@ -74,7 +74,7 @@ test_that("strings_as_factors_linter catches more functions with string output", expect_lint("data.frame(a = toString(x))", lint_msg, linter) expect_lint("data.frame(a = encodeString(x))", lint_msg, linter) # but not for row.names - expect_lint("data.frame(a = 1:10, row.names = paste(1:10))", NULL, linter) + expect_no_lint("data.frame(a = 1:10, row.names = paste(1:10))", linter) }) test_that("lints vectorize", { diff --git a/tests/testthat/test-system_file_linter.R b/tests/testthat/test-system_file_linter.R index f60c3aa8c..c46f69456 100644 --- a/tests/testthat/test-system_file_linter.R +++ b/tests/testthat/test-system_file_linter.R @@ -1,8 +1,8 @@ test_that("system_file_linter skips allowed usages", { linter <- system_file_linter() - expect_lint("system.file('a', 'b', 'c')", NULL, linter) - expect_lint("file.path('a', 'b', 'c')", NULL, linter) + expect_no_lint("system.file('a', 'b', 'c')", linter) + expect_no_lint("file.path('a', 'b', 'c')", linter) }) test_that("system_file_linter blocks simple disallowed usages", { diff --git a/tests/testthat/test-trailing_blank_lines_linter.R b/tests/testthat/test-trailing_blank_lines_linter.R index 5b6f89511..14b5df0b2 100644 --- a/tests/testthat/test-trailing_blank_lines_linter.R +++ b/tests/testthat/test-trailing_blank_lines_linter.R @@ -1,10 +1,10 @@ test_that("trailing_blank_lines_linter doesn't block allowed usages", { linter <- trailing_blank_lines_linter() - expect_lint("blah", NULL, linter) - expect_lint("blah <- 1 ", NULL, linter) - expect_lint("blah <- 1\nblah", NULL, linter) - expect_lint("blah <- 1\nblah\n \n blah", NULL, linter) + expect_no_lint("blah", linter) + expect_no_lint("blah <- 1 ", linter) + expect_no_lint("blah <- 1\nblah", linter) + expect_no_lint("blah <- 1\nblah\n \n blah", linter) tmp <- withr::local_tempfile(lines = "lm(y ~ x)") expect_lint(file = tmp, checks = NULL, linters = linter) diff --git a/tests/testthat/test-trailing_whitespace_linter.R b/tests/testthat/test-trailing_whitespace_linter.R index 329f5a24f..c7d74424e 100644 --- a/tests/testthat/test-trailing_whitespace_linter.R +++ b/tests/testthat/test-trailing_whitespace_linter.R @@ -2,7 +2,7 @@ test_that("returns the correct linting", { linter <- trailing_whitespace_linter() lint_msg <- rex::rex("Remove trailing whitespace.") - expect_lint("blah", NULL, linter) + expect_no_lint("blah", linter) expect_lint( "blah <- 1 ", @@ -35,18 +35,14 @@ test_that("also handles completely empty lines per allow_empty_lines argument", trailing_whitespace_linter(allow_empty_lines = TRUE) ) - expect_lint( - "blah <- 1\n \n'hi'\na <- 2", - NULL, - trailing_whitespace_linter(allow_empty_lines = TRUE) - ) + expect_no_lint("blah <- 1\n \n'hi'\na <- 2", trailing_whitespace_linter(allow_empty_lines = TRUE)) }) test_that("also handles trailing whitespace in string constants", { linter <- trailing_whitespace_linter() lint_msg <- rex::rex("Remove trailing whitespace.") - expect_lint("blah <- ' \n \n'", NULL, linter) + expect_no_lint("blah <- ' \n \n'", linter) # Don't exclude past the end of string expect_lint( "blah <- ' \n \n' ", diff --git a/tests/testthat/test-unreachable_code_linter.R b/tests/testthat/test-unreachable_code_linter.R index b54d3b11e..e98d9a334 100644 --- a/tests/testthat/test-unreachable_code_linter.R +++ b/tests/testthat/test-unreachable_code_linter.R @@ -4,7 +4,7 @@ test_that("unreachable_code_linter works in simple function", { return(bar) } ") - expect_lint(lines, NULL, unreachable_code_linter()) + expect_no_lint(lines, unreachable_code_linter()) }) test_that("unreachable_code_linter works in sub expressions", { @@ -70,7 +70,7 @@ test_that("unreachable_code_linter works in sub expressions", { } ") - expect_lint(lines, NULL, linter) + expect_no_lint(lines, linter) lines <- trim_some(" foo <- function(bar) { @@ -163,7 +163,7 @@ test_that("unreachable_code_linter works with next and break in sub expressions" } ") - expect_lint(lines, NULL, linter) + expect_no_lint(lines, linter) lines <- trim_some(" foo <- function(bar) { @@ -198,11 +198,11 @@ test_that("unreachable_code_linter works with next and break in sub expressions" }) test_that("unreachable_code_linter ignores expressions that aren't functions", { - expect_lint("x + 1", NULL, unreachable_code_linter()) + expect_no_lint("x + 1", unreachable_code_linter()) }) test_that("unreachable_code_linter ignores anonymous/inline functions", { - expect_lint("lapply(rnorm(10), function(x) x + 1)", NULL, unreachable_code_linter()) + expect_no_lint("lapply(rnorm(10), function(x) x + 1)", unreachable_code_linter()) }) test_that("unreachable_code_linter passes on multi-line functions", { @@ -212,7 +212,7 @@ test_that("unreachable_code_linter passes on multi-line functions", { return(y) } ") - expect_lint(lines, NULL, unreachable_code_linter()) + expect_no_lint(lines, unreachable_code_linter()) }) test_that("unreachable_code_linter ignores comments on the same expression", { @@ -223,7 +223,7 @@ test_that("unreachable_code_linter ignores comments on the same expression", { ) # y^3 } ") - expect_lint(lines, NULL, unreachable_code_linter()) + expect_no_lint(lines, unreachable_code_linter()) }) test_that("unreachable_code_linter ignores comments on the same line", { @@ -232,7 +232,7 @@ test_that("unreachable_code_linter ignores comments on the same line", { return(y^2) # y^3 } ") - expect_lint(lines, NULL, unreachable_code_linter()) + expect_no_lint(lines, unreachable_code_linter()) }) test_that("unreachable_code_linter identifies simple unreachable code", { @@ -349,28 +349,20 @@ test_that("unreachable_code_linter finds code after stop()", { test_that("unreachable_code_linter ignores code after foo$stop(), which might be stopping a subprocess, for example", { linter <- unreachable_code_linter() - expect_lint( - trim_some(" + expect_no_lint(trim_some(" foo <- function(x) { bar <- get_process() bar$stop() TRUE } - "), - NULL, - linter - ) - expect_lint( - trim_some(" + "), linter) + expect_no_lint(trim_some(" foo <- function(x) { bar <- get_process() bar@stop() TRUE } - "), - NULL, - linter - ) + "), linter) }) test_that("unreachable_code_linter ignores terminal nolint end comments", { @@ -381,8 +373,7 @@ test_that("unreachable_code_linter ignores terminal nolint end comments", { lintr.exclude_end = "#\\s*TestNoLintEnd" )) - expect_lint( - trim_some(" + expect_no_lint(trim_some(" foo <- function() { do_something # TestNoLintStart: one_linter. @@ -390,13 +381,9 @@ test_that("unreachable_code_linter ignores terminal nolint end comments", { return(a) # TestNoLintEnd } - "), - NULL, - list(linter, one_linter = assignment_linter()) - ) + "), list(linter, one_linter = assignment_linter())) - expect_lint( - trim_some(" + expect_no_lint(trim_some(" foo <- function() { do_something # TestNoLintStart: one_linter. @@ -404,10 +391,7 @@ test_that("unreachable_code_linter ignores terminal nolint end comments", { next # TestNoLintEnd } - "), - NULL, - linter - ) + "), linter) }) test_that("unreachable_code_linter identifies unreachable code in conditional loops", { @@ -592,15 +576,14 @@ test_that("function shorthand is handled", { }) test_that("Do not lint inline else after stop", { - - expect_lint("if (x > 3L) stop() else x + 3", NULL, unreachable_code_linter()) + expect_no_lint("if (x > 3L) stop() else x + 3", unreachable_code_linter()) }) test_that("Do not lint inline else after stop in inline function", { linter <- unreachable_code_linter() - expect_lint("function(x) if (x > 3L) stop() else x + 3", NULL, linter) - expect_lint("function(x) if (x > 3L) { stop() } else {x + 3}", NULL, linter) + expect_no_lint("function(x) if (x > 3L) stop() else x + 3", linter) + expect_no_lint("function(x) if (x > 3L) { stop() } else {x + 3}", linter) }) test_that("Do not lint inline else after stop in inline lambda function", { @@ -608,8 +591,8 @@ test_that("Do not lint inline else after stop in inline lambda function", { linter <- unreachable_code_linter() - expect_lint("\\(x) if (x > 3L) stop() else x + 3", NULL, linter) - expect_lint("\\(x){ if (x > 3L) stop() else x + 3 }", NULL, linter) + expect_no_lint("\\(x) if (x > 3L) stop() else x + 3", linter) + expect_no_lint("\\(x){ if (x > 3L) stop() else x + 3 }", linter) }) test_that("allow_comment_regex= works", { @@ -619,87 +602,59 @@ test_that("allow_comment_regex= works", { linter_xxxx <- unreachable_code_linter(allow_comment_regex = "#.*xxxx") linter_x1x2 <- unreachable_code_linter(allow_comment_regex = c("#x", "#y")) - expect_lint( - trim_some(" + expect_no_lint(trim_some(" function() { return(1) # nocov end } - "), - NULL, - linter_covr - ) + "), linter_covr) - expect_lint( - trim_some(" + expect_no_lint(trim_some(" function() { return(1) # TestNoLintEnd # nocov end } - "), - NULL, - linter_covr - ) + "), linter_covr) - expect_lint( - trim_some(" + expect_no_lint(trim_some(" function() { return(1) # ABCDxxxx } - "), - NULL, - linter_xxxx - ) + "), linter_xxxx) - expect_lint( - trim_some(" + expect_no_lint(trim_some(" function() { return(1) # TestNoLintEnd # ABCDxxxx } - "), - NULL, - linter_xxxx - ) + "), linter_xxxx) - expect_lint( - trim_some(" + expect_no_lint(trim_some(" function() { return(1) #x } - "), - NULL, - linter_x1x2 - ) + "), linter_x1x2) - expect_lint( - trim_some(" + expect_no_lint(trim_some(" function() { return(1) #xABC #yDEF } - "), - NULL, - linter_x1x2 - ) + "), linter_x1x2) # might contain capture groups, #2678 - expect_lint( - trim_some(" + expect_no_lint(trim_some(" function() { stop('a') # a # ab } - "), - NULL, - unreachable_code_linter(allow_comment_regex = "#\\s*(a|ab|abc)") - ) + "), unreachable_code_linter(allow_comment_regex = "#\\s*(a|ab|abc)")) }) test_that("allow_comment_regex= obeys covr's custom exclusion when set", { @@ -710,26 +665,18 @@ test_that("allow_comment_regex= obeys covr's custom exclusion when set", { linter_covr <- unreachable_code_linter() - expect_lint( - trim_some(" + expect_no_lint(trim_some(" function() { return(1) # TestNoCovEnd } - "), - NULL, - linter_covr - ) + "), linter_covr) - expect_lint( - trim_some(" + expect_no_lint(trim_some(" function() { return(1) # TestNoLintEnd # TestNoCovEnd } - "), - NULL, - linter_covr - ) + "), linter_covr) })