-
-
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
Implement ExplicitCollectionElementAccessMethod rule #2215
Implement ExplicitCollectionElementAccessMethod rule #2215
Conversation
Please rebase since #2217 was closed. |
50a3667
to
9925c4a
Compare
Codecov Report
@@ Coverage Diff @@
## master #2215 +/- ##
============================================
- Coverage 81.35% 81.24% -0.11%
- Complexity 2067 2111 +44
============================================
Files 341 349 +8
Lines 5968 6053 +85
Branches 1086 1106 +20
============================================
+ Hits 4855 4918 +63
- Misses 532 535 +3
- Partials 581 600 +19
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.
Thanks for implementing this rule. First time Kotlin users will certainly benefit from this rule! 👍
Can we please make sure that the implementation is thoroughly tested? Codecov does report some misses for the rule implementation. After that, the build is completely green and I'll merge this!
Please see my other minor comments about the implementation.
...main/kotlin/io/gitlab/arturbosch/detekt/rules/style/ExplicitCollectionElementAccessMethod.kt
Outdated
Show resolved
Hide resolved
...main/kotlin/io/gitlab/arturbosch/detekt/rules/style/ExplicitCollectionElementAccessMethod.kt
Show resolved
Hide resolved
...main/kotlin/io/gitlab/arturbosch/detekt/rules/style/ExplicitCollectionElementAccessMethod.kt
Outdated
Show resolved
Hide resolved
...main/kotlin/io/gitlab/arturbosch/detekt/rules/style/ExplicitCollectionElementAccessMethod.kt
Outdated
Show resolved
Hide resolved
?.text in setOf("get", "put") | ||
} | ||
|
||
@Suppress("ReturnCount") |
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.
Please try to work around this @Suppress
by merging the first two if's for example.
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've refactored this class to avoid usage of @Suppress
, please check it one more time
.../kotlin/io/gitlab/arturbosch/detekt/rules/style/ExplicitCollectionElementAccessMethodSpec.kt
Outdated
Show resolved
Hide resolved
.../kotlin/io/gitlab/arturbosch/detekt/rules/style/ExplicitCollectionElementAccessMethodSpec.kt
Outdated
Show resolved
Hide resolved
.../kotlin/io/gitlab/arturbosch/detekt/rules/style/ExplicitCollectionElementAccessMethodSpec.kt
Outdated
Show resolved
Hide resolved
.../kotlin/io/gitlab/arturbosch/detekt/rules/style/ExplicitCollectionElementAccessMethodSpec.kt
Outdated
Show resolved
Hide resolved
.../kotlin/io/gitlab/arturbosch/detekt/rules/style/ExplicitCollectionElementAccessMethodSpec.kt
Outdated
Show resolved
Hide resolved
…/style/ExplicitCollectionElementAccessMethod.kt Co-Authored-By: M Schalk <30376729+schalkms@users.noreply.github.com>
…/style/ExplicitCollectionElementAccessMethod.kt Co-Authored-By: M Schalk <30376729+schalkms@users.noreply.github.com>
…/style/ExplicitCollectionElementAccessMethodSpec.kt Co-Authored-By: M Schalk <30376729+schalkms@users.noreply.github.com>
…/style/ExplicitCollectionElementAccessMethodSpec.kt Co-Authored-By: M Schalk <30376729+schalkms@users.noreply.github.com>
…/style/ExplicitCollectionElementAccessMethodSpec.kt Co-Authored-By: M Schalk <30376729+schalkms@users.noreply.github.com>
…/style/ExplicitCollectionElementAccessMethodSpec.kt Co-Authored-By: M Schalk <30376729+schalkms@users.noreply.github.com>
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 that looks good!
...main/kotlin/io/gitlab/arturbosch/detekt/rules/style/ExplicitCollectionElementAccessMethod.kt
Outdated
Show resolved
Hide resolved
…/style/ExplicitCollectionElementAccessMethod.kt Co-Authored-By: M Schalk <30376729+schalkms@users.noreply.github.com>
This PR adds new rule
ExplicitCollectionElementAccessMethod
tostyle
ruleset.Rule
ExplicitCollectionElementAccessMethod
reports usage ofget
orput
methods and suggests to use Indexed access operator:[]
. This rule can be applied to Kotlin collections which implementMap
orList
interfaces as well as Java collectionsjava.util.AbstractMap
andjava.util.AbstractList
.Noncompliant Code:
Compliant Code:
This is a rule for Style ruleset. It is implemented to introduce users to indexed access operator and help them write shorter and more idiomatic code.