lint: exempt shared library/e2ee/games from OneComposablePerFile; exempt e2ee from PackageStructure
- Commit
e69176cebb086a8741103e7f0ef0e62aa1c2cf7c- Author
- vayun-mathur <[email protected]>
- When
- 2026-08-15 23:31 UTC (3 months ago)
- Parents
f259814
Diff
lint-rules/src/main/java/com/vayunmathur/lint/LintPackageExclusions.kt
diff --git a/lint-rules/src/main/java/com/vayunmathur/lint/LintPackageExclusions.kt b/lint-rules/src/main/java/com/vayunmathur/lint/LintPackageExclusions.ktnew file mode 100644index 0000000000..188495f4c0--- /dev/null+++ b/lint-rules/src/main/java/com/vayunmathur/lint/LintPackageExclusions.kt@@ -0,0 +1,37 @@+package com.vayunmathur.lint++/**+ * Package prefixes that are exempt from the app-structure lints+ * ([PackageStructureDetector] and [OneComposablePerFileDetector]).+ *+ * Both rules encode APP conventions — the closed canonical root allow-list and+ * one public @Composable per screen file. The prefixes below are NOT apps, so+ * those conventions do not apply and must be skipped by both detectors (kept in+ * one place so the two stay in sync):+ * - `com.vayunmathur.library` — shared UI/util library. `library/ui` is a+ * Material + icon shim that is intentionally many-composables-per-file+ * (e.g. Icons.kt, MaterialComponents.kt), and its flat package layout is+ * not the app root structure.+ * - `com.vayunmathur.e2ee` — shared end-to-end-encryption library+ * (`library/e2ee-p2p`); a flat crypto API package, not an app root.+ * - `com.vayunmathur.sdk` — shared SDK modules.+ * - `com.vayunmathur.games` — games use their own UI structure; the+ * one-public-composable-per-file splits were deliberately deferred.+ * - `com.vayunmathur.tools` — internal tooling, not shipped apps.+ * - `com.vayunmathur.personal` — personal/scratch modules.+ */+object LintPackageExclusions {++ val EXCLUDED_PREFIXES: List<String> = listOf(+ "com.vayunmathur.library",+ "com.vayunmathur.e2ee",+ "com.vayunmathur.sdk",+ "com.vayunmathur.games",+ "com.vayunmathur.tools",+ "com.vayunmathur.personal",+ )++ /** True if [packageName] is (or is nested under) an excluded module prefix. */+ fun isExcluded(packageName: String): Boolean =+ EXCLUDED_PREFIXES.any { packageName == it || packageName.startsWith("$it.") }+}
lint-rules/src/main/java/com/vayunmathur/lint/OneComposablePerFileDetector.kt
diff --git a/lint-rules/src/main/java/com/vayunmathur/lint/OneComposablePerFileDetector.kt b/lint-rules/src/main/java/com/vayunmathur/lint/OneComposablePerFileDetector.ktindex 370ccbc1c7..0df3fa4097 100644--- a/lint-rules/src/main/java/com/vayunmathur/lint/OneComposablePerFileDetector.kt+++ b/lint-rules/src/main/java/com/vayunmathur/lint/OneComposablePerFileDetector.kt@@ -31,6 +31,12 @@ class OneComposablePerFileDetector : Detector(), SourceCodeScanner { override fun createUastHandler(context: JavaContext): UElementHandler = object : UElementHandler() { override fun visitFile(node: UFile) {+ // App-screen rule only: skip shared library / e2ee / sdk / games /+ // tools / personal modules (same exclusion set as PackageStructure).+ // The library/ui Material+icon shim is many-composables-per-file by+ // design, and games splits were deliberately deferred.+ if (LintPackageExclusions.isExcluded(node.packageName)) return+ // Names of public top-level composables already seen in this file. // The first is allowed; each additional *distinct* name is a violation. // Overloads reuse a name, so they never trip the check.
lint-rules/src/main/java/com/vayunmathur/lint/PackageStructureDetector.kt
diff --git a/lint-rules/src/main/java/com/vayunmathur/lint/PackageStructureDetector.kt b/lint-rules/src/main/java/com/vayunmathur/lint/PackageStructureDetector.ktindex 5677fce426..4f7bf0127f 100644--- a/lint-rules/src/main/java/com/vayunmathur/lint/PackageStructureDetector.kt+++ b/lint-rules/src/main/java/com/vayunmathur/lint/PackageStructureDetector.kt@@ -107,16 +107,12 @@ class PackageStructureDetector : Detector(), SourceCodeScanner { "service", "provider", "widget", "notifications", "auth", "sync", "telephony" ) - private val EXCLUDED_PREFIXES = listOf(- "com.vayunmathur.library",- "com.vayunmathur.sdk",- "com.vayunmathur.games",- "com.vayunmathur.tools",- "com.vayunmathur.personal",- )-+ // Shared with OneComposablePerFileDetector via [LintPackageExclusions] so+ // both app-structure lints skip the same non-app modules (shared library,+ // e2ee crypto lib, sdk, games, tools, personal). See that file for the+ // per-prefix rationale. fun isExcluded(packageName: String): Boolean =- EXCLUDED_PREFIXES.any { packageName == it || packageName.startsWith("$it.") }+ LintPackageExclusions.isExcluded(packageName) // JNI carve-out: a handful of classes have their fully-qualified name frozen // because the native side binds to it via RegisterNatives / C++ symbol mangling.