Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop our internal %|||% helper #2810

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions .lintr
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@ linters: all_linters(
line_length_linter(120L),
object_overwrite_linter(allow_names = c("line", "lines", "pipe", "symbols")),
todo_comment_linter(
except_regex = rex::rex(
"TODO(",
# GitHub issue number #1234, possibly from another repo org/repo#5678
maybe(one_or_more(character_class("a-zA-Z0-9-")), "/", one_or_more(character_class("a-zA-Z0-9._-"))),
"#", one_or_more(digit),
")"
except_regex = c(
rex::rex(
"TODO(",
# GitHub issue number #1234, possibly from another repo org/repo#5678
maybe(one_or_more(character_class("a-zA-Z0-9-")), "/", one_or_more(character_class("a-zA-Z0-9._-"))),
"#", one_or_more(digit),
")"
),
rex::rex(
"TODO(",
"R>", maybe("="), digit, ".", digit, maybe(".", digit),
")"
)
)
),
undesirable_function_name_linter = undesirable_function_linter(modify_defaults(
Expand Down
2 changes: 1 addition & 1 deletion R/methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ summary.lints <- function(object, ...) {
tbl <- table(filenames, types)
filenames <- rownames(tbl)
res <- as.data.frame.matrix(tbl, row.names = NULL)
res$filenames <- filenames %|||% character()
res$filenames <- filenames %||% character()
nms <- colnames(res)
res[order(res$filenames), c("filenames", nms[nms != "filenames"])]
}
2 changes: 1 addition & 1 deletion R/object_usage_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ object_usage_linter <- function(interpret_glue = NULL, interpret_extensions = c(
Linter(linter_level = "file", function(source_expression) {
pkg_name <- pkg_name(find_package(dirname(source_expression$filename)))

declared_globals <- try_silently(globalVariables(package = pkg_name %|||% globalenv()))
declared_globals <- try_silently(globalVariables(package = pkg_name %||% globalenv()))

xml <- source_expression$full_xml_parsed_content

Expand Down
2 changes: 1 addition & 1 deletion R/settings.R
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ validate_named_exclusion <- function(exclusions, idx) {
lintr_option <- function(setting, default = NULL) getOption(paste0("lintr.", setting), default)

get_setting <- function(setting, config, defaults) {
lintr_option(setting) %|||% config[[setting]] %|||% defaults[[setting]]
lintr_option(setting) %||% config[[setting]] %||% defaults[[setting]]
}

reset_settings <- function() list2env(default_settings, envir = settings)
Expand Down
3 changes: 2 additions & 1 deletion R/settings_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,6 @@ pkg_name <- function(path = find_package()) {
if (is.null(path)) {
return(NULL)
}
read.dcf(file.path(path, "DESCRIPTION"), fields = "Package")[1L]
nm <- read.dcf(file.path(path, "DESCRIPTION"), fields = "Package")[1L]
if (!is.na(nm)) nm
}
4 changes: 3 additions & 1 deletion R/trailing_blank_lines_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ trailing_blank_lines_linter <- function() {

if (identical(source_expression$terminal_newline, FALSE)) { # could use isFALSE, but needs backports
last_line <- tail(source_expression$file_lines, 1L)
line_width <- nchar(last_line)
if (is.na(line_width)) line_width <- 0L

lints[[length(lints) + 1L]] <- Lint(
filename = source_expression$filename,
line_number = length(source_expression$file_lines),
column_number = (nchar(last_line) %|||% 0L) + 1L,
column_number = line_width + 1L,
type = "style",
message = "Add a terminal newline.",
line = last_line
Expand Down
13 changes: 5 additions & 8 deletions R/utils.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
# TODO(#2768): possibly just use %||% instead
`%|||%` <- function(x, y) {
if (is.null(x) || length(x) == 0L || (is.atomic(x[[1L]]) && is.na(x[[1L]]))) {
y
} else {
x
}
# TODO(R>=4.4.0): remove this.
# NB: {backports} approach doesn't work since we need this before .onLoad() in names2()
if (!exists("%||%", "package:base")) {
`%||%` <- function(x, y) if (is.null(x)) y else x # nolint: coalesce_linter.
}

`%==%` <- function(x, y) {
Expand Down Expand Up @@ -84,7 +81,7 @@ auto_names <- function(x) {

# The following functions is from dplyr
names2 <- function(x) {
names(x) %|||% rep("", length(x))
names(x) %||% rep("", length(x))
}

get_content <- function(lines, info) {
Expand Down
3 changes: 0 additions & 3 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,6 @@ logical_env <- function(x, unset = "") {
# R>=4.1.0: ...names
backports::import(pkgname, "...names")

# R>=4.4.0: %||%
backports::import(pkgname, "%||%")

utils::assignInMyNamespace("default_settings", list(
linters = default_linters,
encoding = "UTF-8",
Expand Down
Loading