-
-
Notifications
You must be signed in to change notification settings - Fork 779
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
Add UseIsNullOrEmpty rule #3469
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3469 +/- ##
============================================
- Coverage 80.28% 80.09% -0.19%
- Complexity 2784 2824 +40
============================================
Files 454 455 +1
Lines 8414 8490 +76
Branches 1608 1637 +29
============================================
+ Hits 6755 6800 +45
- Misses 789 793 +4
- Partials 870 897 +27
Continue to review full report at Codecov.
|
caab90d
to
e2b8e62
Compare
detekt-rules-style/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/style/UseIsNullOrEmpty.kt
Outdated
Show resolved
Hide resolved
…/rules/style/UseIsNullOrEmpty.kt Co-authored-by: Nicola Corti <corti.nico@gmail.com>
left.isZero() -> right.safeAs<KtDotQualifiedExpression>() to false | ||
else -> null | ||
} ?: return null | ||
when { |
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.
Given that we are having nested whens, I would recommend simplifying by extracting this when into two separate functions so that:
val (expression, isEmptyString) = when {
right.isEmptyString() -> sizeCheckedEmptyString(left as? KtSimpleNameExpression)
left.isEmptyString() -> sizeCheckedEmptyString(right as? KtSimpleNameExpression)
right.isZero() -> sizeCheckedEqualToZero(left as? KtDotQualifiedExpression)
left.isZero() -> sizeCheckedEqualToZero(right as? KtDotQualifiedExpression)
else -> null
} ?: return null
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.
Fixes #3466