From ed0d93d5401b0b13d1aae2c6c7cd0d451d6ec5a0 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Thu, 2 May 2024 22:25:54 -0700 Subject: [PATCH] lint-test-literal --- .ci/linters/dt_test_literal_linter.R | 10 ++++++++++ inst/tests/tests.Rraw | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 .ci/linters/dt_test_literal_linter.R diff --git a/.ci/linters/dt_test_literal_linter.R b/.ci/linters/dt_test_literal_linter.R new file mode 100644 index 000000000..fa07d068a --- /dev/null +++ b/.ci/linters/dt_test_literal_linter.R @@ -0,0 +1,10 @@ +# Avoid test(SYMBOL) and test(SYMBOL+...) except in rare cases. +# in the latter case, prefer test(NUMBER+expr). +dt_test_literal_linter <- lintr::make_linter_from_xpath( + " + //SYMBOL_FUNCTION_CALL[text() = 'test'] + /parent::expr + /following-sibling::expr[1][SYMBOL or expr[1]/SYMBOL] + ", + "Prefer test's 'num' argument to start with a numeric literal except in rare cases, e.g. test(123, ...) or test(123+x/6, ...)" +) diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index 68f12bd2b..7bc8b2ad8 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -9769,7 +9769,7 @@ nqjoin_test <- function(x, y, k=1L, test_no, mult="all") { ans1 = nq(x, y, thiscols, thisops, 0L, mult=mult) ans2 = check(x, y, thiscols, thisops, mult=mult) test_no = test_no + .001 - test(test_no, ans1, ans2) + test(test_no, ans1, ans2) # nolint: dt_test_literal_linter. } gc() # no longer needed but left in place just in case, no harm }