-
-
Notifications
You must be signed in to change notification settings - Fork 784
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 MultilineLambdaItParameter rule #3259
Add MultilineLambdaItParameter rule #3259
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3259 +/- ##
============================================
- Coverage 80.34% 80.29% -0.06%
+ Complexity 2724 2723 -1
============================================
Files 445 446 +1
Lines 8177 8251 +74
Branches 1555 1565 +10
============================================
+ Hits 6570 6625 +55
- Misses 774 785 +11
- Partials 833 841 +8
Continue to review full report at Codecov.
|
...-style/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/style/MultilineLambdaItParameter.kt
Outdated
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.
Thanks for your contribution @adamkobor.
I'd love to hear other members feedback on the idea behind your rule. I'm also wondering if we should merge the behavior inside the ExplicitItLambdaParameter
rule and treat this as a config option.
...-style/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/style/MultilineLambdaItParameter.kt
Outdated
Show resolved
Hide resolved
...le/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/MultilineLambdaItParameterSpec.kt
Outdated
Show resolved
Hide resolved
Thanks! Initially, I was thinking about the same (extending |
Nice rule! I think that they are different rules. We need new buckets to define rules because this one helps readability but the other just removes redundant code. I would keep this one as a different rule. And should we care if the code defines the parameter as |
...-style/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/style/MultilineLambdaItParameter.kt
Outdated
Show resolved
Hide resolved
...-style/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/style/MultilineLambdaItParameter.kt
Show resolved
Hide resolved
* val digits = 1234.let { it -> listOf(it) } | ||
* val digits = 1234.let { it -> | ||
* listOf(it) | ||
* } |
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.
These are actually code smells, right? https://github.com/detekt/detekt/blob/master/detekt-rules-style/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/style/ExplicitItLambdaParameter.kt
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.
IT_LITERAL in parameterNames
is already checked in the rule mentioned above, so we don't need to double report
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, I totally agree that these rules actually have some overlap, but I think their perspective are quite different. Therefore, I wouldn't remove this overlap, because it's possible that someone is using only one of them. What do you think?
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.
People may enable both rules, and they may get double issues...
That could be our expectation since abusing it
is lowering the readability significantly.
I am okay with keeping it as is.
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.
People may enable both rules, and they may get double issues...
True, that's a scenario that will lead to a double reporting:
val digits = 1234.let { it ->
println(it)
listOf(it)
}
(i.e. multiline lambdas + explicit it). I'm anyway fine with it as the only way to resolve this is to have an explicit lambda parameter name.
So I'm still in for merging this rule 👌
Sorry for the late answer, I will look into this in the coming days, but we have family issues right now at home with our newborn, so my time is quite limited :) |
Co-authored-by: Nicola Corti <corti.nico@gmail.com>
c5927ea
to
b2720e6
Compare
Sure take your time :) If you need some help just drop us a message |
Thanks @cortinico, I already made the adjustments you and @chao2zhang requested, so if you have some time, please take a look at it :) |
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.
Other than minor comments, LGTM 👍
* val digits = 1234.let { it -> listOf(it) } | ||
* val digits = 1234.let { it -> | ||
* listOf(it) | ||
* } |
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.
People may enable both rules, and they may get double issues...
True, that's a scenario that will lead to a double reporting:
val digits = 1234.let { it ->
println(it)
listOf(it)
}
(i.e. multiline lambdas + explicit it). I'm anyway fine with it as the only way to resolve this is to have an explicit lambda parameter name.
So I'm still in for merging this rule 👌
...le/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/MultilineLambdaItParameterSpec.kt
Outdated
Show resolved
Hide resolved
...le/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/MultilineLambdaItParameterSpec.kt
Outdated
Show resolved
Hide resolved
...le/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/MultilineLambdaItParameterSpec.kt
Outdated
Show resolved
Hide resolved
...le/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/MultilineLambdaItParameterSpec.kt
Outdated
Show resolved
Hide resolved
...le/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/MultilineLambdaItParameterSpec.kt
Outdated
Show resolved
Hide resolved
...le/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/MultilineLambdaItParameterSpec.kt
Outdated
Show resolved
Hide resolved
...le/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/MultilineLambdaItParameterSpec.kt
Outdated
Show resolved
Hide resolved
...le/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/MultilineLambdaItParameterSpec.kt
Outdated
Show resolved
Hide resolved
Co-authored-by: Nicola Corti <corti.nico@gmail.com>
Thanks, I also applied your suggestions 🙌 |
This new rule checks if there is any multiline lambda with a parameter called
it
(whether it's an implicit or an explicit one, it doesn't matter).