Repository navigation
Correct axis for scoped lint in implicit_assignment_linter - #2914
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2914 +/- ##
=======================================
Coverage 99.28% 99.28%
=======================================
Files 129 129
Lines 7266 7266
=======================================
Hits 7214 7214
Misses 52 52 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Bisaloo
left a comment
There was a problem hiding this comment.
Isn't this supposed to lint?
lintr::lint(
text = "if (a <- 1) print(b)",
linters = lintr::implicit_assignment_linter(allow_scoped = TRUE)
)
#> ℹ No lints found.Created on 2025-07-31 with reprex v2.1.1
Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#> setting value
#> version R Under development (unstable) (2025-07-15 r88411)
#> os Ubuntu 24.04.2 LTS
#> system x86_64, linux-gnu
#> ui X11
#> language en_US
#> collate en_GB.UTF-8
#> ctype en_GB.UTF-8
#> tz Europe/Paris
#> date 2025-07-31
#> pandoc 3.6.3 @ /usr/share/positron/resources/app/quarto/bin/tools/x86_64/ (via rmarkdown)
#> quarto 1.8.14 @ /opt/quarto/bin/quarto
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────
#> package * version date (UTC) lib source
#> backports 1.5.0 2024-05-23 [1] RSPM (R 4.6.0)
#> cli 3.6.5 2025-04-23 [1] RSPM (R 4.6.0)
#> digest 0.6.37 2024-08-19 [1] RSPM
#> evaluate 1.0.4 2025-06-18 [1] RSPM (R 4.6.0)
#> fastmap 1.2.0 2024-05-15 [1] RSPM (R 4.6.0)
#> fs 1.6.6 2025-04-12 [1] RSPM (R 4.6.0)
#> glue 1.8.0 2024-09-30 [1] RSPM (R 4.6.0)
#> htmltools 0.5.8.1 2024-04-04 [1] RSPM (R 4.6.0)
#> knitr 1.50 2025-03-16 [1] RSPM (R 4.6.0)
#> lazyeval 0.2.2 2019-03-15 [1] RSPM (R 4.6.0)
#> lifecycle 1.0.4.9000 2025-07-19 [1] Github (r-lib/lifecycle@2a852fe)
#> lintr 3.2.0.9000 2025-07-31 [1] Github (r-lib/lintr@384012b)
#> reprex 2.1.1 2024-07-06 [1] RSPM
#> rex 1.2.1 2021-11-26 [1] RSPM (R 4.6.0)
#> rlang 1.1.6 2025-04-11 [1] RSPM (R 4.6.0)
#> rmarkdown 2.29 2024-11-04 [1] RSPM
#> rstudioapi 0.17.1 2024-10-22 [1] RSPM (R 4.6.0)
#> sessioninfo 1.2.3 2025-02-05 [1] RSPM (R 4.6.0)
#> withr 3.0.2 2024-10-28 [1] RSPM (R 4.6.0)
#> xfun 0.52 2025-04-02 [1] RSPM (R 4.6.0)
#> xml2 1.3.8 2025-03-14 [1] RSPM (R 4.6.0)
#> xmlparsedata 1.0.5 2021-03-06 [1] RSPM (R 4.6.0)
#> yaml 2.3.10 2024-07-26 [1] RSPM (R 4.6.0)
#>
#> [1] /home/hugo/.local/share/R/x86_64-pc-linux-gnu-library/4.6
#> [2] /opt/R/devel/lib/R/library
#>
#> ──────────────────────────────────────────────────────────────────────────────|
I think I misspoke in the issue 🤭 the current logic ignores the actual branch entirely I think object_usage_linter can deal with that in more realistic examples, especially after it is working on scripts. I would handle that as a follow-up in any case |
|
Oh okay, I get it now. |
Bisaloo
left a comment
There was a problem hiding this comment.
I think Tim's case was addressed so feel free to merge.
I think we have however another edge case to cover at some point:
lintr::lint(
text = "if (a <- 1 && b <- 2) { print(a) }
print(a)",
linters = lintr::implicit_assignment_linter(allow_scoped = TRUE)
)
#> <text>:1:5: warning: [implicit_assignment_linter] Avoid implicit assignments in function calls. For example, instead of `if (x <- 1L) { ... }`, write `x <- 1L; if (x) { ... }`.
#> if (a <- 1 && b <- 2) { print(a) }
#> ^~~~~~~~~~~~~~~~
lintr::lint(
text = "if (a <- 1 && b <- 2) { print(b) }
print(b)",
linters = lintr::implicit_assignment_linter(allow_scoped = TRUE)
)
#> ℹ No lints found.Created on 2025-08-03 with reprex v2.1.1
Yea, that's the current behavior. I'm not married to it... but it does seem a bit impractical (i.e., not likely to come up in real code). I can think of two cases:
|
Closes #2913
This previously assumed a nested implicit assignment like
if (foo(l <- r)), the correction allows for plain assignments as observedif (l <- r).