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

enable infix_spaces_linter, and apply it to the package #639

Merged
merged 9 commits into from
Dec 5, 2020
1 change: 0 additions & 1 deletion .lintr
Original file line number Diff line number Diff line change
@@ -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)
spaces_inside_linter = NULL, # TODO enable (#598)
Expand Down
2 changes: 1 addition & 1 deletion R/T_and_F_symbol_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"]]
Expand Down
4 changes: 2 additions & 2 deletions R/commas_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion R/expect_lint.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion R/extraction_operator_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion R/namespace.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion R/object_name_linters.R
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
4 changes: 2 additions & 2 deletions R/path_linters.R
Original file line number Diff line number Diff line change
@@ -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("*", "?", "\"", "<", ">", "|", ":", "/", "\\"))
Expand Down Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion R/undesirable_function_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions R/undesirable_operator_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"]]
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down