Skip to content
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

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

Open
theapache64 opened this issue Sep 9, 2024 · 1 comment

Comments

@theapache64
Copy link

Code: Modified avoid AvoidDateDetector.kt

override fun getApplicableConstructorTypes(): List<String> = 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

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants