Skip to content

Commit

Permalink
Fix matched := when using 'allow_equal_assign'
Browse files Browse the repository at this point in the history
  • Loading branch information
J-Moravec committed Sep 29, 2024
1 parent 445f40f commit a4fb906
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/assignment_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ assignment_linter <- function(allow_cascading_assign = TRUE,

xpath <- paste(collapse = " | ", c(
# always block = (NB: the parser differentiates EQ_ASSIGN, EQ_SUB, and EQ_FORMALS)
if (allow_equal_assign) "//LEFT_ASSIGN" else "//EQ_ASSIGN",
if (allow_equal_assign) "//LEFT_ASSIGN[text() = '<-']" 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 Down
3 changes: 3 additions & 0 deletions tests/testthat/test-assignment_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,7 @@ test_that("= instead of <- can be used for assignment", {

expect_lint("blah = 1", NULL, linter)
expect_lint("blah <- 1", lint_msg, linter)

# data.table's left assign := needs to be silent
expect_lint("dt[, x := 42]", NULL, linter)
})

0 comments on commit a4fb906

Please sign in to comment.