diff --git a/.lintr_new b/.lintr_new index b3aabf487..4e9195d35 100644 --- a/.lintr_new +++ b/.lintr_new @@ -23,6 +23,7 @@ linters: linters_with_defaults( redundant_ifelse_linter(), sprintf_linter(), strings_as_factors_linter(), + undesirable_operator_linter(), unnecessary_lambda_linter(), unneeded_concatenation_linter(allow_single_expression = FALSE), yoda_test_linter() diff --git a/R/expect_lint.R b/R/expect_lint.R index 5031c4aaa..9d041d9e3 100644 --- a/R/expect_lint.R +++ b/R/expect_lint.R @@ -84,7 +84,7 @@ expect_lint <- function(content, checks, ..., file = NULL, language = "en") { lint_fields <- unique(c(names(formals(Lint)), "linter")) Map( function(lint, check) { - itr <<- itr + 1L + itr <<- itr + 1L # nolint: undesirable_operator. lapply(names(check), function(field) { if (!field %in% lint_fields) { stop(sprintf( diff --git a/R/get_source_expressions.R b/R/get_source_expressions.R index 0495599d2..cd2ab6aa8 100644 --- a/R/get_source_expressions.R +++ b/R/get_source_expressions.R @@ -588,7 +588,7 @@ tab_offsets <- function(tab_columns) { tab_columns - 1L, function(tab_idx) { offset <- 7L - (tab_idx + cum_offset) %% 8L # using a tab width of 8 characters - cum_offset <<- cum_offset + offset + cum_offset <<- cum_offset + offset # nolint: undesirable_operator. offset }, integer(1L), diff --git a/R/lint.R b/R/lint.R index 310fb69ba..6c0f0d349 100644 --- a/R/lint.R +++ b/R/lint.R @@ -641,8 +641,7 @@ sarif_output <- function(lints, filename = "lintr_results.sarif") { one_result <- append(one_result, c(ruleId = lint$linter)) one_result <- append(one_result, c(ruleIndex = rule_index)) - one_result <- - append(one_result, list(message = list(text = lint$message))) + one_result <- append(one_result, list(message = list(text = lint$message))) one_location <- list(physicalLocation = list( artifactLocation = list( uri = gsub("\\", "/", lint$filename, fixed = TRUE), @@ -654,11 +653,8 @@ sarif_output <- function(lints, filename = "lintr_results.sarif") { snippet = list(text = lint$line) ) )) - one_result <- - append(one_result, c(locations = list(list(one_location)))) - - sarif$runs[[1L]]$results <- - append(sarif$runs[[1L]]$results, list(one_result)) + one_result <- append(one_result, c(locations = list(list(one_location)))) + sarif$runs[[1L]]$results <- append(sarif$runs[[1L]]$results, list(one_result)) } write(jsonlite::toJSON(sarif, pretty = TRUE, auto_unbox = TRUE), filename) @@ -670,8 +666,7 @@ highlight_string <- function(message, column_number = NULL, ranges = NULL) { line <- fill_with(" ", maximum) lapply(ranges, function(range) { - substr(line, range[1L], range[2L]) <<- - fill_with("~", range[2L] - range[1L] + 1L) + substr(line, range[1L], range[2L]) <<- fill_with("~", range[2L] - range[1L] + 1L) # nolint: undesirable_operator. }) substr(line, column_number, column_number + 1L) <- "^" diff --git a/R/object_usage_linter.R b/R/object_usage_linter.R index b1c94b3e6..d425bb616 100644 --- a/R/object_usage_linter.R +++ b/R/object_usage_linter.R @@ -248,7 +248,7 @@ parse_check_usage <- function(expression, vals <- list() report <- function(x) { - vals[[length(vals) + 1L]] <<- x + vals[[length(vals) + 1L]] <<- x # nolint: undesirable_operator. } withr::with_options( diff --git a/R/utils.R b/R/utils.R index e3c814458..779659e1b 100644 --- a/R/utils.R +++ b/R/utils.R @@ -28,8 +28,8 @@ flatten_list <- function(x, class) { itr <- 1L assign_item <- function(x) { if (inherits(x, class)) { - res[[itr]] <<- x - itr <<- itr + 1L + res[[itr]] <<- x # nolint: undesirable_operator. + itr <<- itr + 1L # nolint: undesirable_operator. } else if (is.list(x)) { lapply(x, assign_item) } @@ -174,7 +174,7 @@ read_lines <- function(file, encoding = settings$encoding, ...) { readLines(file, warn = TRUE, ...), warning = function(w) { if (grepl("incomplete final line found on", w$message, fixed = TRUE)) { - terminal_newline <<- FALSE + terminal_newline <<- FALSE # nolint: undesirable_operator. invokeRestart("muffleWarning") } } diff --git a/R/zzz.R b/R/zzz.R index 1e6be7915..760df5f7e 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -295,7 +295,7 @@ settings <- NULL } } - default_settings <<- list( + default_settings <<- list( # nolint: undesirable_operator. linters = default_linters, encoding = "UTF-8", exclude = rex::rex("#", any_spaces, "nolint"), @@ -325,7 +325,7 @@ settings <- NULL error_on_lint = logical_env("LINTR_ERROR_ON_LINT") %||% FALSE ) - settings <<- list2env(default_settings, parent = emptyenv()) + settings <<- list2env(default_settings, parent = emptyenv()) # nolint: undesirable_operator. invisible() } # nocov end