Skip to content

Commit c8c35f3

Browse files
Activate 5 more linters, including return_linter (#6128)
* missing_argument_linter and return_linter * add scalar_in_linter * nzchar_linter too * errant character * errant character was masking more lints; fixed * correct error message in test * fix test, use nolint * remove overly-cautious keepNA=TRUE
1 parent 3a31e58 commit c8c35f3

File tree

18 files changed

+56
-57
lines changed

18 files changed

+56
-57
lines changed

.ci/.lintr.R

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,14 @@ linters = c(dt_linters, all_linters(
5454
todo_comment_linter = NULL,
5555
# TODO(michaelchirico): Enforce these and re-activate them one-by-one.
5656
brace_linter = NULL,
57-
condition_call_linter = NULL,
5857
fixed_regex_linter = NULL,
5958
if_not_else_linter = NULL,
6059
implicit_assignment_linter = NULL,
6160
implicit_integer_linter = NULL,
6261
keyword_quote_linter = NULL,
63-
missing_argument_linter = NULL,
64-
nzchar_linter = NULL,
6562
object_overwrite_linter = NULL,
6663
paren_body_linter = NULL,
6764
redundant_equals_linter = NULL,
68-
return_linter = NULL,
69-
scalar_in_linter = NULL,
7065
undesirable_function_linter = NULL,
7166
unnecessary_concatenation_linter = NULL,
7267
unnecessary_nesting_linter = NULL,
@@ -101,8 +96,10 @@ exclusions = c(local({
10196
undesirable_operator_linter = Inf, # For ':::', possibly we could be more careful to only exclude ':::'.
10297
# TODO(michaelchirico): Enforce these and re-activate them one-by-one.
10398
comparison_negation_linter = Inf,
99+
condition_call_linter = Inf,
104100
duplicate_argument_linter = Inf,
105101
equals_na_linter = Inf,
102+
missing_argument_linter = Inf,
106103
paste_linter = Inf,
107104
rep_len_linter = Inf,
108105
sample_int_linter = Inf,

R/IDateTime.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ round.IDate = function(x, digits=c("weeks", "months", "quarters", "years"), ...)
129129
}
130130
ans = as.integer(unclass(e1) - unclass(e2))
131131
if (!inherits(e2, "Date")) setattr(ans, "class", c("IDate", "Date"))
132-
return(ans)
132+
ans
133133
}
134134

135135

@@ -177,7 +177,7 @@ as.ITime.character = function(x, format, ...) {
177177
w = w[!nna]
178178
}
179179
}
180-
return(as.ITime(y, ...))
180+
as.ITime(y, ...)
181181
}
182182

183183
as.ITime.POSIXlt = function(x, ms = 'truncate', ...) {

R/as.data.table.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ as.data.table.list = function(x,
180180
if (eachnrow[i]>1L && nrow%%eachnrow[i]!=0L) # in future: eachnrow[i]!=nrow
181181
warningf("Item %d has %d rows but longest item has %d; recycled with remainder.", i, eachnrow[i], nrow)
182182
if (is.data.table(xi)) { # matrix and data.frame were coerced to data.table above
183-
prefix = if (!isFALSE(.named[i]) && isTRUE(nchar(names(x)[i])>0L)) paste0(names(x)[i],".") else "" # test 2058.12
183+
prefix = if (!isFALSE(.named[i]) && isTRUE(nzchar(names(x)[i], keepNA=TRUE))) paste0(names(x)[i],".") else "" # test 2058.12
184184
for (j in seq_along(xi)) {
185185
ans[[k]] = recycle(xi[[j]], nrow)
186186
vnames[k] = paste0(prefix, names(xi)[j])
@@ -251,5 +251,5 @@ as.data.table.data.table = function(x, ...) {
251251
x = copy(x) # #1681
252252
# fix for #1078 and #1128, see .resetclass() for explanation.
253253
setattr(x, 'class', .resetclass(x, "data.table"))
254-
return(x)
254+
x
255255
}

R/bmerge.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,5 +185,5 @@ bmerge = function(i, x, icols, xcols, roll, rollends, nomatch, mult, ops, verbos
185185
# TO DO: xo could be moved inside Cbmerge
186186

187187
ans$xo = xo # for further use by [.data.table
188-
return(ans)
188+
ans
189189
}

R/cedta.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ cedta.pkgEvalsUserCode = c("gWidgetsWWW","statET","FastRWeb","slidify","rmarkdow
3535
the_call <- calls[[ii]][[1L]]
3636
if (is.name(the_call) && (the_call %chin% c("eval", "evalq"))) return(TRUE)
3737
}
38-
return(FALSE)
38+
FALSE
3939
}
4040
# nocov end
4141

R/data.table.R

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ replace_dot_alias = function(e) {
618618
else stopf("i evaluates to a logical vector length %d but there are %d rows. Recycling of logical i is no longer allowed as it hides more bugs than is worth the rare convenience. Explicitly use rep(...,length=.N) if you really need to recycle.", length(i), nrow(x))
619619
} else {
620620
irows = as.integer(i) # e.g. DT[c(1,3)] and DT[c(-1,-3)] ok but not DT[c(1,-3)] (caught as error)
621-
if (nomatch0) warning("Please use nomatch=NULL instead of nomatch=0; see news item 5 in v1.12.0 (Jan 2019)")
621+
if (nomatch0) warningf("Please use nomatch=NULL instead of nomatch=0; see news item 5 in v1.12.0 (Jan 2019)")
622622
# warning only for this case where nomatch was ignored before v1.14.2; #3109
623623
irows = .Call(CconvertNegAndZeroIdx, irows, nrow(x),
624624
is.null(jsub) || root!=":=", # allowOverMax (NA when selecting, error when assigning)
@@ -803,7 +803,7 @@ replace_dot_alias = function(e) {
803803
nzidx = nzchar(bysub)
804804
# by='' means by=NULL, tests 592&596
805805
if (!all(nzidx)) {
806-
if (length(bysub) > 1L) stop("At least one entry of by is empty")
806+
if (length(bysub) > 1L) stopf("At least one entry of by is empty")
807807
bysub = NULL
808808
} else {
809809
bysub = as.call(c(list(quote(list)), lapply(bysub, as.name)))
@@ -948,7 +948,7 @@ replace_dot_alias = function(e) {
948948
nm = names(q[-1L]) # check list(a=sum(v),v)
949949
if (is.null(nm)) nm = rep.int("", qlen-1L)
950950
# attempt to auto-name unnamed columns
951-
for (jj in which(nm=="")) {
951+
for (jj in which(!nzchar(nm))) {
952952
thisq = q[[jj + 1L]]
953953
if (missing(thisq)) stopf("Item %d of the .() or list() passed to j is missing", jj) #3507
954954
if (is.name(thisq)) nm[jj] = drop_dot(thisq)
@@ -976,7 +976,7 @@ replace_dot_alias = function(e) {
976976
if (length(q) == 4L && !is.null(q[[4L]])) q[[4L]] = do_j_names(q[[4L]])
977977
return(q)
978978
}
979-
return(q)
979+
q
980980
}
981981
if (is.name(jsub)) {
982982
# j is a single unquoted column name
@@ -1453,13 +1453,14 @@ replace_dot_alias = function(e) {
14531453
# independently by group & attr mismatch among groups is ignored. The latter
14541454
# is a more general issue but the former can be fixed by forcing units='secs'
14551455
SDenv$`-.POSIXt` = function(e1, e2) {
1456-
if (inherits(e2, 'POSIXt')) {
1457-
if (verbose && !get0('done_units_report', parent.frame(), ifnotfound = FALSE)) {
1458-
catf('\nNote: forcing units="secs" on implicit difftime by group; call difftime explicitly to choose custom units\n')
1459-
assign('done_units_report', TRUE, parent.frame())
1460-
}
1461-
return(difftime(e1, e2, units='secs'))
1462-
} else return(base::`-.POSIXt`(e1, e2))
1456+
if (!inherits(e2, 'POSIXt')) {
1457+
return(base::`-.POSIXt`(e1, e2))
1458+
}
1459+
if (verbose && !get0('done_units_report', parent.frame(), ifnotfound = FALSE)) {
1460+
catf('\nNote: forcing units="secs" on implicit difftime by group; call difftime explicitly to choose custom units\n')
1461+
assign('done_units_report', TRUE, parent.frame())
1462+
}
1463+
difftime(e1, e2, units='secs')
14631464
}
14641465

14651466
if (byjoin) {
@@ -1948,7 +1949,7 @@ replace_dot_alias = function(e) {
19481949
if (is.null(jvnames)) jvnames = character(length(ans)-length(bynames))
19491950
if (length(bynames)+length(jvnames)!=length(ans))
19501951
stopf("Internal error: jvnames is length %d but ans is %d and bynames is %d", length(jvnames), length(ans), length(bynames)) # nocov
1951-
ww = which(jvnames=="")
1952+
ww = which(!nzchar(jvnames))
19521953
if (any(ww)) jvnames[ww] = paste0("V",ww)
19531954
setattr(ans, "names", c(bynames, jvnames))
19541955
} else {
@@ -2293,7 +2294,7 @@ transform.data.table = function(`_data`, ...)
22932294
if (!cedta()) return(NextMethod()) # nocov
22942295
`_data` = copy(`_data`)
22952296
e = eval(substitute(list(...)), `_data`, parent.frame())
2296-
set(`_data`, ,names(e), e)
2297+
set(`_data`, NULL, names(e), e)
22972298
`_data`
22982299
}
22992300

@@ -2804,7 +2805,7 @@ setDF = function(x, rownames=NULL) {
28042805
if (is.null(xn)) {
28052806
setattr(x, "names", paste0("V",seq_len(length(x))))
28062807
} else {
2807-
idx = xn %chin% ""
2808+
idx = !nzchar(xn) # NB: keepNA=FALSE intentional
28082809
if (any(idx)) {
28092810
xn[idx] = paste0("V", seq_along(which(idx)))
28102811
setattr(x, "names", xn)
@@ -2877,7 +2878,7 @@ setDT = function(x, keep.rownames=FALSE, key=NULL, check.names=FALSE) {
28772878
if (is.null(xn)) {
28782879
setattr(x, "names", paste0("V", seq_along(x)))
28792880
} else {
2880-
idx = xn %chin% "" # names can be NA - test 1006 caught that!
2881+
idx = !nzchar(xn) # NB: keepNA=FALSE intentionally, see test 1006
28812882
if (any(idx)) {
28822883
xn[idx] = paste0("V", seq_along(which(idx)))
28832884
setattr(x, "names", xn)
@@ -3052,7 +3053,8 @@ is_constantish = function(q, check_singleton=FALSE) {
30523053
if (is.symbol(q1)) return(if (q1 %chin% gfuns) q1)
30533054
if (!q1 %iscall% "::") return(NULL)
30543055
if (q1[[2L]] != "data.table") return(NULL)
3055-
return(if (q1[[3L]] %chin% gdtfuns) q1[[3L]])
3056+
if (q1[[3L]] %chin% gdtfuns) return(q1[[3L]])
3057+
NULL
30563058
}
30573059
.gforce_ok = function(q, x) {
30583060
if (is.N(q)) return(TRUE) # For #334
@@ -3291,7 +3293,7 @@ is_constantish = function(q, check_singleton=FALSE) {
32913293
## search for column names
32923294
thisCols = c(thisCols, trimws(strsplit(pieces[[i]][j], pat)[[1L]]))
32933295
## there can be empty string column names because of trimws, remove them
3294-
thisCols = thisCols[thisCols != ""]
3296+
thisCols = thisCols[nzchar(thisCols)]
32953297
j = j+1L
32963298
}
32973299
}
@@ -3336,5 +3338,5 @@ is_constantish = function(q, check_singleton=FALSE) {
33363338
## the final on will contain the xCol as name, the iCol as value
33373339
on = iCols
33383340
names(on) = xCols
3339-
return(list(on = on, ops = idx_op))
3341+
list(on = on, ops = idx_op)
33403342
}

R/fcast.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ guess = function(x) {
55
return("(all)")
66
var = names(x)[ncol(x)]
77
messagef("Using '%s' as value column. Use 'value.var' to override", var)
8-
return(var)
8+
var
99
}
1010

1111
dcast <- function(

R/fmelt.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ measure = function(..., sep="_", pattern, cols, multiple.keyword="value.name") {
3939
formal.names = names(formals())
4040
formal.i.vec = which(names(L) %in% formal.names)
4141
fun.list = L[-formal.i.vec]
42-
user.named = names(fun.list) != ""
42+
user.named = nzchar(names(fun.list))
4343
is.symb = sapply(fun.list, is.symbol)
4444
bad.i = which((!user.named) & (!is.symb))
4545
if (length(bad.i)) {
@@ -73,7 +73,7 @@ measurev = function(fun.list, sep="_", pattern, cols, multiple.keyword="value.na
7373
if (!missing(sep) && !missing(pattern)) {
7474
stopf("both sep and pattern arguments used; must use either sep or pattern (not both)")
7575
}
76-
if (!(is.character(multiple.keyword) && length(multiple.keyword)==1 && !is.na(multiple.keyword) && nchar(multiple.keyword)>0)) {
76+
if (!(is.character(multiple.keyword) && length(multiple.keyword)==1 && !is.na(multiple.keyword) && nzchar(multiple.keyword))) {
7777
stopf("multiple.keyword must be a character string with nchar>0")
7878
}
7979
if (!is.character(cols)) {
@@ -82,7 +82,7 @@ measurev = function(fun.list, sep="_", pattern, cols, multiple.keyword="value.na
8282
prob.i <- if (is.null(names(fun.list))) {
8383
seq_along(fun.list)
8484
} else {
85-
which(names(fun.list) == "")
85+
which(!nzchar(names(fun.list)))
8686
}
8787
if (length(prob.i)) {
8888
stopf("in measurev, %s must be named, problems: %s", group.desc, brackify(prob.i))

R/fread.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,10 @@ yaml=FALSE, autostart=NA, tmpdir=tempdir(), tz="UTC")
153153
if (length(tt)) {
154154
msg = gettextf('na.strings[%d]=="%s" consists only of whitespace, ignoring', tt[1L], na.strings[tt[1L]])
155155
if (strip.white) {
156-
if (any(na.strings=="")) {
157-
warningf('%s. strip.white==TRUE (default) and "" is present in na.strings, so any number of spaces in string columns will already be read as <NA>.', msg)
158-
} else {
156+
if (all(nzchar(na.strings))) {
159157
warningf('%s. Since strip.white=TRUE (default), use na.strings="" to specify that any number of spaces in a string column should be read as <NA>.', msg)
158+
} else {
159+
warningf('%s. strip.white==TRUE (default) and "" is present in na.strings, so any number of spaces in string columns will already be read as <NA>.', msg)
160160
}
161161
na.strings = na.strings[-tt]
162162
} else {
@@ -299,7 +299,7 @@ yaml=FALSE, autostart=NA, tmpdir=tempdir(), tz="UTC")
299299
}
300300

301301
colClassesAs = attr(ans, "colClassesAs", exact=TRUE) # should only be present if one or more are != ""
302-
for (j in which(colClassesAs!="")) { # # 1634
302+
for (j in which(nzchar(colClassesAs))) { # # 1634
303303
v = .subset2(ans, j)
304304
new_class = colClassesAs[j]
305305
new_v = tryCatch({ # different to read.csv; i.e. won't error if a column won't coerce (fallback with warning instead)
@@ -317,7 +317,7 @@ yaml=FALSE, autostart=NA, tmpdir=tempdir(), tz="UTC")
317317
},
318318
warning = fun <- function(e) {
319319
warningf("Column '%s' was requested to be '%s' but fread encountered the following %s:\n\t%s\nso the column has been left as type '%s'", names(ans)[j], new_class, if (inherits(e, "error")) "error" else "warning", e$message, typeof(v))
320-
return(v)
320+
v
321321
},
322322
error = fun)
323323
set(ans, j = j, value = new_v) # aside: new_v == v if the coercion was aborted

R/fwrite.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ fwrite = function(x, file="", append=FALSE, quote="auto",
4848
}
4949
stopifnot(is.list(x),
5050
identical(quote,"auto") || isTRUEorFALSE(quote),
51-
is.character(sep) && length(sep)==1L && (nchar(sep) == 1L || sep == ""),
51+
is.character(sep) && length(sep)==1L && (nchar(sep) == 1L || identical(sep, "")),
5252
is.character(sep2) && length(sep2)==3L && nchar(sep2[2L])==1L,
5353
is.character(dec) && length(dec)==1L && nchar(dec) == 1L,
5454
dec != sep, # sep2!=dec and sep2!=sep checked at C level when we know if list columns are present

0 commit comments

Comments
 (0)