Skip to content

Commit

Permalink
Merge branch 'main' into check-random-order
Browse files Browse the repository at this point in the history
  • Loading branch information
IndrajeetPatil authored Jun 17, 2024
2 parents 8099d9e + 10de2ae commit 49cd1c4
Show file tree
Hide file tree
Showing 29 changed files with 244 additions and 264 deletions.
2 changes: 2 additions & 0 deletions .lintr
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ linters: all_linters(
absolute_path_linter = NULL,
library_call_linter = NULL,
nonportable_path_linter = NULL,
# We now require R>=4.0.0
strings_as_factors_linter = NULL,
todo_comment_linter = NULL,
# TODO(#2327): Enable this.
unreachable_code_linter = NULL
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ License: MIT + file LICENSE
URL: https://lintr.r-lib.org, https://github.com/r-lib/lintr
BugReports: https://github.com/r-lib/lintr/issues
Depends:
R (>= 3.6)
R (>= 4.0)
Imports:
backports (>= 1.1.7),
cli (>= 3.4.0),
Expand Down
7 changes: 1 addition & 6 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
# Generated by roxygen2: do not edit by hand


if (getRversion() >= "4.0.0") {
importFrom(tools, R_user_dir)
} else {
importFrom(backports, R_user_dir)
}
S3method("[",lints)
S3method(as.data.frame,lints)
S3method(format,lint)
Expand Down Expand Up @@ -183,6 +177,7 @@ importFrom(rex,re_substitutes)
importFrom(rex,regex)
importFrom(rex,rex)
importFrom(stats,na.omit)
importFrom(tools,R_user_dir)
importFrom(utils,capture.output)
importFrom(utils,getParseData)
importFrom(utils,getTxtProgressBar)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
## Notes

* All user-facing messages are now prepared using the `{cli}` package (#2418, @IndrajeetPatil). All messages have been reviewed and updated to be more informative and consistent.
* {lintr} now depends on R version 4.0.0. It already does so implicitly due to recursive upstream dependencies requiring this version; we've simply made that dependency explicit and up-front (#2569, @MichaelChirico).

# lintr 3.1.2

Expand Down
4 changes: 1 addition & 3 deletions R/absolute_path_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
#' * contain at least two path elements, with one having at least two characters and
#' * contain only alphanumeric chars (including UTF-8), spaces, and win32-allowed punctuation
#'
#' @examplesIf getRversion() >= "4.0"
#' # Following examples use raw character constant syntax introduced in R 4.0.
#'
#' @examples
#' # will produce lints
#' lint(
#' text = 'R"--[/blah/file.txt]--"',
Expand Down
8 changes: 4 additions & 4 deletions R/cache.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ load_cache <- function(file, path = NULL) {
invokeRestart("muffleWarning")
},
error = function(e) {
cli_warn(c(
x = "Could not load cache file {.file {file}}:",
i = conditionMessage(e)
))
cli_warn(
"Could not load cache file {.file {file}}:",
parent = e
)
}
)
} # else nothing to do for source file that has no cache
Expand Down
3 changes: 1 addition & 2 deletions R/get_source_expressions.R
Original file line number Diff line number Diff line change
Expand Up @@ -636,8 +636,7 @@ fix_eq_assigns <- function(pc) {
parent = integer(n_expr),
token = character(n_expr),
terminal = logical(n_expr),
text = character(n_expr),
stringsAsFactors = FALSE
text = character(n_expr)
)

