Repository navigation
Fix false positive for null coalescing without else clause - #2938
Merged
Merged
Conversation
Signed-off-by: Emmanuel Ferdman <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2938 +/- ##
=======================================
Coverage 99.24% 99.24%
=======================================
Files 129 129
Lines 7282 7283 +1
=======================================
+ Hits 7227 7228 +1
Misses 55 55 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Collaborator
|
Thanks! I added your name to the NEWS entry. We might also consider extended tests of nested cases like |
MichaelChirico
approved these changes
Oct 6, 2025
TimTaylor
pushed a commit
to TimTaylor/lintr
that referenced
this pull request
Oct 29, 2025
* Fix false positive for null coalescing without else clause Signed-off-by: Emmanuel Ferdman <[email protected]> * cite in NEWS --------- Signed-off-by: Emmanuel Ferdman <[email protected]> Co-authored-by: Michael Chirico <[email protected]>
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.
PR Summary
This PR fixes a bug where
coalesce_linter()incorrectly warned for if statements without else clauses:The XPath query had two branches for detecting coalesce patterns. The first branch (for
is.nullpatterns) correctly checked for an ELSE node, but the second branch (for!is.nullpatterns) was missing this check, causing false positives. Added one line (and parent::expr/following-sibling::ELSE) to ensure both branches only match if-else statements, not plain if statements. Includes 3 regression tests.Fixes #2936.