Repository navigation
fix: Avoid implicit assignments inside expect_warning() - #545
Merged
Merged
Conversation
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
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up on #542: fixes the
implicit_assignment_linterviolations (9 occurrences).regexp = NA, 4 sites): rewritten asres <- expect_warning(expr, NA).expect_warning()returns the value of its object when no condition is caught, so the assigned value is unchanged.expect_warning(res2 <- dbSendQuery(con, "SELECT 2"))): the assignment must stay insideexpect_warning(), because when a warning is caughtexpect_warning()returns the condition, not the value (see r-lib/lintr#2267). Rather than inlinenolintdirectives, these are allowlisted via the linter'sexceptconfig in.lintr.R(see ci: Re-enable linters fixed after #542 #550).dbWithTransaction(con, a <- 42)inwith_transaction_side_effectsdeliberately assigns inside the transaction to test that side effects propagate; it keeps a# nolintdirective (it is not anexpect_warning()call, so theexceptconfig 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