feat: add kotlin commands and skill pack

This commit is contained in:
Affaan Mustafa
2026-03-10 21:25:52 -07:00
parent 82f9f58d28
commit 135eb4c98d
14 changed files with 3900 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
---
description: "Kotlin coding style extending common rules"
globs: ["**/*.kt", "**/*.kts", "**/build.gradle.kts"]
alwaysApply: false
---
# Kotlin Coding Style
> This file extends the common coding style rule with Kotlin-specific content.
## Formatting
- **ktfmt** or **ktlint** are mandatory for consistent formatting
- Use trailing commas in multiline declarations
## Immutability
- `val` over `var` always
- Immutable collections by default (`List`, `Map`, `Set`)
- Use `data class` with `copy()` for immutable updates
## Null Safety
- Avoid `!!` -- use `?.`, `?:`, `require`, or `checkNotNull`
- Handle platform types explicitly at Java interop boundaries
## Expression Bodies
Prefer expression bodies for single-expression functions:
```kotlin
fun isAdult(age: Int): Boolean = age >= 18
```
## Reference
See skill: `kotlin-patterns` for comprehensive Kotlin idioms and patterns.

View File

@@ -0,0 +1,16 @@
---
description: "Kotlin hooks extending common rules"
globs: ["**/*.kt", "**/*.kts", "**/build.gradle.kts"]
alwaysApply: false
---
# Kotlin Hooks
> This file extends the common hooks rule with Kotlin-specific content.
## PostToolUse Hooks
Configure in `~/.claude/settings.json`:
- **ktfmt/ktlint**: Auto-format `.kt` and `.kts` files after edit
- **detekt**: Run static analysis after editing Kotlin files
- **./gradlew build**: Verify compilation after changes

View File

@@ -0,0 +1,50 @@
---
description: "Kotlin patterns extending common rules"
globs: ["**/*.kt", "**/*.kts", "**/build.gradle.kts"]
alwaysApply: false
---
# Kotlin Patterns
> This file extends the common patterns rule with Kotlin-specific content.
## Sealed Classes
Use sealed classes/interfaces for exhaustive type hierarchies:
```kotlin
sealed class Result<out T> {
data class Success<T>(val data: T) : Result<T>()
data class Failure(val error: AppError) : Result<Nothing>()
}
```
## Extension Functions
Add behavior without inheritance, scoped to where they're used:
```kotlin
fun String.toSlug(): String =
lowercase().replace(Regex("[^a-z0-9\\s-]"), "").replace(Regex("\\s+"), "-")
```
## Scope Functions
- `let`: Transform nullable or scoped result
- `apply`: Configure an object
- `also`: Side effects
- Avoid nesting scope functions
## Dependency Injection
Use Koin for DI in Ktor projects:
```kotlin
val appModule = module {
single<UserRepository> { ExposedUserRepository(get()) }
single { UserService(get()) }
}
```
## Reference
See skill: `kotlin-patterns` for comprehensive Kotlin patterns including coroutines, DSL builders, and delegation.

View File

@@ -0,0 +1,58 @@
---
description: "Kotlin security extending common rules"
globs: ["**/*.kt", "**/*.kts", "**/build.gradle.kts"]
alwaysApply: false
---
# Kotlin Security
> This file extends the common security rule with Kotlin-specific content.
## Secret Management
```kotlin
val apiKey = System.getenv("API_KEY")
?: throw IllegalStateException("API_KEY not configured")
```
## SQL Injection Prevention
Always use Exposed's parameterized queries:
```kotlin
// Good: Parameterized via Exposed DSL
UsersTable.selectAll().where { UsersTable.email eq email }
// Bad: String interpolation in raw SQL
exec("SELECT * FROM users WHERE email = '$email'")
```
## Authentication
Use Ktor's Auth plugin with JWT:
```kotlin
install(Authentication) {
jwt("jwt") {
verifier(
JWT.require(Algorithm.HMAC256(secret))
.withAudience(audience)
.withIssuer(issuer)
.build()
)
validate { credential ->
val payload = credential.payload
if (payload.audience.contains(audience) &&
payload.issuer == issuer &&
payload.subject != null) {
JWTPrincipal(payload)
} else {
null
}
}
}
}
```
## Null Safety as Security
Kotlin's type system prevents null-related vulnerabilities -- avoid `!!` to maintain this guarantee.

View File

@@ -0,0 +1,38 @@
---
description: "Kotlin testing extending common rules"
globs: ["**/*.kt", "**/*.kts", "**/build.gradle.kts"]
alwaysApply: false
---
# Kotlin Testing
> This file extends the common testing rule with Kotlin-specific content.
## Framework
Use **Kotest** with spec styles (StringSpec, FunSpec, BehaviorSpec) and **MockK** for mocking.
## Coroutine Testing
Use `runTest` from `kotlinx-coroutines-test`:
```kotlin
test("async operation completes") {
runTest {
val result = service.fetchData()
result.shouldNotBeEmpty()
}
}
```
## Coverage
Use **Kover** for coverage reporting:
```bash
./gradlew koverHtmlReport
./gradlew koverVerify
```
## Reference
See skill: `kotlin-testing` for detailed Kotest patterns, MockK usage, and property-based testing.