lint: codify package structure and make all lint rules blocking
- Commit
01048a815917b0faaddc86bde9fc8a160d9b17e5- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-19 03:42 UTC (17 days ago)
- Parents
be1348e
Adds docs/package-structure.md as the normative package grammar (closed roots, flat singular widget/, banned descendant segments, per-root ownership of Networking, native wrappers, preferences, and intent contracts) and points root AGENTS.md §2 at it. PackageStructureDetector now reports banned descendant segments (widget.<child>, api, impl, util, viewmodel, ...) in addition to the closed roots and app-root file contracts. The remaining advisory detectors (CommentedOutCode, ExceptionMarkerFormat, TodoEvasion, WindowInsetsInReusableComponent) move to Severity.ERROR, and both the app and library Gradle conventions list all thirteen Modern-Apps lint issues as fatal, so a custom-lint finding can no longer land as a warning. Verified: :lint-rules:compileKotlin, plus :calendar:lintDev and :weather:lintDev green under the all-fatal configuration.
Diff
AGENTS.md
diff --git a/AGENTS.md b/AGENTS.mdindex 0c92f7f3d0..add3e04fbf 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -68,6 +68,11 @@ The backend (relay server for findfamily/everysync/office/voxels) lives outside - Room 3 only. Literal `androidx.room.` flagged even in comments. Never `buildDatabase()` at call site — subclass `library.room.RoomRepository`. - Network only via `library.network.NetworkClient` + `TrustBundle` narrowest (`FIRST_PARTY/STANDARD/EXTENDED/SYSTEM/ESIM`). - Package roots closed set: `ui data domain platform network intents service provider widget notifications auth sync telephony`. No `util/`. One public `@Composable` per file, named as file. `domain/` pure (no Android/Compose).+- Package grammar is normative in `docs/package-structure.md`: package segments name responsibilities/features, never generic buckets (`util`, `common`, `helper`, `manager`, `api`, `viewmodel`, …) or UI toolkits. Widget code is flat in `widget/` — never `widgets/`, `widget/glance/`, `glance/`, or any `widget.<child>/`.+- Every app with networking has exactly one public `network.Networking` entry point. It owns `NetworkClient`, the narrowest `TrustBundle`, URLs, endpoint paths, auth headers, retries, and status mapping. No package outside `network/` (and `library.network`) may construct raw API requests.+- Every native library has exactly one guarded wrapper in `platform/` named `<Feature>Native`; it is the only `System.loadLibrary` caller for that library and exposes availability instead of letting initialization fail. JNI-frozen FQNs are the only package exceptions and must carry the verbatim JNI marker.+- Every app has exactly one preferences owner in `data/` named `<App>Prefs`; only it opens the app’s DataStore/SharedPreferences, and it recovers from corruption with documented defaults. Persisted/external decoding goes through non-throwing helpers in `data/` or `domain/`; Room converters never throw.+- Every exported entry point has one validated contract in `intents/`; entry points consume validated values only. Regexes must be Android-ICU-valid (escape literal braces outside quantifiers/character classes). Widgets render from one immutable snapshot and use fallbacks for missing keys/items. - Escape hatches verbatim: `// PACKAGE STRUCTURE EXCEPTION (JNI)`, `// RAW SCAFFOLD EXCEPTION: <reason>`, `// TOAST EXCEPTION: <reason>`, `// RAW ANIMATION EXCEPTION: <reason>`. - detekt rules live in `detekt.yml` (ui/domain/odf/service scoping rationale inline). Fix code, not config, to green a module.
build-logic/src/main/kotlin/common-conventions-app.gradle.kts
diff --git a/build-logic/src/main/kotlin/common-conventions-app.gradle.kts b/build-logic/src/main/kotlin/common-conventions-app.gradle.ktsindex 2b6b431c6c..1a33023e70 100644--- a/build-logic/src/main/kotlin/common-conventions-app.gradle.kts+++ b/build-logic/src/main/kotlin/common-conventions-app.gradle.kts@@ -183,15 +183,6 @@ configure<com.android.build.api.dsl.ApplicationExtension> { // as warnings; they promote to fatal with the rest at promotion. warning += listOf( "HardcodedText",- // Repo rules from :lint-rules. Only the three gates below are not advisory.- "DirectBuildDatabase",- "OneComposablePerFile",- "PackageStructure",- "RawScaffoldInApp",- "Room2Usage",- "ExceptionMarkerFormat",- "TodoEvasion",- "CommentedOutCode", // Built-in checks. "ContextCastToActivity", "ExtraTranslation",@@ -214,14 +205,27 @@ configure<com.android.build.api.dsl.ApplicationExtension> { "UnsafeOptInUsageError", "WrongConstant", )- // Toast is banned repo-wide; this one fails the build even though- // everything else is advisory. See :lint-rules.- // DirectComposeAnimation keeps motion in the shared helpers, so the same- // interaction cannot pick up a different duration on every screen.- // FileLength caps Kotlin file size (350 ui / 800 elsewhere): oversized- // screen files hide brace-imbalance breakage and rot into helper- // grab-bags. Split first — the build fails until each file fits.- fatal += listOf("ToastUsage", "DirectComposeAnimation", "FileLength", "DirectAndroidLog")+ // Every Modern-Apps lint issue is blocking. A finding must be fixed in+ // code; it may not be demoted, suppressed, or baselined to land.+ // Toast is banned repo-wide, DirectComposeAnimation keeps motion in+ // the shared helpers, and FileLength caps Kotlin file size (350 ui /+ // 800 elsewhere): oversized screen files hide brace-imbalance+ // breakage and rot into helper grab-bags. Split first.+ fatal += listOf(+ "ToastUsage",+ "DirectAndroidLog",+ "DirectBuildDatabase",+ "DirectComposeAnimation",+ "FileLength",+ "OneComposablePerFile",+ "PackageStructure",+ "RawScaffoldInApp",+ "Room2Usage",+ "WindowInsetsInReusableComponent",+ "ExceptionMarkerFormat",+ "TodoEvasion",+ "CommentedOutCode",+ ) } // Every app declares the same res/resources.properties (unqualifiedResLocale) for
build-logic/src/main/kotlin/common-conventions-library.gradle.kts
diff --git a/build-logic/src/main/kotlin/common-conventions-library.gradle.kts b/build-logic/src/main/kotlin/common-conventions-library.gradle.ktsindex fd64ccba6a..d4ea2093f6 100644--- a/build-logic/src/main/kotlin/common-conventions-library.gradle.kts+++ b/build-logic/src/main/kotlin/common-conventions-library.gradle.kts@@ -64,15 +64,26 @@ configure<com.android.build.api.dsl.LibraryExtension> { } lint {- // Toast is banned repo-wide. Apps also catch this transitively via- // checkDependencies, but failing here gives faster feedback when- // working inside a library module.- // FileLength caps Kotlin file size, same as apps: split first.- // DirectAndroidLog keeps all logging on the repo facade.- fatal += listOf("ToastUsage", "FileLength", "DirectAndroidLog")- // Lint sweep (warn-then-error): mirror the app warnings so- // library modules surface marker-shape drift without failing the build.- warning += listOf("ExceptionMarkerFormat", "TodoEvasion", "CommentedOutCode")+ // Every Modern-Apps lint issue is blocking in library modules too.+ // A finding must be fixed in code; it may not be demoted, suppressed,+ // or baselined to land. Toast is banned repo-wide, FileLength caps+ // Kotlin file size (split first), and DirectAndroidLog keeps all+ // logging on the repo facade.+ fatal += listOf(+ "ToastUsage",+ "DirectAndroidLog",+ "DirectBuildDatabase",+ "DirectComposeAnimation",+ "FileLength",+ "OneComposablePerFile",+ "PackageStructure",+ "RawScaffoldInApp",+ "Room2Usage",+ "WindowInsetsInReusableComponent",+ "ExceptionMarkerFormat",+ "TodoEvasion",+ "CommentedOutCode",+ ) } }
calendar/src/main/java/com/vayunmathur/calendar/widget/CalendarGlanceWidget.kt
diff --git a/calendar/src/main/java/com/vayunmathur/calendar/widget/glance/CalendarGlanceWidget.kt b/calendar/src/main/java/com/vayunmathur/calendar/widget/CalendarGlanceWidget.ktsimilarity index 100%rename from calendar/src/main/java/com/vayunmathur/calendar/widget/glance/CalendarGlanceWidget.ktrename to calendar/src/main/java/com/vayunmathur/calendar/widget/CalendarGlanceWidget.kt
calendar/src/main/java/com/vayunmathur/calendar/widget/CalendarGlanceWidgetReceiver.kt
diff --git a/calendar/src/main/java/com/vayunmathur/calendar/widget/glance/CalendarGlanceWidgetReceiver.kt b/calendar/src/main/java/com/vayunmathur/calendar/widget/CalendarGlanceWidgetReceiver.ktsimilarity index 100%rename from calendar/src/main/java/com/vayunmathur/calendar/widget/glance/CalendarGlanceWidgetReceiver.ktrename to calendar/src/main/java/com/vayunmathur/calendar/widget/CalendarGlanceWidgetReceiver.kt
calendar/src/main/java/com/vayunmathur/calendar/widget/CalendarMonthGlanceWidget.kt
diff --git a/calendar/src/main/java/com/vayunmathur/calendar/widget/glance/CalendarMonthGlanceWidget.kt b/calendar/src/main/java/com/vayunmathur/calendar/widget/CalendarMonthGlanceWidget.ktsimilarity index 100%rename from calendar/src/main/java/com/vayunmathur/calendar/widget/glance/CalendarMonthGlanceWidget.ktrename to calendar/src/main/java/com/vayunmathur/calendar/widget/CalendarMonthGlanceWidget.kt
calendar/src/main/java/com/vayunmathur/calendar/widget/CalendarMonthGlanceWidgetReceiver.kt
diff --git a/calendar/src/main/java/com/vayunmathur/calendar/widget/glance/CalendarMonthGlanceWidgetReceiver.kt b/calendar/src/main/java/com/vayunmathur/calendar/widget/CalendarMonthGlanceWidgetReceiver.ktsimilarity index 100%rename from calendar/src/main/java/com/vayunmathur/calendar/widget/glance/CalendarMonthGlanceWidgetReceiver.ktrename to calendar/src/main/java/com/vayunmathur/calendar/widget/CalendarMonthGlanceWidgetReceiver.kt
calendar/src/test/java/com/vayunmathur/calendar/widget/GlanceContentTest.kt
diff --git a/calendar/src/test/java/com/vayunmathur/calendar/glance/GlanceContentTest.kt b/calendar/src/test/java/com/vayunmathur/calendar/widget/GlanceContentTest.ktsimilarity index 100%rename from calendar/src/test/java/com/vayunmathur/calendar/glance/GlanceContentTest.ktrename to calendar/src/test/java/com/vayunmathur/calendar/widget/GlanceContentTest.kt
docs/package-structure.md
diff --git a/docs/package-structure.md b/docs/package-structure.mdnew file mode 100644index 0000000000..3c4355f8b2--- /dev/null+++ b/docs/package-structure.md@@ -0,0 +1,247 @@+# Package and code-structure mandate++This document is normative. “Must” and “must not” are merge requirements,+not preferences. The root `AGENTS.md` §2 is the short form; this file is the+complete rulebook. A change that needs a new package root, package segment,+or structural exception must update this document, `AGENTS.md`, and the+relevant lint detector in the same change. A suppression, lint baseline, or+detekt/lint config relaxation is not an exception mechanism.++## 1. Applicability and profiles++### 1.1 App profile++The app profile applies to every shipped Android app whose base package is+`com.vayunmathur.<app>`, including the nested `com.vayunmathur.cast.tv`+app. The Gradle module layout must mirror the package ownership below.++### 1.2 Shared-library and SDK profile++`com.vayunmathur.library.*`, `com.vayunmathur.sdk.*`, and the two wire-format+packages `com.vayunmathur.cast.protocol` and `com.vayunmathur.auto.protocol`+are shared-library packages, not app packages. Their first segment names the+library or wire module. Files inside them still follow the responsibility+rules in §4–§10: transport code in the networking library, persistence code+in the persistence library, native bridges behind guarded wrappers, and no+generic dumping-ground packages.++### 1.3 Games profile++Game packages under `com.vayunmathur.games.<game>` are not silently exempt+from architecture review. They use the same responsibility vocabulary+(`ui`, `data`, `domain`, `platform`, `network`, `intents`, `service`,+`provider`, `widget`, `notifications`, `auth`, `sync`, `telephony`) below+the game segment. A game may keep an existing game-specific layout only as+migration debt; it must not add a new top-level game root or a generic+package segment.++## 2. Package grammar++An app package has this shape:++```text+com.vayunmathur.<app>[.<root>[.<feature>[.<subfeature>]]]+```++1. Every segment is lowercase ASCII and uses a singular responsibility noun+ (for example `widget`, not `widgets`).+2. The first segment after the app base is called the **root**. Roots are a+ closed set (§3). No other root may be introduced without amending this+ document, `AGENTS.md`, and `PackageStructureDetector` together.+3. A segment below the root names a feature, capability, provider, protocol,+ or data boundary. It must not name a programming-language construct, UI+ toolkit, generic class type, or vague bucket.+4. The following segments are forbidden at every depth:+ `api`, `apis`, `base`, `common`, `core`, `feature`, `features`, `helper`,+ `helpers`, `impl`, `manager`, `managers`, `misc`, `presentation`,+ `repository`, `repositories`, `screen`, `screens`, `util`, `utils`,+ `view`, `views`, `viewmodel`, and `viewmodels`.+5. The canonical class-shape exceptions are `ui/components`, `ui/dialogs`,+ and `data/model`. They are allowed only with those exact meanings:+ reusable UI pieces, modal UI, and persisted/wire data shapes. They do not+ authorize synonyms elsewhere.+6. A package must not be created for one trivial file unless it is a root or+ one of the explicit structural owners in §§5–10.+7. The directory path and the Kotlin `package` declaration must agree.++## 3. Closed app roots and root files++### 3.1 Allowed roots++An app may use only these roots:++| Root | Sole responsibility |+|---|---|+| `ui` | Screens, screen content, dialogs, and reusable app UI components. |+| `data` | Room, DataStore, files, repositories, persistence/wire DTO mapping, and the single preferences owner. |+| `domain` | Pure models, algorithms, parsers, validators, and business rules with no Android or Compose dependency. |+| `platform` | ViewModels, Android-framework adapters, sensors, system-service integration, and guarded native bridges. |+| `network` | The app’s single public `Networking` entry point and its private endpoint/protocol implementation. |+| `intents` | Assistant/cross-app IPC contracts and exported-intent parsing/validation. |+| `service` | Android `Service` implementations and service-owned helpers. |+| `provider` | Android `ContentProvider` implementations. |+| `widget` | All home-screen widget code, flat: Glance widgets, legacy widget providers, receivers, actions, and widget state. |+| `notifications` | Notification channels, builders, actions, and presentation. |+| `auth` | Sign-in, credentials, account/session state, and authentication flows. |+| `sync` | Sync adapters, sync workers, and reconciliation. |+| `telephony` | Carrier, SIM, telephony, and messaging-transport adapters. |++### 3.2 Widget package rule++Widget code must be directly under `.<app>.widget`. The following are+forbidden:++- `.<app>.widgets`+- `.<app>.widget.glance`+- `.<app>.glance`+- any other descendant of `.<app>.widget`++`Glance` is an implementation detail of the widget surface, not a package+boundary. A widget receiver, widget class, action callback, and immutable+widget snapshot all belong directly in `widget`.++### 3.3 App-root files++When the base package `com.vayunmathur.<app>` is not empty, it may contain+only:++- `MainActivity.kt`, containing only `class MainActivity : MaActivity`;+- `Route.kt`, containing only `sealed interface Route : NavKey` and nested+ route declarations;+- `Navigation.kt`, containing only `@Composable fun Navigation(...)`;+- `*Application.kt`, containing only the matching `Application` subclass.++No other declaration may live in the app-root package.++## 4. Root ownership rules++### 4.1 `ui`++- A screen or content composable lives in `ui`; a ViewModel never lives in+ `ui`.+- There is one public `@Composable` per file, and the file is named for it.+- `ui` must not construct HTTP requests, open databases, access raw+ preferences, load native libraries, or parse exported intents.+- Feature subpackages are allowed. `ui/components` and `ui/dialogs` are the+ only class-shape subpackages.++### 4.2 `data`++- Room databases, DAOs, repositories, DataStore owners, files, and DTO+ mapping live here.+- Every app has exactly one preferences owner in `data`, named+ `<App>Prefs` (for example `CalendarPrefs`). It is the only app code that+ opens that app’s DataStore or SharedPreferences. It must expose typed+ values/flows and must recover from `CorruptionException` by returning the+ documented default state instead of crashing.+- Persisted or external data must be decoded through non-throwing helpers+ in `data` or `domain`. A Room type converter must never throw; corrupt+ input maps to null, an empty value, or a clamped valid value.++### 4.3 `domain`++- `domain` is pure Kotlin: no `android.*`, `androidx.*`, Compose, Android+ resources, Context, or file/network I/O.+- Models, algorithms, parsers, validators, recurrence/date logic, and+ safe-decoding primitives belong here when they do not need Android.+- A parser for untrusted or persisted input must return a result/null (or a+ sealed failure), not throw for malformed data.++### 4.4 `platform`++- ViewModels, Android-framework adapters, permission/system-service glue,+ sensors, workers that are not sync-owned, and native bridges live here.+- A native library has exactly one Kotlin wrapper in `platform`, named+ `<Feature>Native`. That wrapper is the only app file that may call+ `System.loadLibrary` for that library. It must expose an `available`+ result and must never let a load failure poison class initialization.+- JNI-frozen fully-qualified names are the only exception, and each one must+ carry `// PACKAGE STRUCTURE EXCEPTION (JNI)`.+- Exported-intent parsing does not belong in an Activity. It belongs in an+ `intents` contract (§4.6); `platform` may consume the validated result.++### 4.5 `network`++- Every app that talks to a network has exactly one public networking entry+ point in `network`, named `Networking` (an `object`, or a single+ injectable class with that name). Other packages call only `Networking`.+- `Networking` owns the `NetworkClient`, the narrowest applicable+ `TrustBundle`, base URLs, endpoint paths, HTTP methods, authentication+ headers, retries, cancellation, and response-status mapping.+- Endpoint-specific clients, DTOs, and protocol helpers inside `network`+ are implementation details. They must not be called from `ui`, `data`,+ `domain`, `platform`, `service`, `provider`, `widget`, or `intents`.+- No code outside `network` and `library.network` may construct a raw HTTP+ request or open a raw network socket for an API call. This includes+ `NetworkClient`, `HttpURLConnection`, `URL.openConnection`, OkHttp, and+ Retrofit.+- Protocol libraries that are inherently connection-oriented (for example+ IMAP/SMTP) live under `network` by protocol; their public surface is still+ mediated by `Networking`.++### 4.6 `intents`++- Every exported Activity, Service, Receiver, provider, or assistant action+ has exactly one contract type here, named `<Feature>IntentContract` or+ the existing app-specific contract name ending in `Intent`.+- The contract owns extra keys, type checks, numeric ranges, enum parsing,+ defaults, and malformed-input rejection. Entry points consume only the+ validated result.+- Cross-app IPC payload types live here, not in `ui` or `platform`.++### 4.7 `service`, `provider`, `notifications`, `auth`, `sync`, `telephony`++- `service` contains Android Service implementations; a Service’s parsing+ and business rules belong in `intents`, `domain`, or `data` as above.+- `provider` contains ContentProvider implementations and stays flat.+- `notifications` owns notification construction; it does not own the work+ that produces the notified event.+- `auth` owns authentication and session state; credential persistence goes+ through the single `data` preferences/database owner.+- `sync` owns sync orchestration and reconciliation; remote calls go+ through `network.Networking`.+- `telephony` owns carrier/SIM/telephony adapters; message business rules+ belong in `domain` and network transport in `network`.++## 5. Initialization and parsing safety++1. A companion object, object initializer, top-level property, or class+ initializer must not perform unguarded I/O, parsing, database access, or+ native-library loading.+2. A throwing initializer is a crash bug even if the input that triggers it+ is rare. Initializers use defaults, lazy initialization, or an explicit+ guarded `available`/failure state.+3. `Json.decodeFromString`, `Base64.decode`, `UUID.fromString`, enum+ `valueOf`, and date/time `parse` calls on persisted, IPC, file, or network+ data must go through a non-throwing helper in `data` or `domain`.+4. Room converters and widget state loaders must be total functions: bad+ persisted data produces a documented fallback, never an exception.++## 6. Regex rule++Regex patterns that can receive process death, restore, IPC, file, or user+input must be valid for Android’s ICU-backed `java.util.regex`, not merely+for the desktop JVM. In particular, a literal `{` or `}` outside a valid+quantifier or character class must be escaped. Regex constants belong in+`domain` when pure, or beside the single parser that owns them in `data`.++## 7. Widget state rule++A widget must render from one immutable snapshot loaded for that render.+It must not combine a newly computed date/index/key with a stale map or+list without a fallback. Indexing widget state uses `getOrNull`, an empty+default, or an explicit loading state.++## 8. Enforcement++1. `PackageStructure` lint is blocking. It enforces the closed roots, the+ app-root file contracts, and the flat `widget` rule.+2. Every Modern-Apps lint issue is blocking. An issue may not be made+ advisory to land a change.+3. A violation is fixed by moving/factoring the code, not by adding a+ suppression, lint baseline, detekt baseline, or config relaxation.+4. The only package exception is a JNI-frozen fully-qualified name, marked+ verbatim with `// PACKAGE STRUCTURE EXCEPTION (JNI)`.+5. Existing violations are migration debt, not precedents. Touching a file+ in a violating package requires either migrating that package or leaving+ the code in a package that complies with this document.
lint-rules/AGENTS.md
diff --git a/lint-rules/AGENTS.md b/lint-rules/AGENTS.mdindex 7c557b8e44..53a58b8b0d 100644--- a/lint-rules/AGENTS.md+++ b/lint-rules/AGENTS.md@@ -12,8 +12,7 @@ ## Overview **Purpose:** Custom Android-lint detectors enforcing repo conventions at build time — the executable form of root `AGENTS.md` §2. Fatal detectors break the build; advisory ones warn.-**Fatal:** `ToastUsage` (no `Toast` — use messenger), `DirectComposeAnimation` (no raw animation at call sites), `FileLength`, `DirectAndroidLog` (no `androidx.room.`/`android.util.Log` literals), plus comment-hygiene detectors (`CommentedOutCode`, `ExceptionMarkerFormat`, `TodoEvasion` with `CommentOnlyMatcher`).-**Advisory:** `DirectBuildDatabase` (subclass `RoomRepository`), `OneComposablePerFile`, `PackageStructure` (closed roots), `RawScaffoldInApp` (use `AppScaffold`), `Room2Usage` (Room 3 only), `WindowInsetsInReusableComponent` (no padding in `library.ui`).+**Blocking:** every Modern-Apps detector is fatal in the app and library conventions. That includes `ToastUsage` (no `Toast` — use messenger), `DirectComposeAnimation` (no raw animation at call sites), `FileLength`, `DirectAndroidLog` (no direct `android.util.Log`), `DirectBuildDatabase` (subclass `RoomRepository`), `OneComposablePerFile`, `PackageStructure` (closed roots and flat `widget`), `RawScaffoldInApp` (use `AppScaffold`), `Room2Usage` (Room 3 only), `WindowInsetsInReusableComponent` (no padding in `library.ui`), and the comment-hygiene detectors (`CommentedOutCode`, `ExceptionMarkerFormat`, `TodoEvasion` with `CommentOnlyMatcher`). **Entry points:** `ModernAppsIssueRegistry.kt` → the detector for your rule → `LintPackageExclusions.kt` for scope. **Gotchas:** New detectors need registry entries + severity decisions (fatal vs advisory is a deliberate call). Fix code to green modules, never relax config (`detekt.yml` rationale is inline per the root card).
lint-rules/src/main/java/com/vayunmathur/lint/CommentedOutCodeDetector.kt
diff --git a/lint-rules/src/main/java/com/vayunmathur/lint/CommentedOutCodeDetector.kt b/lint-rules/src/main/java/com/vayunmathur/lint/CommentedOutCodeDetector.ktindex dc9629d0aa..f8d2c15b78 100644--- a/lint-rules/src/main/java/com/vayunmathur/lint/CommentedOutCodeDetector.kt+++ b/lint-rules/src/main/java/com/vayunmathur/lint/CommentedOutCodeDetector.kt@@ -33,7 +33,7 @@ import java.io.File * * Comment-only via [CommentOnlyMatcher]: string literals are never scanned. *- * Warn-then-error: WARNING now (zero-today baseline), promote once green.+ * Blocking: every finding is an error. */ class CommentedOutCodeDetector : Detector(), SourceCodeScanner { @@ -177,7 +177,7 @@ class CommentedOutCodeDetector : Detector(), SourceCodeScanner { """.trimIndent(), category = Category.PRODUCTIVITY, priority = 4,- severity = Severity.WARNING,+ severity = Severity.ERROR, implementation = Implementation( CommentedOutCodeDetector::class.java, Scope.JAVA_FILE_SCOPE,
lint-rules/src/main/java/com/vayunmathur/lint/ExceptionMarkerFormatDetector.kt
diff --git a/lint-rules/src/main/java/com/vayunmathur/lint/ExceptionMarkerFormatDetector.kt b/lint-rules/src/main/java/com/vayunmathur/lint/ExceptionMarkerFormatDetector.ktindex da60006952..a8d7bd81fb 100644--- a/lint-rules/src/main/java/com/vayunmathur/lint/ExceptionMarkerFormatDetector.kt+++ b/lint-rules/src/main/java/com/vayunmathur/lint/ExceptionMarkerFormatDetector.kt@@ -40,9 +40,8 @@ import java.io.File * Comment-only via [CommentOnlyMatcher]: a marker inside a string literal must * neither opt a file out nor trip this check. *- * Warn-then-error: WARNING now, promote to ERROR once the owning slices are- * green (a bare `// RAW SCAFFOLD EXCEPTION` with no reason is the one known- * live shape this will surface first).+ * Blocking: every finding is an error (a bare `// RAW SCAFFOLD EXCEPTION`+ * with no reason is one live shape this surfaces). */ class ExceptionMarkerFormatDetector : Detector(), SourceCodeScanner { @@ -224,7 +223,7 @@ class ExceptionMarkerFormatDetector : Detector(), SourceCodeScanner { """.trimIndent(), category = Category.CORRECTNESS, priority = 6,- severity = Severity.WARNING,+ severity = Severity.ERROR, implementation = Implementation( ExceptionMarkerFormatDetector::class.java, Scope.JAVA_FILE_SCOPE,
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 9efd9bf670..1052474b99 100644--- a/lint-rules/src/main/java/com/vayunmathur/lint/PackageStructureDetector.kt+++ b/lint-rules/src/main/java/com/vayunmathur/lint/PackageStructureDetector.kt@@ -24,7 +24,9 @@ import org.jetbrains.uast.UFile * Each app's `src/main/java/com/vayunmathur/<app>/` may only contain the * closed set of roots; anything else is a violation. The check derives * `<app>` from the file's `package` declaration (source of truth, not file- * path) and inspects the first segment after `com.vayunmathur.<app>`.+ * path) and inspects the full segment path after `com.vayunmathur.<app>`:+ * the first segment must be an allowed root, descendant segments must name+ * features/capabilities rather than generic buckets, and `widget` is flat. * * Files whose package is exactly `com.vayunmathur.<app>` (no sub-package) are * further gated to the closed file allow-list: MainActivity.kt, Route.kt,@@ -44,10 +46,22 @@ class PackageStructureDetector : Detector(), SourceCodeScanner { if (isExcluded(packageName)) return if (!packageName.startsWith("com.vayunmathur.")) return - val result = deriveAppBaseAndSegment(packageName) ?: return- val segment = result.second+ val result = deriveAppBaseAndSegments(packageName) ?: return+ val segments = result.second+ val segment = segments.firstOrNull() if (segment != null) {- if (segment in ALLOWED_ROOTS) return+ if (segment in ALLOWED_ROOTS) {+ val subpackageViolation = validateSubpackages(packageName, segments)+ if (subpackageViolation != null) {+ context.report(+ ISSUE,+ node,+ context.getLocation(node),+ subpackageViolation,+ )+ }+ return+ } // Unknown root — report. val suggestion = aliasSuggestion(segment)@@ -152,13 +166,11 @@ class PackageStructureDetector : Detector(), SourceCodeScanner { } /**- * Derives the app base package and the first segment after it.+ * Derives the app base package and every segment after it. * Returns null if the package does not start with `com.vayunmathur.`.- * Returns Pair(base, null) for root files (no extra segment).- *- * Source: plan §5.3 normative snippet.+ * Returns Pair(base, emptyList()) for root files (no extra segment). */- private fun deriveAppBaseAndSegment(packageName: String): Pair<String, String?>? {+ private fun deriveAppBaseAndSegments(packageName: String): Pair<String, List<String>>? { if (!packageName.startsWith("com.vayunmathur.")) return null val remainder = packageName.removePrefix("com.vayunmathur.") if (remainder.isEmpty()) return null@@ -167,20 +179,48 @@ class PackageStructureDetector : Detector(), SourceCodeScanner { // as app `cast` with a root segment `tv`, which is not in the allow-list and never // could be. for (base in NESTED_APP_BASES) {- if (remainder == base) return Pair("com.vayunmathur.$base", null)+ if (remainder == base) return Pair("com.vayunmathur.$base", emptyList()) if (remainder.startsWith("$base.")) {- val segment = remainder.removePrefix("$base.").substringBefore('.')- return Pair("com.vayunmathur.$base", segment)+ val segments = remainder.removePrefix("$base.").split('.')+ return Pair("com.vayunmathur.$base", segments) } } val dot = remainder.indexOf('.') return if (dot == -1) {- Pair("com.vayunmathur.$remainder", null)+ Pair("com.vayunmathur.$remainder", emptyList()) } else { val app = remainder.substring(0, dot)- val segment = remainder.substring(dot + 1).substringBefore('.')- Pair("com.vayunmathur.$app", segment)+ val segments = remainder.substring(dot + 1).split('.')+ Pair("com.vayunmathur.$app", segments)+ }+ }++ private val BANNED_DESCENDANT_SEGMENTS = setOf(+ "api", "apis", "base", "common", "core", "feature", "features",+ "glance", "helper", "helpers", "impl", "manager", "managers",+ "misc", "presentation", "repository", "repositories", "screen",+ "screens", "util", "utils", "view", "views", "viewmodel",+ "viewmodels", "widget", "widgets",+ )++ private fun validateSubpackages(packageName: String, segments: List<String>): String? {+ val root = segments.firstOrNull() ?: return null+ if (root == "widget" && segments.size > 1) {+ return "Package `$packageName` fragments widget code below `widget`. " ++ "Widget code must be directly in the flat `widget` root; Glance is an " ++ "implementation detail, not a package boundary. Move the file to " ++ "`${packageName.substringBefore(".widget")}.widget`. " ++ "See docs/package-structure.md §3.2." }+ val banned = segments.drop(1).firstOrNull { it in BANNED_DESCENDANT_SEGMENTS }+ if (banned != null) {+ return "Package `$packageName` uses banned package segment `$banned` below " ++ "root `$root`. Package segments name a responsibility, feature, provider, " ++ "or protocol—not a generic bucket, class type, synonym, or UI toolkit. " ++ "Move the file under the closest canonical responsibility in " ++ "docs/package-structure.md §2–§4."+ }+ return null } /**@@ -448,7 +488,8 @@ class PackageStructureDetector : Detector(), SourceCodeScanner { "api" to "network/", "model" to "data/ (or data/model/ subpackage)", "viewmodel" to "platform/",- "glance" to "widget/ (move glance/Foo → widget/glance/Foo)",+ "widgets" to "widget/ (singular and flat)",+ "glance" to "widget/ (flat; Glance is an implementation detail, not a package)", "composer" to "ui/composer/", "shields" to "domain/shields/", "syntax" to "domain/syntax/",@@ -478,7 +519,12 @@ class PackageStructureDetector : Detector(), SourceCodeScanner { Each app's `src/main/java/com/vayunmathur/<app>/` may only contain the closed \ set of roots: [ui, data, domain, platform, network, intents, service, provider, \ widget, notifications, auth, sync, telephony]. Any other top-level segment is a \- violation. Additionally, files whose package is exactly `com.vayunmathur.<app>` \+ violation. Descendant segments must name a responsibility, feature, provider, \+ or protocol; generic buckets and synonyms (`util`, `common`, `helper`, \+ `manager`, `api`, `viewmodel`, `widgets`, …) are violations. `widget` is \+ singular and flat: `widget.glance` and every other `widget.<child>` are \+ violations because Glance is an implementation detail, not a package boundary. \+ Additionally, files whose package is exactly `com.vayunmathur.<app>` \ (app root) are restricted to a closed file allow-list: [MainActivity.kt (only \ class MainActivity), Route.kt (only sealed interface Route : NavKey), \ Navigation.kt (only @Composable fun Navigation(...)), *Application.kt (only the \
lint-rules/src/main/java/com/vayunmathur/lint/TodoEvasionDetector.kt
diff --git a/lint-rules/src/main/java/com/vayunmathur/lint/TodoEvasionDetector.kt b/lint-rules/src/main/java/com/vayunmathur/lint/TodoEvasionDetector.ktindex e53a62f7ef..0b08aac84c 100644--- a/lint-rules/src/main/java/com/vayunmathur/lint/TodoEvasionDetector.kt+++ b/lint-rules/src/main/java/com/vayunmathur/lint/TodoEvasionDetector.kt@@ -26,7 +26,7 @@ import java.io.File * (`// ---- TODO / FIXME ----`) * * The base ban stays blocking in detekt; these evasion shapes land here as a- * warning first and join the ban at promotion (Phase 4). Comment-only via+ * an error like the rest of the ban. Comment-only via * [CommentOnlyMatcher]: an identifier or string literal that happens to * contain `TODO` must not trip this check. */@@ -117,7 +117,7 @@ class TodoEvasionDetector : Detector(), SourceCodeScanner { """.trimIndent(), category = Category.PRODUCTIVITY, priority = 5,- severity = Severity.WARNING,+ severity = Severity.ERROR, implementation = Implementation( TodoEvasionDetector::class.java, Scope.JAVA_FILE_SCOPE,
lint-rules/src/main/java/com/vayunmathur/lint/WindowInsetsInReusableComponentDetector.kt
diff --git a/lint-rules/src/main/java/com/vayunmathur/lint/WindowInsetsInReusableComponentDetector.kt b/lint-rules/src/main/java/com/vayunmathur/lint/WindowInsetsInReusableComponentDetector.ktindex 524a0784d2..8ce9c47abe 100644--- a/lint-rules/src/main/java/com/vayunmathur/lint/WindowInsetsInReusableComponentDetector.kt+++ b/lint-rules/src/main/java/com/vayunmathur/lint/WindowInsetsInReusableComponentDetector.kt@@ -72,7 +72,7 @@ class WindowInsetsInReusableComponentDetector : Detector(), SourceCodeScanner { """.trimIndent(), category = Category.CORRECTNESS, priority = 6,- severity = Severity.WARNING,+ severity = Severity.ERROR, implementation = Implementation( WindowInsetsInReusableComponentDetector::class.java, Scope.JAVA_FILE_SCOPE,
weather/src/main/java/com/vayunmathur/weather/widget/WeatherBlobGlanceWidget.kt
diff --git a/weather/src/main/java/com/vayunmathur/weather/widget/glance/WeatherBlobGlanceWidget.kt b/weather/src/main/java/com/vayunmathur/weather/widget/WeatherBlobGlanceWidget.ktsimilarity index 100%rename from weather/src/main/java/com/vayunmathur/weather/widget/glance/WeatherBlobGlanceWidget.ktrename to weather/src/main/java/com/vayunmathur/weather/widget/WeatherBlobGlanceWidget.kt
weather/src/main/java/com/vayunmathur/weather/widget/WeatherBlobGlanceWidgetReceiver.kt
diff --git a/weather/src/main/java/com/vayunmathur/weather/widget/glance/WeatherBlobGlanceWidgetReceiver.kt b/weather/src/main/java/com/vayunmathur/weather/widget/WeatherBlobGlanceWidgetReceiver.ktsimilarity index 100%rename from weather/src/main/java/com/vayunmathur/weather/widget/glance/WeatherBlobGlanceWidgetReceiver.ktrename to weather/src/main/java/com/vayunmathur/weather/widget/WeatherBlobGlanceWidgetReceiver.kt
weather/src/main/java/com/vayunmathur/weather/widget/WeatherGlanceWidget.kt
diff --git a/weather/src/main/java/com/vayunmathur/weather/widget/glance/WeatherGlanceWidget.kt b/weather/src/main/java/com/vayunmathur/weather/widget/WeatherGlanceWidget.ktsimilarity index 100%rename from weather/src/main/java/com/vayunmathur/weather/widget/glance/WeatherGlanceWidget.ktrename to weather/src/main/java/com/vayunmathur/weather/widget/WeatherGlanceWidget.kt
weather/src/main/java/com/vayunmathur/weather/widget/WeatherGlanceWidgetReceiver.kt
diff --git a/weather/src/main/java/com/vayunmathur/weather/widget/glance/WeatherGlanceWidgetReceiver.kt b/weather/src/main/java/com/vayunmathur/weather/widget/WeatherGlanceWidgetReceiver.ktsimilarity index 100%rename from weather/src/main/java/com/vayunmathur/weather/widget/glance/WeatherGlanceWidgetReceiver.ktrename to weather/src/main/java/com/vayunmathur/weather/widget/WeatherGlanceWidgetReceiver.kt
weather/src/main/java/com/vayunmathur/weather/widget/WidgetWeather.kt
diff --git a/weather/src/main/java/com/vayunmathur/weather/widget/glance/WidgetWeather.kt b/weather/src/main/java/com/vayunmathur/weather/widget/WidgetWeather.ktsimilarity index 100%rename from weather/src/main/java/com/vayunmathur/weather/widget/glance/WidgetWeather.ktrename to weather/src/main/java/com/vayunmathur/weather/widget/WidgetWeather.kt