googlesamples / googlesamples/android-custom-lint-rules

constructor detection for `com.google.gson.Gson` is working but tests unable to detect

Open
#96 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Kotlin
Stars
1k
Forks
176
PR merge metrics
No merged PRs in 30d

Description

**Code: Modified avoid AvoidDateDetector.kt**
```kotlin
override fun getApplicableConstructorTypes(): List = listOf("com.google.gson.Gson")

override fun visitConstructor(
context: JavaContext,
node: UCallExpression,
constructor: PsiMethod,
) {
context.report(
ISSUE,
node,
context.getLocation(node),
"Don't use `Gson`;",
)
}
```

**Test**
```kotlin
fun testDocumentationExample() {
lint()
.files(
kotlin(
"""
package test.pkg
import com.google.gson.Gson
fun test() {
val gson = Gson()
}
"""
)
.indented(),
)
.allowCompilationErrors()
.run()
.expectErrorCount(1)
}
```

**Result**
- `./gradlew lint` is detecting this but test can't and the above test fails

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.