Fix lint checks.

This commit is contained in:
jeffrey-signal
2026-01-07 17:59:05 -05:00
parent 7c11239875
commit 9cf77d320c
10 changed files with 123 additions and 0 deletions

View File

@@ -13,6 +13,7 @@ class AlertDialogBuilderDetectorTest {
fun androidAlertDialogBuilderUsed_LogAlertDialogBuilderUsage_1_arg() {
TestLintTask.lint()
.files(
androidAlertDialogStub,
java(
"""
package foo;
@@ -26,6 +27,7 @@ class AlertDialogBuilderDetectorTest {
)
)
.issues(AlertDialogBuilderDetector.ALERT_DIALOG_BUILDER_USAGE)
.allowMissingSdk()
.run()
.expect(
"""
@@ -49,6 +51,7 @@ class AlertDialogBuilderDetectorTest {
fun androidAlertDialogBuilderUsed_LogAlertDialogBuilderUsage_2_arg() {
TestLintTask.lint()
.files(
androidAlertDialogStub,
java(
"""
package foo;
@@ -62,6 +65,7 @@ class AlertDialogBuilderDetectorTest {
)
)
.issues(AlertDialogBuilderDetector.ALERT_DIALOG_BUILDER_USAGE)
.allowMissingSdk()
.run()
.expect(
"""
@@ -85,6 +89,7 @@ class AlertDialogBuilderDetectorTest {
fun androidAlertDialogBuilderUsed_withAssignment_LogAlertDialogBuilderUsage_1_arg() {
TestLintTask.lint()
.files(
androidAlertDialogStub,
java(
"""
package foo;
@@ -99,6 +104,7 @@ class AlertDialogBuilderDetectorTest {
)
)
.issues(AlertDialogBuilderDetector.ALERT_DIALOG_BUILDER_USAGE)
.allowMissingSdk()
.run()
.expect(
"""
@@ -136,6 +142,7 @@ class AlertDialogBuilderDetectorTest {
)
)
.issues(AlertDialogBuilderDetector.ALERT_DIALOG_BUILDER_USAGE)
.allowMissingSdk()
.run()
.expect(
"""
@@ -173,6 +180,7 @@ class AlertDialogBuilderDetectorTest {
)
)
.issues(AlertDialogBuilderDetector.ALERT_DIALOG_BUILDER_USAGE)
.allowMissingSdk()
.run()
.expect(
"""
@@ -211,6 +219,7 @@ class AlertDialogBuilderDetectorTest {
)
)
.issues(AlertDialogBuilderDetector.ALERT_DIALOG_BUILDER_USAGE)
.allowMissingSdk()
.run()
.expect(
"""
@@ -231,6 +240,7 @@ class AlertDialogBuilderDetectorTest {
}
companion object {
private val androidAlertDialogStub = kotlin(readResourceAsString("AndroidAlertDialogStub.kt"))
private val appCompatAlertDialogStub = kotlin(readResourceAsString("AppCompatAlertDialogStub.kt"))
private fun readResourceAsString(@Suppress("SameParameterValue") resourceName: String): String {

View File

@@ -27,6 +27,7 @@ class CardViewDetectorTest {
)
)
.issues(CardViewDetector.CARD_VIEW_USAGE)
.allowMissingSdk()
.run()
.expect(
"""
@@ -64,6 +65,7 @@ class CardViewDetectorTest {
)
)
.issues(CardViewDetector.CARD_VIEW_USAGE)
.allowMissingSdk()
.run()
.expect(
"""
@@ -102,6 +104,7 @@ class CardViewDetectorTest {
)
)
.issues(CardViewDetector.CARD_VIEW_USAGE)
.allowMissingSdk()
.run()
.expect(
"""

View File

@@ -23,6 +23,7 @@ class RecipientIdDatabaseDetectorTest {
)
)
.issues(RecipientIdDatabaseDetector.RECIPIENT_ID_DATABASE_REFERENCE_ISSUE)
.allowMissingSdk()
.run()
.expect(
"""
@@ -52,6 +53,7 @@ class RecipientIdDatabaseDetectorTest {
)
)
.issues(RecipientIdDatabaseDetector.RECIPIENT_ID_DATABASE_REFERENCE_ISSUE)
.allowMissingSdk()
.run()
.expectClean()
}

View File

@@ -14,6 +14,7 @@ class SignalLogDetectorTest {
fun androidLogUsed_LogNotSignal_2_args() {
TestLintTask.lint()
.files(
androidLogStub,
java(
"""
package foo;
@@ -27,6 +28,7 @@ class SignalLogDetectorTest {
)
)
.issues(SignalLogDetector.LOG_NOT_SIGNAL)
.allowMissingSdk()
.run()
.expect(
"""
@@ -50,6 +52,7 @@ class SignalLogDetectorTest {
fun androidLogUsed_LogNotSignal_3_args() {
TestLintTask.lint()
.files(
androidLogStub,
java(
"""
package foo;
@@ -63,6 +66,7 @@ class SignalLogDetectorTest {
)
)
.issues(SignalLogDetector.LOG_NOT_SIGNAL)
.allowMissingSdk()
.run()
.expect(
"""
@@ -100,6 +104,7 @@ class SignalLogDetectorTest {
)
)
.issues(SignalLogDetector.LOG_NOT_APP)
.allowMissingSdk()
.run()
.expect(
"""
@@ -137,6 +142,7 @@ class SignalLogDetectorTest {
)
)
.issues(SignalLogDetector.LOG_NOT_APP)
.allowMissingSdk()
.run()
.expect(
"""
@@ -175,6 +181,7 @@ class SignalLogDetectorTest {
)
)
.issues(SignalLogDetector.INLINE_TAG)
.allowMissingSdk()
.run()
.expectClean()
}
@@ -198,6 +205,7 @@ class SignalLogDetectorTest {
)
)
.issues(SignalLogDetector.INLINE_TAG)
.allowMissingSdk()
.skipTestModes(TestMode.REORDER_ARGUMENTS)
.run()
.expectClean()
@@ -225,6 +233,7 @@ class SignalLogDetectorTest {
)
)
.issues(SignalLogDetector.INLINE_TAG)
.allowMissingSdk()
.skipTestModes(TestMode.REORDER_ARGUMENTS)
.run()
.expectClean()
@@ -248,6 +257,7 @@ class SignalLogDetectorTest {
)
)
.issues(SignalLogDetector.INLINE_TAG)
.allowMissingSdk()
.run()
.expect(
"""
@@ -278,6 +288,7 @@ class SignalLogDetectorTest {
)
)
.issues(SignalLogDetector.INLINE_TAG)
.allowMissingSdk()
.run()
.expect(
"""
@@ -308,6 +319,7 @@ class SignalLogDetectorTest {
)
)
.issues(SignalLogDetector.LOG_NOT_SIGNAL)
.allowMissingSdk()
.run()
.expect(
"""
@@ -328,6 +340,7 @@ class SignalLogDetectorTest {
}
companion object {
private val androidLogStub = kotlin(readResourceAsString("AndroidLogStub.kt"))
private val serviceLogStub = kotlin(readResourceAsString("ServiceLogStub.kt"))
private val appLogStub = kotlin(readResourceAsString("AppLogStub.kt"))
private val glideLogStub = kotlin(readResourceAsString("GlideLogStub.kt"))

View File

@@ -23,6 +23,7 @@ class ThreadIdDatabaseDetectorTest {
)
)
.issues(ThreadIdDatabaseDetector.THREAD_ID_DATABASE_REFERENCE_ISSUE)
.allowMissingSdk()
.run()
.expect(
"""
@@ -52,6 +53,7 @@ class ThreadIdDatabaseDetectorTest {
)
)
.issues(ThreadIdDatabaseDetector.THREAD_ID_DATABASE_REFERENCE_ISSUE)
.allowMissingSdk()
.run()
.expectClean()
}

View File

@@ -13,6 +13,7 @@ class VersionCodeDetectorTest {
fun version_code_constant_referenced_in_code() {
TestLintTask.lint()
.files(
androidBuildStub,
java(
"""
package foo;
@@ -28,6 +29,7 @@ class VersionCodeDetectorTest {
)
)
.issues(VersionCodeDetector.VERSION_CODE_USAGE)
.allowMissingSdk()
.run()
.expect(
"""
@@ -51,6 +53,7 @@ class VersionCodeDetectorTest {
fun numeric_value_referenced_in_code() {
TestLintTask.lint()
.files(
androidBuildStub,
java(
"""
package foo;
@@ -66,6 +69,7 @@ class VersionCodeDetectorTest {
)
)
.issues(VersionCodeDetector.VERSION_CODE_USAGE)
.allowMissingSdk()
.run()
.expectClean()
}
@@ -74,6 +78,7 @@ class VersionCodeDetectorTest {
fun non_version_code_constant_referenced_in_code() {
TestLintTask.lint()
.files(
androidBuildStub,
java(
"""
package foo;
@@ -90,6 +95,7 @@ class VersionCodeDetectorTest {
)
)
.issues(VersionCodeDetector.VERSION_CODE_USAGE)
.allowMissingSdk()
.run()
.expectClean()
}
@@ -98,6 +104,8 @@ class VersionCodeDetectorTest {
fun version_code_constant_referenced_in_TargetApi_attribute_and_inner_class_import() {
TestLintTask.lint()
.files(
androidBuildStub,
androidAnnotationStub,
java(
"""
package foo;
@@ -112,6 +120,7 @@ class VersionCodeDetectorTest {
)
)
.issues(VersionCodeDetector.VERSION_CODE_USAGE)
.allowMissingSdk()
.run()
.expect(
"""
@@ -135,6 +144,8 @@ class VersionCodeDetectorTest {
fun version_code_constant_referenced_in_RequiresApi_attribute_with_named_parameter() {
TestLintTask.lint()
.files(
androidBuildStub,
androidAnnotationStub,
requiresApiStub,
java(
"""
@@ -150,6 +161,7 @@ class VersionCodeDetectorTest {
)
)
.issues(VersionCodeDetector.VERSION_CODE_USAGE)
.allowMissingSdk()
.run()
.expect(
"""
@@ -170,6 +182,8 @@ class VersionCodeDetectorTest {
}
companion object {
private val androidBuildStub = kotlin(readResourceAsString("AndroidBuildStub.kt"))
private val androidAnnotationStub = kotlin(readResourceAsString("AndroidAnnotationStub.kt"))
private val requiresApiStub = kotlin(readResourceAsString("RequiresApiStub.kt"))
private fun readResourceAsString(@Suppress("SameParameterValue") resourceName: String): String {

View File

@@ -0,0 +1,13 @@
package android.app
class AlertDialog {
class Builder {
constructor(context: Context?)
constructor(context: Context?, themeOverrideId: Int)
fun show(): AlertDialog? {
return null
}
}
}
class Context

View File

@@ -0,0 +1,5 @@
package android.annotation
annotation class TargetApi(val value: Int)
annotation class RequiresApi(val app: Int = 1)

View File

@@ -0,0 +1,14 @@
package android.os
class Build {
object VERSION {
const val SDK_INT = 0
}
object VERSION_CODES {
const val LOLLIPOP = 21
const val LOLLIPOP_MR1 = 22
const val M = 23
const val N = 24
}
}

View File

@@ -0,0 +1,47 @@
package android.util
object Log {
fun v(tag: String?, msg: String?): Int {
return 0
}
fun v(tag: String?, msg: String?, tr: Throwable?): Int {
return 0
}
fun d(tag: String?, msg: String?): Int {
return 0
}
fun d(tag: String?, msg: String?, tr: Throwable?): Int {
return 0
}
fun i(tag: String?, msg: String?): Int {
return 0
}
fun i(tag: String?, msg: String?, tr: Throwable?): Int {
return 0
}
fun w(tag: String?, msg: String?): Int {
return 0
}
fun w(tag: String?, msg: String?, tr: Throwable?): Int {
return 0
}
fun w(tag: String?, tr: Throwable?): Int {
return 0
}
fun e(tag: String?, msg: String?): Int {
return 0
}
fun e(tag: String?, msg: String?, tr: Throwable?): Int {
return 0
}
}