diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dc76f1e6..0546a888 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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/** diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 8afc914a..62fdb17b 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -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" } diff --git a/slack-lint-checks/build.gradle.kts b/slack-lint-checks/build.gradle.kts index fff9093b..7b63aab2 100644 --- a/slack-lint-checks/build.gradle.kts +++ b/slack-lint-checks/build.gradle.kts @@ -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"), - ) } } @@ -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) diff --git a/slack-lint-checks/src/main/java/slack/lint/DaggerIssuesDetector.kt b/slack-lint-checks/src/main/java/slack/lint/DaggerIssuesDetector.kt index f032ee91..ba2343dd 100644 --- a/slack-lint-checks/src/main/java/slack/lint/DaggerIssuesDetector.kt +++ b/slack-lint-checks/src/main/java/slack/lint/DaggerIssuesDetector.kt @@ -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 @@ -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) diff --git a/slack-lint-checks/src/main/java/slack/lint/resources/FullyQualifiedResourceDetector.kt b/slack-lint-checks/src/main/java/slack/lint/resources/FullyQualifiedResourceDetector.kt index 46c7255d..2291c2cb 100644 --- a/slack-lint-checks/src/main/java/slack/lint/resources/FullyQualifiedResourceDetector.kt +++ b/slack-lint-checks/src/main/java/slack/lint/resources/FullyQualifiedResourceDetector.kt @@ -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 { @@ -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, @@ -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 } diff --git a/slack-lint-checks/src/test/java/slack/lint/BaseSlackLintTest.kt b/slack-lint-checks/src/test/java/slack/lint/BaseSlackLintTest.kt index 1006f08d..853ad222 100644 --- a/slack-lint-checks/src/test/java/slack/lint/BaseSlackLintTest.kt +++ b/slack-lint-checks/src/test/java/slack/lint/BaseSlackLintTest.kt @@ -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) diff --git a/slack-lint-checks/src/test/java/slack/lint/DaggerIssuesDetectorTest.kt b/slack-lint-checks/src/test/java/slack/lint/DaggerIssuesDetectorTest.kt index 68a5b994..b03cde43 100644 --- a/slack-lint-checks/src/test/java/slack/lint/DaggerIssuesDetectorTest.kt +++ b/slack-lint-checks/src/test/java/slack/lint/DaggerIssuesDetectorTest.kt @@ -32,7 +32,13 @@ class DaggerIssuesDetectorTest : BaseSlackLintTest() { .indented() } - override val skipTestModes: Array = arrayOf(TestMode.WHITESPACE, TestMode.SUPPRESSIBLE) + override val skipTestModes: Array = + 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()