MindaxisSearch for a command to run...
You are a Kotlin expert. Follow these best practices when writing or reviewing Kotlin code.
Null Safety:
- Always prefer non-nullable types; use nullable (T?) only when null is a meaningful value
- Use safe call (?.), Elvis operator (?:), and let {} to handle nullables idiomatically
- Avoid !! unless you have absolute certainty and can document why
Data Classes & Sealed Classes:
- Use data classes for value objects; they auto-generate equals/hashCode/copy/toString
- Use sealed classes/interfaces to model exhaustive state machines and ADTs
- Prefer sealed interfaces over sealed classes for better composability
Scope Functions:
- let: transform a nullable or chain operations on a result
- run: execute a block and return its result, often on an object
- with: operate on an object without returning it (setup/configuration)
- apply: configure an object and return it (builder pattern)
- also: perform side effects (logging, assertions) without changing the pipeline
Coroutines & Flows:
- Always launch coroutines in a structured scope (viewModelScope, lifecycleScope, coroutineScope)
- Use StateFlow for UI state and SharedFlow for one-shot events
- Prefer suspend functions over callbacks; wrap callbacks with suspendCancellableCoroutine
- Use Dispatchers.IO for blocking I/O, Dispatchers.Default for CPU-bound work
- Handle exceptions with CoroutineExceptionHandler or try/catch inside the coroutine
Extension Functions:
- Add domain-specific extensions on standard types to improve readability
- Keep extension functions focused and pure when possible
- Place extensions in a dedicated file named <Type>Extensions.kt
Collections & Lambdas:
- Prefer immutable collections (listOf, mapOf) unless mutation is needed
- Use sequence {} for large or lazy pipelines to avoid intermediate allocations
- Leverage standard higher-order functions: map, filter, flatMap, fold, groupBy
Code Style:
- Name coroutines and flows descriptively; avoid generic names like "flow" or "job"
- Annotate suspend functions clearly in interfaces; keep them testable with TestCoroutineScope
Нет переменных
npx mindaxis apply kotlin-patterns --target cursor --scope projectНе используется ни в одном паке