Skip to content

Commit 84d3f8c

Browse files
Correct axis for scoped lint in implicit_assignment_linter (#2914)
* correct axis for scoped lint * news
1 parent acaa5c7 commit 84d3f8c

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ files in Windows (#2882, @Bisaloo).
7272
* `assignment_linter()` with `operator = "="` does a better job of skipping implicit assignments, which are intended to be governed by `implicit_assignment_linter()` (#2765, @MichaelChirico).
7373
* `expect_true_false_linter()` is pipe-aware, so that `42 |> expect_identical(x, ignore_attr = TRUE)` no longer lints (#1520, @MichaelChirico).
7474
* `T_and_F_symbol_linter()` ignores `T` and `F` used as symbols in formulas (`y ~ T + F`), which can represent variables in data not controlled by the author (#2637, @MichaelChirico).
75+
* `implicit_assignment_linter()` with `allow_scoped=TRUE` doesn't lint for `if (a <- 1) print(a)` (#2913, @MichaelChirico).
7576

7677
### Lint accuracy fixes: removing false negatives
7778

R/implicit_assignment_linter.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ implicit_assignment_linter <- function(except = c("bquote", "expression", "expr"
9494
}
9595
if (allow_scoped) {
9696
# force 2nd preceding to ensure we're in the loop condition, not the loop expression
97-
in_branch_cond <- "ancestor::expr[preceding-sibling::*[2][self::IF or self::WHILE]]"
97+
in_branch_cond <- "ancestor-or-self::expr[preceding-sibling::*[2][self::IF or self::WHILE]]"
9898
xpath <- paste0(
9999
xpath,
100100
# _if_ we're in an IF/WHILE branch, lint if the assigned SYMBOL appears anywhere later on.

tests/testthat/test-implicit_assignment_linter.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,9 @@ test_that("allow_scoped skips scoped assignments", {
386386
lint_message,
387387
linter
388388
)
389+
390+
expect_no_lint("if (a <- 1) print(a)", linter)
391+
389392
# only applies to the branch condition itself -- within the branch, still lint
390393
expect_lint(
391394
trim_some("

0 commit comments

Comments
 (0)