Skip to content

fix: Avoid implicit assignments inside expect_warning() - #545

Merged
krlmlr merged 3 commits into
mainfrom
lint/implicit-assignment
Jul 23, 2026
Merged

krlmlr merged 3 commits into
mainfrom
lint/implicit-assignment

Conversation

@krlmlr

@krlmlr krlmlr commented Jul 23, 2026 •

Copy link
Copy Markdown
Member

Follow-up on #542: fixes the implicit_assignment_linter violations (9 occurrences).

  • No warning expected (regexp = NA, 4 sites): rewritten as res <- expect_warning(expr, NA). expect_warning() returns the value of its object when no condition is caught, so the assigned value is unchanged.
  • Warning expected (4 sites, e.g. expect_warning(res2 <- dbSendQuery(con, "SELECT 2"))): the assignment must stay inside expect_warning(), because when a warning is caught expect_warning() returns the condition, not the value (see r-lib/lintr#2267). Rather than inline nolint directives, these are allowlisted via the linter's except config in .lintr.R (see ci: Re-enable linters fixed after #542 #550).
  • dbWithTransaction(con, a <- 42) in with_transaction_side_effects deliberately assigns inside the transaction to test that side effects propagate; it keeps a # nolint directive (it is not an expect_warning() call, so the except config does not cover it).

The linter is re-enabled (with the except) in #550 once all the code fixes have landed.

🤖 Generated with Claude Code

https://claude.ai/code/session_01RvAeoWDREMgDse3TQgFDNp

Moves `res <- ` out of `expect_warning()` calls; expect_warning()
returns the value of its object invisibly, so behavior is unchanged.
The intentional side-effect assignment inside dbWithTransaction() is
marked with a nolint directive. Satisfies implicit_assignment_linter.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01RvAeoWDREMgDse3TQgFDNp
claude added 2 commits July 23, 2026 13:48
expect_warning(expr) returns the warning condition, not the value of
expr, so `x <- expect_warning(expr)` would assign the condition. Only
the `regexp = NA` form (no warning expected) returns the value. Revert
the four warning-expecting sites to `expect_warning(x <- expr)` with a
nolint directive; the NA sites keep the `x <- expect_warning(expr, NA)`
form.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01RvAeoWDREMgDse3TQgFDNp
The `regexp = NA` sites become `x <- expect_warning(expr, NA)`, which
returns the value. The warning-expecting sites keep the assignment
inside expect_warning() (it returns the condition, not the value);
these are allowlisted via the linter's `except` config in .lintr.R
instead of inline nolint directives. The intentional assignment inside
dbWithTransaction() keeps its nolint directive.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01RvAeoWDREMgDse3TQgFDNp
@krlmlr
krlmlr enabled auto-merge (squash) July 23, 2026 15:23
@krlmlr
krlmlr merged commit 104a70b into main Jul 23, 2026
13 checks passed
@krlmlr
krlmlr deleted the lint/implicit-assignment branch July 23, 2026 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants