Skip to content

Commit b94b7ca

Browse files
New linter for test(symbol) (#6120)
This is a follow-up to #6041 that will prevent regression on that front going forward.
1 parent 4e48c47 commit b94b7ca

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Avoid test(SYMBOL) and test(SYMBOL+...) except in rare cases.
2+
# in the latter case, prefer test(NUMBER+expr).
3+
dt_test_literal_linter <- lintr::make_linter_from_xpath(
4+
"
5+
//SYMBOL_FUNCTION_CALL[text() = 'test']
6+
/parent::expr
7+
/following-sibling::expr[1][SYMBOL or expr[1]/SYMBOL]
8+
",
9+
"Prefer test's 'num' argument to start with a numeric literal except in rare cases, e.g. test(123, ...) or test(123+x/6, ...)"
10+
)

inst/tests/tests.Rraw

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9769,7 +9769,7 @@ nqjoin_test <- function(x, y, k=1L, test_no, mult="all") {
97699769
ans1 = nq(x, y, thiscols, thisops, 0L, mult=mult)
97709770
ans2 = check(x, y, thiscols, thisops, mult=mult)
97719771
test_no = test_no + .001
9772-
test(test_no, ans1, ans2)
9772+
test(test_no, ans1, ans2) # nolint: dt_test_literal_linter.
97739773
}
97749774
gc() # no longer needed but left in place just in case, no harm
97759775
}

0 commit comments

Comments
 (0)