Skip to content

Commit

Permalink
correct message among several lints
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelChirico committed Jul 25, 2023
1 parent bf3a49e commit 12b596a
Show file tree
Hide file tree
Showing 2 changed files with 14 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 @@ -112,7 +112,7 @@ assignment_linter <- function(allow_cascading_assign = TRUE,
}

operator <- xml2::xml_text(bad_expr)
lint_message_fmt <- "Use <-, not %s, for assignment."
lint_message_fmt <- rep("Use <-, not %s, for assignment.", length(operator))
lint_message_fmt[operator %in% c("<<-", "->>")] <-
"%s can have hard-to-predict behavior; prefer assigning to a specific environment instead (with assign() or <-)."
lint_message_fmt[operator == "%<>%"] <-
Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/test-assignment_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,16 @@ test_that("%<>% throws a lint", {
# interaction with allow_trailing
expect_lint("x %<>%\n sum()", "Assignment %<>% should not be trailing", assignment_linter(allow_trailing = FALSE))
})

test_that("multiple lints throw correct messages", {
expect_lint(
"{ x <<- 1; y ->> 2; z -> 3; x %<>% as.character() }",
list(
list(message = "<<- can have hard-to-predict behavior"),
list(message = "->> can have hard-to-predict behavior"),
list(message = "Use <-, not ->"),
list(message = "Avoid the assignment pipe %<>%")
),
assignment_linter(allow_cascading_assign = FALSE)
)
})

0 comments on commit 12b596a

Please sign in to comment.