New Rule: DoubleMutabilityForCollection#3553
Merged
chao2zhang merged 2 commits intodetekt:mainfrom Apr 10, 2021
Merged
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.
|
BraisGabin
approved these changes
Mar 14, 2021
Member
BraisGabin
left a comment
There was a problem hiding this comment.
👍
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
t-kameyama
reviewed
Mar 17, 2021
...rone/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/bugs/DoubleMutabilityForCollection.kt
Show resolved
Hide resolved
chao2zhang
approved these changes
Mar 24, 2021
Member
chao2zhang
left a comment
There was a problem hiding this comment.
Let's keep in mind that we need to annotate this rule later with the new @RequiresTypeResolution #3579
Member
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I'm adding a new rule that detects if you're declaring a
varwith also a Mutable type like:Instead you should prefer to:
Having "double mutability" is considered an anti-pattern as the
myListvariable can both be reassigned and.clear()-ed.