diff --git a/.dev/compare_branches.R b/.dev/compare_branches.R index 2d0b2ac69..ea2e78287 100755 --- a/.dev/compare_branches.R +++ b/.dev/compare_branches.R @@ -226,7 +226,7 @@ test_encoding <- function(dir) { for (r_file in list.files(dir, pattern = "(?i)\\.r(?:md)?$", recursive = TRUE, full.names = TRUE)) { # lintr has better encoding support since 8cd6ad~linter>2.0.1~Jul 2021; use # the accompanying helper if possible. clunkier default otherwise. - encoding <- tryCatch(lintr:::find_default_encoding(r_file), error = function(...) NULL) + encoding <- tryCatch(lintr:::find_default_encoding(r_file), error = \(...) NULL) local({ con <- file(r_file, encoding = encoding %||% "UTF-8") on.exit(close(con)) @@ -360,7 +360,7 @@ get_linter_from_name <- function(linter_name) { } else { eval(call(linter_name)) }, - error = function(cond) eval(as.name(linter_name)) + error = \(cond) eval(as.name(linter_name)) ) } @@ -580,7 +580,7 @@ if (params$benchmark) { idcol = "package", lapply( linter, - function(package) data.table::data.table(filename = names(package), duration = unlist(package)) + \(package) data.table::data.table(filename = names(package), duration = unlist(package)) ) ) ) diff --git a/.dev/revdep_compare_releases.R b/.dev/revdep_compare_releases.R index e18886446..7d9870c67 100755 --- a/.dev/revdep_compare_releases.R +++ b/.dev/revdep_compare_releases.R @@ -44,7 +44,7 @@ snake_case_linter <- trailing_semicolons_linter <- function(...) { # .call=TRUE means the linter name will be displayed in the warning warning("Using deleted linter") - Linter(function(...) list()) + Linter(\(...) list()) } @@ -146,7 +146,7 @@ summarize_failures <- function(version, failures) { files <- result_path(version, failures) packages <- gsub("\\.failures$", "", failures) - package_failures <- sapply(files, function(x) paste(unique(readLines(x)), collapse = " ||| ")) + package_failures <- sapply(files, \(x) paste(unique(readLines(x)), collapse = " ||| ")) paste(sprintf(" %s: %s", packages, package_failures), collapse = "\n") } diff --git a/DESCRIPTION b/DESCRIPTION index 169edc70e..7c18391c4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -24,9 +24,8 @@ 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 (>= 4.0) + R (>= 4.1.0) Imports: - backports (>= 1.5.0), cli (>= 3.4.0), codetools, digest, diff --git a/NEWS.md b/NEWS.md index decb4d744..5eddfba41 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,10 @@ * Six linters fully deprecated in the previous release are now removed: `consecutive_stopifnot_linter()`, `extraction_operator_linter()`, `no_tab_linter()`, `single_quotes_linter()`, `unnecessary_nested_if_linter()`, and `unneeded_concatenation_linter()`. +## Notes + +* {lintr} now requires R 4.1.0 + # lintr (3.3.0-1) ## Deprecations & breaking changes diff --git a/R/backport_linter.R b/R/backport_linter.R index a285c7e39..546463072 100644 --- a/R/backport_linter.R +++ b/R/backport_linter.R @@ -50,7 +50,7 @@ backport_linter <- function(r_version = getRversion(), except = character()) { r_version <- normalize_r_version(r_version) if (all(r_version >= R_system_version(names(backports)))) { - return(Linter(function(source_expression) list(), linter_level = "file")) + return(Linter(\(source_expression) list(), linter_level = "file")) } backport_blacklist <- backports[r_version < R_system_version(names(backports))] diff --git a/R/conjunct_test_linter.R b/R/conjunct_test_linter.R index e8ab9742d..a1a49ea0d 100644 --- a/R/conjunct_test_linter.R +++ b/R/conjunct_test_linter.R @@ -12,8 +12,7 @@ #' if you're using another function named `filter()`, e.g. [stats::filter()], please namespace-qualify it to avoid #' false positives. You can omit linting `filter()` expressions altogether via `allow_filter = TRUE`. #' -#' @param allow_named_stopifnot Logical, `TRUE` by default. If `FALSE`, "named" calls to `stopifnot()`, -#' available since R 4.0.0 to provide helpful messages for test failures, are also linted. +#' @param allow_named_stopifnot Logical, `TRUE` by default. If `FALSE`, "named" calls to `stopifnot()` are also linted. #' @param allow_filter Character naming the method for linting calls to `filter()`. The default, `"never"`, means #' `filter()` and `dplyr::filter()` calls are linted; `"not_dplyr"` means only `dplyr::filter()` calls are linted; #' and `"always"` means no calls to `filter()` are linted. Calls like `stats::filter()` are never linted. diff --git a/R/exclude.R b/R/exclude.R index 55ff90866..6033f1226 100644 --- a/R/exclude.R +++ b/R/exclude.R @@ -75,7 +75,7 @@ is_excluded <- function(line_number, linter, file_exclusion) { is_excluded_file <- function(file_exclusion) { any(vapply( file_exclusion[!nzchar(names2(file_exclusion))], - function(full_exclusion) Inf %in% full_exclusion, + \(full_exclusion) Inf %in% full_exclusion, logical(1L) )) } @@ -170,7 +170,7 @@ parse_exclusions <- function(file, exclusions <- add_exclusions(exclusions, nextt + 1L, linters_string, exclude_linter_sep, linter_names) } - exclusions[] <- lapply(exclusions, function(lines) sort(unique(lines))) + exclusions[] <- lapply(exclusions, \(lines) sort(unique(lines))) exclusions } @@ -413,6 +413,6 @@ remove_linter_duplicates <- function(x) { # Removes linter exclusions without lines and files without any linter exclusions. remove_empty <- function(x) { - x[] <- lapply(x, function(ex) ex[lengths(ex) > 0L]) + x[] <- lapply(x, \(ex) ex[lengths(ex) > 0L]) x[lengths(x) > 0L] } diff --git a/R/expect_lint.R b/R/expect_lint.R index 9d4d3f87b..5a4a60435 100644 --- a/R/expect_lint.R +++ b/R/expect_lint.R @@ -79,9 +79,9 @@ expect_lint <- function(content, checks, ..., file = NULL, language = "en", igno lints <- lints[lint_order] check_order <- order( - vapply(checks, function(x) x$line_number %||% 0L, FUN.VALUE = integer(1L)), - vapply(checks, function(x) x$column_number %||% 0L, FUN.VALUE = integer(1L)), - vapply(checks, function(x) x$linter %||% "", FUN.VALUE = character(1L)) + vapply(checks, \(x) x$line_number %||% 0L, FUN.VALUE = integer(1L)), + vapply(checks, \(x) x$column_number %||% 0L, FUN.VALUE = integer(1L)), + vapply(checks, \(x) x$linter %||% "", FUN.VALUE = character(1L)) ) checks <- checks[check_order] } diff --git a/R/get_source_expressions.R b/R/get_source_expressions.R index 3b0114fb2..3ed31b802 100644 --- a/R/get_source_expressions.R +++ b/R/get_source_expressions.R @@ -77,11 +77,11 @@ get_source_expressions <- function(filename, lines = NULL) { source_expression$lines <- extract_r_source( filename = source_expression$filename, lines = source_expression$lines, - error = function(e) lint_rmd_error(e, source_expression) + error = \(e) lint_rmd_error(e, source_expression) ) names(source_expression$lines) <- seq_along(source_expression$lines) source_expression$content <- get_content(source_expression$lines) - parsed_content <- get_source_expression(source_expression, error = function(e) lint_parse_error(e, source_expression)) + parsed_content <- get_source_expression(source_expression, error = \(e) lint_parse_error(e, source_expression)) # Currently no way to distinguish the source of the warning # from the message itself, so we just grep the source for the @@ -218,7 +218,7 @@ parser_warning_regexes <- list( #' #' @noRd fixup_line <- function(line) { - nchars <- tryCatch(nchar(line, type = "chars"), error = function(e) NA_integer_) + nchars <- tryCatch(nchar(line, type = "chars"), error = \(e) NA_integer_) if (is.na(nchars)) { "" } else { @@ -584,7 +584,7 @@ maybe_append_expression_xml <- function(expressions, xml_parsed_content) { } expression_xmls <- lapply( xml_find_all(xml_parsed_content, "/exprlist/*"), - function(top_level_expr) xml2::xml_add_parent(xml2::xml_new_root(top_level_expr), "exprlist") + \(top_level_expr) xml2::xml_add_parent(xml2::xml_new_root(top_level_expr), "exprlist") ) for (i in seq_along(expressions)) { expressions[[i]]$xml_parsed_content <- expression_xmls[[i]] @@ -625,7 +625,7 @@ fix_tab_indentations <- function(source_expression) { tab_cols <- gregexpr("\t", source_expression[["lines"]], fixed = TRUE) names(tab_cols) <- seq_along(tab_cols) - matched_lines <- vapply(tab_cols, function(line_match) !is.na(line_match[1L]) && line_match[1L] > 0L, logical(1L)) + matched_lines <- vapply(tab_cols, \(line_match) !is.na(line_match[1L]) && line_match[1L] > 0L, logical(1L)) if (!any(matched_lines)) { return(parse_data) } diff --git a/R/indentation_linter.R b/R/indentation_linter.R index 3533eac39..c779cc019 100644 --- a/R/indentation_linter.R +++ b/R/indentation_linter.R @@ -133,7 +133,7 @@ indentation_linter <- function(indent = 2L, hanging_indent_style = c("tidy", "al find_indent_type <- switch(hanging_indent_style, tidy = build_indentation_style_tidy(), always = build_indentation_style_always(), - never = function(change) "block" + never = \(change) "block" ) if (isTRUE(assignment_as_infix)) { diff --git a/R/line_length_linter.R b/R/line_length_linter.R index 0cc51c1fc..7b1216767 100644 --- a/R/line_length_linter.R +++ b/R/line_length_linter.R @@ -117,7 +117,7 @@ is_in_string_body <- function(parse_data, max_length, long_idx) { # right delimiter just ends at 'col2', but 'col1' takes some sleuthing str_data$line1_width <- nchar(vapply( strsplit(str_data$text, "\n", fixed = TRUE), - function(x) x[1L], + \(x) x[1L], FUN.VALUE = character(1L), USE.NAMES = FALSE )) diff --git a/R/lint.R b/R/lint.R index 7e7c4db57..49fe83e1d 100644 --- a/R/lint.R +++ b/R/lint.R @@ -232,7 +232,7 @@ lint_dir <- function(path = ".", ..., drop_excluded <- function(files, exclusions) { to_exclude <- vapply( files, - function(file) file %in% names(exclusions) && is_excluded_file(exclusions[[file]]), + \(file) file %in% names(exclusions) && is_excluded_file(exclusions[[file]]), logical(1L) ) files[!to_exclude] @@ -612,7 +612,7 @@ sarif_output <- function(lints, filename = "lintr_results.sarif") { rule_index_exists <- which(vapply( sarif$runs[[1L]]$tool$driver$rules, - function(x) x$id == lint$linter, + \(x) x$id == lint$linter, logical(1L) )) if (length(rule_index_exists) == 0L || is.na(rule_index_exists[1L])) { diff --git a/R/linter_tags.R b/R/linter_tags.R index 316a65244..e9bebf1da 100644 --- a/R/linter_tags.R +++ b/R/linter_tags.R @@ -85,11 +85,11 @@ build_available_linters <- function(available, package, tags, exclude_tags) { 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)) + matches_tags <- vapply(available_df$tags, \(linter_tags) any(linter_tags %in% tags), logical(1L)) available_df <- available_df[matches_tags, ] } if (!is.null(exclude_tags)) { - matches_exclude <- vapply(available_df$tags, function(linter_tags) any(linter_tags %in% exclude_tags), logical(1L)) + matches_exclude <- vapply(available_df$tags, \(linter_tags) any(linter_tags %in% exclude_tags), logical(1L)) available_df <- available_df[!matches_exclude, ] } @@ -184,7 +184,7 @@ rd_linters <- function(tag_name) { rd_taglist <- function() { linters <- available_linters(exclude_tags = NULL) # don't count tags on deprecated linters to the counts of other tags - linters$tags <- lapply(linters$tags, function(x) if ("deprecated" %in% x) "deprecated" else x) + linters$tags <- lapply(linters$tags, \(x) if ("deprecated" %in% x) "deprecated" else x) tag_table <- table(unlist(linters[["tags"]])) tags <- platform_independent_sort(names(tag_table)) diff --git a/R/literal_coercion_linter.R b/R/literal_coercion_linter.R index b458eaf43..99dc0e000 100644 --- a/R/literal_coercion_linter.R +++ b/R/literal_coercion_linter.R @@ -101,7 +101,7 @@ literal_coercion_linter <- function() { # TODO(#2473): Avoid a recommendation like '1' that clashes with implicit_integer_linter(). literal_equivalent_str <- vapply( str2expression(coercion_str), - function(expr) deparse1(suppressWarnings(eval(expr))), + \(expr) deparse1(suppressWarnings(eval(expr))), character(1L) ) lint_message <- sprintf( diff --git a/R/namespace.R b/R/namespace.R index 01ae56328..7d6c5a966 100644 --- a/R/namespace.R +++ b/R/namespace.R @@ -2,7 +2,7 @@ namespace_imports <- function(path = find_package(".")) { namespace_data <- tryCatch( parseNamespaceFile(basename(path), package.lib = file.path(path, "..")), - error = function(e) NULL + error = \(e) NULL ) if (length(namespace_data$imports) == 0L) { @@ -57,7 +57,7 @@ imported_s3_generics <- function(ns_imports) { exported_s3_generics <- function(path = find_package(".")) { namespace_data <- tryCatch( parseNamespaceFile(basename(path), package.lib = file.path(path, "..")), - error = function(e) NULL + error = \(e) NULL ) if (length(namespace_data$S3methods) == 0L || nrow(namespace_data$S3methods) == 0L) { diff --git a/R/namespace_linter.R b/R/namespace_linter.R index c64a39bfe..d27b97bae 100644 --- a/R/namespace_linter.R +++ b/R/namespace_linter.R @@ -79,7 +79,7 @@ namespace_linter <- function(check_exports = TRUE, check_nonexports = TRUE) { ## Case 2/3/4: problems with foo in pkg::foo / pkg:::foo # run here, not in the factory, to allow for run- vs. "compile"-time differences in package structure - namespaces <- lapply(packages, function(package) tryCatch(getNamespace(package), error = identity)) + namespaces <- lapply(packages, \(package) tryCatch(getNamespace(package), error = identity)) failed_namespace <- vapply(namespaces, inherits, "condition", FUN.VALUE = logical(1L)) # nocov start @@ -126,7 +126,7 @@ namespace_symbols <- function(ns, exported = TRUE) { is_in_pkg <- function(symbols, namespaces, exported = TRUE) { vapply( seq_along(symbols), - function(ii) symbols[[ii]] %in% namespace_symbols(namespaces[[ii]], exported = exported), + \(ii) symbols[[ii]] %in% namespace_symbols(namespaces[[ii]], exported = exported), logical(1L) ) } diff --git a/R/object_overwrite_linter.R b/R/object_overwrite_linter.R index acee4c2ea..6d7f62a9e 100644 --- a/R/object_overwrite_linter.R +++ b/R/object_overwrite_linter.R @@ -63,7 +63,7 @@ object_overwrite_linter <- function( pkg_exports <- lapply( packages, # .__C__ etc.: drop 150+ "virtual" names since they are very unlikely to appear anyway - function(pkg) setdiff(grep("^[.]__[A-Z]__", getNamespaceExports(pkg), value = TRUE, invert = TRUE), allow_names) + \(pkg) setdiff(grep("^[.]__[A-Z]__", getNamespaceExports(pkg), value = TRUE, invert = TRUE), allow_names) ) pkg_exports <- data.frame( package = rep(packages, lengths(pkg_exports)), diff --git a/R/object_usage_linter.R b/R/object_usage_linter.R index cb533b422..33ffec4ab 100644 --- a/R/object_usage_linter.R +++ b/R/object_usage_linter.R @@ -190,7 +190,7 @@ make_check_env <- function(pkg_name, xml, library_lint_hook) { # Just assign them an empty function for (symbol in symbols) { - assign(symbol, function(...) invisible(), envir = env) + assign(symbol, \(...) invisible(), envir = env) } env } diff --git a/R/package_hooks_linter.R b/R/package_hooks_linter.R index c7aa269be..a9725d084 100644 --- a/R/package_hooks_linter.R +++ b/R/package_hooks_linter.R @@ -70,7 +70,7 @@ package_hooks_linter <- function() { " bad_call_xpaths <- vapply( seq_along(bad_calls), - function(ii) sprintf(bad_msg_call_xpath_fmt, names(bad_calls)[ii], xp_text_in_table(bad_calls[[ii]])), + \(ii) sprintf(bad_msg_call_xpath_fmt, names(bad_calls)[ii], xp_text_in_table(bad_calls[[ii]])), character(1L) ) names(bad_call_xpaths) <- names(bad_calls) diff --git a/R/settings.R b/R/settings.R index 6469ca157..7577f3d8b 100644 --- a/R/settings.R +++ b/R/settings.R @@ -244,7 +244,7 @@ validate_exclusions <- function(exclusions) { exclusion_names <- names2(exclusions) has_names <- nzchar(exclusion_names) unnamed_is_string <- - vapply(exclusions[!has_names], function(x) is.character(x) && length(x) == 1L && !is.na(x), logical(1L)) + vapply(exclusions[!has_names], \(x) is.character(x) && length(x) == 1L && !is.na(x), logical(1L)) if (!all(unnamed_is_string)) { problematic_entries <- which(!has_names)[!unnamed_is_string] # nolint: object_usage_linter. TODO(#2252). cli_abort(c( @@ -258,7 +258,7 @@ validate_exclusions <- function(exclusions) { validate_named_exclusion <- function(exclusions, idx) { entry <- exclusions[[idx]] if (is.list(entry)) { - valid_entry <- vapply(entry, function(x) is.numeric(x) && !anyNA(x), logical(1L)) + valid_entry <- vapply(entry, \(x) is.numeric(x) && !anyNA(x), logical(1L)) } else { valid_entry <- is.numeric(entry) && !anyNA(entry) } @@ -298,8 +298,8 @@ get_encoding_from_dcf <- function(file) { encodings <- tryCatch( unname(drop(read.dcf(file, "Encoding"))), - error = function(e) NULL, - warning = function(e) NULL + error = \(e) NULL, + warning = \(e) NULL ) encodings <- encodings[!is.na(encodings)] diff --git a/R/shared_constants.R b/R/shared_constants.R index ba1b98af7..2174502e8 100644 --- a/R/shared_constants.R +++ b/R/shared_constants.R @@ -309,8 +309,8 @@ glue_parse_failure_warning <- function(cond) { glue_symbol_extractor <- function(text, envir, data) { symbols <- tryCatch( all.vars(parse(text = text), functions = TRUE), - error = function(...) NULL, - warning = function(...) NULL + error = \(...) NULL, + warning = \(...) NULL ) for (sym in symbols) { assign(sym, NULL, envir = envir) diff --git a/R/trailing_whitespace_linter.R b/R/trailing_whitespace_linter.R index ba1e5ef25..d8243a565 100644 --- a/R/trailing_whitespace_linter.R +++ b/R/trailing_whitespace_linter.R @@ -59,7 +59,7 @@ trailing_whitespace_linter <- function(allow_empty_lines = FALSE, allow_in_strin start_lines <- as.integer(xml_attr(all_str_consts, "line1")) end_lines <- as.integer(xml_attr(all_str_consts, "line2")) - is_in_str <- vapply(bad_lines, function(ln) any(start_lines <= ln & ln < end_lines), logical(1L)) + is_in_str <- vapply(bad_lines, \(ln) any(start_lines <= ln & ln < end_lines), logical(1L)) bad_lines <- bad_lines[!is_in_str] } diff --git a/R/utils.R b/R/utils.R index f78ecb98c..6ff2ead83 100644 --- a/R/utils.R +++ b/R/utils.R @@ -263,7 +263,7 @@ is_tainted <- function(lines) { #' @param ref_help Help page to refer users hitting an error to. #' @noRd check_dots <- function(dot_names, ref_calls, ref_help = as.character(sys.call(-1L)[[1L]])) { - valid_args <- unlist(lapply(ref_calls, function(f) names(formals(f)))) + valid_args <- unlist(lapply(ref_calls, \(f) names(formals(f)))) is_valid <- dot_names %in% valid_args if (all(is_valid)) { return(invisible()) diff --git a/R/xml_utils.R b/R/xml_utils.R index 831259195..7068621d0 100644 --- a/R/xml_utils.R +++ b/R/xml_utils.R @@ -42,7 +42,7 @@ safe_parse_to_xml <- function(parsed_content) { tryCatch( xml2::read_xml(xmlparsedata::xml_parse_data(parsed_content)), # use xml_missing so that code doesn't always need to condition on XML existing - error = function(e) xml2::xml_missing() + error = \(e) xml2::xml_missing() ) } diff --git a/R/zzz.R b/R/zzz.R index efc5f1e5d..76c2e4e76 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -307,9 +307,6 @@ logical_env <- function(x, unset = "") { toset <- !(names(op_lintr) %in% names(op)) if (any(toset)) options(op_lintr[toset]) - # R>=4.1.0: ...names - backports::import(pkgname, "...names") - utils::assignInMyNamespace("default_settings", list( linters = default_linters, encoding = "UTF-8", diff --git a/man/conjunct_test_linter.Rd b/man/conjunct_test_linter.Rd index 8d7eb9630..ef4daaa01 100644 --- a/man/conjunct_test_linter.Rd +++ b/man/conjunct_test_linter.Rd @@ -10,8 +10,7 @@ conjunct_test_linter( ) } \arguments{ -\item{allow_named_stopifnot}{Logical, \code{TRUE} by default. If \code{FALSE}, "named" calls to \code{stopifnot()}, -available since R 4.0.0 to provide helpful messages for test failures, are also linted.} +\item{allow_named_stopifnot}{Logical, \code{TRUE} by default. If \code{FALSE}, "named" calls to \code{stopifnot()} are also linted.} \item{allow_filter}{Character naming the method for linting calls to \code{filter()}. The default, \code{"never"}, means \code{filter()} and \code{dplyr::filter()} calls are linted; \code{"not_dplyr"} means only \code{dplyr::filter()} calls are linted; diff --git a/man/library_call_linter.Rd b/man/library_call_linter.Rd index cf2a62a5f..e34b089e8 100644 --- a/man/library_call_linter.Rd +++ b/man/library_call_linter.Rd @@ -21,7 +21,7 @@ This linter covers several rules related to \code{\link[=library]{library()}} ca \item Block usage of argument \code{character.only}, in particular for loading packages in a loop. \item Block consecutive calls to \code{suppressMessages(library(.))} -in favor of using \code{\link[backports:suppressWarnings]{backports::suppressMessages()}} only once to suppress +in favor of using \code{\link[=suppressMessages]{suppressMessages()}} only once to suppress messages from all \code{library()} calls. Ditto \code{\link[=suppressPackageStartupMessages]{suppressPackageStartupMessages()}}. } } diff --git a/tests/testthat/helper.R b/tests/testthat/helper.R index 66d3a24ce..082d93939 100644 --- a/tests/testthat/helper.R +++ b/tests/testthat/helper.R @@ -68,17 +68,16 @@ skip_if_not_utf8_locale <- function() { } safe_load_help_db <- function() { - help_db <- tryCatch(tools::Rd_db("lintr"), error = function(e) NULL) + help_db <- tryCatch(tools::Rd_db("lintr"), error = \(e) NULL) # e.g. in dev under pkgload::load_all() if (length(help_db) == 0L) { - help_db <- tryCatch(tools::Rd_db(dir = testthat::test_path("..", "..")), error = function(e) NULL) + help_db <- tryCatch(tools::Rd_db(dir = testthat::test_path("..", "..")), error = \(e) NULL) testthat::skip_if_not(length(help_db) > 0L, message = "Package help corrupted or not installed") } help_db } pipes <- function(exclude = NULL) { - if (getRversion() < "4.1.0") exclude <- unique(c(exclude, "|>")) all_pipes <- c( standard = "%>%", greedy = "%!>%", diff --git a/tests/testthat/test-brace_linter.R b/tests/testthat/test-brace_linter.R index 2257dc49f..22147a812 100644 --- a/tests/testthat/test-brace_linter.R +++ b/tests/testthat/test-brace_linter.R @@ -597,8 +597,6 @@ test_that("code with pipes is handled correctly", { linter ) - skip_if_not_r_version("4.1.0") - expect_no_lint( trim_some(" out <- lapply(stuff, function(i) { @@ -618,7 +616,6 @@ test_that("code with pipes is handled correctly", { }) test_that("function shorthand is treated like 'full' function", { - skip_if_not_r_version("4.1.0") linter <- brace_linter() expect_no_lint("a <- \\() { \n}", linter) diff --git a/tests/testthat/test-cache.R b/tests/testthat/test-cache.R index 2021307b1..7740a4d24 100644 --- a/tests/testthat/test-cache.R +++ b/tests/testthat/test-cache.R @@ -35,8 +35,8 @@ fhash <- function(filename) { test_that("clear_cache deletes the directory if no file is given", { local_mocked_bindings( - read_settings = function(...) invisible(...), - unlink = function(...) list(...) + read_settings = \(...) invisible(...), + unlink = \(...) list(...) ) expect_identical(clear_cache(file = NULL, path = "."), list(".", recursive = TRUE)) @@ -59,7 +59,7 @@ test_that("lint with cache uses the provided relative cache directory", { test_that("it works outside of a package", { linter <- assignment_linter() - local_mocked_bindings(find_package = function(...) NULL) + local_mocked_bindings(find_package = \(...) NULL) path <- withr::local_tempfile(pattern = "my_cache_dir_") expect_false(dir.exists(path)) expect_lint("a <- 1", NULL, linter, cache = path) diff --git a/tests/testthat/test-ci.R b/tests/testthat/test-ci.R index 40401e934..d1740ee59 100644 --- a/tests/testthat/test-ci.R +++ b/tests/testthat/test-ci.R @@ -32,7 +32,7 @@ patrick::with_parameters_test_that( l <- lint(tmp) - local_mocked_bindings(quit = function(...) cat("Tried to quit.\n")) + local_mocked_bindings(quit = \(...) cat("Tried to quit.\n")) expect_output(print(l), "::warning file", fixed = TRUE) }, env_var_value = list("T", "true") diff --git a/tests/testthat/test-commented_code_linter.R b/tests/testthat/test-commented_code_linter.R index 80143631f..24a281e30 100644 --- a/tests/testthat/test-commented_code_linter.R +++ b/tests/testthat/test-commented_code_linter.R @@ -95,8 +95,6 @@ test_that("commented_code_linter can detect operators in comments and lint corre }) test_that("commented_code_linter can detect operators in comments and lint correctly", { - skip_if_not_r_version("4.1.0") - expect_lint( "# 1:3 |> sum()", rex::rex("Remove commented code."), @@ -109,7 +107,5 @@ test_that("commented_code_linter can detect commented code ending with pipes", { lint_msg <- rex::rex("Remove commented code.") expect_lint("# f() %>%", lint_msg, linter) - - skip_if_not_r_version("4.1.0") expect_lint("# f() |>", lint_msg, linter) }) diff --git a/tests/testthat/test-consecutive_mutate_linter.R b/tests/testthat/test-consecutive_mutate_linter.R index 044ad18ad..eced3c392 100644 --- a/tests/testthat/test-consecutive_mutate_linter.R +++ b/tests/testthat/test-consecutive_mutate_linter.R @@ -143,8 +143,6 @@ test_that("'parallel' calls are not linted", { }) test_that("native pipe is linted", { - skip_if_not_r_version("4.1.0") - linter <- consecutive_mutate_linter() lint_msg <- rex::rex("Unify consecutive calls to mutate().") diff --git a/tests/testthat/test-cyclocomp_linter.R b/tests/testthat/test-cyclocomp_linter.R index 391973c2f..26b599b45 100644 --- a/tests/testthat/test-cyclocomp_linter.R +++ b/tests/testthat/test-cyclocomp_linter.R @@ -63,7 +63,7 @@ test_that("returns the correct linting", { test_that("a null linter is returned, with warning, if cyclocomp is unavailable", { # simple requireNamspace->FALSE won't work since expect_no_lint checks for testthat local_mocked_bindings( - requireNamespace = function(pkg, ...) pkg != "cyclocomp" && base::requireNamespace(pkg, ...) + requireNamespace = \(pkg, ...) pkg != "cyclocomp" && base::requireNamespace(pkg, ...) ) expect_warning(regexp = "Please install", fixed = TRUE, { linter <- cyclocomp_linter(1L) diff --git a/tests/testthat/test-defaults.R b/tests/testthat/test-defaults.R index 15ca6e9cd..a0511bf78 100644 --- a/tests/testthat/test-defaults.R +++ b/tests/testthat/test-defaults.R @@ -19,7 +19,7 @@ test_that("undesirable functions and operators", { expect_type(x, "list") expect_gt(length(x), 0L) expect_true(all(nzchar(names(x)))) - expect_true(all(vapply(x, function(x) is.na(x) || is.character(x), logical(1L)))) + expect_true(all(vapply(x, \(x) is.na(x) || is.character(x), logical(1L)))) expect_true(all(lengths(x) == 1L)) } }) diff --git a/tests/testthat/test-duplicate_argument_linter.R b/tests/testthat/test-duplicate_argument_linter.R index 44040ab26..74ddd85cf 100644 --- a/tests/testthat/test-duplicate_argument_linter.R +++ b/tests/testthat/test-duplicate_argument_linter.R @@ -90,7 +90,6 @@ test_that("doesn't lint duplicated arguments in allowed functions", { linter ) - skip_if_not_r_version("4.1.0") expect_lint( "x |> dplyr::mutate( diff --git a/tests/testthat/test-expect_lint.R b/tests/testthat/test-expect_lint.R index bd6c37eeb..599d25aeb 100644 --- a/tests/testthat/test-expect_lint.R +++ b/tests/testthat/test-expect_lint.R @@ -76,7 +76,7 @@ test_that("expect_lint doesn't change language", { }) test_that("execution without testthat gives the right errors", { - local_mocked_bindings(requireNamespace = function(...) FALSE) + local_mocked_bindings(requireNamespace = \(...) FALSE) lint_msg <- function(nm) rex::rex("`", nm, "()` is designed to work", anything, "testthat") expect_error(expect_lint(), lint_msg("expect_lint")) @@ -87,7 +87,7 @@ test_that("execution without testthat gives the right errors", { test_that("lint order can be ignored", { linters <- list(assignment_linter(), infix_spaces_linter()) - expected <- lapply(linters, function(l) list(linter = attr(l, "name"))) + expected <- lapply(linters, \(l) list(linter = attr(l, "name"))) expect_success(expect_lint("a=1", expected, linters, ignore_order = TRUE)) expect_success(expect_lint("a=1", rev(expected), linters, ignore_order = TRUE)) diff --git a/tests/testthat/test-expect_true_false_linter.R b/tests/testthat/test-expect_true_false_linter.R index 8afc0edfb..ab6ee15ab 100644 --- a/tests/testthat/test-expect_true_false_linter.R +++ b/tests/testthat/test-expect_true_false_linter.R @@ -7,8 +7,6 @@ test_that("expect_true_false_linter skips allowed usages", { expect_no_lint("42 %>% expect_identical(42, ignore_attr = TRUE)", linter) expect_no_lint("42 %>% expect_identical(42, TRUE)", linter) - - skip_if_not_r_version("4.1.0") expect_no_lint("42 |> expect_identical(42, ignore_attr = TRUE)", linter) }) @@ -29,8 +27,6 @@ test_that("expect_true_false_linter blocks simple disallowed usages", { expect_lint("expect_equal(TRUE, foo(x))", lint_msg, linter) expect_lint("42 %T>% expect_equal(TRUE)", lint_msg, linter) - - skip_if_not_r_version("4.1.0") expect_lint("42 |> expect_equal(TRUE)", lint_msg, linter) }) diff --git a/tests/testthat/test-fixed_regex_linter.R b/tests/testthat/test-fixed_regex_linter.R index 5ce25a2dd..c3a4f979e 100644 --- a/tests/testthat/test-fixed_regex_linter.R +++ b/tests/testthat/test-fixed_regex_linter.R @@ -270,9 +270,7 @@ test_that("fixed replacement is correct with UTF-8", { #' are valid replacements. #' @noRd robust_non_printable_unicode <- function() { - if (getRversion() < "4.1.0") { - "abc\\U000a0defghi" - } else if (.Platform$OS.type == "windows") { + if (.Platform$OS.type == "windows") { "abc\U{0a0def}ghi" } else { "abc\\U{0a0def}ghi" @@ -315,12 +313,8 @@ local({ R"([\xa])", R"([\xa])", R"(\n)" ) if (.Platform$OS.type == "windows" && !hasName(R.Version(), "crt")) { - skip_cases <- c( - # These require UTF-8 support - "abc\\U{A0DEF}ghi", "[\\U1d4d7]", "[\\U{1D4D7}]", "\\u{A0}\\U{0001d4d7}", - # R version-specific difference in output message on Windows (probably r80051) - if (getRversion() == "4.0.4") "[\\U{F7D5}]" - ) + # These require UTF-8 support + skip_cases <- c("abc\\U{A0DEF}ghi", "[\\U1d4d7]", "[\\U{1D4D7}]", "\\u{A0}\\U{0001d4d7}") } else { skip_cases <- character() } diff --git a/tests/testthat/test-function_argument_linter.R b/tests/testthat/test-function_argument_linter.R index 8462d4d77..fc067f602 100644 --- a/tests/testthat/test-function_argument_linter.R +++ b/tests/testthat/test-function_argument_linter.R @@ -54,7 +54,6 @@ test_that("function_argument_linter blocks disallowed usages", { }) test_that("function_argument_linter also lints lambda expressions", { - skip_if_not_r_version("4.1.0") linter <- function_argument_linter() lint_msg <- rex::rex("Arguments without defaults should come before arguments with defaults.") diff --git a/tests/testthat/test-function_left_parentheses_linter.R b/tests/testthat/test-function_left_parentheses_linter.R index e45b1b7b0..8491ab043 100644 --- a/tests/testthat/test-function_left_parentheses_linter.R +++ b/tests/testthat/test-function_left_parentheses_linter.R @@ -198,7 +198,6 @@ test_that("newline in character string doesn't trigger false positive (#1963)", }) test_that("shorthand functions are handled", { - skip_if_not_r_version("4.1.0") linter <- function_left_parentheses_linter() fun_lint_msg <- rex::rex("Remove spaces before the left parenthesis in a function definition.") diff --git a/tests/testthat/test-implicit_assignment_linter.R b/tests/testthat/test-implicit_assignment_linter.R index 7621f7b62..a90e59ad1 100644 --- a/tests/testthat/test-implicit_assignment_linter.R +++ b/tests/testthat/test-implicit_assignment_linter.R @@ -91,7 +91,6 @@ test_that("implicit_assignment_linter skips allowed usages", { linter ) - skip_if_not_r_version("4.1.0") expect_no_lint( trim_some(" map(1:4, \\(x) { @@ -334,12 +333,9 @@ test_that("implicit_assignment_linter works as expected with pipes and walrus op expect_no_lint("data %>% mutate(a := b)", linter) expect_no_lint("dt %>% .[, z := x + y]", linter) expect_no_lint("data %<>% mutate(a := b)", linter) + expect_no_lint("data |> mutate(a := b)", linter) expect_no_lint("DT[i, x := i]", linter) - - skip_if_not_r_version("4.1.0") - - expect_no_lint("data |> mutate(a := b)", linter) }) test_that("parenthetical assignments are caught", { diff --git a/tests/testthat/test-indentation_linter.R b/tests/testthat/test-indentation_linter.R index a4e1f6a55..e9a24e03f 100644 --- a/tests/testthat/test-indentation_linter.R +++ b/tests/testthat/test-indentation_linter.R @@ -802,7 +802,6 @@ test_that("consecutive same-level lints are suppressed", { }) test_that("native pipe is supported", { - skip_if_not_r_version("4.1.0") linter <- indentation_linter() expect_no_lint( @@ -828,7 +827,6 @@ test_that("it doesn't error on invalid code", { }) test_that("function shorthand is handled", { - skip_if_not_r_version("4.1.0") linter <- indentation_linter() expect_no_lint( diff --git a/tests/testthat/test-infix_spaces_linter.R b/tests/testthat/test-infix_spaces_linter.R index 245ac8a4e..8cdd004f0 100644 --- a/tests/testthat/test-infix_spaces_linter.R +++ b/tests/testthat/test-infix_spaces_linter.R @@ -172,7 +172,6 @@ test_that("Rules around missing arguments are respected", { }) test_that("native pipe is supported", { - skip_if_not_r_version("4.1.0") linter <- infix_spaces_linter() expect_no_lint("a |> foo()", linter) diff --git a/tests/testthat/test-lengths_linter.R b/tests/testthat/test-lengths_linter.R index fbca36bd8..7b22befbe 100644 --- a/tests/testthat/test-lengths_linter.R +++ b/tests/testthat/test-lengths_linter.R @@ -32,8 +32,6 @@ test_that("lengths_linter blocks simple disallowed purrr usages", { }) test_that("lengths_linter blocks simple disallowed usages with pipes", { - skip_if_not_r_version("4.1.0") - linter <- lengths_linter() lint_msg <- rex::rex("Use lengths() to find the length of each element in a list.") diff --git a/tests/testthat/test-library_call_linter.R b/tests/testthat/test-library_call_linter.R index 0a6521734..da48da922 100644 --- a/tests/testthat/test-library_call_linter.R +++ b/tests/testthat/test-library_call_linter.R @@ -233,7 +233,6 @@ test_that("skips allowed usages of library()/character.only=TRUE", { expect_no_lint("function(pkg) library(pkg, character.only = TRUE)", linter) expect_no_lint("function(pkgs) sapply(pkgs, require, character.only = TRUE)", linter) - skip_if_not_r_version("4.1.0") expect_no_lint("\\(pkg) library(pkg, character.only = TRUE)", linter) expect_no_lint("\\(pkgs) sapply(pkgs, require, character.only = TRUE)", linter) }) diff --git a/tests/testthat/test-lint.R b/tests/testthat/test-lint.R index e47fbe339..1260fbb8a 100644 --- a/tests/testthat/test-lint.R +++ b/tests/testthat/test-lint.R @@ -205,7 +205,7 @@ test_that("old compatibility usage errors", { ) expect_error( - lint("a <- 1\n", linters = function(two, arguments) NULL), + lint("a <- 1\n", linters = \(two, arguments) NULL), error_msg ) @@ -218,7 +218,7 @@ test_that("old compatibility usage errors", { test_that("Linters throwing an error give a helpful error", { tmp_file <- withr::local_tempfile(lines = "a <- 1") lintr_error_msg <- "a broken linter" - linter <- function() Linter(function(source_expression) cli_abort(lintr_error_msg)) + linter <- function() Linter(\(source_expression) cli_abort(lintr_error_msg)) # NB: Some systems/setups may use e.g. symlinked files when creating under tempfile(); # we don't care much about that, so just check basename() expect_error(lint(tmp_file, linter()), lintr_error_msg, fixed = TRUE) @@ -227,7 +227,7 @@ test_that("Linters throwing an error give a helpful error", { test_that("Linter() input is validated", { expect_error(Linter(1L), "`fun` must be a function taking exactly one argument", fixed = TRUE) - expect_error(Linter(function(a, b) TRUE), "`fun` must be a function taking exactly one argument", fixed = TRUE) + expect_error(Linter(\(a, b) TRUE), "`fun` must be a function taking exactly one argument", fixed = TRUE) }) test_that("typo in argument name gives helpful error", { diff --git a/tests/testthat/test-linter_tags.R b/tests/testthat/test-linter_tags.R index b68c835ff..030a5dc24 100644 --- a/tests/testthat/test-linter_tags.R +++ b/tests/testthat/test-linter_tags.R @@ -34,7 +34,7 @@ test_that("available_tags returns a character vector", { test_that("default_linters and default tag match up", { avail <- available_linters() - tagged_default <- avail[["linter"]][vapply(avail[["tags"]], function(tags) "default" %in% tags, logical(1L))] + tagged_default <- avail[["linter"]][vapply(avail[["tags"]], \(tags) "default" %in% tags, logical(1L))] expect_identical(tagged_default, names(default_linters)) }) @@ -96,7 +96,7 @@ test_that("lintr help files are up to date", { lintr_db <- available_linters(exclude_tags = NULL) lintr_db$package <- NULL - lintr_db$tags <- lapply(lintr_db$tags, function(x) if ("deprecated" %in% x) "deprecated" else sort(x)) + lintr_db$tags <- lapply(lintr_db$tags, \(x) if ("deprecated" %in% x) "deprecated" else sort(x)) lintr_db <- lintr_db[order(lintr_db$linter), ] expect_true("linters.Rd" %in% names(help_db), info = "?linters exists") @@ -189,7 +189,7 @@ test_that("lintr help files are up to date", { )[[1L]] # those entries in available_linters() with the current tag - db_linter_has_tag <- vapply(lintr_db$tags, function(linter_tag) any(tag %in% linter_tag), logical(1L)) + db_linter_has_tag <- vapply(lintr_db$tags, \(linter_tag) any(tag %in% linter_tag), logical(1L)) expected <- lintr_db$linter[db_linter_has_tag] expect_identical( @@ -201,11 +201,11 @@ test_that("lintr help files are up to date", { # (3) the 'configurable' tag applies if and only if the linter has parameters has_args <- 0L < lengths(Map( - function(linter, tags) if ("deprecated" %in% tags) NULL else formals(match.fun(linter)), + \(linter, tags) if ("deprecated" %in% tags) NULL else formals(match.fun(linter)), lintr_db$linter, lintr_db$tags )) - has_configurable_tag <- vapply(lintr_db$tags, function(tags) "configurable" %in% tags, logical(1L)) + has_configurable_tag <- vapply(lintr_db$tags, \(tags) "configurable" %in% tags, logical(1L)) expect_identical(has_configurable_tag, unname(has_args)) }) @@ -226,7 +226,7 @@ test_that("all linters have at least one tag", { test_that("other packages' linters can be included", { db_loc <- withr::local_tempdir() local_mocked_bindings( - system.file = function(..., package) file.path(db_loc, package, ...) + system.file = \(..., package) file.path(db_loc, package, ...) ) custom_db <- data.frame( diff --git a/tests/testthat/test-methods.R b/tests/testthat/test-methods.R index f8aef14e1..aaa7159a7 100644 --- a/tests/testthat/test-methods.R +++ b/tests/testthat/test-methods.R @@ -100,7 +100,7 @@ test_that("print.lint works for inline data, even in RStudio", { skip_if_not_installed("rstudioapi") local_mocked_bindings( - hasFun = function(...) FALSE, + hasFun = \(...) FALSE, .package = "rstudioapi" ) withr::with_options( diff --git a/tests/testthat/test-nested_pipe_linter.R b/tests/testthat/test-nested_pipe_linter.R index 1e1679238..8b922146e 100644 --- a/tests/testthat/test-nested_pipe_linter.R +++ b/tests/testthat/test-nested_pipe_linter.R @@ -127,8 +127,6 @@ test_that("allow_outer_calls= argument works", { }) test_that("Native pipes are handled as well", { - skip_if_not_r_version("4.1.0") - linter <- nested_pipe_linter() linter_inline <- nested_pipe_linter(allow_inline = FALSE) lint_msg <- rex::rex("Don't nest pipes inside other calls.") diff --git a/tests/testthat/test-nrow_subset_linter.R b/tests/testthat/test-nrow_subset_linter.R index 8f1d49f24..9a059017d 100644 --- a/tests/testthat/test-nrow_subset_linter.R +++ b/tests/testthat/test-nrow_subset_linter.R @@ -45,8 +45,6 @@ test_that("linter is pipeline-aware", { lint_msg <- "Use arithmetic to count the number of rows satisfying a condition" expect_lint("x %>% subset(y == z) %>% nrow()", lint_msg, linter) - expect_lint("filter(x, y == z) %>% nrow()", lint_msg, linter) - - skip_if_not_r_version("4.1.0") expect_lint("x |> subset(y == z) |> nrow()", lint_msg, linter) + expect_lint("filter(x, y == z) %>% nrow()", lint_msg, linter) }) diff --git a/tests/testthat/test-object_length_linter.R b/tests/testthat/test-object_length_linter.R index 051c6bf2f..aeabce9af 100644 --- a/tests/testthat/test-object_length_linter.R +++ b/tests/testthat/test-object_length_linter.R @@ -66,8 +66,6 @@ test_that("object_length_linter won't fail if dependency has no exports", { }) test_that("function shorthand is caught", { - skip_if_not_r_version("4.1.0") - expect_lint( "abcdefghijklm <- \\() NULL", "function names", diff --git a/tests/testthat/test-object_name_linter.R b/tests/testthat/test-object_name_linter.R index ad09b06c7..2e1db7f95 100644 --- a/tests/testthat/test-object_name_linter.R +++ b/tests/testthat/test-object_name_linter.R @@ -26,7 +26,7 @@ test_that("default styles are linted correctly", { function(nm, ok) { lapply( setdiff(1L:30L, ok), - function(bad) list(linter = nm, line_number = bad) + \(bad) list(linter = nm, line_number = bad) ) }, names(ok_lines), @@ -305,8 +305,6 @@ test_that("complex LHS of := doesn't cause false positive", { }) test_that("function shorthand also lints", { - skip_if_not_r_version("4.1.0") - expect_lint("aBc <- \\() NULL", "function name style", object_name_linter()) }) diff --git a/tests/testthat/test-object_overwrite_linter.R b/tests/testthat/test-object_overwrite_linter.R index 175c4e7e8..679513470 100644 --- a/tests/testthat/test-object_overwrite_linter.R +++ b/tests/testthat/test-object_overwrite_linter.R @@ -139,8 +139,6 @@ test_that("non-<- assignments are detected", { }) test_that("shorthand lambda is detected", { - skip_if_not_r_version("4.1.0") - expect_lint("\\() data <- 1", "'data' is an exported object", object_overwrite_linter()) }) diff --git a/tests/testthat/test-object_usage_linter.R b/tests/testthat/test-object_usage_linter.R index 4283e16d6..df481b891 100644 --- a/tests/testthat/test-object_usage_linter.R +++ b/tests/testthat/test-object_usage_linter.R @@ -802,8 +802,6 @@ test_that("NSE-ish symbols after $/@ are ignored as sources for lints", { }) test_that("functional lambda definitions are also caught", { - skip_if_not_r_version("4.1.0") - expect_lint( trim_some(" fun <- \\() { diff --git a/tests/testthat/test-one_call_pipe_linter.R b/tests/testthat/test-one_call_pipe_linter.R index 9cf7a60e9..94b32cf66 100644 --- a/tests/testthat/test-one_call_pipe_linter.R +++ b/tests/testthat/test-one_call_pipe_linter.R @@ -70,8 +70,6 @@ test_that("multiple lints are generated correctly", { # nofuzz }) test_that("Native pipes are handled as well", { - skip_if_not_r_version("4.1.0") - linter <- one_call_pipe_linter() expect_lint( # nofuzz diff --git a/tests/testthat/test-package_hooks_linter.R b/tests/testthat/test-package_hooks_linter.R index 7a668b833..c72427128 100644 --- a/tests/testthat/test-package_hooks_linter.R +++ b/tests/testthat/test-package_hooks_linter.R @@ -256,7 +256,6 @@ test_that("package_hooks_linter detects bad argument names in 'teardown' hooks", }) test_that("function shorthand is handled", { - skip_if_not_r_version("4.1.0") linter <- package_hooks_linter() expect_lint( diff --git a/tests/testthat/test-paren_body_linter.R b/tests/testthat/test-paren_body_linter.R index dac02cae4..e461ea1a3 100644 --- a/tests/testthat/test-paren_body_linter.R +++ b/tests/testthat/test-paren_body_linter.R @@ -44,7 +44,6 @@ testthat::test_that("paren_body_linter returns correct lints", { expect_lint("function()if(TRUE)while(TRUE)test", list(lint_msg, lint_msg, lint_msg), linter) # No space after the closing parenthesis of an anonymous function prompts a lint - skip_if_not_r_version("4.1.0") expect_lint("\\()test", lint_msg, linter) }) @@ -77,7 +76,6 @@ test_that("multi-line versions are caught", { linter ) - skip_if_not_r_version("4.1.0") expect_lint( trim_some(" \\(var @@ -89,7 +87,6 @@ test_that("multi-line versions are caught", { }) test_that("function shorthand is handled", { - skip_if_not_r_version("4.1.0") linter <- paren_body_linter() lint_msg <- rex::rex("Put a space between a right parenthesis and a body expression.") diff --git a/tests/testthat/test-pipe_consistency_linter.R b/tests/testthat/test-pipe_consistency_linter.R index 2197fa329..8a677cbb6 100644 --- a/tests/testthat/test-pipe_consistency_linter.R +++ b/tests/testthat/test-pipe_consistency_linter.R @@ -1,6 +1,5 @@ # nofuzz start test_that("pipe_consistency skips allowed usage", { - skip_if_not_r_version("4.1.0") linter <- pipe_consistency_linter() expect_no_lint("1:3 |> mean() |> as.character()", linter) @@ -18,7 +17,6 @@ test_that("pipe_consistency skips allowed usage", { }) test_that("pipe_consistency lints blocked usage", { - skip_if_not_r_version("4.1.0") linter <- pipe_consistency_linter() lint_message <- rex::rex("Use the |> pipe operator instead of the %>% pipe operator.") @@ -56,8 +54,6 @@ test_that("pipe_consistency lints blocked usage", { test_that("pipe_consistency_linter works with |> argument", { - skip_if_not_r_version("4.1.0") - linter <- pipe_consistency_linter(pipe = "|>") lint_message <- rex::rex("Use the |> pipe operator instead of the %>% pipe operator.") lint_message_tee <- rex::rex("Use the |> pipe operator instead of the %T>% pipe operator.") @@ -114,8 +110,6 @@ test_that("pipe_consistency_linter works with |> argument", { }) test_that("pipe_consistency_linter works with %>% argument", { - skip_if_not_r_version("4.1.0") - linter <- pipe_consistency_linter(pipe = "%>%") expected_message <- rex::rex("Use the %>% pipe operator instead of the |> pipe operator.") @@ -151,8 +145,6 @@ test_that("pipe_consistency_linter works with %>% argument", { }) test_that("simply enforcing a consistent style is supported", { - skip_if_not_r_version("4.1.0") - linter <- pipe_consistency_linter("auto") lint_message <- rex::rex("Stick to one pipe operator; found 1 instances of %>% and 1 instances of |>.") diff --git a/tests/testthat/test-pipe_continuation_linter.R b/tests/testthat/test-pipe_continuation_linter.R index 89633f6b2..31ae665a4 100644 --- a/tests/testthat/test-pipe_continuation_linter.R +++ b/tests/testthat/test-pipe_continuation_linter.R @@ -76,8 +76,6 @@ test_that("pipe-continuation linter correctly handles nesting", { }) test_that("pipe-continuation linter handles native pipe", { - skip_if_not_r_version("4.1.0") - linter <- pipe_continuation_linter() lint_msg_native <- rex::rex("Put a space before `|>` and a new line after it,") lint_msg_magrittr <- rex::rex("Put a space before `%>%` and a new line after it,") diff --git a/tests/testthat/test-return_linter.R b/tests/testthat/test-return_linter.R index 1a228e912..871bc4f4b 100644 --- a/tests/testthat/test-return_linter.R +++ b/tests/testthat/test-return_linter.R @@ -31,8 +31,6 @@ test_that("Lint return on end of function", { }) test_that("Lint return on end of lambda function", { - skip_if_not_r_version("4.1.0") - expect_lint( trim_some(" \\(bar) { @@ -781,8 +779,6 @@ test_that("return_linter skips invokeRestart(), tryInvokeRestart()", { # NB: x |> return() is blocked by the parser, so no need to test that. test_that("Native pipes are handled correctly", { - skip_if_not_r_version("4.1.0") - linter <- return_linter(return_style = "explicit") lint_msg <- rex::rex("All functions must have an explicit return().") diff --git a/tests/testthat/test-rstudio_markers.R b/tests/testthat/test-rstudio_markers.R index 50adcd1cf..6f261027b 100644 --- a/tests/testthat/test-rstudio_markers.R +++ b/tests/testthat/test-rstudio_markers.R @@ -1,8 +1,8 @@ test_that("it returns markers which match lints", { skip_if_not_installed("rstudioapi") local_mocked_bindings( - callFun = function(...) list(...), - executeCommand = function(...) NULL, + callFun = \(...) list(...), + executeCommand = \(...) NULL, .package = "rstudioapi" ) @@ -57,8 +57,8 @@ test_that("it returns markers which match lints", { test_that("it prepends the package path if it exists", { skip_if_not_installed("rstudioapi") local_mocked_bindings( - callFun = function(...) list(...), - executeCommand = function(...) NULL, + callFun = \(...) list(...), + executeCommand = \(...) NULL, .package = "rstudioapi" ) @@ -86,8 +86,8 @@ test_that("it prepends the package path if it exists", { test_that("it returns an empty list of markers if there are no lints", { skip_if_not_installed("rstudioapi") local_mocked_bindings( - callFun = function(...) list(...), - executeCommand = function(...) NULL, + callFun = \(...) list(...), + executeCommand = \(...) NULL, .package = "rstudioapi" ) @@ -105,10 +105,10 @@ test_that("rstudio_source_markers apply to print within rstudio", { skip_if_not_installed("rstudioapi") local_mocked_bindings( - hasFun = function(...) TRUE, + hasFun = \(...) TRUE, .package = "rstudioapi" ) - local_mocked_bindings(rstudio_source_markers = function(x) cat("matched\n")) + local_mocked_bindings(rstudio_source_markers = \(x) cat("matched\n")) l <- lint(tmp, seq_linter()) expect_output(print(l), "matched", fixed = TRUE) diff --git a/tests/testthat/test-spaces_inside_linter.R b/tests/testthat/test-spaces_inside_linter.R index ff0981ab5..d467ef7ae 100644 --- a/tests/testthat/test-spaces_inside_linter.R +++ b/tests/testthat/test-spaces_inside_linter.R @@ -199,8 +199,6 @@ test_that("multi-line expressions have good markers", { }) test_that("spaces_inside_linter blocks disallowed usages with a pipe", { - skip_if_not_r_version("4.1.0") - linter <- spaces_inside_linter() expect_lint( diff --git a/tests/testthat/test-sprintf_linter.R b/tests/testthat/test-sprintf_linter.R index 25905febc..d82be1ebc 100644 --- a/tests/testthat/test-sprintf_linter.R +++ b/tests/testthat/test-sprintf_linter.R @@ -20,7 +20,7 @@ patrick::with_parameters_test_that( "sprintf_linter blocks disallowed usages", { linter <- sprintf_linter() - unused_arg_msg <- if (getRversion() >= "4.1.0") "one argument not used by format" else NULL + unused_arg_msg <- "one argument not used by format" expect_lint(paste0(call_name, "('hello', 1)"), "constant", linter) @@ -138,7 +138,7 @@ local({ # Nested pipes expect_lint( paste("'%%sb'", pipe, "sprintf('%s')", pipe, "sprintf('a')"), - if (getRversion() >= "4.1.0") list(column_number = nchar(paste("'%%sb'", pipe, "x")), message = "constant"), + list(column_number = nchar(paste("'%%sb'", pipe, "x")), message = "constant"), linter ) expect_lint( @@ -178,8 +178,6 @@ test_that("pipe logic survives adversarial comments", { }) test_that("lints vectorize", { - skip_if_not_r_version("4.1.0") - expect_lint( trim_some("{ sprintf('%s', a, b) diff --git a/tests/testthat/test-terminal_close_linter.R b/tests/testthat/test-terminal_close_linter.R index 2423745c5..9d327788a 100644 --- a/tests/testthat/test-terminal_close_linter.R +++ b/tests/testthat/test-terminal_close_linter.R @@ -27,7 +27,6 @@ test_that("terminal_close_linter skips allowed cases", { ") expect_no_lint(lines, linter) - skip_if_not_r_version("4.1.0") lines <- trim_some(" foo <- \\(bar) { close <- bar + 1 @@ -83,8 +82,6 @@ test_that("terminal_close_linter blocks simple cases", { }) test_that("lints vectorize", { - skip_if_not_r_version("4.1.0") - expect_lint( trim_some("{ foo <- function() { diff --git a/tests/testthat/test-unnecessary_lambda_linter.R b/tests/testthat/test-unnecessary_lambda_linter.R index f3228058b..b03a0e4ae 100644 --- a/tests/testthat/test-unnecessary_lambda_linter.R +++ b/tests/testthat/test-unnecessary_lambda_linter.R @@ -277,7 +277,6 @@ test_that("cases with braces are caught", { }) test_that("function shorthand is handled", { - skip_if_not_r_version("4.1.0") linter <- unnecessary_lambda_linter() linter_allow <- unnecessary_lambda_linter(allow_comparison = TRUE) diff --git a/tests/testthat/test-unnecessary_nesting_linter.R b/tests/testthat/test-unnecessary_nesting_linter.R index 64c09855a..745897cf4 100644 --- a/tests/testthat/test-unnecessary_nesting_linter.R +++ b/tests/testthat/test-unnecessary_nesting_linter.R @@ -187,7 +187,6 @@ test_that("unnecessary_nesting_linter skips one-line functions", { ) # ditto short-hand lambda - skip_if_not_r_version("4.1.0") expect_no_lint( trim_some(" foo <- \\(x) { diff --git a/tests/testthat/test-unreachable_code_linter.R b/tests/testthat/test-unreachable_code_linter.R index b54d3b11e..3b644b94c 100644 --- a/tests/testthat/test-unreachable_code_linter.R +++ b/tests/testthat/test-unreachable_code_linter.R @@ -574,8 +574,6 @@ test_that("unreachable_code_linter identifies unreachable code in mixed conditio }) test_that("function shorthand is handled", { - skip_if_not_r_version("4.1.0") - expect_lint( trim_some(" foo <- \\(bar) { @@ -604,8 +602,6 @@ test_that("Do not lint inline else after stop in inline function", { }) test_that("Do not lint inline else after stop in inline lambda function", { - skip_if_not_r_version("4.1.0") - linter <- unreachable_code_linter() expect_lint("\\(x) if (x > 3L) stop() else x + 3", NULL, linter) diff --git a/tests/testthat/test-vector_logic_linter.R b/tests/testthat/test-vector_logic_linter.R index d9d5d2f20..dcb991c70 100644 --- a/tests/testthat/test-vector_logic_linter.R +++ b/tests/testthat/test-vector_logic_linter.R @@ -115,8 +115,6 @@ test_that("incorrect subset/filter usage is caught", { }) test_that("native pipe usage is caught in subset/filter logic", { - skip_if_not_r_version("4.1.0") - expect_lint("x |> filter(y && z)", rex::rex("Use `&` in subsetting"), vector_logic_linter()) }) diff --git a/tests/testthat/test-whitespace_linter.R b/tests/testthat/test-whitespace_linter.R index 76bfab1ed..a308060c8 100644 --- a/tests/testthat/test-whitespace_linter.R +++ b/tests/testthat/test-whitespace_linter.R @@ -39,8 +39,6 @@ test_that("whitespace_linter blocks disallowed usages", { }) test_that("whitespace_linter blocks disallowed usages with a pipe", { - skip_if_not_r_version("4.1.0") - linter <- whitespace_linter() lint_msg <- rex::rex("Use spaces to indent, not tabs.") diff --git a/tests/testthat/test-with.R b/tests/testthat/test-with.R index dc0e19494..2dd9fb854 100644 --- a/tests/testthat/test-with.R +++ b/tests/testthat/test-with.R @@ -53,7 +53,6 @@ test_that("all default linters are tagged default", { expect_length(linters_with_tags(NULL, exclude_tags = available_tags()), 0L) # Check that above test also trips on default arguments. - skip_if_not_r_version("4.1.0") # Desired all.equal behavior only available in >= 4.1 expect_identical( all.equal(linters_with_tags("default"), linters_with_defaults(line_length_linter(120L))), c( @@ -94,7 +93,7 @@ test_that("linters_with_defaults(default = .) is supported with a deprecation wa expect_named(linters, c("default", "whitespace_linter")) # if default= is explicitly provided alongside defaults=, assume that was intentional - default <- Linter(function(.) list()) + default <- Linter(\(.) list()) expect_silent({ linters <- linters_with_defaults(defaults = list(), default = default) })