Skip to content

Commit ca815ba

Browse files
Run linters on test scripts (#6121)
The default pattern for files to lint is `pattern = "(?i)[.](r|rmd|qmd|rnw|rhtml|rrst|rtex|rtxt)$"`, i.e. not `Rraw`. We don't need the other extensions, so trim them also for simplicity. See: https://lintr.r-lib.org/reference/lint.html
1 parent b94b7ca commit ca815ba

File tree

6 files changed

+77
-65
lines changed

6 files changed

+77
-65
lines changed

.ci/.lintr.R

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ linters = c(dt_linters, all_linters(
3131
)),
3232
# TODO(lintr#2441): Use upstream implementation.
3333
assignment_linter = NULL,
34+
absolute_path_linter = NULL, # too many false positives
3435
# TODO(lintr#2442): Use this once x[ , j, by] is supported.
3536
commas_linter = NULL,
3637
commented_code_linter = NULL,
@@ -89,9 +90,9 @@ linters = c(dt_linters, all_linters(
8990
rm(dt_linters)
9091

9192
# TODO(lintr#2172): Glob with lintr itself.
92-
exclusions = local({
93+
exclusions = c(local({
9394
exclusion_for_dir <- function(dir, exclusions) {
94-
files = list.files(dir, pattern = "\\.(R|Rmd)$")
95+
files = file.path("..", list.files(dir, pattern = "\\.(R|Rmd|Rraw)$", full.names=TRUE))
9596
stats::setNames(rep(list(exclusions), length(files)), files)
9697
}
9798
c(
@@ -106,6 +107,18 @@ exclusions = local({
106107
quotes_linter = Inf
107108
# strings_as_factors_linter = Inf
108109
# system_time_linter = Inf
110+
)),
111+
exclusion_for_dir("inst/tests", list(
112+
library_call_linter = Inf,
113+
numeric_leading_zero_linter = Inf,
114+
undesirable_operator_linter = Inf, # For ':::', possibly we could be more careful to only exclude ':::'.
115+
# TODO(michaelchirico): Enforce these and re-activate them one-by-one.
116+
comparison_negation_linter = Inf,
117+
duplicate_argument_linter = Inf,
118+
equals_na_linter = Inf,
119+
paste_linter = Inf
109120
))
110121
)
111-
})
122+
}),
123+
list(`../inst/tests/froll.Rraw` = list(dt_test_literal_linter = Inf)) # TODO(michaelchirico): Fix these once #5898, #5692, #5682, #5576, #5575, #5441 are merged.
124+
)

.github/workflows/lint.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
needs: lint
2929

3030
- name: Lint
31-
run: lintr::lint_package()
31+
run: lintr::lint_package(pattern = "(?i)[.](r|rmd|rraw)$") # TODO(#5830): use the default pattern
3232
shell: Rscript {0}
3333
env:
3434
LINTR_ERROR_ON_LINT: true

inst/tests/benchmark.Rraw

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ test(647, ans1, ans3)
6060
# this'll error with `valgrind` because of the 'long double' usage in gsumm.c (although I wonder if we need long double precision).
6161
# http://valgrind.org/docs/manual/manual-core.html#manual-core.limits
6262
# http://comments.gmane.org/gmane.comp.debugging.valgrind/10340
63-
test(648, any(is.na(ans1$V1)) && !any(is.nan(ans1$V1)))
63+
test(648, anyNA(ans1$V1) && !any(is.nan(ans1$V1)))
6464
# test 649 removed as compared 1.1s to 1.1s
6565
if (.devtesting) test(650, tt1["user.self"] < tt3["user.self"])
6666

@@ -500,5 +500,3 @@ start = gc()["Vcells",2]
500500
for (i in 1:10) data.table::fread("out.tsv")
501501
end = gc()["Vcells",2]
502502
test(, end/start < 1.05)
503-
504-

inst/tests/nafill.Rraw

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,4 +345,3 @@ test(99.3, data.table(a=1,b=2)[1,1, verbose=NA], error="verbose must be length 1
345345
options(datatable.verbose=1)
346346
test(99.4, coerceAs(1, 2L), error="verbose option must be length 1 non-NA logical or integer")
347347
options(datatable.verbose=FALSE)
348-

inst/tests/other.Rraw

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ if (exists("test.data.table",.GlobalEnv,inherits=FALSE) ||
2020
test = data.table:::test
2121
INT = data.table:::INT
2222

23-
if (any(duplicated(pkgs))) stop("Packages defined to be loaded for integration tests in 'inst/tests/other.Rraw' contains duplicates.")
23+
if (anyDuplicated(pkgs)) stop("Packages defined to be loaded for integration tests in 'inst/tests/other.Rraw' contains duplicates.")
2424

2525
f = function(pkg) suppressWarnings(suppressMessages(isTRUE(
2626
library(pkg, character.only=TRUE, logical.return=TRUE, quietly=TRUE, warn.conflicts=FALSE, pos="package:base") # attach at the end for #5101
2727
)))
2828
loaded = sapply(pkgs, f)
29-
if (any(!loaded)) {
29+
if (!all(loaded)) {
3030
stop("test.data.table('other.Rraw') is missing required package(s): ", toString(names(loaded)[!loaded]), ". If you can't install them and this is R CMD check, please set environment variable TEST_DATA_TABLE_WITH_OTHER_PACKAGES back to the default, false.")
3131
# Would like to install them now for convenience but gitlab-ci.yml seems to install to bus/mirror-other-packages/cran.
3232
# If that's a cache, that's nice, but we don't know at this point whether this script is being run by GLCI or by a user or in dev.
@@ -646,7 +646,7 @@ if (loaded[["nanotime"]]) {
646646
test(21.2, shift(x, fill=0L), c(nanotime::nanotime(0L), x[1:3]))
647647
test(21.3, shift(x, 1, type="cyclic"), c(x[4L], x[-4L]))
648648
test(21.4, shift(x, -1, type="cyclic"), c(x[-1L], x[1L]))
649-
649+
650650
# was 1752 in tests.Rraw, #5516
651651
DT = data.table(A=nanotime(tt<-c("2016-09-28T15:30:00.000000070Z",
652652
"2016-09-29T23:59:00.000000001Z",
@@ -661,7 +661,7 @@ if (loaded[["nanotime"]]) {
661661
"1967-03-15T00:00:00.300000002Z",
662662
"1967-03-15T23:59:59.300000002Z")))
663663
test(22, capture.output(fwrite(DT, verbose=FALSE))[-1], tt)
664-
664+
665665
# was 2060.401-405 in tests.Rraw, #5516
666666
nt = nanotime(c(1L, 2L, NA_integer_, 4L))
667667
nt_val = nanotime(1:4)
@@ -670,7 +670,7 @@ if (loaded[["nanotime"]]) {
670670
test(23.3, as.character(fcoalesce(nt, nanotime(rep(3, 4L)))), as.character(nt_val))
671671
test(23.4, fcoalesce(nt, 1), error='Item 2 has a different class than item 1')
672672
test(23.5, fcoalesce(nt, 1L), error = 'Item 2 is type integer but the first item is type double')
673-
673+
674674
# was 2080.01-05 in tests.Rraw, #5516
675675
n = nanotime(1:4)
676676
n[2L] = NA
@@ -681,15 +681,15 @@ if (loaded[["nanotime"]]) {
681681
options(opt)
682682
test(24.4, between(1:10, nanotime(3), nanotime(6)), error="x is not integer64 but.*Please align classes")
683683
test(24.5, between(1:10, 3, nanotime(6)), error="x is not integer64 but.*Please align classes")
684-
684+
685685
# was 2085.11 in tests.Rraw, #5516
686686
n = nanotime(1:4)
687687
test(25, fifelse(c(TRUE,FALSE,NA,TRUE), n, n+100), c(n[1L], n[2L]+100, nanotime(NA), n[4]))
688688

689689
# was 2127.27 in tests.Rraw, #5516
690690
n = nanotime(1:12)
691691
test(26, fcase(c(-5L:5L<0L,NA), n, c(-5L:5L>0L,NA), n+100), c(n[1L:5L], nanotime(NA), n[7L:11L]+100, as.integer64(NA)))
692-
692+
693693
# na.omit works for nanotime, #4744. Was 2205 in tests.Rraw, #5516
694694
DT = data.table(time=nanotime(c(1,NA,3)))
695695
test(27, na.omit(DT), DT[c(1,3)])
@@ -728,5 +728,5 @@ if (FALSE) { # moved from tests.Rraw in #5517 and not yet back on; wasn't sure
728728
if (loaded[["dplyr"]]) {
729729
# regression test for converting character->list column in a magrittr (dplyr) pipe, #2651
730730
DT = data.table(a = 1, b = 2, c = '1,2,3,4', d = 4)
731-
test(30, DT[, c := strsplit(c, ',', fixed = TRUE) %>% lapply(as.integer) %>% as.list]$c, list(1:4))
731+
test(30, DT[, c := strsplit(c, ',', fixed = TRUE) %>% lapply(as.integer) %>% as.list]$c, list(1:4)) # nolint: pipe_call_linter. Mimicking MRE as filed.
732732
}

0 commit comments

Comments
 (0)