-
-
Notifications
You must be signed in to change notification settings - Fork 778
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: ObjectLiteralToLambda #3599
Conversation
…le-abstract-method
Codecov Report
@@ Coverage Diff @@
## main #3599 +/- ##
============================================
+ Coverage 77.97% 78.00% +0.02%
- Complexity 2837 2897 +60
============================================
Files 467 472 +5
Lines 9139 9306 +167
Branches 1737 1776 +39
============================================
+ Hits 7126 7259 +133
- Misses 1071 1077 +6
- Partials 942 970 +28
Continue to review full report at Codecov.
|
* } | ||
* </compliant> | ||
* | ||
* @active since v1.17.0 |
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.
Don't activate it by default please.
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.
Thank you. Are there any criteria to set the rule to be enabled by default?
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.
We never enable a rule by default the first time we introduced it because it can have false positives and we will impact to a lot of users. We prefer to enable it later if we think that its a rule that nearly all our user base will like to have it. But we don't have any defined rule here.
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.
Nice test coverage 👍
...rules-style/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/style/ObjectLiteralToLambda.kt
Show resolved
Hide resolved
Debt.FIVE_MINS | ||
) | ||
|
||
private val KotlinType.isSamInterface |
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.
private val KotlinType.isSamInterface | |
private val KotlinType.couldBeSamInterface |
According to its original documentation, isDefinitelyNotSamInterface
may return falsely false
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.
done
* An anonymous object that does nothing other than the implementation of a single method | ||
* can be used as a lambda. | ||
* | ||
* See https://kotlinlang.org/docs/fun-interfaces.html |
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.
Would this rule detect findings when the consuming code is Kotlin 1.3 or 1.3-?
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 may be good at least to call it out in the documentation)
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 wandering looking for a way to test. Can you give me a hint? @chao2zhang
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 believe this requires us to set up a sample project and set its kotlin version to 1.3.*
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.
When running detektMain with java.util.Runnable in 1.3.72, it was confirmed that it is detected as a test case.
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.
Couldn't we get that information from CompilerResources
?
About how to test that if
... we don't have any way to make it right now. But maybe we can create an issue to fix that and accept that if
untested for now.
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.
Everything is new, so I'm grasping it. :loading:
Please let me know if you have any misunderstandings.
From what I checked, in CompileResource
, We can only see that the version is 1.3, and it seems that We can't actually compile with 1.3. Is that right?
What we want to check is the latter, and in java-interop there is nothing we can do with LanguageVersion.KOTLIN_1_3
because the code we need to detect is exactly the same.
When I tested fun interface
in 1.3, there is nothing else to do because it fails in the :compileKotlin task.
If I make an issue
, I think I will have to rewrite the case in the module implementing 1.3, but I wonder if this falls within the scope of the project's support.
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.
The bottom line is that we do not crash when compiling Kotlin 1.3.
What's better is that even if the code does not compile, detekt findings should be easy to understand.
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.
Currently, the default configured detekt
task does not depend on compileKotlin
. If the error message is confusing, we should consider adding a LanguageVersion.KOTLIN_1_3
version check, otherwise, this PR should be good to go.
...s-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/ObjectLiteralToLambdaSpec.kt
Show resolved
Hide resolved
Actually, I also find that converting to SAM may indicate anonymous object converted to singleton: JetBrains/kotlin@99a6bde I guess this is an edge case but we should at least call it out. (We can soon have @Controverial annotation) |
In the process of adding the case, there have been many modifications to the code and JetBrains/kotlin@99a6bde is still under research. |
...s-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/ObjectLiteralToLambdaSpec.kt
Show resolved
Hide resolved
* An anonymous object that does nothing other than the implementation of a single method | ||
* can be used as a lambda. | ||
* | ||
* See https://kotlinlang.org/docs/fun-interfaces.html |
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.
Couldn't we get that information from CompilerResources
?
About how to test that if
... we don't have any way to make it right now. But maybe we can create an issue to fix that and accept that if
untested for now.
...s-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/ObjectLiteralToLambdaSpec.kt
Show resolved
Hide resolved
...s-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/ObjectLiteralToLambdaSpec.kt
Show resolved
Hide resolved
...s-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/ObjectLiteralToLambdaSpec.kt
Show resolved
Hide resolved
…/rules/style/ObjectLiteralToLambdaSpec.kt
...s-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/ObjectLiteralToLambdaSpec.kt
Outdated
Show resolved
Hide resolved
...s-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/ObjectLiteralToLambdaSpec.kt
Outdated
Show resolved
Hide resolved
…/rules/style/ObjectLiteralToLambdaSpec.kt
…/rules/style/ObjectLiteralToLambdaSpec.kt
@chao2zhang Please change the linked issue to #3528 |
Should Detekt support primarily the current and the immediate previous feature release? |
Is there something else I need to add for this? |
Kotlin 1.5 has arrived already (Not in Detekt yet), we could say that Detekt at maximum will be supporting 2 major releases of Kotlin. |
apply #3528
I hope there isn't much I've missed.
Thank you @cortinico