@mrciphersmith/keryx 0.4.28 → 0.4.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +4916 -3655
- package/dist/core.js +91 -28
- package/dist/keryx-general-worker-entry.js +413 -240
- package/package.json +1 -1
- package/src/gdskills/bundled/install-manifest.json +3 -0
- package/src/gdskills/bundled/rules/core/api-contracts.mdc +21 -136
- package/src/gdskills/bundled/rules/core/async-patterns.mdc +18 -171
- package/src/gdskills/bundled/rules/core/clean-architecture.mdc +40 -150
- package/src/gdskills/bundled/rules/core/cli-interface-design.mdc +63 -194
- package/src/gdskills/bundled/rules/core/code-style-patterns.mdc +36 -48
- package/src/gdskills/bundled/rules/core/concurrency-patterns.mdc +32 -0
- package/src/gdskills/bundled/rules/core/database-patterns.mdc +26 -148
- package/src/gdskills/bundled/rules/core/error-handling.mdc +57 -109
- package/src/gdskills/bundled/rules/core/frontend-assistant.mdc +14 -29
- package/src/gdskills/bundled/rules/core/layout-rendering.mdc +51 -0
- package/src/gdskills/bundled/rules/core/mobx-store-template.mdc +69 -511
- package/src/gdskills/bundled/rules/core/nestjs-dto.mdc +18 -36
- package/src/gdskills/bundled/rules/core/playwright-testing.mdc +35 -308
- package/src/gdskills/bundled/rules/core/security-baseline.mdc +18 -140
- package/src/gdskills/bundled/rules/core/skill-authoring.mdc +190 -0
- package/src/gdskills/bundled/rules/core/skills-storage-workflow.mdc +5 -0
- package/src/gdskills/bundled/rules/core/solid-principles.mdc +70 -121
- package/src/gdskills/bundled/rules/core/storybook-guidelines.mdc +20 -22
- package/src/gdskills/bundled/rules/core/tdd-workflow.mdc +37 -74
- package/src/gdskills/bundled/rules/core/ui-anti-slop.mdc +48 -37
- package/src/gdskills/bundled/skills/orchestration/task-implementer/SKILL.md +2 -2
- package/src/gdskills/bundled/skills/quality/deprecation-path/SKILL.md +1 -1
- package/src/gdskills/bundled/skills/quality/tests-creator/SKILL.md +1 -1
- package/src/gdskills/bundled/skills/review/review-architecture/SKILL.md +25 -61
- package/src/gdskills/bundled/skills/review/review-backend/SKILL.md +15 -69
- package/src/gdskills/bundled/skills/review/review-clean-code/SKILL.md +84 -418
- package/src/gdskills/bundled/skills/review/review-core-boundaries/SKILL.md +2 -2
- package/src/gdskills/bundled/skills/review/review-degradation/SKILL.md +1 -1
- package/src/gdskills/bundled/skills/review/review-flow-graph/SKILL.md +1 -1
- package/src/gdskills/bundled/skills/review/review-frontend/SKILL.md +17 -311
- package/src/gdskills/bundled/skills/review/review-frontend-conventions/SKILL.md +8 -22
- package/src/gdskills/bundled/skills/review/review-highload/SKILL.md +84 -228
- package/src/gdskills/bundled/skills/review/review-layout/SKILL.md +22 -28
- package/src/gdskills/bundled/skills/review/review-logic/SKILL.md +9 -10
- package/src/gdskills/bundled/skills/review/review-performance/SKILL.md +16 -38
- package/src/gdskills/bundled/skills/review/review-premise/SKILL.md +1 -1
- package/src/gdskills/bundled/skills/review/review-regression/SKILL.md +1 -1
- package/src/gdskills/bundled/skills/review/review-security-code/SKILL.md +8 -8
- package/src/gdskills/bundled/skills/review/review-style/SKILL.md +49 -88
- package/src/gdskills/bundled/skills/review/review-testing-practices/SKILL.md +22 -40
- package/src/gdskills/bundled/skills/review/review-ui-ux/SKILL.md +42 -82
- package/src/gdskills/bundled/stacks/angular/rules/coding-style.mdc +15 -57
- package/src/gdskills/bundled/stacks/angular/rules/patterns.mdc +16 -60
- package/src/gdskills/bundled/stacks/angular/rules/security.mdc +11 -49
- package/src/gdskills/bundled/stacks/angular/rules/testing.mdc +13 -52
- package/src/gdskills/bundled/stacks/c-cpp/rules/coding-style.mdc +33 -57
- package/src/gdskills/bundled/stacks/c-cpp/rules/patterns.mdc +35 -62
- package/src/gdskills/bundled/stacks/c-cpp/rules/security.mdc +35 -62
- package/src/gdskills/bundled/stacks/c-cpp/rules/testing.mdc +34 -54
- package/src/gdskills/bundled/stacks/ci-github-gitlab/rules/patterns.mdc +27 -56
- package/src/gdskills/bundled/stacks/ci-github-gitlab/rules/security.mdc +51 -119
- package/src/gdskills/bundled/stacks/csharp-dotnet/rules/coding-style.mdc +42 -74
- package/src/gdskills/bundled/stacks/csharp-dotnet/rules/patterns.mdc +45 -83
- package/src/gdskills/bundled/stacks/csharp-dotnet/rules/security.mdc +34 -59
- package/src/gdskills/bundled/stacks/csharp-dotnet/rules/testing.mdc +33 -62
- package/src/gdskills/bundled/stacks/django/rules/coding-style.mdc +15 -56
- package/src/gdskills/bundled/stacks/django/rules/patterns.mdc +16 -68
- package/src/gdskills/bundled/stacks/django/rules/security.mdc +13 -71
- package/src/gdskills/bundled/stacks/django/rules/testing.mdc +16 -62
- package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/coding-style.mdc +30 -53
- package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/patterns.mdc +20 -56
- package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/security.mdc +52 -122
- package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/testing.mdc +23 -42
- package/src/gdskills/bundled/stacks/fastapi/rules/coding-style.mdc +13 -47
- package/src/gdskills/bundled/stacks/fastapi/rules/patterns.mdc +18 -81
- package/src/gdskills/bundled/stacks/fastapi/rules/security.mdc +13 -75
- package/src/gdskills/bundled/stacks/fastapi/rules/testing.mdc +14 -58
- package/src/gdskills/bundled/stacks/flutter-dart/rules/coding-style.mdc +36 -74
- package/src/gdskills/bundled/stacks/flutter-dart/rules/patterns.mdc +30 -66
- package/src/gdskills/bundled/stacks/flutter-dart/rules/security.mdc +33 -67
- package/src/gdskills/bundled/stacks/flutter-dart/rules/testing.mdc +41 -73
- package/src/gdskills/bundled/stacks/go/rules/coding-style.mdc +36 -57
- package/src/gdskills/bundled/stacks/go/rules/patterns.mdc +27 -42
- package/src/gdskills/bundled/stacks/go/rules/security.mdc +26 -43
- package/src/gdskills/bundled/stacks/go/rules/testing.mdc +23 -41
- package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/coding-style.mdc +21 -40
- package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/patterns.mdc +26 -43
- package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/security.mdc +25 -37
- package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/testing.mdc +34 -50
- package/src/gdskills/bundled/stacks/kotlin-android/rules/coding-style.mdc +28 -65
- package/src/gdskills/bundled/stacks/kotlin-android/rules/patterns.mdc +34 -78
- package/src/gdskills/bundled/stacks/kotlin-android/rules/security.mdc +35 -68
- package/src/gdskills/bundled/stacks/kotlin-android/rules/testing.mdc +34 -68
- package/src/gdskills/bundled/stacks/mobx/rules/coding-style.mdc +18 -64
- package/src/gdskills/bundled/stacks/mobx/rules/patterns.mdc +13 -66
- package/src/gdskills/bundled/stacks/mobx/rules/security.mdc +8 -35
- package/src/gdskills/bundled/stacks/mobx/rules/testing.mdc +10 -39
- package/src/gdskills/bundled/stacks/nestjs/rules/coding-style.mdc +32 -45
- package/src/gdskills/bundled/stacks/nestjs/rules/patterns.mdc +40 -60
- package/src/gdskills/bundled/stacks/nestjs/rules/security.mdc +30 -50
- package/src/gdskills/bundled/stacks/nestjs/rules/testing.mdc +27 -47
- package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/coding-style.mdc +14 -48
- package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/patterns.mdc +15 -67
- package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/security.mdc +12 -50
- package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/testing.mdc +11 -43
- package/src/gdskills/bundled/stacks/php-laravel/rules/coding-style.mdc +17 -58
- package/src/gdskills/bundled/stacks/php-laravel/rules/patterns.mdc +15 -56
- package/src/gdskills/bundled/stacks/php-laravel/rules/security.mdc +13 -50
- package/src/gdskills/bundled/stacks/php-laravel/rules/testing.mdc +14 -55
- package/src/gdskills/bundled/stacks/python/rules/coding-style.mdc +13 -41
- package/src/gdskills/bundled/stacks/python/rules/patterns.mdc +20 -61
- package/src/gdskills/bundled/stacks/python/rules/security.mdc +15 -57
- package/src/gdskills/bundled/stacks/python/rules/testing.mdc +16 -50
- package/src/gdskills/bundled/stacks/react/rules/coding-style.mdc +14 -40
- package/src/gdskills/bundled/stacks/react/rules/patterns.mdc +15 -55
- package/src/gdskills/bundled/stacks/react/rules/security.mdc +13 -49
- package/src/gdskills/bundled/stacks/react/rules/testing.mdc +10 -37
- package/src/gdskills/bundled/stacks/ruby-rails/rules/coding-style.mdc +15 -48
- package/src/gdskills/bundled/stacks/ruby-rails/rules/patterns.mdc +18 -67
- package/src/gdskills/bundled/stacks/ruby-rails/rules/security.mdc +11 -60
- package/src/gdskills/bundled/stacks/ruby-rails/rules/testing.mdc +14 -65
- package/src/gdskills/bundled/stacks/rust/rules/coding-style.mdc +39 -65
- package/src/gdskills/bundled/stacks/rust/rules/patterns.mdc +33 -60
- package/src/gdskills/bundled/stacks/rust/rules/security.mdc +35 -57
- package/src/gdskills/bundled/stacks/rust/rules/testing.mdc +29 -52
- package/src/gdskills/bundled/stacks/sql-db/rules/coding-style.mdc +12 -48
- package/src/gdskills/bundled/stacks/sql-db/rules/patterns.mdc +22 -113
- package/src/gdskills/bundled/stacks/sql-db/rules/security.mdc +11 -56
- package/src/gdskills/bundled/stacks/sql-db/rules/testing.mdc +14 -59
- package/src/gdskills/bundled/stacks/swift-ios/rules/coding-style.mdc +29 -65
- package/src/gdskills/bundled/stacks/swift-ios/rules/patterns.mdc +41 -88
- package/src/gdskills/bundled/stacks/swift-ios/rules/security.mdc +28 -53
- package/src/gdskills/bundled/stacks/swift-ios/rules/testing.mdc +32 -65
- package/src/gdskills/bundled/stacks/vue/rules/coding-style.mdc +17 -52
- package/src/gdskills/bundled/stacks/vue/rules/patterns.mdc +17 -63
- package/src/gdskills/bundled/stacks/vue/rules/security.mdc +11 -41
- package/src/gdskills/bundled/stacks/vue/rules/testing.mdc +16 -48
|
@@ -7,83 +7,46 @@ metadata:
|
|
|
7
7
|
|
|
8
8
|
# Kotlin/Android coding style
|
|
9
9
|
|
|
10
|
-
Narrows `core-common-rules`'
|
|
11
|
-
Kotlin/Android idiom. Applies only to `*.kt`/`*.kts` files — everything
|
|
12
|
-
not Kotlin-specific still comes from the common rules this file `extends`.
|
|
10
|
+
Narrows `core-common-rules`' style rules to the Kotlin coding conventions and Android idiom.
|
|
13
11
|
|
|
14
12
|
## Naming and structure
|
|
15
13
|
|
|
16
|
-
- `
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
- A `@Composable` function that returns a value instead of emitting UI
|
|
21
|
-
(e.g. `rememberX`) still reads as a normal function name, not a noun —
|
|
22
|
-
reserve the noun-style name for functions that actually emit UI.
|
|
23
|
-
- Keep a file's top-level surface small: one primary class/object per
|
|
24
|
-
file named after it, with small private helpers colocated rather than
|
|
25
|
-
scattered into a shared `Utils.kt`.
|
|
26
|
-
- Package names are all lowercase, no underscores, matching the directory
|
|
27
|
-
layout (`com.example.feature.profile`, not `com.example.Feature.Profile`).
|
|
14
|
+
- A `@Composable` that emits UI is named as a noun (`UserProfileCard`); one that
|
|
15
|
+
returns a value (`rememberX`) is named as a normal function.
|
|
16
|
+
- One primary class/object per file named after it, small private helpers
|
|
17
|
+
colocated; no shared `Utils.kt`.
|
|
28
18
|
|
|
29
19
|
## Data classes vs regular classes
|
|
30
20
|
|
|
31
|
-
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
manager).
|
|
36
|
-
- Prefer `copy()` with named parameters to produce a modified instance
|
|
37
|
-
over building a fresh constructor call by hand; it keeps every unrelated
|
|
38
|
-
field unchanged and the diff at a call site small when a new field is
|
|
39
|
-
added later.
|
|
40
|
-
- A `data class` holding UI state should default every field to a sane
|
|
41
|
-
initial value so `State()` (or `UiState()`) alone is a valid starting
|
|
42
|
-
point.
|
|
21
|
+
- `data class` only for a type whose identity is its held values (DTO, UI state,
|
|
22
|
+
value object); never for an `Activity`, repository or singleton manager.
|
|
23
|
+
- Prefer `copy()` with named parameters over a hand-built constructor call.
|
|
24
|
+
- A `data class` holding UI state defaults every field so `UiState()` alone is valid.
|
|
43
25
|
|
|
44
26
|
## Null-safety idiom
|
|
45
27
|
|
|
46
|
-
- Prefer
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
smart-cast reads more clearly.
|
|
55
|
-
- Prefer `requireNotNull(x) { "why x must be non-null here" }` over `x!!`
|
|
56
|
-
at a boundary (constructor, public function entry) — it fails with a
|
|
57
|
-
message that explains the invariant instead of a bare
|
|
58
|
-
`NullPointerException`.
|
|
59
|
-
- Model "value or absent" with a nullable type or a sealed result type,
|
|
60
|
-
not a sentinel value (`-1`, `""`) that callers have to remember to check
|
|
61
|
-
for.
|
|
28
|
+
- Prefer `?.` or `?:` over `!!`; reserve `!!` for a value a prior check has
|
|
29
|
+
proven non-null, never to get past a nullability warning.
|
|
30
|
+
- Prefer `requireNotNull(x) { "why x must be non-null here" }` over `x!!` at a
|
|
31
|
+
boundary (constructor, public function entry).
|
|
32
|
+
- Use `value?.let { ... }` when the block needs the unwrapped value once; do not
|
|
33
|
+
chain several `?.let` where one `if (value != null)` smart-cast reads better.
|
|
34
|
+
- Model "value or absent" with a nullable or sealed result type, not a sentinel
|
|
35
|
+
(`-1`, `""`).
|
|
62
36
|
|
|
63
37
|
## Sealed classes/interfaces for state modeling
|
|
64
38
|
|
|
65
|
-
- Model
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
- Prefer a `sealed interface` over `sealed class` when a variant needs no
|
|
71
|
-
shared state or behavior; reach for `sealed class` only when the
|
|
72
|
-
variants share a common property or method implementation.
|
|
73
|
-
- Keep a sealed hierarchy's variants in the same file (or a `sealed`-file
|
|
74
|
-
group) as the parent — Kotlin does not require this, but scattering
|
|
75
|
-
variants across files makes the exhaustiveness check hard to audit by
|
|
76
|
-
reading.
|
|
39
|
+
- Model UI or domain state as a `sealed interface`/`sealed class`
|
|
40
|
+
(`Loading`, `Success(data)`, `Error(throwable)`), not one class with nullable
|
|
41
|
+
fields and an `isLoading` boolean.
|
|
42
|
+
- `sealed interface` unless the variants share state or behavior; then `sealed class`.
|
|
43
|
+
- Keep a sealed hierarchy's variants in the same file as the parent.
|
|
77
44
|
|
|
78
45
|
## Extension functions
|
|
79
46
|
|
|
80
|
-
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
-
|
|
85
|
-
|
|
86
|
-
with a vague name invites collisions and surprises at the call site.
|
|
87
|
-
- Avoid extension-function sprawl on core types (`String`, `Int`, `List`)
|
|
88
|
-
for one-off, feature-specific logic — a feature-scoped extension on a
|
|
89
|
-
feature-scoped type keeps the change's blast radius visible.
|
|
47
|
+
- Use an extension for a type this module does not own, or to keep a small helper
|
|
48
|
+
out of a growing class; not in place of a method on a type that is yours to edit.
|
|
49
|
+
- Keep the receiver narrow and the name unambiguous (`String.toDisplayDate()`,
|
|
50
|
+
not `Any.format()`).
|
|
51
|
+
- No extensions on core types (`String`, `Int`, `List`) for one-off,
|
|
52
|
+
feature-specific logic; put them on a feature-scoped type.
|
|
@@ -7,90 +7,46 @@ metadata:
|
|
|
7
7
|
|
|
8
8
|
# Kotlin/Android patterns
|
|
9
9
|
|
|
10
|
-
Narrows `core-common-rules`'
|
|
11
|
-
|
|
12
|
-
`*.kt`/`*.kts` files.
|
|
10
|
+
Narrows `core-common-rules`' design guidance to kotlinx.coroutines structured
|
|
11
|
+
concurrency and Jetpack Compose.
|
|
13
12
|
|
|
14
13
|
## Coroutines: structured concurrency
|
|
15
14
|
|
|
16
|
-
- Launch
|
|
17
|
-
`
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
`
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
them in `coroutineScope { }` and use `async`/`await`, not a `launch`
|
|
26
|
-
fired without an `await` point — `coroutineScope` waits for every child
|
|
27
|
-
to finish (or cancels the rest if one fails) before returning, so a
|
|
28
|
-
caller downstream never observes a half-finished fan-out.
|
|
29
|
-
- Cancellation is cooperative: a long-running loop or CPU-bound block
|
|
30
|
-
inside a coroutine should call `ensureActive()`/check
|
|
31
|
-
`coroutineContext.isActive`, or use a cancellable suspending call
|
|
32
|
-
(`delay`, `yield`), so cancelling the parent scope actually stops it
|
|
33
|
-
instead of running to completion regardless.
|
|
34
|
-
- Switch dispatcher with `withContext(Dispatchers.IO)` around a blocking
|
|
35
|
-
call (network client without its own suspend API, disk I/O), not by
|
|
36
|
-
launching a whole new coroutine on that dispatcher — `withContext`
|
|
37
|
-
keeps the call sequential and propagates cancellation and the result
|
|
38
|
-
back to the caller.
|
|
15
|
+
- Launch from a scope tied to the owning lifecycle: `viewModelScope` in a
|
|
16
|
+
`ViewModel`, `lifecycleScope` in an `Activity`/`Fragment`, `coroutineScope { }`
|
|
17
|
+
or a `suspend` function otherwise. Never `GlobalScope.launch`/`GlobalScope.async`.
|
|
18
|
+
- Run several suspend calls concurrently with `coroutineScope { }` and
|
|
19
|
+
`async`/`await`, not a `launch` with no `await` point.
|
|
20
|
+
- A long-running loop or CPU-bound block calls `ensureActive()`/checks
|
|
21
|
+
`coroutineContext.isActive`, or uses a cancellable suspending call (`delay`, `yield`).
|
|
22
|
+
- Switch dispatcher with `withContext(Dispatchers.IO)` around a blocking call,
|
|
23
|
+
not by launching a new coroutine on that dispatcher.
|
|
39
24
|
|
|
40
25
|
## Compose: recomposition correctness
|
|
41
26
|
|
|
42
|
-
- Strong skipping mode is the
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
- Use `remember { ... }` for state that should survive recomposition but
|
|
57
|
-
not process death or configuration change (a derived value, an
|
|
58
|
-
`Animatable`, a coroutine-backed helper); use `rememberSaveable { ... }`
|
|
59
|
-
when the value must survive activity recreation (rotation, process
|
|
60
|
-
death) — typically UI-only state a `ViewModel` does not already own.
|
|
61
|
-
- Never call a suspend function, fire a one-off event (navigation,
|
|
62
|
-
`Toast`, analytics), or start a coroutine directly in a composable's
|
|
63
|
-
body — route it through `LaunchedEffect(key1, ...) { }` (re-runs when a
|
|
64
|
-
key changes) or `DisposableEffect(key) { onDispose { ... } }` (needs
|
|
65
|
-
cleanup), never as a bare statement that runs on every recomposition.
|
|
66
|
-
- Under strong skipping mode (default since Kotlin 2.0.20), the compiler
|
|
67
|
-
auto-memoizes a lambda declared inside a composable by wrapping it in an
|
|
68
|
-
implicit `remember`, keyed on its captures — a lambda passed inline to a
|
|
69
|
-
hot list item no longer needs manual hoisting for identity stability in
|
|
70
|
-
the common case. Reach for `@DontMemoize` only to opt a specific lambda
|
|
71
|
-
out (e.g. one that must run fresh every recomposition), and still hoist
|
|
72
|
-
a lambda explicitly when it closes over a value from an outer scope that
|
|
73
|
-
changes on a schedule the auto-memoization's capture-based keying
|
|
74
|
-
wouldn't track correctly.
|
|
27
|
+
- Strong skipping mode is the default since Kotlin 2.0.20. Prefer stable
|
|
28
|
+
parameters anyway (primitive, `data class` of stable members, immutable
|
|
29
|
+
collection): identity comparison still recomposes on every NEW instance.
|
|
30
|
+
- Hoist state to the nearest common ancestor that needs it (a caller or the
|
|
31
|
+
owning `ViewModel`); a leaf with no external need can own it via `remember`.
|
|
32
|
+
- `remember { ... }` for state that survives recomposition only;
|
|
33
|
+
`rememberSaveable { ... }` for state that must survive activity recreation.
|
|
34
|
+
- Never call a suspend function, fire a one-off event (navigation, `Toast`,
|
|
35
|
+
analytics) or start a coroutine in a composable's body; use
|
|
36
|
+
`LaunchedEffect(key1, ...)` or `DisposableEffect(key) { onDispose { ... } }`.
|
|
37
|
+
- Under strong skipping a lambda inside a composable is auto-memoized; use
|
|
38
|
+
`@DontMemoize` only to opt a lambda out, and still hoist a lambda explicitly
|
|
39
|
+
when it closes over an outer-scope value whose changes the capture-based
|
|
40
|
+
keying would not track.
|
|
75
41
|
|
|
76
42
|
## State exposure from a ViewModel
|
|
77
43
|
|
|
78
|
-
- Expose
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
- `LiveData` is legacy for new Compose/coroutine-first code: prefer
|
|
88
|
-
`StateFlow`/`SharedFlow` exposed from the `ViewModel` and collected with
|
|
89
|
-
`collectAsStateWithLifecycle()` in Compose. Keep `LiveData` only where a
|
|
90
|
-
project has already standardized on it or where an unconverted
|
|
91
|
-
`View`-based screen still consumes it.
|
|
92
|
-
- Collect a `ViewModel`'s flow in Compose with
|
|
93
|
-
`collectAsStateWithLifecycle()`, not a bare `collectAsState()` — the
|
|
94
|
-
lifecycle-aware variant stops collecting while the screen is stopped
|
|
95
|
-
instead of continuing to observe (and potentially update state) behind
|
|
96
|
-
a backgrounded UI.
|
|
44
|
+
- Expose a read-only `StateFlow`/`SharedFlow` over a private mutable holder
|
|
45
|
+
(`private val _state = MutableStateFlow(...)`, `val state = _state.asStateFlow()`),
|
|
46
|
+
never the mutable type.
|
|
47
|
+
- `StateFlow` for "current value" UI state; `SharedFlow`/`Channel` for one-off
|
|
48
|
+
events (snackbar, navigation) that must not replay.
|
|
49
|
+
- `LiveData` is legacy for new code: use `StateFlow`/`SharedFlow` collected with
|
|
50
|
+
`collectAsStateWithLifecycle()`. Keep `LiveData` only where the project has
|
|
51
|
+
standardized on it or an unconverted `View`-based screen consumes it.
|
|
52
|
+
- Collect in Compose with `collectAsStateWithLifecycle()`, not bare `collectAsState()`.
|
|
@@ -7,84 +7,51 @@ metadata:
|
|
|
7
7
|
|
|
8
8
|
# Kotlin/Android security
|
|
9
9
|
|
|
10
|
-
Narrows `core-common-rules`'
|
|
11
|
-
specific, OWASP Mobile-relevant risks. Applies only to `*.kt`/`*.kts`
|
|
12
|
-
files.
|
|
10
|
+
Narrows `core-common-rules`' security rules to Android risks in OWASP Mobile Top 10.
|
|
13
11
|
|
|
14
12
|
## Secrets and credential storage
|
|
15
13
|
|
|
16
|
-
- Never store a credential, auth token
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
an existing codebase that already depends on it.
|
|
27
|
-
- Never hard-code an API key, client secret, or signing credential as a
|
|
28
|
-
Kotlin string literal or a `BuildConfig` field, whether the value is
|
|
29
|
-
committed or injected at build time from a local, untracked properties
|
|
30
|
-
file (`local.properties`) or a CI secret — either way, a `BuildConfig`
|
|
31
|
-
field is compiled into the APK exactly like a string literal and is
|
|
32
|
-
just as recoverable by decompiling it. Keeping the value out of source
|
|
33
|
-
control (via `local.properties`/a CI secret) only stops it leaking
|
|
34
|
-
through the repository; it does not keep it off the device. For a
|
|
35
|
-
value that must actually stay off the device, fetch it from a backend
|
|
36
|
-
at runtime instead of baking it into the build at all.
|
|
14
|
+
- Never store a credential, auth token or API secret in plain `SharedPreferences`.
|
|
15
|
+
For new code prefer the Android Keystore directly (store the key there, encrypt
|
|
16
|
+
the value yourself) over `EncryptedSharedPreferences`
|
|
17
|
+
(`androidx.security:security-crypto`), which Google no longer recommends for new
|
|
18
|
+
applications; check its current status in the Android docs before using it in a
|
|
19
|
+
codebase that already depends on it.
|
|
20
|
+
- Never hard-code an API key, client secret or signing credential as a Kotlin
|
|
21
|
+
string literal or a `BuildConfig` field, committed or injected at build time
|
|
22
|
+
from `local.properties` or a CI secret: `BuildConfig` is compiled into the APK.
|
|
23
|
+
A value that must stay off the device is fetched from a backend at runtime.
|
|
37
24
|
- Generate and store cryptographic keys through `AndroidKeyStore`
|
|
38
|
-
(`KeyGenParameterSpec`)
|
|
39
|
-
application code — the Keystore keeps key material out of the app's
|
|
40
|
-
own process memory and out of extractable storage.
|
|
25
|
+
(`KeyGenParameterSpec`), not derived or hard-coded in application code.
|
|
41
26
|
|
|
42
27
|
## Manifest and component exposure
|
|
43
28
|
|
|
44
|
-
- Every `<activity>`, `<service>`, `<receiver
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
- An exported component that must stay exported (a deep-link entry point,
|
|
52
|
-
a share target) validates every piece of the incoming `Intent` before
|
|
53
|
-
acting on it — never trusts an extra, a URI path segment, or a
|
|
54
|
-
`ContentProvider` query purely because the intent-filter matched.
|
|
55
|
-
- Guard a `ContentProvider` and any exported component with a
|
|
56
|
-
signature-level custom permission when the caller is meant to be your
|
|
57
|
-
own other app, not "any app that asks."
|
|
29
|
+
- Every `<activity>`, `<service>`, `<receiver>` and `<provider>` not meant to be
|
|
30
|
+
reachable from other apps has `android:exported="false"` (or no `exported`
|
|
31
|
+
attribute and no intent-filter).
|
|
32
|
+
- An exported component that must stay exported (deep-link entry, share target)
|
|
33
|
+
validates every piece of the incoming `Intent` before acting on it.
|
|
34
|
+
- Guard a `ContentProvider` and any exported component with a signature-level
|
|
35
|
+
custom permission when the caller is meant to be your own other app.
|
|
58
36
|
|
|
59
37
|
## Secure intent and deep-link handling
|
|
60
38
|
|
|
61
|
-
- Treat every value
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
`
|
|
69
|
-
|
|
70
|
-
respond, to avoid intent interception by another installed app.
|
|
71
|
-
- Validate a deep-link's scheme/host/path against an allowlist before
|
|
72
|
-
using any part of it to load content or trigger an action —
|
|
73
|
-
`App Links`/verified `https` deep links reduce but do not eliminate
|
|
74
|
-
this: a query parameter or path segment can still carry attacker-
|
|
75
|
-
controlled data even through a verified link.
|
|
39
|
+
- Treat every value from an incoming `Intent` (extras, deep-link segments and
|
|
40
|
+
query params, share `ClipData`) as untrusted: validate shape and range before
|
|
41
|
+
using it to navigate, query a database or build a file path.
|
|
42
|
+
- Prefer an explicit `Intent` within your own app; use an implicit `Intent` only
|
|
43
|
+
when another app must handle it, and set `setPackage` when only your own app
|
|
44
|
+
should respond.
|
|
45
|
+
- Validate a deep-link's scheme/host/path against an allowlist before using any
|
|
46
|
+
part of it; verified `https` App Links do not make a query parameter or path
|
|
47
|
+
segment trusted.
|
|
76
48
|
|
|
77
49
|
## Data and transport
|
|
78
50
|
|
|
79
|
-
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
-
|
|
85
|
-
|
|
86
|
-
`FLAG_SECURE` on the window, rather than relying on the OS default.
|
|
87
|
-
- Avoid logging PII, tokens, or full request/response bodies with
|
|
88
|
-
`Log.d`/`Log.i` in release builds — strip or gate verbose logging
|
|
89
|
-
behind a debug-only build flag so production logs (which can be pulled
|
|
90
|
-
from a device or bug report) do not leak sensitive data.
|
|
51
|
+
- Require TLS for every network call carrying credentials or personal data; no
|
|
52
|
+
custom `TrustManager`/`HostnameVerifier` that accepts all certificates outside
|
|
53
|
+
a short-lived local debug build, and never shipped.
|
|
54
|
+
- Mark a view/field that must not appear in screenshots or the app-switcher
|
|
55
|
+
preview (PIN entry, payment details) with `FLAG_SECURE`.
|
|
56
|
+
- No PII, tokens or full request/response bodies in `Log.d`/`Log.i` in release
|
|
57
|
+
builds; gate verbose logging behind a debug-only flag.
|
|
@@ -7,83 +7,49 @@ metadata:
|
|
|
7
7
|
|
|
8
8
|
# Kotlin/Android testing
|
|
9
9
|
|
|
10
|
-
Narrows `core-common-rules`'
|
|
11
|
-
|
|
12
|
-
Applies only to `*.kt`/`*.kts` files.
|
|
10
|
+
Narrows `core-common-rules`' testing rules to `kotlinx-coroutines-test`, Compose
|
|
11
|
+
UI testing and mocking on Android.
|
|
13
12
|
|
|
14
13
|
## Coroutine test dispatchers
|
|
15
14
|
|
|
16
|
-
- Test a `suspend` function or
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
-
|
|
22
|
-
`UnconfinedTestDispatcher`
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
in a `@Before` and `Dispatchers.resetMain()` in an `@After` (or a JUnit
|
|
26
|
-
rule that wraps this) so `viewModelScope`/`Dispatchers.Main` resolves to
|
|
27
|
-
the test dispatcher instead of throwing or running on a background
|
|
28
|
-
thread the test cannot observe.
|
|
29
|
-
- Prefer `StandardTestDispatcher` (queues work, you advance it explicitly
|
|
30
|
-
with `advanceUntilIdle()`/`runCurrent()`) when a test needs to assert an
|
|
31
|
-
intermediate state (e.g. a loading state before a result arrives); use
|
|
32
|
-
`UnconfinedTestDispatcher` when the test only cares about the end state
|
|
33
|
-
and wants dispatched work to run eagerly.
|
|
34
|
-
- Never synchronize a coroutine test with `Thread.sleep`/a fixed `delay`
|
|
35
|
-
in the test body waiting for background work to finish — that is
|
|
36
|
-
exactly what `runTest`'s virtual time and `advanceUntilIdle()` replace.
|
|
15
|
+
- Test a `suspend` function or `ViewModel` coroutine behavior with `runTest { }`,
|
|
16
|
+
not a real `delay` or blocking sleep.
|
|
17
|
+
- Inject a `TestDispatcher` (`StandardTestDispatcher`/`UnconfinedTestDispatcher`)
|
|
18
|
+
in place of `Dispatchers.Main`/`Dispatchers.IO`; `Dispatchers.setMain(testDispatcher)`
|
|
19
|
+
in `@Before` and `Dispatchers.resetMain()` in `@After` (or a JUnit rule).
|
|
20
|
+
- `StandardTestDispatcher` (advance with `advanceUntilIdle()`/`runCurrent()`) when
|
|
21
|
+
a test asserts an intermediate state; `UnconfinedTestDispatcher` when only the
|
|
22
|
+
end state matters.
|
|
23
|
+
- Never synchronize a coroutine test with `Thread.sleep` or a fixed `delay`.
|
|
37
24
|
|
|
38
25
|
## Compose UI testing
|
|
39
26
|
|
|
40
|
-
- Drive
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
(`
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
`composeTestRule.awaitIdle()`/`mainClock.advanceTimeUntil { }` under
|
|
51
|
-
manual clock control) to wait for an async UI update instead of a
|
|
52
|
-
fixed-duration sleep in the test.
|
|
53
|
-
- Assert both structure and behavior: a node's presence/text via a
|
|
54
|
-
semantics finder, and an interaction's effect (`performClick()` then
|
|
55
|
-
assert the resulting state/text), not just that a composable rendered
|
|
56
|
-
without throwing.
|
|
27
|
+
- Drive assertions through a `ComposeTestRule` (`createComposeRule()`, or
|
|
28
|
+
`createAndroidComposeRule<Activity>()` when a hosting Activity is needed);
|
|
29
|
+
never reach into the `View` tree.
|
|
30
|
+
- Find nodes with `onNodeWithText`, `onNodeWithContentDescription`,
|
|
31
|
+
`onNodeWithTag(testTag)`, not structural/index-based queries; add
|
|
32
|
+
`Modifier.testTag("...")` where there is no stable text or content description.
|
|
33
|
+
- Wait for async UI with `composeTestRule.waitUntil { ... }`, `awaitIdle()` or
|
|
34
|
+
`mainClock.advanceTimeUntil { }`, not a fixed sleep.
|
|
35
|
+
- Assert structure and behavior: presence/text, and an interaction's effect
|
|
36
|
+
(`performClick()` then the resulting state), not just that it rendered.
|
|
57
37
|
|
|
58
38
|
## Mocking at the interface boundary
|
|
59
39
|
|
|
60
|
-
- Mock a `Repository`/`ApiService`/`DataSource` interface
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
object mocks via `mockkObject`) — unless a project has already
|
|
69
|
-
standardized on Mockito with `mockito-kotlin`; match what the project
|
|
70
|
-
already uses rather than introducing a second mocking library.
|
|
71
|
-
- Use `coEvery { repo.fetch() } returns result` /
|
|
72
|
-
`coVerify { repo.fetch() }` (MockK's coroutine-aware variants) for a
|
|
73
|
-
suspend function on a mock, not the plain `every`/`verify` forms, which
|
|
74
|
-
do not handle a `suspend` member correctly.
|
|
75
|
-
- Fake network/database responses at the repository or data-source
|
|
76
|
-
interface (a fake or mocked implementation returning canned data), not
|
|
77
|
-
by hitting a real network or an on-device database from a unit test —
|
|
78
|
-
reserve a real backing store for an instrumented/integration test.
|
|
40
|
+
- Mock a `Repository`/`ApiService`/`DataSource` interface or other clearly-owned
|
|
41
|
+
collaborator boundary; never stub the class under test's own private methods or fields.
|
|
42
|
+
- Prefer MockK for Kotlin code, unless the project has standardized on Mockito
|
|
43
|
+
with `mockito-kotlin`; match the project, do not add a second mocking library.
|
|
44
|
+
- `coEvery { repo.fetch() } returns result` / `coVerify { repo.fetch() }` for a
|
|
45
|
+
suspend function on a mock, not `every`/`verify`.
|
|
46
|
+
- Fake network/database responses at the repository or data-source interface in
|
|
47
|
+
unit tests; a real backing store belongs in an instrumented/integration test.
|
|
79
48
|
|
|
80
49
|
## Layout and lifecycle
|
|
81
50
|
|
|
82
|
-
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
- Use JUnit rules (`MainDispatcherRule` for coroutines,
|
|
88
|
-
`createComposeRule()` for Compose) to keep dispatcher/UI setup and
|
|
89
|
-
teardown out of every individual test method.
|
|
51
|
+
- `ViewModel`/plain Kotlin unit tests under `src/test/`; tests needing an Android
|
|
52
|
+
context or device (Compose UI, `Instrumentation`) under `src/androidTest/`;
|
|
53
|
+
match the project's layout, no third location.
|
|
54
|
+
- Use JUnit rules (`MainDispatcherRule`, `createComposeRule()`) for dispatcher and
|
|
55
|
+
UI setup/teardown.
|
|
@@ -7,85 +7,39 @@ metadata:
|
|
|
7
7
|
|
|
8
8
|
# MobX coding style
|
|
9
9
|
|
|
10
|
-
Narrows the React/TypeScript common rules to MobX's
|
|
11
|
-
observables, and observer components. Everything not MobX-specific
|
|
12
|
-
|
|
10
|
+
Narrows the React/TypeScript common rules to MobX's idiom for stores,
|
|
11
|
+
observables, and observer components. Everything not MobX-specific comes from
|
|
12
|
+
the common and React rules this file `extends`.
|
|
13
13
|
|
|
14
14
|
## Store class shape
|
|
15
15
|
|
|
16
|
-
- Call `makeObservable(this)` (
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
other constructor logic reads `this`.
|
|
20
|
-
- Prefer explicit `@observable`/`@computed`/`@action`/`@action.bound`
|
|
21
|
-
decorators with `makeObservable` over `makeAutoObservable` for any store
|
|
22
|
-
a component subclasses, that mixes injected dependencies with state, or
|
|
23
|
-
that needs a field to stay non-observable — `makeAutoObservable` makes
|
|
24
|
-
every own enumerable property observable and every method an action,
|
|
25
|
-
which is the wrong default once the store has structure to protect.
|
|
26
|
-
- Name store classes `XyzStore` and files `xyz.store.ts`/`XyzStore.ts` to
|
|
27
|
-
match the project's existing convention; keep one store per file.
|
|
16
|
+
- Call `makeObservable(this)` (explicit annotations map, or `makeAutoObservable(this)` for a store with no inheritance and no field that must stay non-observable) once in the constructor, before other constructor logic reads `this`.
|
|
17
|
+
- Prefer explicit `@observable`/`@computed`/`@action`/`@action.bound` with `makeObservable` over `makeAutoObservable` for a store that is subclassed, mixes injected dependencies with state, or needs a non-observable field.
|
|
18
|
+
- Name store classes `XyzStore`, files `xyz.store.ts`/`XyzStore.ts` per the project's convention; one store per file.
|
|
28
19
|
|
|
29
20
|
## Actions
|
|
30
21
|
|
|
31
|
-
- Every method that mutates observable state
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
reference without losing `this`.
|
|
35
|
-
- After an `await` inside an async action, re-enter MobX with
|
|
36
|
-
`runInAction(() => { ... })` before mutating state — the code after the
|
|
37
|
-
`await` runs outside the original action's transaction.
|
|
38
|
-
- Do not call a store method that mutates state directly from a component
|
|
39
|
-
render body; only from an event handler, effect, or another action.
|
|
22
|
+
- Every method that mutates observable state is an `action`; a public method called from a component event handler is `@action.bound`.
|
|
23
|
+
- After an `await` in an async action, re-enter with `runInAction(() => { ... })` before mutating state.
|
|
24
|
+
- Call a state-mutating store method only from an event handler, effect, or another action, never a component render body.
|
|
40
25
|
|
|
41
26
|
## Computed values
|
|
42
27
|
|
|
43
|
-
-
|
|
44
|
-
|
|
45
|
-
on every render or a store method that recomputes and returns a fresh
|
|
46
|
-
value each call. A `@computed` is cached and only re-evaluates when one
|
|
47
|
-
of its own observable dependencies changes.
|
|
48
|
-
- Keep a `@computed` getter free of side effects; it must be safe to
|
|
49
|
-
evaluate speculatively (MobX may read a computed's value to decide
|
|
50
|
-
whether it changed).
|
|
28
|
+
- Put a value derived purely from other observables in a `@computed get`, not a per-render component calculation or a store method that recomputes each call.
|
|
29
|
+
- Keep a `@computed` getter free of side effects.
|
|
51
30
|
|
|
52
31
|
## Observable collections and value types
|
|
53
32
|
|
|
54
|
-
-
|
|
55
|
-
|
|
56
|
-
does not want deeply proxied, `@observable.shallow` for a container
|
|
57
|
-
whose items should stay plain, and `@observable.struct` when a reaction
|
|
58
|
-
should only fire on a structural (deep-equal) change, not fine-grained.
|
|
59
|
-
Reserve the default deep `@observable` for state the store actually
|
|
60
|
-
wants MobX to track recursively.
|
|
61
|
-
- When you need MobX's own collection API (`.replace()`, `.remove()`,
|
|
62
|
-
`.merge()`, `.has()`) on an array or map field, construct it with
|
|
63
|
-
`observable([...])` / `observable(new Map())` and type it as
|
|
64
|
-
`IObservableArray<T>` / `ObservableMap<K, V>`; a plain array/object
|
|
65
|
-
literal assigned to `@observable` is still deeply observed but does not
|
|
66
|
-
expose those methods.
|
|
33
|
+
- `@observable.ref` for an opaque reference not to be deeply proxied (large externally-owned object, DOM/editor instance); `@observable.shallow` for a container whose items stay plain; `@observable.struct` when a reaction should fire only on a structural (deep-equal) change. Default deep `@observable` only for state MobX should track recursively.
|
|
34
|
+
- For MobX's collection API (`.replace()`, `.remove()`, `.merge()`, `.has()`), construct with `observable([...])`/`observable(new Map())` and type as `IObservableArray<T>`/`ObservableMap<K, V>`.
|
|
67
35
|
|
|
68
36
|
## Components
|
|
69
37
|
|
|
70
|
-
- Wrap
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
when that field changes.
|
|
74
|
-
- Read store instances through a typed React context + hook pair
|
|
75
|
-
(`useXyzStore()`), not through a module-level singleton import, so
|
|
76
|
-
components stay testable and providers can swap the instance.
|
|
77
|
-
- Do not destructure observable fields off a store at the top of a
|
|
78
|
-
component body if that breaks fine-grained tracking for a nested
|
|
79
|
-
`<Observer>` boundary further down — read the field where it is
|
|
80
|
-
actually rendered instead.
|
|
38
|
+
- Wrap every function component that reads observable state in `observer` from `mobx-react-lite`.
|
|
39
|
+
- Read stores through a typed React context + hook pair (`useXyzStore()`), not a module-level singleton import.
|
|
40
|
+
- Do not destructure observable fields at the top of a component body when that breaks fine-grained tracking for a nested `<Observer>`; read the field where it renders.
|
|
81
41
|
|
|
82
42
|
## Errors and imports
|
|
83
43
|
|
|
84
|
-
- Import
|
|
85
|
-
|
|
86
|
-
`useLocalObservable` from `"mobx-react-lite"` — do not import from the
|
|
87
|
-
deprecated combined `mobx-react` package in new code unless the project
|
|
88
|
-
has not migrated off it yet.
|
|
89
|
-
- Catch and store errors from an async action's `try/catch` as
|
|
90
|
-
`err: unknown`, narrowing before assigning to an observable `error`
|
|
91
|
-
field (see `rules/patterns.mdc` for the full async-action shape).
|
|
44
|
+
- Import `observable`, `action`, `computed`, `reaction`, `runInAction`, `makeObservable` from `"mobx"`, and `observer`, `useLocalObservable` from `"mobx-react-lite"`; not from the deprecated `mobx-react` in new code unless the project has not migrated.
|
|
45
|
+
- Catch errors from an async action as `err: unknown`, narrowing before assigning to an observable `error` field (full shape in `rules/patterns.mdc`).
|