Skip to content

Commit

Permalink
Fixed use_equal_assign name and position
Browse files Browse the repository at this point in the history
  • Loading branch information
J-Moravec committed Sep 29, 2024
1 parent eabdb9a commit 445f40f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
14 changes: 7 additions & 7 deletions R/assignment_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -72,11 +72,11 @@
#' - <https://style.tidyverse.org/syntax.html#assignment-1>
#' - <https://style.tidyverse.org/pipes.html#assignment-2>
#' @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(
Expand All @@ -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 <<-.
Expand All @@ -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)
)
Expand Down
10 changes: 5 additions & 5 deletions man/assignment_linter.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/testthat/test-assignment_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 445f40f

Please sign in to comment.