Repository navigation
Fix by adding last method call to the set - #6567
Conversation
| .forEach { namedReferencesInKDoc.add(it.split(".")[0]) } | ||
| .forEach { | ||
| namedReferencesInKDoc.add(it.split(".")[0]) | ||
| namedReferencesInKDoc.add(it.split(".").last()) |
There was a problem hiding this comment.
I have added the last method name in the set which will be matched against the import. This might in some scenarios produce false -ve but those cases will be kind of rare and fixing that might require some juggling with binding context to find the eligible last method call(whose extensions are already imported)
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #6567 +/- ##
=========================================
Coverage 85.18% 85.18%
Complexity 4061 4061
=========================================
Files 565 565
Lines 13321 13325 +4
Branches 2401 2401
=========================================
+ Hits 11347 11351 +4
Misses 773 773
Partials 1201 1201
☔ View full report in Codecov by Sentry. |
| .forEach { namedReferencesInKDoc.add(it.split(".")[0]) } | ||
| .forEach { | ||
| namedReferencesInKDoc.add(it.split(".")[0]) | ||
| namedReferencesInKDoc.add(it.split(".").last()) |
There was a problem hiding this comment.
We could store the result of split on a variable to avoid the splitting twice.
| package com.example | ||
|
|
||
| import android.text.TextWatcher | ||
| import android.text.beforeTextChanged |
There was a problem hiding this comment.
This is the false negative that you were talking about, right?
There was a problem hiding this comment.
Hi @BraisGabin yes it is a false negative. There are two currently I can think of
@Test
fun `false -ve #1`() {
val main = """
package com.example
import android.text.TextWatcher
import android.text.beforeTextChanged
class TestClass {
/**
* Below we are referring instance method no extension method
* [TextWatcher.beforeTextChanged]
*/
fun test() {
TODO()
}
}
""".trimIndent()
val additional1 = """
package android.text
class TextWatcher {
fun beforeTextChanged() {}
}
""".trimIndent()
val additional2 = """
package android.text
fun TextWatcher.beforeTextChanged() {}
""".trimIndent()
assertThat(subject.lintWithContext(env, main, additional1, additional2)).isEmpty()
}
@Test
fun `false -ve #2`() {
val main = """
package com.example
import android.text.TextWatcher
import android.text.beforeTextChanged
import test.TextWatcher
import test.beforeTextChanged
class TestClass {
/**
* Below we are referring non existing method extension method receiver is different
* [TextWatcher.beforeTextChanged]
*/
fun test() {
TODO()
}
}
""".trimIndent()
val additional1 = """
package android.text
class TextWatcher
class TextWatcher2
""".trimIndent()
val additional2 = """
package android.text
fun TextWatcher2.beforeTextChanged() {}
""".trimIndent()
assertThat(subject.lintWithContext(env, main, additional1, additional2)).isEmpty()
}
There was a problem hiding this comment.
Then I'll remove the import. We don't want a test that enforces a false positive. We could have an ignored test with the false positive. But, probably, it's better to just remove this import.
There was a problem hiding this comment.
Yes I have updated the TC to make the TC a valid cass
|
@atulgpt can we makesure the website preview doesn't fail? |
Make TC valid case
fefc5ec to
890e919
Compare
| package com.example | ||
|
|
||
| import android.text.TextWatcher | ||
| import android.text.beforeTextChanged |
There was a problem hiding this comment.
To make this case valid shouldn't we remove this line?
| import android.text.beforeTextChanged |
There was a problem hiding this comment.
No, it needs to be imported otherwise you will get the squiggly line in the Kdoc. See class TextWatcher doesn't have this method defined there
| package com.example | ||
|
|
||
| import android.text.TextWatcher | ||
| import android.text.beforeTextChanged |
There was a problem hiding this comment.
Same here
| import android.text.beforeTextChanged |
There was a problem hiding this comment.
Same comment as above
* Fix by adding last method call to the set * Create a variable for split Make TC valid case
* Fix by adding last method call to the set * Create a variable for split Make TC valid case
Fixes #6540