diff --git a/.lintr b/.lintr index 98dcf3ec7e..a111d08d69 100644 --- a/.lintr +++ b/.lintr @@ -1,6 +1,5 @@ linters: with_defaults( # The following TODOs are part of an effort to have {lintr} lint-free (#584) line_length_linter = line_length_linter(120), - infix_spaces_linter = NULL, # TODO enable (#594) cyclocomp_linter = cyclocomp_linter(29), # TODO reduce to 15 object_name_linter = NULL, # TODO enable (#597) equals_na_linter = NULL, # TODO enable (#601) diff --git a/R/T_and_F_symbol_linter.R b/R/T_and_F_symbol_linter.R index 8a7401265f..6858379a43 100644 --- a/R/T_and_F_symbol_linter.R +++ b/R/T_and_F_symbol_linter.R @@ -9,7 +9,7 @@ T_and_F_symbol_linter <- function(source_file) { token <- with_id(source_file, id) symbol <- re_matches(token[["text"]], rex(start, capture(or("T", "F")), end))[1L, 1L] if (!is.na(symbol)) { - replacement <- switch(symbol, "T"="TRUE", "F"="FALSE") + replacement <- switch(symbol, "T" = "TRUE", "F" = "FALSE") line_num <- token[["line2"]] start_col_num <- token[["col1"]] end_col_num <- token[["col2"]] diff --git a/R/commas_linter.R b/R/commas_linter.R index e56d4a4912..5037a772cb 100644 --- a/R/commas_linter.R +++ b/R/commas_linter.R @@ -38,7 +38,7 @@ commas_linter <- function(source_file) { empty_comma <- substr(line, comma_loc - 2L, comma_loc - 1L) %==% ", " parent <- source_file$parsed_content$parent - parent <- replace(parent, parent==0, NA) + parent <- replace(parent, parent == 0, NA) # a variable that is true for every node who has a grandchild that is switch, # i.e, any expression that starts with the function call to switch. @@ -50,7 +50,7 @@ commas_linter <- function(source_file) { is_blank_switch <- any(comma_loc_filter & (source_file$parsed_content$parent %in% switch_grandparents) & c(NA, head(source_file$parsed_content$token, -1)) == "EQ_SUB", - na.rm=TRUE + na.rm = TRUE ) if (has_token && !start_of_line && !empty_comma && !is_blank_switch) { diff --git a/R/expect_lint.R b/R/expect_lint.R index 4fc134d10e..6a67712d56 100644 --- a/R/expect_lint.R +++ b/R/expect_lint.R @@ -51,7 +51,7 @@ expect_lint <- function(content, checks, ..., file = NULL, language = "en") { lints <- lint(file, ...) n_lints <- length(lints) - lint_str <- if (n_lints) paste0(c("", lints), collapse="\n") else "" + lint_str <- if (n_lints) paste0(c("", lints), collapse = "\n") else "" wrong_number_fmt <- "got %d lints instead of %d%s" if (is.null(checks)) { diff --git a/R/extraction_operator_linter.R b/R/extraction_operator_linter.R index 526b6ce6a1..185007bc54 100644 --- a/R/extraction_operator_linter.R +++ b/R/extraction_operator_linter.R @@ -5,7 +5,7 @@ extraction_operator_linter <- function(source_file) { tokens <- source_file[["parsed_content"]] <- filter_out_token_type(source_file[["parsed_content"]], "expr") lapply( - ids_with_token(source_file, c("'$'", "'['"), fun=`%in%`), + ids_with_token(source_file, c("'$'", "'['"), fun = `%in%`), function(token_num) { if (is_dollar_extract(token_num, tokens) || is_bracket_extract(token_num, tokens)) { token <- with_id(source_file, token_num) diff --git a/R/namespace.R b/R/namespace.R index 503126539f..20c92a2b30 100644 --- a/R/namespace.R +++ b/R/namespace.R @@ -2,7 +2,7 @@ namespace_imports <- function(path = find_package()) { imports <- tryCatch({ pkg_name <- suppressWarnings(pkg_name(path)) - data <- parseNamespaceFile(package=pkg_name, package.lib=file.path(path, "..")) + data <- parseNamespaceFile(package = pkg_name, package.lib = file.path(path, "..")) data$imports }, error = function(e) { list() diff --git a/R/object_name_linters.R b/R/object_name_linters.R index 4e420e12c1..5b701d853c 100644 --- a/R/object_name_linters.R +++ b/R/object_name_linters.R @@ -122,7 +122,7 @@ make_object_linter <- function(fun) { function(source_file) { token_nums <- ids_with_token( - source_file, rex(start, "SYMBOL" %if_next_isnt% "_SUB"), fun=re_matches + source_file, rex(start, "SYMBOL" %if_next_isnt% "_SUB"), fun = re_matches ) if (length(token_nums) == 0) { return(list()) diff --git a/R/path_linters.R b/R/path_linters.R index 6d7ab37874..db6ce21ecb 100644 --- a/R/path_linters.R +++ b/R/path_linters.R @@ -1,4 +1,4 @@ -control_char_regex <- rex(one_of(intToUtf8(seq.int(0L, 31L), multiple=TRUE))) +control_char_regex <- rex(one_of(intToUtf8(seq.int(0L, 31L), multiple = TRUE))) # control chars (non-printing) win32_bad_punct_regex <- rex(one_of("*", "?", "\"", "<", ">", "|", ":", "/", "\\")) @@ -121,7 +121,7 @@ split_path <- function(path, sep="/|\\\\") { } i <- i - 1L if (i > 0L) { - dirs <- c(paste0(rep(prefix, i), collapse=""), tail(dirs, -i)) + dirs <- c(paste0(rep(prefix, i), collapse = ""), tail(dirs, -i)) } # add // to protocols (like http, smb, ...) if (length(dirs)) { diff --git a/R/undesirable_function_linter.R b/R/undesirable_function_linter.R index 8ca4d6e083..a367313229 100644 --- a/R/undesirable_function_linter.R +++ b/R/undesirable_function_linter.R @@ -34,7 +34,7 @@ undesirable_function_linter <- function(fun = default_undesirable_functions, line_number = line_num, column_number = start_col_num, type = "warning", - message = paste0(msg, collapse=" "), + message = paste0(msg, collapse = " "), line = source_file[["lines"]][[as.character(line_num)]], ranges = list(c(start_col_num, end_col_num)), linter = "undesirable_function_linter" diff --git a/R/undesirable_operator_linter.R b/R/undesirable_operator_linter.R index cc4430ab11..39370d4a4e 100644 --- a/R/undesirable_operator_linter.R +++ b/R/undesirable_operator_linter.R @@ -13,10 +13,10 @@ op_types <- c( #' @param op Named character vector, where the names are the names of the undesirable operators, #' and the values are the text for the alternative operator to use (or \code{NA}). #' @export -undesirable_operator_linter <- function(op=default_undesirable_operators) { +undesirable_operator_linter <- function(op = default_undesirable_operators) { function(source_file) { lapply( - ids_with_token(source_file, op_types, fun=`%in%`), + ids_with_token(source_file, op_types, fun = `%in%`), function(id) { token <- with_id(source_file, id) op_name <- token[["text"]] @@ -34,7 +34,7 @@ undesirable_operator_linter <- function(op=default_undesirable_operators) { line_number = line_num, column_number = start_col_num, type = "warning", - message = paste0(msg, collapse=" "), + message = paste0(msg, collapse = " "), line = source_file[["lines"]][[as.character(line_num)]], ranges = list(c(start_col_num, end_col_num)), linter = "undesirable_function_linter" diff --git a/R/utils.R b/R/utils.R index 4754e92e89..dc88a89416 100644 --- a/R/utils.R +++ b/R/utils.R @@ -182,7 +182,7 @@ escape_chars <- c( unescape <- function(str, q="`") { names(q) <- paste0("\\", q) my_escape_chars <- c(escape_chars, q) - res <- gregexpr(text=str, pattern=rex(or(names(my_escape_chars)))) + res <- gregexpr(text = str, pattern = rex(or(names(my_escape_chars)))) all_matches <- regmatches(str, res) regmatches(str, res) <- lapply( all_matches,