agentleFS
liuyi0808liuyi0808/android-review/skills/kotlin-quality/SKILL.md

kotlin-quality

Skill17 starsChanged 9 months agoMITView on GitHub

Kotlin code quality review for Android projects. Covers coroutine structured concurrency, Flow operators, null safety, type design (sealed classes, data classes, value objects), and collection/functional patterns. Use when: reviewing Kotlin code in PRs, auditing coroutine usage, checking null safety patterns, evaluating type design decisions, or improving code readability and correctness.

The file

We split this skill into the rules it gives an agent

9 rules. About 0 are common, 6 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈6

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Run all applicable categories in PARALLEL using independent Task agents.

    line 32
  2. Distinctive:

    Read matched files to confirm the finding is real

    line 35
  3. Very specific:

    NEVER use GlobalScope — bind to viewModelScope/lifecycleScope/custom scope with cancellation.

    line 137
  4. Distinctive:

    Use supervisorScope to isolate child coroutine failures.

    line 142
  5. Distinctive:

    Prefer requireNotNull/checkNotNull over !!

    line 153
  6. Distinctive:

    Use value class over typealias for primitive wrappers.

    line 162
  7. Distinctive:

    No Pair/Triple in public API — use named data class.

    line 163
  8. Very specific:

    No side effects in map/filter/flatMap — use onEach/forEach.

    line 166
  9. Very specific:

    Prefer buildList/buildMap/buildSet over toMutableX pattern.

    line 170

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Kotlin Code Quality Review

Evaluate Kotlin code across five quality categories and produce structured findings with concrete fixes.

Review Process

Phase 1: Triage

Scan project structure (build.gradle, source tree, imports) to determine which categories apply. SKIP categories only when the skip condition is met.

CategorySkip If
CoroutinesNo kotlinx-coroutines dependency
FlowNo import kotlinx.coroutines.flow in source
Null SafetyNEVER skip
Type DesignNEVER skip
CollectionsNEVER skip

Phase 2: Parallel Scan

Run all applicable categories in PARALLEL using independent Task agents. Each agent:

  1. Grep for the category's anti-patterns (see search guide below)
  2. Read matched files to confirm the finding is real
  3. Return findings in the output format below

Phase 3: Report

Merge parallel results into a single structured report, grouped by category and sorted by severity.


Output Format

[KT-{CATEGORY}-{NNN}] severity: CRITICAL | HIGH | MEDIUM | LOW
  Finding: <description>
  Location: <file:line>
  Fix: <concrete action>

Reference Guide — Load on Demand

Each reference file contains detailed patterns, code examples, and rationale. Read the relevant file when reviewing that category.

#Reference FileContentWhen to Load
1references/coroutines.mdStructured concurrency, Scope, exception propagation, DispatcherReviewing coroutine usage or async code
2references/flow.mdCold/hot Flow, operators, stateIn/shareIn, lifecycle collectionReviewing Flow usage or reactive streams
3references/null-safety.md!! elimination, lateinit alternatives, safe casts, ?. chainsReviewing null handling patterns
4references/type-design.mdSealed class/interface, data class, value class, genericsReviewing type definitions or API design
5references/collections.mdImmutability, sequence vs list, scope functionsReviewing collection operations or functional patterns

Anti-Pattern Search Guide

Grep-ready patterns per category. Only search categories that passed triage.

Coroutines

