For #17917 - Remove the Kotlin synthetics Lint detector

Since all usages of Kotlin synthetics are removed and no such code is generated
anymore there is no need to keep around this Detector anymore.
releases_v93.0.0
Mugurell 1 year ago committed by mergify[bot]
parent cb32b1437e
commit 0fa9363f99
  1. 1254
      app/lint-baseline.xml
  2. 62
      mozilla-lint-rules/src/main/java/org/mozilla/fenix/lintrules/KotlinSyntheticsDetector.kt
  3. 3
      mozilla-lint-rules/src/main/java/org/mozilla/fenix/lintrules/LintIssueRegistry.kt
  4. 71
      mozilla-lint-rules/src/test/java/org/mozilla/fenix/lintrules/KotlinSyntheticsDetectorTest.kt

File diff suppressed because it is too large Load Diff

@ -1,62 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
@file:Suppress("UnstableApiUsage")
package org.mozilla.fenix.lintrules
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 org.jetbrains.uast.UElement
import org.jetbrains.uast.UImportStatement
/**
* Custom Lint detector that checks for deprecated "kotlinx.android.synthetic" imports.
*/
class KotlinSyntheticsDetector : Detector(), SourceCodeScanner {
override fun createUastHandler(context: JavaContext) = object : UElementHandler() {
override fun visitImportStatement(node: UImportStatement) {
node.importReference?.asSourceString()?.let { import ->
if (import.startsWith(SYNTHETIC_IMPORT_PATTERN)) {
context.report(
DEPRECATED_KOTLIN_SYNTHETICS_ISSUE,
node,
context.getLocation(node),
DEPRECATED_KOTLIN_SYNTHETICS_MESSAGE
)
}
}
}
}
override fun getApplicableUastTypes(): List<Class<out UElement>> {
return listOf(UImportStatement::class.java)
}
companion object {
private const val DEPRECATED_KOTLIN_SYNTHETICS_MESSAGE = "Kotlin synthetics are to be replaced with Jetpack View Binding. " +
"Please refer to https://github.com/mozilla-mobile/fenix/issues/17917 for more details."
private const val SYNTHETIC_IMPORT_PATTERN = "kotlinx.android.synthetic"
val DEPRECATED_KOTLIN_SYNTHETICS_ISSUE = Issue.create(
"KotlinSyntheticsDeprecation",
briefDescription = "Kotlin synthetics are deprecated and actively refactored out",
explanation = "The 'kotlin-android-extensions' Gradle plugin is deprecated and " +
"will be removed in a future Kotlin release in (or after) September 2021. " +
"We are to migrate to Jetpack View Binding. " +
"Please refer to https://github.com/mozilla-mobile/fenix/issues/17917",
category = Category.PRODUCTIVITY,
severity = Severity.ERROR,
implementation = Implementation(KotlinSyntheticsDetector::class.java, Scope.JAVA_FILE_SCOPE)
)
}
}

@ -21,8 +21,7 @@ class LintIssueRegistry : IssueRegistry() {
TextViewAndroidSrcXmlDetector.ISSUE_XML_SRC_USAGE,
ImageViewAndroidTintXmlDetector.ISSUE_XML_SRC_USAGE,
LicenseDetector.ISSUE_MISSING_LICENSE,
LicenseDetector.ISSUE_INVALID_LICENSE_FORMAT,
KotlinSyntheticsDetector.DEPRECATED_KOTLIN_SYNTHETICS_ISSUE
LicenseDetector.ISSUE_INVALID_LICENSE_FORMAT
) + ConstraintLayoutPerfDetector.ISSUES + ContextCompatDetector.ISSUES
override val vendor: Vendor = Vendor(
vendorName = "Mozilla",

@ -1,71 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
@file:Suppress("UnstableApiUsage")
package org.mozilla.fenix.lintrules
import com.android.tools.lint.checks.infrastructure.LintDetectorTest
import com.android.tools.lint.checks.infrastructure.TestFiles
import com.android.tools.lint.detector.api.Detector
import com.android.tools.lint.detector.api.Issue
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.mozilla.fenix.lintrules.KotlinSyntheticsDetector.Companion.DEPRECATED_KOTLIN_SYNTHETICS_ISSUE
@RunWith(JUnit4::class)
class KotlinSyntheticsDetectorTest : LintDetectorTest() {
override fun getIssues(): MutableList<Issue> = mutableListOf(DEPRECATED_KOTLIN_SYNTHETICS_ISSUE)
override fun getDetector(): Detector = KotlinSyntheticsDetector()
@Test
fun `GIVEN no kotlin synthetics import WHEN KotlinSyntheticsDetector runs THEN there are no errors or exceptions`() {
val code = """
|package example
|
|import org.mozilla.fenix.databinding.OnboardingTrackingProtectionBinding
|
|class SomeExample {
| fun hello() {
| println("World")
| }
|}""".trimMargin()
lint()
.files(TestFiles.kt(code))
.allowCompilationErrors()
.allowMissingSdk(true)
.run()
.expectClean()
}
@Test
fun `GIVEN a kotlin synthetics import WHEN KotlinSyntheticsDetector runs THEN there are no errors or exceptions`() {
val code = """
|package example
|
|import kotlinx.android.synthetic.main.layout
|
|class SomeExample {
| fun hello() {
| println("World")
| }
|}""".trimMargin()
val expectedReport = """
|src/example/SomeExample.kt:3: Error: Kotlin synthetics are to be replaced with Jetpack View Binding. Please refer to https://github.com/mozilla-mobile/fenix/issues/17917 for more details. [KotlinSyntheticsDeprecation]
|import kotlinx.android.synthetic.main.layout
|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|1 errors, 0 warnings""".trimMargin()
lint()
.files(TestFiles.kt(code))
.allowMissingSdk(true)
.run()
.expect(expectedReport)
}
}
Loading…
Cancel
Save