Skip to content

Commit

Permalink
Update lint to v31.7.0-alpha09 (#291)
Browse files Browse the repository at this point in the history
* Update lint to v31.6.0-rc01

* 31.7

* Fix quote

* Normalize source strings

* Skip overloads in DaggerIssuesDetector

* Skip overloads in test modes

* Differentiate reports

* Alpha 9

* Update and use direct property

* Update plugin

* Disable noisy awt launchers

* Disable noisy awt launchers

---------

Co-authored-by: Zac Sweers <[email protected]>
  • Loading branch information
slack-oss-bot and ZacSweers authored Sep 2, 2024
1 parent a431f0e commit 9b219e0
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ jobs:

- name: Build and run tests
id: gradle
run: ./gradlew check --quiet -DuseK2Uast=${{ matrix.useK2Uast }}
run: ./gradlew check --quiet -Dlint.use.fir.uast=${{ matrix.useK2Uast }}

- name: (Fail-only) Upload build reports
if: failure()
uses: actions/upload-artifact@v4
with:
name: reports
name: reports-useK2Uast=${{ matrix.useK2Uast }}
path: |
**/build/reports/**
Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ jdk = "21"
# lint checks must target JDK 17, but the runtime should remain 11
lintJvmTarget = "17"
runtimeJvmTarget = "11"
lint = "31.6.0-alpha07"
lint = "31.7.0-alpha09"

[plugins]
buildConfig = { id = "com.github.gmazzo.buildconfig", version = "5.4.0" }
detekt = { id = "io.gitlab.arturbosch.detekt", version = "1.23.6" }
dokka = { id = "org.jetbrains.dokka", version = "1.9.20" }
lint = { id = "com.android.lint", version = "8.7.0-alpha07" }
lint = { id = "com.android.lint", version = "8.7.0-alpha09" }
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
ksp = { id = "com.google.devtools.ksp", version = "2.0.20-1.0.24" }
mavenPublish = { id = "com.vanniktech.maven.publish", version = "0.29.0" }
Expand Down
11 changes: 5 additions & 6 deletions slack-lint-checks/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ buildConfig {
"LINT_KOTLIN_VERSION",
"KotlinVersion(${lintKotlinVersion.major}, ${lintKotlinVersion.minor}, ${lintKotlinVersion.patch})",
)
buildConfigField(
"Boolean",
"USE_K2_UAST",
providers.systemProperty("useK2Uast").orElse("false"),
)
}
}

Expand All @@ -48,7 +43,11 @@ val shade: Configuration = configurations.maybeCreate("compileShaded")

configurations.getByName("compileOnly").extendsFrom(shade)

tasks.test { maxParallelForks = Runtime.getRuntime().availableProcessors() * 2 }
tasks.test {
// Disable noisy java applications launching during tests
jvmArgs("-Djava.awt.headless=true")
maxParallelForks = Runtime.getRuntime().availableProcessors() * 2
}

dependencies {
compileOnly(libs.bundles.lintApi)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.android.tools.lint.detector.api.JavaContext
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 com.android.tools.lint.detector.api.isDuplicatedOverload
import com.android.tools.lint.detector.api.isReceiver
import com.intellij.lang.jvm.JvmClassKind
import com.intellij.psi.PsiTypes
Expand Down Expand Up @@ -132,6 +133,9 @@ class DaggerIssuesDetector : Detector(), SourceCodeScanner {
override fun createUastHandler(context: JavaContext): UElementHandler {
return object : UElementHandler() {
override fun visitMethod(node: UMethod) {
if (node.isDuplicatedOverload()) {
return
}
if (!node.isConstructor) {
val isBinds = node.hasAnnotation(BINDS_ANNOTATION)
val isProvides = node.hasAnnotation(PROVIDES_ANNOTATION)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import slack.lint.resources.ImportAliasesLoader.IMPORT_ALIASES
import slack.lint.util.sourceImplementation

private const val FQN_ANDROID_R = "android.R"
private val WHITESPACE_REGEX = "\\s+".toRegex()

/** Reports an error when an R class is referenced using its fully qualified name. */
class FullyQualifiedResourceDetector : Detector(), SourceCodeScanner {
Expand All @@ -42,8 +43,9 @@ class FullyQualifiedResourceDetector : Detector(), SourceCodeScanner {
if (!isKotlin(node.lang)) return

val qualifier = node.receiver.asSourceString()
if (qualifier.endsWith(".R") && qualifier != FQN_ANDROID_R) {
val alias = importAliases[qualifier]
val normalized = qualifier.trim().replace(WHITESPACE_REGEX, "")
if (normalized.endsWith(".R") && normalized != FQN_ANDROID_R) {
val alias = importAliases[normalized]

context.report(
ISSUE,
Expand Down Expand Up @@ -88,7 +90,7 @@ class FullyQualifiedResourceDetector : Detector(), SourceCodeScanner {
!imports.any {
val importDirective = it.sourcePsi as? KtImportDirective

val importedFqNameString = importDirective?.importedFqName?.asString()
val importedFqNameString = importDirective?.importedFqName?.asString()?.trim()
qualifier == importedFqNameString && alias == importDirective.aliasName
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ abstract class BaseSlackLintTest : LintDetectorTest() {
override fun lint(): TestLintTask {
val sdkLocation = System.getProperty("android.sdk") ?: System.getenv("ANDROID_HOME")
val lintTask = super.lint()
lintTask.configureOptions { flags -> flags.setUseK2Uast(TestBuildConfig.USE_K2_UAST) }
sdkLocation?.let { lintTask.sdkHome(File(it)) }
lintTask.allowCompilationErrors(false)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ class DaggerIssuesDetectorTest : BaseSlackLintTest() {
.indented()
}

override val skipTestModes: Array<TestMode> = arrayOf(TestMode.WHITESPACE, TestMode.SUPPRESSIBLE)
override val skipTestModes: Array<TestMode> =
arrayOf(
TestMode.WHITESPACE,
TestMode.SUPPRESSIBLE,
// This mode adds new parameters to binds() functions, resulting in different error messages
TestMode.JVM_OVERLOADS,
)

override fun getDetector() = DaggerIssuesDetector()

Expand Down

0 comments on commit 9b219e0

Please sign in to comment.