for (i in seq_len(n_expr)) {
Expand Down
42 changes: 21 additions & 21 deletions R/lint.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ lint <- function(filename, linters = NULL, ..., cache = FALSE, parse_settings =
lints[[length(lints) + 1L]] <- withCallingHandlers(
get_lints(expr, linter, linters[[linter]], lint_cache, source_expressions$lines),
error = function(cond) {
cli_abort(c(
cli_abort(
"Linter {.fn linter} failed in {.file {filename}}:",
conditionMessage(cond)
))
parent = cond
)
}
)
}
Expand Down Expand Up @@ -410,16 +410,13 @@ Lint <- function(filename, line_number = 1L, column_number = 1L, # nolint: objec
}
max_col <- max(nchar(line) + 1L, 1L, na.rm = TRUE)
if (!is_number(column_number) || column_number < 0L || column_number > max_col) {
cli_abort(c(
i = "{.arg column_number} must be an integer between {.val {0}} and {.code nchar(line) + 1} ({.val {max_col}})",
x = "Instead, it was {.val {column_number}}."
))
cli_abort("
{.arg column_number} must be an integer between {.val {0}} and {.val {max_col}} ({.code nchar(line) + 1}),
not {.obj_type_friendly {column_number}}.
")
}
if (!is_number(line_number) || line_number < 1L) {
cli_abort(c(
i = "{.arg line_number} must be a positive integer.",
x = "Instead, it was {.val {line_number}}."
))
cli_abort("{.arg line_number} must be a positive integer, not {.obj_type_friendly {line_number}}.")
}
check_ranges(ranges, max_col)

Expand Down Expand Up @@ -449,25 +446,28 @@ is_valid_range <- function(range, max_col) {
range[[2L]] <= max_col
}

check_ranges <- function(ranges, max_col) {
check_ranges <- function(ranges, max_col, call = parent.frame()) {
if (is.null(ranges)) {
return()
}
if (!is.list(ranges)) {
cli_abort(c(
i = "{.arg ranges} must be {.code NULL} or a {.cls list}.",
x = "Instead, it was {.cls {class(ranges)}}."
))
cli_abort(
"{.arg ranges} must be {.code NULL} or a list, not {.obj_type_friendly {ranges}}.",
call = call
)
}

for (range in ranges) {
if (!is_number(range, 2L)) {
cli_abort("{.arg ranges} must only contain {.cls integer} vectors of length 2 without {.code NA}s.")
cli_abort(
"{.arg ranges} must only contain integer vectors of length 2 without {.code NA}s.",
call = call
)
} else if (!is_valid_range(range, max_col)) {
cli_abort(c(
x = "Invalid range specified.",
i = "Argument {.arg ranges} must satisfy 0 <= range[1L] <= range[2L] <= nchar(line) + 1 ({.val {max_col}})."
))
cli_abort(
"{.arg ranges} must satisfy {.val {0}} <= range[1L] <= range[2L] <= {.val {max_col}} (nchar(line) + 1).",
call = call
)
}
}
}
Expand Down
8 changes: 2 additions & 6 deletions R/linter_tags.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,7 @@ available_linters <- function(packages = "lintr", tags = NULL, exclude_tags = "d
}

build_available_linters <- function(available, package, tags, exclude_tags) {
available_df <- data.frame(
linter = available[["linter"]],
package,
stringsAsFactors = FALSE
)
available_df <- data.frame(linter = available[["linter"]], package)
available_df$tags <- strsplit(available[["tags"]], split = " ", fixed = TRUE)
if (!is.null(tags)) {
matches_tags <- vapply(available_df$tags, function(linter_tags) any(linter_tags %in% tags), logical(1L))
Expand All @@ -108,7 +104,7 @@ build_available_linters <- function(available, package, tags, exclude_tags) {
#' `data.frame` constructors don't handle zero-row list-columns properly, so supply `tags` afterwards.
#' @noRd
empty_linters <- function() {
empty_df <- data.frame(linter = character(), package = character(), stringsAsFactors = FALSE)
empty_df <- data.frame(linter = character(), package = character())
empty_df$tags <- list()
empty_df
}
Expand Down
7 changes: 1 addition & 6 deletions R/lintr-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,11 @@
#' @importFrom glue glue glue_collapse
#' @importFrom rex rex regex re_matches re_substitutes character_class
#' @importFrom stats na.omit
#' @importFrom tools R_user_dir
#' @importFrom utils capture.output getParseData getTxtProgressBar globalVariables head relist
#' setTxtProgressBar tail txtProgressBar
#' @importFrom xml2 as_list
#' xml_attr xml_children xml_find_all xml_find_chr xml_find_lgl xml_find_num xml_find_first xml_name xml_text
#' @rawNamespace
#' if (getRversion() >= "4.0.0") {
#' importFrom(tools, R_user_dir)
#' } else {
#' importFrom(backports, R_user_dir)
#' }
## lintr namespace: end
NULL

Expand Down
5 changes: 2 additions & 3 deletions R/methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@ as.data.frame.lints <- function(x, row.names = NULL, optional = FALSE, ...) { #
type = vapply(x, `[[`, character(1L), "type"),
message = vapply(x, `[[`, character(1L), "message"),
line = vapply(x, `[[`, character(1L), "line"),
linter = vapply(x, `[[`, character(1L), "linter"),
stringsAsFactors = FALSE
linter = vapply(x, `[[`, character(1L), "linter")
)
}

Expand Down Expand Up @@ -198,7 +197,7 @@ summary.lints <- function(object, ...) {
)
tbl <- table(filenames, types)
filenames <- rownames(tbl)
res <- as.data.frame.matrix(tbl, stringsAsFactors = FALSE, row.names = NULL)
res <- as.data.frame.matrix(tbl, row.names = NULL)
res$filenames <- filenames %||% character()
nms <- colnames(res)
res[order(res$filenames), c("filenames", nms[nms != "filenames"])]
Expand Down
12 changes: 4 additions & 8 deletions R/namespace.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ safe_get_exports <- function(ns) {

# importFrom directives appear as list(ns, imported_funs)
if (length(ns) > 1L) {
return(data.frame(pkg = ns[[1L]], fun = ns[[2L]], stringsAsFactors = FALSE))
return(data.frame(pkg = ns[[1L]], fun = ns[[2L]]))
}

# relevant only if there are any exported objects
fun <- getNamespaceExports(ns)
if (length(fun) > 0L) {
data.frame(pkg = ns, fun = fun, stringsAsFactors = FALSE)
data.frame(pkg = ns, fun = fun)
}
}

empty_namespace_data <- function() {
data.frame(pkg = character(), fun = character(), stringsAsFactors = FALSE)
data.frame(pkg = character(), fun = character())
}

# filter namespace_imports() for S3 generics
Expand Down Expand Up @@ -64,11 +64,7 @@ exported_s3_generics <- function(path = find_package(".")) {
return(empty_namespace_data())
}

data.frame(
pkg = basename(path),
fun = unique(namespace_data$S3methods[, 1L]),
stringsAsFactors = FALSE
)
data.frame(pkg = basename(path), fun = unique(namespace_data$S3methods[, 1L]))
}

is_s3_generic <- function(fun) {
Expand Down
3 changes: 1 addition & 2 deletions R/object_overwrite_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ object_overwrite_linter <- function(
)
pkg_exports <- data.frame(
package = rep(packages, lengths(pkg_exports)),
name = unlist(pkg_exports),
stringsAsFactors = FALSE
name = unlist(pkg_exports)
)

# Take the first among duplicate names, e.g. 'plot' resolves to base::plot, not graphics::plot
Expand Down
Loading

0 comments on commit 49cd1c4

Please sign in to comment.