diff --git a/R/assignment_linter.R b/R/assignment_linter.R index c2839b2fc..92d7836be 100644 --- a/R/assignment_linter.R +++ b/R/assignment_linter.R @@ -2,13 +2,13 @@ #' #' Check that `<-` is always used for assignment. #' -#' @param allow_equal_assignment Logical, default `FALSE`. -#' If `TRUE`, `=` instead of `<-` is used for assignment. #' @param allow_cascading_assign Logical, default `TRUE`. #' If `FALSE`, [`<<-`][base::assignOps] and `->>` are not allowed. #' @param allow_right_assign Logical, default `FALSE`. If `TRUE`, `->` and `->>` are allowed. #' @param allow_trailing Logical, default `TRUE`. If `FALSE` then assignments aren't allowed at end of lines. #' @param allow_pipe_assign Logical, default `FALSE`. If `TRUE`, magrittr's `%<>%` assignment is allowed. +#' @param allow_equal_assign Logical, default `FALSE`. +#' If `TRUE`, `=` instead of `<-` is used for assignment. #' #' @examples #' # will produce lints @@ -72,11 +72,11 @@ #' - #' - #' @export -assignment_linter <- function(allow_equal_assignment = FALSE, - allow_cascading_assign = TRUE, +assignment_linter <- function(allow_cascading_assign = TRUE, allow_right_assign = FALSE, allow_trailing = TRUE, - allow_pipe_assign = FALSE) { + allow_pipe_assign = FALSE, + allow_equal_assign = FALSE) { trailing_assign_xpath <- paste( collapse = " | ", c( @@ -91,7 +91,7 @@ assignment_linter <- function(allow_equal_assignment = FALSE, xpath <- paste(collapse = " | ", c( # always block = (NB: the parser differentiates EQ_ASSIGN, EQ_SUB, and EQ_FORMALS) - if (allow_equal_assignment) "//LEFT_ASSIGN" else "//EQ_ASSIGN", + if (allow_equal_assign) "//LEFT_ASSIGN" else "//EQ_ASSIGN", # -> and ->> are both 'RIGHT_ASSIGN' if (!allow_right_assign) "//RIGHT_ASSIGN" else if (!allow_cascading_assign) "//RIGHT_ASSIGN[text() = '->>']", # <-, :=, and <<- are all 'LEFT_ASSIGN'; check the text if blocking <<-. @@ -113,7 +113,7 @@ assignment_linter <- function(allow_equal_assignment = FALSE, operator <- xml_text(bad_expr) lint_message_fmt <- rep( paste0("Use ", - if (allow_equal_assignment) "=" else "<-", + if (allow_equal_assign) "=" else "<-", ", not %s, for assignment."), length(operator) ) diff --git a/man/assignment_linter.Rd b/man/assignment_linter.Rd index 2a925d169..592f3c990 100644 --- a/man/assignment_linter.Rd +++ b/man/assignment_linter.Rd @@ -5,17 +5,14 @@ \title{Assignment linter} \usage{ assignment_linter( - allow_equal_assignment = FALSE, allow_cascading_assign = TRUE, allow_right_assign = FALSE, allow_trailing = TRUE, - allow_pipe_assign = FALSE + allow_pipe_assign = FALSE, + allow_equal_assign = FALSE ) } \arguments{ -\item{allow_equal_assignment}{Logical, default \code{FALSE}. -If \code{TRUE}, \code{=} instead of \verb{<-} is used for assignment.} - \item{allow_cascading_assign}{Logical, default \code{TRUE}. If \code{FALSE}, \code{\link[base:assignOps]{<<-}} and \verb{->>} are not allowed.} @@ -24,6 +21,9 @@ If \code{FALSE}, \code{\link[base:assignOps]{<<-}} and \verb{->>} are not allowe \item{allow_trailing}{Logical, default \code{TRUE}. If \code{FALSE} then assignments aren't allowed at end of lines.} \item{allow_pipe_assign}{Logical, default \code{FALSE}. If \code{TRUE}, magrittr's \verb{\%<>\%} assignment is allowed.} + +\item{allow_equal_assign}{Logical, default \code{FALSE}. +If \code{TRUE}, \code{=} instead of \verb{<-} is used for assignment.} } \description{ Check that \verb{<-} is always used for assignment. diff --git a/tests/testthat/test-assignment_linter.R b/tests/testthat/test-assignment_linter.R index 71d008d06..27a87d816 100644 --- a/tests/testthat/test-assignment_linter.R +++ b/tests/testthat/test-assignment_linter.R @@ -193,8 +193,8 @@ test_that("multiple lints throw correct messages", { ) }) -test_that("equal = instead of <- can be used for assignment", { - linter <- assignment_linter(allow_equal_assignment = TRUE) +test_that("= instead of <- can be used for assignment", { + linter <- assignment_linter(allow_equal_assign = TRUE) lint_msg <- rex::rex("Use =, not <-, for assignment.") expect_lint("blah = 1", NULL, linter)