Skip to content

Commit

Permalink
Update Lint to API 30 (#454)
Browse files Browse the repository at this point in the history
* Update lint dependency to 30.0.0

* Add Vendor information

* Make AutoDisposeDetectorTest internal to make visibility happy

This is a bug in the explicitApi() extension for applying it to tests

* Bump to kotlin 1.4 targeting

* Fix all the test issues + paper over some

* Update lint API

* Update rxjava jar
  • Loading branch information
ZacSweers authored Aug 9, 2021
1 parent a4539c5 commit 311aa3c
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 131 deletions.
2 changes: 1 addition & 1 deletion gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def versions = [
gjf: '1.7',
nullawayPlugin: '1.1.0',
kotlin: '1.5.21',
lint: '27.2.2',
lint: '30.0.0',
ktlint: '0.42.1',
spotless: '5.14.2'
]
Expand Down
1 change: 1 addition & 0 deletions static-analysis/autodispose-lint/api/autodispose-lint.api
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ public final class autodispose2/lint/AutoDisposeIssueRegistry : com/android/tool
public fun <init> ()V
public fun getApi ()I
public fun getIssues ()Ljava/util/List;
public fun getVendor ()Lcom/android/tools/lint/client/api/Vendor;
}

6 changes: 3 additions & 3 deletions static-analysis/autodispose-lint/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ targetCompatibility = deps.build.javaVersion

compileKotlin {
kotlinOptions {
// Lint runs with 1.3 still, so we need to emit 1.3-compatible code
apiVersion = "1.3"
languageVersion = "1.3"
// Lint runs with 1.4 still, so we need to emit 1.4-compatible code
apiVersion = "1.4"
languageVersion = "1.4"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ 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.google.common.collect.HashMultimap
import com.google.common.collect.Multimap
import com.intellij.psi.PsiMethod
import com.intellij.psi.PsiType
import com.intellij.psi.util.PsiUtil
Expand Down Expand Up @@ -95,7 +93,7 @@ public class AutoDisposeDetector : Detector(), SourceCodeScanner {
private const val KOTLIN_EXTENSIONS = "autodispose2.KotlinExtensions"

// The default scopes for Android.
private val DEFAULT_SCOPES = listOf(
private val DEFAULT_SCOPES = setOf(
"androidx.lifecycle.LifecycleOwner",
"autodispose2.ScopeProvider",
"android.app.Activity",
Expand All @@ -115,16 +113,16 @@ public class AutoDisposeDetector : Detector(), SourceCodeScanner {
// The scopes that are applicable for the lint check.
// This includes the DEFAULT_SCOPES as well as any custom scopes
// defined by the consumer.
private lateinit var appliedScopes: Set<String>
private lateinit var ktExtensionMethodToPackageMap: Multimap<String, String>
private lateinit var appliedMethodNames: List<String>
private var appliedScopes: Set<String> = DEFAULT_SCOPES
private var ktExtensionMethodToPackageMap: Map<String, Set<String>> = emptyMap()
private var appliedMethodNames: List<String> = REACTIVE_SUBSCRIBE_METHOD_NAMES.toList()

private var lenient: Boolean = false

override fun beforeCheckRootProject(context: Context) {
var overrideScopes = false
val scopes = mutableSetOf<String>()
val ktExtensionMethodToPackageMap = HashMultimap.create<String, String>()
val ktExtensionMethodToPackageMap = mutableMapOf<String, MutableSet<String>>()

// Add the custom scopes defined in configuration.
val props = Properties()
Expand All @@ -145,7 +143,7 @@ public class AutoDisposeDetector : Detector(), SourceCodeScanner {
val arr = it.split("#", limit = 2)
if (arr.size >= 2) {
val (packageName, methodName) = arr
ktExtensionMethodToPackageMap.put(methodName, packageName)
ktExtensionMethodToPackageMap.getOrPut(methodName, ::mutableSetOf).add(packageName)
}
}
}
Expand All @@ -162,7 +160,7 @@ public class AutoDisposeDetector : Detector(), SourceCodeScanner {
}
this.appliedScopes = scopes
this.ktExtensionMethodToPackageMap = ktExtensionMethodToPackageMap
this.appliedMethodNames = (REACTIVE_SUBSCRIBE_METHOD_NAMES + ktExtensionMethodToPackageMap.keySet()).toList()
this.appliedMethodNames = (REACTIVE_SUBSCRIBE_METHOD_NAMES + ktExtensionMethodToPackageMap.keys).toList()
}

override fun getApplicableMethodNames(): List<String> = appliedMethodNames
Expand Down Expand Up @@ -290,9 +288,9 @@ public class AutoDisposeDetector : Detector(), SourceCodeScanner {
}

private fun isKotlinExtension(evaluator: JavaEvaluator, method: PsiMethod): Boolean {
return ktExtensionMethodToPackageMap.get(method.name).any {
return ktExtensionMethodToPackageMap[method.name]?.any {
evaluator.isMemberInClass(method, it)
}
} ?: false
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@
package autodispose2.lint

import com.android.tools.lint.client.api.IssueRegistry
import com.android.tools.lint.client.api.Vendor
import com.android.tools.lint.detector.api.CURRENT_API
import com.android.tools.lint.detector.api.Issue
import com.google.auto.service.AutoService

@AutoService(IssueRegistry::class)
public class AutoDisposeIssueRegistry() : IssueRegistry() {
public class AutoDisposeIssueRegistry : IssueRegistry() {
override val issues: List<Issue> = listOf(AutoDisposeDetector.ISSUE)
override val api: Int = CURRENT_API

override val vendor: Vendor
get() = Vendor("Uber", "AutoDispose", "https://github.com/uber/AutoDispose/issues")
}
Loading

0 comments on commit 311aa3c

Please sign in to comment.