askill
kotlin-conventions

kotlin-conventionsSafety 80Repository

Forge 项目 Kotlin 约定。data class 边界、scope function 选用、协程结构化并发、null safety 规则。

33 stars
1.2k downloads
Updated 3/1/2026

Package Files

Loading files...
SKILL.md

Kotlin Conventions — Forge 项目约定

Data Class 规则

  • DTO / Value Object / Config 用 data class
  • 不用 data class 的场景: 有可变状态的 Entity、继承层次、字段数 > 7
  • init 块用于前置条件校验(require

Scope Function 选用规则

函数对象引用返回值使用场景
letitLambda 结果null 检查 + 变换
applythis对象本身对象配置(builder 风格)
alsoit对象本身副作用(日志、验证)
runthisLambda 结果对象上计算结果

禁止: 嵌套超过 2 层 scope function。

协程规则

  • 并行操作用 coroutineScope + async
  • 独立操作(一个失败不影响其他)用 supervisorScope
  • 禁止 GlobalScope

Null Safety 规则

  • 可选链用 ?.let
  • 默认值用 ?: elvis
  • 边界处用 requireNotNull / checkNotNull
  • 禁止生产代码使用 !!(测试除外)

扩展函数规则

  • 用于添加对象的自然行为(order.isEditable()
  • 用于领域特定格式化(money.toDisplayString()
  • 禁止 通过扩展函数添加不相关行为(order.sendEmail() 不属于 Order)

Companion Object 约定

  • Logger 放在 companion object
  • 工厂方法放在 companion object(Order.create(...)

枚举序列化约定

  • 所有枚举必须加 @JsonValue 返回小写
  • 新增枚举时立即全局排查 grep -r "enum class" --include="*.kt"

Install

Download ZIP
Requires askill CLI v1.0+

AI Quality Score

74/100Analyzed 3/2/2026

Well-structured Kotlin conventions reference document covering 7 areas (data class, scope functions, coroutines, null safety, extension functions, companion objects, enums). Includes trigger section, tags, and is in a dedicated skills folder. High-density technical content with clear tables and specific rules. Main limitations: lacks code examples for implementation, written in Chinese which limits audience, and some rules are project-specific reducing reusability. Score reflects strong reference content with moderate actionability."

80
75
65
70
60

Metadata

Licenseunknown
Version2.0
Updated3/1/2026
Publisherpan94u

Tags

No tags yet.