Scribe-Android
Scribe-Android copied to clipboard
Fix linting issues caused due to Loop With Too Many Jump Statements as detected by detekt
Terms
- [X] I have searched open and closed feature requests
- [X] I agree to follow Scribe-Android's Code of Conduct
Description
Loops with too many break, continue, or return statements can make the code harder to follow.
To fix this issue the loops have to be simplified to reduce the number of breaking statements like if conditions.
Example: Before Fixing:
fun processItems(items: List<Int>) {
for (item in items) {
if (item == 0) break // Too many jump statements in this loop
if (item % 2 == 0) continue
println(item)
}
}
After fixing:
fun processItems(items: List<Int>) {
for (item in items.filter { it != 0 && it % 2 != 0 }) {
println(item) // Simplified logic with fewer jump statements
}
}
More of this could be found from the docs These can be identified across the code by the following steps:
- Enable the LoopWithTooManyJumpStatements rule in detekt.yml.
- Run ./gradlew detekt to detect such loops.
- Refactor the identified loops to reduce complexity.
Contribution
I would love to work on this and am more than willing to help anyone solve this issue. 😄