Skip to content
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

Merged
merged 4 commits into from
Feb 17, 2021
Merged

Conversation

t-kameyama
Copy link
Contributor

Fixes #3466

@codecov
Copy link

codecov bot commented Feb 13, 2021

Codecov Report

Merging #3469 (7181506) into master (230bd48) will decrease coverage by 0.18%.
The diff coverage is 59.74%.

Impacted file tree graph

@@             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     
Impacted Files Coverage Δ Complexity Δ
.../arturbosch/detekt/rules/style/UseIsNullOrEmpty.kt 58.66% <58.66%> (ø) 40.00 <40.00> (?)
...rturbosch/detekt/rules/style/StyleGuideProvider.kt 100.00% <100.00%> (ø) 3.00 <0.00> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 230bd48...de22e9c. Read the comment docs.

…/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 {
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@schalkms schalkms merged commit b485435 into detekt:master Feb 17, 2021
@t-kameyama t-kameyama deleted the UseIsNullOrEmpty branch February 17, 2021 21:50
@cortinico cortinico added this to the 1.16.0 milestone Feb 19, 2021
This was referenced Mar 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New Rule: UseIsNullOrEmpty
4 participants