-
-
Notifications
You must be signed in to change notification settings - Fork 777
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UnnecessaryLet: fix false positive when let is used for destructuring #2968
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2968 +/- ##
============================================
+ Coverage 80.25% 80.29% +0.03%
- Complexity 2465 2478 +13
============================================
Files 423 424 +1
Lines 7440 7479 +39
Branches 1358 1370 +12
============================================
+ Hits 5971 6005 +34
+ Misses 763 760 -3
- Partials 706 714 +8
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏👏👏
return bodyExpression?.countVarRefs(firstParameter?.text ?: IT_LITERAL) | ||
private fun KtLambdaExpression.countReferences(): Int { | ||
val bodyExpression = bodyExpression ?: return 0 | ||
val firstParameter = firstParameter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this one can be removed safely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
val firstParameter = firstParameter
👏 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution 🙏
val bodyExpression = bodyExpression ?: return 0 | ||
val firstParameter = firstParameter | ||
val destructuringDeclaration = firstParameter?.destructuringDeclaration | ||
return destructuringDeclaration?.entries?.sumBy { bodyExpression.countVarRefs(it.nameAsSafeName.asString()) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you divide this expression in 2? Having multiple occurrencies of the elvis operator on the same line makes the code harder to read.
Fixes #2966