AgentLint 实测验证 94/100基于 70 个 Kotlin 开源仓库统计
Kotlin CLAUDE.md & AGENTS.md 模板
结构化协程安全、ktlint/detekt 静态门禁与 Gradle 定向单测,提炼自 Kotlin 仓库。
# Kotlin Project — Kotlin Harness Kotlin + Gradle project using structured concurrency, ktlint, detekt, and JUnit 5. ## Commands - Fast unit test: `./gradlew :core:test --tests '*TargetTest'` - Full verification: `./gradlew check` - Static checks: `./gradlew ktlintCheck detekt` ## Rules - Don't use `!!` (not-null assertion) in production code. Instead use safe calls (`?.`), Elvis defaults, or `requireNotNull` with an explicit message. Because `!!` throws opaque NPEs. - Don't launch work on `GlobalScope`. Instead inject a structured `CoroutineScope`. Because unscoped coroutines leak memory and break cancellation. - When updating Compose UI or navigation routes, read `docs/navigation.md`. ## Continuity - Keep `local.properties`, keystores, and `CLAUDE.local.md` gitignored and update `HANDOFF.md`.
Kotlin 开源生态中最常采用的工程规则
基于 4,533 仓库研究中 70 个公开 Kotlin 仓库的实测统计:
gradle-kotlin工具链
Gradle with Kotlin DSL
54.0%27 个仓库
jetpack-compose框架
Jetpack Compose for UI
50.0%25 个仓库
unit-tests测试
Write unit tests for all changes
48.0%24 个仓库
data-class代码规范
Use data classes
38.0%19 个仓库
mvvm-kotlin代码规范
MVVM architecture
36.0%18 个仓库
ci-cd工具链
CI/CD pipeline must pass
34.0%17 个仓库
coroutines代码规范
Kotlin coroutines
34.0%17 个仓库
error-handling代码规范
Proper error handling with context
32.0%16 个仓库
必写验证命令(对应规则 W1 与 W7)
- 安装依赖
- ./gradlew dependencies
- 快速单测(秒级迭代)
- ./gradlew :app:testDebugUnitTest --tests '*TargetTest'
- 全量测试
- ./gradlew check
- Lint 与静态检查
- ./gradlew ktlintCheck detekt
- 生产构建
- ./gradlew assembleDebug
Kotlin 项目中 AI 代理常见踩坑
- 01使用
GlobalScope.launch会导致协程泄漏且脱离页面或请求生命周期。 - 02滥用
!!非空断言绕过 Kotlin 整个空安全体系。