PatternDetection TargetSeverity
GlobalScope\.launch|GlobalScope\.asyncGlobalScope misuseCRITICAL
CoroutineScope\( not in class propertyTemporary Scope leakHIGH
launch\s*\{ without try or CoroutineExceptionHandlerException swallowedCRITICAL
async\s*\{ without .await()Result discardedHIGH
runBlocking\s*\{ not in main() or testBlocks threadCRITICAL
Dispatchers\.IO with CPU work (sort, serialize, encrypt)Wrong DispatcherMEDIUM
withContext\(Dispatchers\.Main\) with I/OMain thread I/OCRITICAL
delay\( for polling instead of FlowManual pollingMEDIUM

Flow

PatternDetection TargetSeverity
.collect\s*\{ in launch without repeatOnLifecycleBackground collectionHIGH
stateIn\( with SharingStarted.EagerlyWasteful hot flowMEDIUM
shareIn\( vs stateIn\( confusionWrong sharing strategyMEDIUM
.catch\s*\{ after .collectcatch position wrongHIGH
.flowOn\( after .collectflowOn position wrongHIGH
MutableStateFlow / MutableSharedFlow as publicMutable flow exposedHIGH
flow \{ with side effects mixed with emitImpure flow builderLOW

Null Safety

PatternDetection TargetSeverity
!!Non-null assertion riskHIGH
lateinit var outside DI/lifecycleMisused lateinitHIGH
3+ level ?. chainNull chain nestingMEDIUM
as\s+\w+ without ? outside whenUnsafe castHIGH
catch.*\{\s*\} or catch.*\{.*nullException swallowedCRITICAL
.get\( / \[.*\] on Map/List without safe accessIndex/key crashMEDIUM

Type Design

PatternDetection TargetSeverity
when + else on sealed typesNon-exhaustiveHIGH
3+ same-type primitive parametersParameter confusionMEDIUM
data class with varMutable data classHIGH
Pair< / Triple<Unnamed tupleMEDIUM
Any as parameter/returnType erasureHIGH
enum with complex when branchesShould be sealed + polymorphismLOW
typealias wrapping primitiveShould be value classMEDIUM

Collections

PatternDetection TargetSeverity
Side effects in .map\s*\{ (Log, println, network, DB)Impure mapHIGH
4+ chained operators without asSequence()Multiple traversalsMEDIUM
Public mutableListOf|mutableMapOf|mutableSetOfMutable collection leakHIGH
for loop replaceable by map/filter/foldImperative styleLOW
Scope function nesting >1 levelReadability lossMEDIUM
toMutableList() modify-then-returnShould use buildListLOW

Rules Summary

Coroutines (6 rules)

  1. NEVER use GlobalScope — bind to viewModelScope/lifecycleScope/custom scope with cancellation.
  2. launch exceptions don't propagate — must handle via try/catch or CoroutineExceptionHandler.
  3. async Deferred must be awaited — otherwise exceptions silently lost.
  4. runBlocking only in main() and tests — forbidden in production.
  5. Match Dispatcher to work type: IO for I/O, Default for CPU, Main for UI only.
  6. Use supervisorScope to isolate child coroutine failures.

Flow (5 rules)

  1. UI collection must use repeatOnLifecycle or collectAsStateWithLifecycle.
  2. MutableStateFlow/MutableSharedFlow must be private, expose as read-only.
  3. catch only catches upstream — must precede collect.
  4. flowOn only changes upstream Dispatcher — must precede collect.
  5. stateIn for UI state (has initial value), shareIn for events (no replay).

Null Safety (5 rules)

  1. !! only when compiler can't infer but you can prove non-null — must have comment.
  2. Prefer requireNotNull/checkNotNull over !! for meaningful errors.
  3. lateinit only for DI and lifecycle — else use lazy or nullable.
  4. Flatten null chains: max 2 levels of ?. — use early return or when.
  5. Unsafe as only inside when type branches — else use as? + Elvis.

Type Design (5 rules)

  1. Sealed when must exhaust all subtypes — no else fallback.
  2. 3+ same-type params must be wrapped in data class or use named arguments.
  3. Data class fields must all be val.
  4. Use value class over typealias for primitive wrappers.
  5. No Pair/Triple in public API — use named data class.

Collections (5 rules)

  1. No side effects in map/filter/flatMap — use onEach/forEach.
  2. Public properties expose immutable collections.
  3. 3+ chained operators on large collections use asSequence().
  4. Scope function nesting max 1 level.
  5. Prefer buildList/buildMap/buildSet over toMutableX pattern.

Checklists

Coroutines

  • No GlobalScope usage
  • All launch blocks have exception handling
  • All async Deferred values are awaited
  • No runBlocking in production code
  • Dispatcher matches work type (IO/Default/Main)
  • CoroutineScope bound to lifecycle or has cancellation
  • Child failures isolated with supervisorScope

Flow

  • UI collect uses repeatOnLifecycle or collectAsStateWithLifecycle
  • MutableStateFlow/MutableSharedFlow are private
  • catch precedes collect
  • flowOn precedes collect
  • stateIn for state, shareIn for events
  • No side effects in flow {} builder

Null Safety

  • No unjustified !! usage
  • lateinit only for DI and lifecycle
  • No 3+ level ?. chain nesting
  • Unsafe as only in when type branches
  • No catch-and-return-null swallowing
  • Map/List access uses safe methods (getOrNull/getOrElse)

Type Design

  • Sealed when exhausts all subtypes (no else)
  • No 3+ same-type primitive parameters
  • Data class fields all val
  • No Pair/Triple in public API
  • No Any as parameter or return type
  • Primitive wrappers use value class not typealias

Collections

  • No side effects in map/filter
  • Public properties expose immutable collections
  • Large collection chains use asSequence
  • Scope function nesting max 1 level
  • Uses buildList/buildMap over toMutableX pattern

For architecture patterns (ViewModel, UseCase, Repository), see the architecture skill. For Compose UI patterns, see the compose-ui skill. For performance optimization, see the performance skill.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.