Skip to content

Commit

Permalink
Allow providers to be called in tests (#316)
Browse files Browse the repository at this point in the history
Resolves #162
  • Loading branch information
ZacSweers authored Oct 2, 2024
1 parent 852b0c6 commit 4375a29
Showing 1 changed file with 2 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,21 @@ package slack.lint
import com.android.tools.lint.client.api.UElementHandler
import com.android.tools.lint.detector.api.Category
import com.android.tools.lint.detector.api.Detector
import com.android.tools.lint.detector.api.Implementation
import com.android.tools.lint.detector.api.Issue
import com.android.tools.lint.detector.api.JavaContext
import com.android.tools.lint.detector.api.Scope
import com.android.tools.lint.detector.api.Severity
import com.android.tools.lint.detector.api.SourceCodeScanner
import com.android.tools.lint.detector.api.TextFormat
import java.util.EnumSet
import org.jetbrains.uast.UCallExpression
import org.jetbrains.uast.UClass
import org.jetbrains.uast.getParentOfType
import slack.lint.util.sourceImplementation

@Suppress("UnstableApiUsage")
class DoNotCallProvidersDetector : Detector(), SourceCodeScanner {

companion object {
// We use the overloaded constructor that takes a varargs of `Scope` as the last param.
// This is to enable on-the-fly IDE checks. We are telling lint to run on both
// JAVA and TEST_SOURCES in the `scope` parameter but by providing the `analysisScopes`
// params, we're indicating that this check can run on either JAVA or TEST_SOURCES and
// doesn't require both of them together.
// From discussion on lint-dev https://groups.google.com/d/msg/lint-dev/ULQMzW1ZlP0/1dG4Vj3-AQAJ
// This was supposed to be fixed in AS 3.4 but still required as recently as 3.6-alpha10.
private val SCOPES =
Implementation(
DoNotCallProvidersDetector::class.java,
EnumSet.of(Scope.JAVA_FILE, Scope.TEST_SOURCES),
EnumSet.of(Scope.JAVA_FILE),
EnumSet.of(Scope.TEST_SOURCES),
)
sourceImplementation<DoNotCallProvidersDetector>(shouldRunOnTestSources = false)

val ISSUE: Issue =
Issue.create(
Expand Down

0 comments on commit 4375a29

Please sign in to comment.