fixed the issue of guard clauses#9424
Open
Phoenix1808 wants to merge 2 commits into
Open
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #9424 +/- ##
============================================
+ Coverage 84.72% 84.73% +0.01%
Complexity 4492 4492
============================================
Files 571 571
Lines 12407 12410 +3
Branches 2767 2766 -1
============================================
+ Hits 10512 10516 +4
Misses 694 694
+ Partials 1201 1200 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Fixes #8993
Problem
When
excludeGuardClauses = truethen ReturnCount and ThrowsCount should not count guard clauses but if function was starting with normal local variable declaration then the guard clause coming after it was counted as well which results in false positive.Root cause lies in file Junk.kt method
yieldStatementsSkippingGuardClauseswhich keeps flag firstNonGuardFound. The moment statement isn't guard clause, this flag becomes true and after that every statement is counted. A local val/var declaration was treated as such a non-guard statement, so it was ending the guard section too early.Fix
We generalized the exisiting
isScopedAssignmenthelper intoisLocalVariableDeclaration, earlier onlyval x = xwas transparent now it's valid for any local var/val declaration. Also added the test cases to both ReturnCountSpec.kt and ThrowsCountSpec.kt for guard clauses interleaved with local variable declarations and one existing test updated.The one updated test "(should not ignore scoped .... )" reflects this a differently named local like val data1= data no longer ends the guard section. This maybe slightly broadens #7931 @eygraber
Testing
First Reproduced bug as a failing test using issue's scenario before the fix it failed with same message from issue after the fix, new tests pass and all exisiting ReturnCount/ThrowsCount test still pass.
@schalkms