Skip to content

Commit

Permalink
also cover for loop
Browse files Browse the repository at this point in the history
  • Loading branch information
IndrajeetPatil committed Dec 8, 2022
1 parent aa57f79 commit 2cc6460
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions R/implicit_assignment_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ implicit_assignment_linter <- function(except = c(
"
//WHILE
/following-sibling::expr[1]
/",
# e.g. for (x in y <- 1:10) { ... }
"
//forcond
/expr[1]
/"
)
xpath_controls_assignment <- paste0(
Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/test-implicit_assignment_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ test_that("implicit_assignment_linter skips allowed usages", {
expect_lint("x <- 1L", NULL, linter)
expect_lint("1L -> x", NULL, linter)
expect_lint("y <- if (is.null(x)) z else x", NULL, linter)
expect_lint("for (x in 1:10) x <- x + 1", NULL, linter)

expect_lint("abc <- mean(1:4)", NULL, linter)
expect_lint("mean(1:4) -> abc", NULL, linter)
Expand Down Expand Up @@ -125,6 +126,8 @@ test_that("implicit_assignment_linter blocks disallowed usages", {
expect_lint("if (1L -> x) TRUE", lint_message, linter)
expect_lint("while (x <- 0L) FALSE", lint_message, linter)
expect_lint("while (0L -> x) FALSE", lint_message, linter)
expect_lint("for (x in y <- 1:10) print(x)", lint_message, linter)
expect_lint("for (x in 1:10 -> y) print(x)", lint_message, linter)

expect_lint("mean(x <- 1:4)", lint_message, linter)
expect_lint("y <- median(x <- 1:4)", lint_message, linter)
Expand Down

0 comments on commit 2cc6460

Please sign in to comment.