Modern Apps git

← Modern-Apps.git

lint: ScaffoldSearch no longer flags ordinary Research fields

Commit
8c9667544b3cc8fa9f35ccdfca5d902e688ca77f
Author
Vayun Mathur <[email protected]>
When
2026-12-01 10:28 UTC (4 days ago)
Parents
60fe00d
looksLikeSearch substring-matched 'search' in literals and
resource names, so an ordinary form field labelled
'Research topic' (or R.string.research_topic) was flagged
as screen-level search — against the detector's own
contract ('reliably identifiable as search'; 'Ordinary form
fields never match, which is deliberate').

The literal path now requires a token starting with search
at a word boundary, and the resource path requires search
at a snake_case segment start: 'Search stars' and
R.string.search_stars still flag, the Research shapes are
clean. Three regression tests (two expectClean, one
still-flagged) failed 2/3 pre-fix. Verified: :lint-rules:
test BUILD SUCCESSFUL, 75 tests pass. Other agents'
in-flight detectors were left untouched.

Diff

lint-rules/src/main/java/com/vayunmathur/lint/ScaffoldSearchDetector.kt
diff --git a/lint-rules/src/main/java/com/vayunmathur/lint/ScaffoldSearchDetector.kt b/lint-rules/src/main/java/com/vayunmathur/lint/ScaffoldSearchDetector.ktindex cb71c4cd05..03b019beb0 100644--- a/lint-rules/src/main/java/com/vayunmathur/lint/ScaffoldSearchDetector.kt+++ b/lint-rules/src/main/java/com/vayunmathur/lint/ScaffoldSearchDetector.kt@@ -91,7 +91,7 @@ class ScaffoldSearchDetector : Detector(), SourceCodeScanner {         val source = node.asSourceString()         if (source.contains(ICON_SEARCH)) return true         if (SEARCH_RESOURCE.containsMatchIn(source)) return true-        return STRING_LITERAL.findAll(source).any { it.groupValues[1].lowercase().contains(SEARCH_WORD) }+        return STRING_LITERAL.findAll(source).any { SEARCH_WORD.containsMatchIn(it.groupValues[1]) }     }      companion object {@@ -99,7 +99,6 @@ class ScaffoldSearchDetector : Detector(), SourceCodeScanner {         private const val LIBRARY_PREFIX = "com.vayunmathur.library"         private const val MATERIAL3_PREFIX = "androidx.compose.material3"         private const val ICON_SEARCH = "IconSearch"-        private const val SEARCH_WORD = "search"          const val EXCEPTION_MARKER = "// SCAFFOLD SEARCH EXCEPTION:" @@ -116,7 +115,13 @@ class ScaffoldSearchDetector : Detector(), SourceCodeScanner {          private val SEARCH_CALLS = DIRECT_SEARCH_CALLS + TEXT_FIELD_CALLS -        private val SEARCH_RESOURCE = Regex("""\.\s*string\s*\.\s*\w*[Ss]earch\w*""")+        // A `search` token at a word/segment start, never embedded in+        // another word: "Research topic" / `R.string.research_topic` are+        // ordinary form fields, while "Search stars" / `R.string.search_stars`+        // (and "Searching…") identify search.+        private val SEARCH_WORD = Regex("""\bsearch""", RegexOption.IGNORE_CASE)+        private val SEARCH_RESOURCE =+            Regex("""\.\s*string\s*\.\s*(?:[A-Za-z0-9]+_)*search""", RegexOption.IGNORE_CASE)         private val STRING_LITERAL = Regex("\"([^\"]*)\"")          private fun isLibraryPackage(packageName: String): Boolean =
lint-rules/src/test/java/com/vayunmathur/lint/ScaffoldSearchDetectorTest.kt
diff --git a/lint-rules/src/test/java/com/vayunmathur/lint/ScaffoldSearchDetectorTest.kt b/lint-rules/src/test/java/com/vayunmathur/lint/ScaffoldSearchDetectorTest.ktindex 33e86c44dd..74ef6d58ae 100644--- a/lint-rules/src/test/java/com/vayunmathur/lint/ScaffoldSearchDetectorTest.kt+++ b/lint-rules/src/test/java/com/vayunmathur/lint/ScaffoldSearchDetectorTest.kt@@ -100,6 +100,21 @@ class ScaffoldSearchDetectorTest : LintDetectorTest() {         )).run().expectErrorCount(1)     } +    @Test+    fun searchingTextFieldByLiteralIsFlagged() {+        lint().files(UI_STUBS, COMPOSABLE_STUB, LAYOUT_STUB, kotlin(+            """+            package com.vayunmathur.example.ui+            import androidx.compose.runtime.Composable+            import com.vayunmathur.library.ui.OutlinedTextField+            import com.vayunmathur.library.ui.Text+            @Composable fun Screen(q: String) {+                OutlinedTextField(value = q, onValueChange = {}, label = { Text("Searching stars") })+            }+            """.trimIndent(),+        )).run().expectErrorCount(1)+    }+     @Test     fun searchTextFieldByResourceIsFlagged() {         lint().files(UI_STUBS, COMPOSABLE_STUB, LAYOUT_STUB, kotlin(@@ -134,6 +149,40 @@ class ScaffoldSearchDetectorTest : LintDetectorTest() {         )).run().expectClean()     } +    @Test+    fun researchFormFieldIsClean() {+        lint().files(UI_STUBS, COMPOSABLE_STUB, LAYOUT_STUB, kotlin(+            """+            package com.vayunmathur.example.ui+            import androidx.compose.runtime.Composable+            import com.vayunmathur.library.ui.OutlinedTextField+            import com.vayunmathur.library.ui.Text+            @Composable fun Screen(q: String) {+                OutlinedTextField(value = q, onValueChange = {}, label = { Text("Research topic") })+            }+            """.trimIndent(),+        )).run().expectClean()+    }++    @Test+    fun researchResourceFormFieldIsClean() {+        lint().files(UI_STUBS, COMPOSABLE_STUB, LAYOUT_STUB, kotlin(+            """+            package com.vayunmathur.example.ui+            import androidx.compose.runtime.Composable+            import com.vayunmathur.library.ui.OutlinedTextField+            import com.vayunmathur.library.ui.Text+            @Composable fun Screen(q: String) {+                OutlinedTextField(+                    value = q,+                    onValueChange = {},+                    label = { Text(com.vayunmathur.example.R.string.research_topic) },+                )+            }+            """.trimIndent(),+        )).run().expectClean()+    }+     @Test     fun exceptionMarkerOptsOut() {         lint().files(UI_STUBS, COMPOSABLE_STUB, LAYOUT_STUB, kotlin(