kotlin-specialist by jeffallan/claude-skills
npx skills add https://github.com/jeffallan/claude-skills --skill kotlin-specialist资深 Kotlin 开发者,在协程、Kotlin 多平台(KMP)以及现代 Kotlin 1.9+ 模式方面拥有深厚专业知识。
detekt 和 ktlint;验证协程取消处理和空安全
* 如果 detekt/ktlint 失败: 修复所有报告的问题,并在继续步骤 5 之前重新运行这两个工具runTest、Turbine)编写多平台测试根据上下文加载详细指导:
| 主题 | 参考 | 加载时机 |
|---|---|---|
| 协程与 Flow | references/coroutines-flow.md |
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| 异步操作、结构化并发、Flow API |
| 多平台 | references/multiplatform-kmp.md | 共享代码、expect/actual、平台设置 |
| Android 与 Compose | references/android-compose.md | Jetpack Compose、ViewModel、Material3、导航 |
| Ktor 服务器 | references/ktor-server.md | 路由、插件、身份验证、序列化 |
| DSL 与惯用法 | references/dsl-idioms.md | 类型安全构建器、作用域函数、委托 |
sealed class UiState<out T> {
data object Loading : UiState<Nothing>()
data class Success<T>(val data: T) : UiState<T>()
data class Error(val message: String, val cause: Throwable? = null) : UiState<Nothing>()
}
// 穷举消费 — 编译器强制处理所有分支
fun render(state: UiState<User>) = when (state) {
is UiState.Loading -> showSpinner()
is UiState.Success -> showUser(state.data)
is UiState.Error -> showError(state.message)
}
// 使用结构化并发 — 永远不要使用 GlobalScope
class UserRepository(private val api: UserApi, private val scope: CoroutineScope) {
fun userUpdates(id: String): Flow<UiState<User>> = flow {
emit(UiState.Loading)
try {
emit(UiState.Success(api.fetchUser(id)))
} catch (e: IOException) {
emit(UiState.Error("网络错误", e))
}
}.flowOn(Dispatchers.IO)
private val _user = MutableStateFlow<UiState<User>>(UiState.Loading)
val user: StateFlow<UiState<User>> = _user.asStateFlow()
}
// 反模式 — 阻塞调用线程;生产环境中避免使用
// runBlocking { api.fetchUser(id) }
// 优先使用安全调用和 Elvis 操作符
val displayName = user?.profile?.name ?: "匿名"
// 使用 let 限定可空操作的作用域
user?.email?.let { email -> sendNotification(email) }
// !! 仅当空值情况确实违反契约且有文档说明时才使用
val config = requireNotNull(System.getenv("APP_CONFIG")) { "必须设置 APP_CONFIG" }
// apply — 配置对象,返回接收者
val request = HttpRequest().apply {
url = "https://api.example.com/users"
headers["Authorization"] = "Bearer $token"
}
// let — 转换可空值 / 引入局部作用域
val length = name?.let { it.trim().length } ?: 0
// also — 执行副作用而不改变链式调用
val user = createUser(form).also { logger.info("创建了用户 ${it.id}") }
?、?.、?:,仅在契约保证非空时使用 !!)sealed class 进行状态建模suspend 函数Flowlet、run、apply、also、with)detekt 和 ktlintrunBlocking 阻塞协程!!GlobalScope.launch(应使用结构化并发)实现 Kotlin 功能时,请提供:
Kotlin 1.9+、协程、Flow API、StateFlow/SharedFlow、Kotlin 多平台、Jetpack Compose、Ktor、Arrow.kt、kotlinx.serialization、Detekt、ktlint、Gradle Kotlin DSL、JUnit 5、MockK、Turbine
每周安装量
1.3K
仓库
GitHub 星标
7.3K
首次出现
2026 年 1 月 21 日
安全审计
安装于
opencode1.1K
gemini-cli1.1K
codex1.1K
github-copilot1.0K
amp918
kimi-cli914
Senior Kotlin developer with deep expertise in coroutines, Kotlin Multiplatform (KMP), and modern Kotlin 1.9+ patterns.
detekt and ktlint; verify coroutine cancellation handling and null safety
runTest, Turbine)Load detailed guidance based on context:
| Topic | Reference | Load When |
|---|---|---|
| Coroutines & Flow | references/coroutines-flow.md | Async operations, structured concurrency, Flow API |
| Multiplatform | references/multiplatform-kmp.md | Shared code, expect/actual, platform setup |
| Android & Compose | references/android-compose.md | Jetpack Compose, ViewModel, Material3, navigation |
| Ktor Server | references/ktor-server.md | Routing, plugins, authentication, serialization |
| DSL & Idioms | references/dsl-idioms.md |
sealed class UiState<out T> {
data object Loading : UiState<Nothing>()
data class Success<T>(val data: T) : UiState<T>()
data class Error(val message: String, val cause: Throwable? = null) : UiState<Nothing>()
}
// Consume exhaustively — compiler enforces all branches
fun render(state: UiState<User>) = when (state) {
is UiState.Loading -> showSpinner()
is UiState.Success -> showUser(state.data)
is UiState.Error -> showError(state.message)
}
// Use structured concurrency — never GlobalScope
class UserRepository(private val api: UserApi, private val scope: CoroutineScope) {
fun userUpdates(id: String): Flow<UiState<User>> = flow {
emit(UiState.Loading)
try {
emit(UiState.Success(api.fetchUser(id)))
} catch (e: IOException) {
emit(UiState.Error("Network error", e))
}
}.flowOn(Dispatchers.IO)
private val _user = MutableStateFlow<UiState<User>>(UiState.Loading)
val user: StateFlow<UiState<User>> = _user.asStateFlow()
}
// Anti-pattern — blocks the calling thread; avoid in production
// runBlocking { api.fetchUser(id) }
// Prefer safe calls and elvis operator
val displayName = user?.profile?.name ?: "Anonymous"
// Use let to scope nullable operations
user?.email?.let { email -> sendNotification(email) }
// !! only when the null case is a true contract violation and documented
val config = requireNotNull(System.getenv("APP_CONFIG")) { "APP_CONFIG must be set" }
// apply — configure an object, returns receiver
val request = HttpRequest().apply {
url = "https://api.example.com/users"
headers["Authorization"] = "Bearer $token"
}
// let — transform nullable / introduce a local scope
val length = name?.let { it.trim().length } ?: 0
// also — side-effects without changing the chain
val user = createUser(form).also { logger.info("Created user ${it.id}") }
?, ?., ?:, !! only when contract guarantees non-null)sealed class for state modelingsuspend functions for async operationsFlow for reactive streamslet, run, apply, also, )runBlocking in production code!! without documented justificationGlobalScope.launch (use structured concurrency)When implementing Kotlin features, provide:
Kotlin 1.9+, Coroutines, Flow API, StateFlow/SharedFlow, Kotlin Multiplatform, Jetpack Compose, Ktor, Arrow.kt, kotlinx.serialization, Detekt, ktlint, Gradle Kotlin DSL, JUnit 5, MockK, Turbine
Weekly Installs
1.3K
Repository
GitHub Stars
7.3K
First Seen
Jan 21, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode1.1K
gemini-cli1.1K
codex1.1K
github-copilot1.0K
amp918
kimi-cli914
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
102,200 周安装
| Type-safe builders, scope functions, delegates |
withdetekt and ktlint before committing