-
-
Notifications
You must be signed in to change notification settings - Fork 758
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
New Rule: DoubleMutabilityForCollection #3553
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3553 +/- ##
============================================
+ Coverage 77.53% 77.56% +0.03%
- Complexity 2829 2833 +4
============================================
Files 464 465 +1
Lines 8769 8795 +26
Branches 1713 1716 +3
============================================
+ Hits 6799 6822 +23
Misses 1046 1046
- Partials 924 927 +3
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.
👍
Once we have a real support for severity I'd like to add a rule to detect all the usages of var
. There are very few cases where it uses make sense.
...e/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/bugs/DoubleMutabilityInCollectionSpec.kt
Show resolved
Hide resolved
...rone/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/bugs/DoubleMutabilityForCollection.kt
Show resolved
Hide resolved
...e/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/bugs/DoubleMutabilityInCollectionSpec.kt
Show resolved
Hide resolved
...rone/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/bugs/DoubleMutabilityForCollection.kt
Show resolved
Hide resolved
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.
Let's keep in mind that we need to annotate this rule later with the new @RequiresTypeResolution #3579
I'm adding a new rule that detects if you're declaring a
var
with also a Mutable type like:Instead you should prefer to:
Having "double mutability" is considered an anti-pattern as the
myList
variable can both be reassigned and.clear()
-ed.