From 69841ea10e94c6cf9914ab84c05b9db43e2bf9c4 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Tue, 28 Jan 2025 21:48:18 +0000 Subject: [PATCH] NEWS, and mention "any" in man --- NEWS.md | 2 ++ R/assignment_linter.R | 3 ++- man/assignment_linter.Rd | 3 ++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index 688c18fab..072f1b81d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -18,6 +18,7 @@ * `scalar_in_linter` is now configurable to allow other `%in%` like operators to be linted. The data.table operator `%chin%` is no longer linted by default; use `in_operators = "%chin%"` to continue linting it. (@F-Noelle) * `lint()` and friends now normalize paths to forward slashes on Windows (@olivroy, #2613). * `undesirable_function_linter()`, `undesirable_operator_linter()`, and `list_comparison_linter()` were removed from the tag `efficiency` (@IndrajeetPatil, #2655). If you use `linters_with_tags("efficiency")` to include these linters, you'll need to adjust your config to keep linting your code against them. We did not find any such users on GitHub. +* Arguments `allow_cascading_assign=`, `allow_right_assign=`, and `allow_pipe_assign=` to `assignment_linter()` are all deprecated in favor of the new `operator=` argument. See below about the new argument. ## Bug fixes @@ -61,6 +62,7 @@ * `expect_no_lint()` was added as new function to cover the typical use case of expecting no lint message, akin to the recent {testthat} functions like `expect_no_warning()` (#2580, @F-Noelle). * `lint()` and friends emit a message if no lints are found (#2643, @IndrajeetPatil). * `{lintr}` now has a hex sticker (https://github.com/rstudio/hex-stickers/pull/110). Thank you, @gregswinehart! +* `assignment_linter()` can be fully customized with the new `operator=` argument to specify an exact vector of assignment operators to allow (#2441, @MichaelChirico and @J-Moravec). The default is `<-` and `<<-`; authors wishing to use `=` (only) for assignment in their codebase can use `operator = "="`. This supersedes several old arguments: to accomplish `allow_cascading_assign=TRUE`, add `"<<-"` (and/or `"->>"`) to `operator=`; for `allow_right_assign=TRUE`, add `"->"` (and/or `"->>"`) to `operator=`; for `allow_pipe_assign=TRUE`, add `"%<>%"` to `operator=`. Use `operator = "any"` to denote "ignore all assignment operators"; in this case, only the value of `allow_trailing=` matters. Implicit assignments with `<-` are always ignored by `assignment_linter()`; use `implicit_assignment_linter()` to handle linting these. ### New linters diff --git a/R/assignment_linter.R b/R/assignment_linter.R index 0fd443f59..683407cb9 100644 --- a/R/assignment_linter.R +++ b/R/assignment_linter.R @@ -3,7 +3,8 @@ #' Check that the specified operator is used for assignment. #' #' @param operator Character vector of valid assignment operators. Defaults to allowing `<-` and `<<-`; other valid -#' options are `=`, `->`, `->>`, and `%<>%`. +#' options are `=`, `->`, `->>`, `%<>%`; use `"any"` to denote "allow all operators", in which case this linter only +#' considers `allow_trailing` for generating lints. #' @param allow_cascading_assign (Deprecated) Logical, default `TRUE`. #' If `FALSE`, [`<<-`][base::assignOps] and `->>` are not allowed. #' @param allow_right_assign (Deprecated) Logical, default `FALSE`. If `TRUE`, `->` and `->>` are allowed. diff --git a/man/assignment_linter.Rd b/man/assignment_linter.Rd index 9ed11c6f3..9efc4bbd1 100644 --- a/man/assignment_linter.Rd +++ b/man/assignment_linter.Rd @@ -14,7 +14,8 @@ assignment_linter( } \arguments{ \item{operator}{Character vector of valid assignment operators. Defaults to allowing \verb{<-} and \verb{<<-}; other valid -options are \code{=}, \verb{->}, \verb{->>}, and \verb{\%<>\%}.} +options are \code{=}, \verb{->}, \verb{->>}, \verb{\%<>\%}; use \code{"any"} to denote "allow all operators", in which case this linter only +considers \code{allow_trailing} for generating lints.} \item{allow_cascading_assign}{(Deprecated) Logical, default \code{TRUE}. If \code{FALSE}, \code{\link[base:assignOps]{<<-}} and \verb{->>} are not allowed.}