@mrciphersmith/keryx 0.4.29 → 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 +2408 -1369
- package/dist/core.js +90 -27
- package/dist/keryx-general-worker-entry.js +82 -25
- package/package.json +1 -1
- package/src/gdskills/bundled/install-manifest.json +2 -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 +21 -3
- package/src/gdskills/bundled/rules/core/cli-interface-design.mdc +63 -194
- package/src/gdskills/bundled/rules/core/code-style-patterns.mdc +36 -49
- 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 +7 -8
- 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/solid-principles.mdc +31 -7
- 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/quality/deprecation-path/SKILL.md +1 -1
- package/src/gdskills/bundled/skills/review/review-architecture/SKILL.md +24 -60
- package/src/gdskills/bundled/skills/review/review-backend/SKILL.md +13 -65
- package/src/gdskills/bundled/skills/review/review-clean-code/SKILL.md +22 -35
- package/src/gdskills/bundled/skills/review/review-frontend/SKILL.md +16 -309
- package/src/gdskills/bundled/skills/review/review-frontend-conventions/SKILL.md +7 -21
- package/src/gdskills/bundled/skills/review/review-highload/SKILL.md +83 -227
- package/src/gdskills/bundled/skills/review/review-layout/SKILL.md +22 -28
- package/src/gdskills/bundled/skills/review/review-logic/SKILL.md +8 -8
- package/src/gdskills/bundled/skills/review/review-performance/SKILL.md +15 -37
- package/src/gdskills/bundled/skills/review/review-security-code/SKILL.md +7 -7
- package/src/gdskills/bundled/skills/review/review-style/SKILL.md +31 -66
- package/src/gdskills/bundled/skills/review/review-testing-practices/SKILL.md +21 -39
- 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 -84
- 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 +18 -37
- 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 +12 -45
- 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,82 +7,46 @@ metadata:
|
|
|
7
7
|
|
|
8
8
|
# Flutter/Dart patterns
|
|
9
9
|
|
|
10
|
-
Narrows `core-common-rules`'
|
|
11
|
-
widget lifecycle, state handling, and async patterns. Applies only to
|
|
12
|
-
`*.dart` files. Flutter has no single mandated state-management story —
|
|
13
|
-
`Provider`, `Riverpod`, `Bloc`, and plain `StatefulWidget` all appear
|
|
14
|
-
across real projects — so this rule gives lifecycle-correct guidance that
|
|
15
|
-
applies regardless of which the project has chosen; match whichever one is
|
|
16
|
-
already in use rather than introducing a second approach.
|
|
10
|
+
Narrows `core-common-rules`' design guidance to Flutter's widget lifecycle, state handling and async patterns. The rules apply whichever of `Provider`, `Riverpod`, `Bloc` or plain `StatefulWidget` the project uses; match the one already in use, do not introduce a second.
|
|
17
11
|
|
|
18
12
|
## Widget lifecycle correctness
|
|
19
13
|
|
|
20
14
|
- `initState()` is for one-time setup that needs `this` (subscribing to a
|
|
21
|
-
controller, starting a timer
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
`ScrollController` the `State` created, and call `super.dispose()` last,
|
|
29
|
-
not first. A controller created in `initState` and never disposed leaks
|
|
30
|
-
its underlying resources for the life of the app.
|
|
31
|
-
- `didUpdateWidget(oldWidget)` is where a `StatefulWidget` reacts to a
|
|
32
|
-
changed constructor parameter from its parent (e.g. re-subscribing to a
|
|
33
|
-
different id) — comparing `oldWidget.someId != widget.someId` there,
|
|
34
|
-
not inside `build()`, keeps that reaction from re-running on every
|
|
35
|
-
rebuild.
|
|
15
|
+
controller, starting a timer); it calls `super.initState()` first. Read an
|
|
16
|
+
inherited widget in `didChangeDependencies()`, not `initState()`.
|
|
17
|
+
- `dispose()` releases everything acquired: cancel every `StreamSubscription`,
|
|
18
|
+
call `.dispose()` on every `TextEditingController`/`AnimationController`/
|
|
19
|
+
`FocusNode`/`ScrollController` the `State` created, and call `super.dispose()` last.
|
|
20
|
+
- React to a changed constructor parameter in `didUpdateWidget(oldWidget)`
|
|
21
|
+
(`oldWidget.someId != widget.someId`), not in `build()`.
|
|
36
22
|
|
|
37
23
|
## setState and BuildContext after an async gap
|
|
38
24
|
|
|
39
|
-
- After any `await`
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
reading `Theme.of(context)`/`Navigator.of(context)`, or anything else —
|
|
47
|
-
never assume the widget that owns it is still in the tree just because
|
|
48
|
-
the `Future` completed. This applies whether the context came from a
|
|
49
|
-
`StatefulWidget`'s own `State` or from a `StatelessWidget`'s `build`
|
|
50
|
-
parameter.
|
|
51
|
-
- An early-return `if` check on `context.mounted` (or `mounted` inside
|
|
52
|
-
`State`) immediately after the `await`, before the first subsequent use
|
|
53
|
-
of `context`/`setState`, is the fix — not a `try`/`catch` around the
|
|
54
|
-
eventual error, and not skipping the check because the async call
|
|
55
|
-
"usually" resolves quickly.
|
|
25
|
+
- After any `await` in a `State` method, check `mounted` before `setState()`.
|
|
26
|
+
- After any `await` in a callback holding a `BuildContext` (`onPressed`, a
|
|
27
|
+
`Future` continuation), check `context.mounted` before using it, whether the
|
|
28
|
+
context came from a `State` or a `StatelessWidget`'s `build` parameter.
|
|
29
|
+
- The fix is an early-return `if` on `context.mounted`/`mounted` immediately
|
|
30
|
+
after the `await`, not a `try`/`catch` around the error and not skipping the
|
|
31
|
+
check because the call "usually" resolves quickly.
|
|
56
32
|
|
|
57
33
|
## Async patterns
|
|
58
34
|
|
|
59
|
-
- Prefer `async`/`await` over chained `.then()`
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
the `State` subscribes to manually) in `dispose()` — `StreamBuilder`
|
|
67
|
-
itself manages its subscription's lifecycle and needs no manual cancel.
|
|
68
|
-
- Guard a `FutureBuilder`/`StreamBuilder`'s `snapshot.connectionState`
|
|
69
|
-
before reading `snapshot.data` — a `ConnectionState.waiting` or
|
|
70
|
-
`.none` snapshot with a stale or null `data` rendered as if it were
|
|
71
|
-
ready is a common source of a flashed empty/error state on first frame.
|
|
35
|
+
- Prefer `async`/`await` over chained `.then()` beyond a single continuation.
|
|
36
|
+
- For a value arriving over time, use a `Stream` with `StreamBuilder` (or the
|
|
37
|
+
state-management approach's own listener), not a `Future` polled on a timer.
|
|
38
|
+
- Cancel a manually subscribed `StreamSubscription` in `dispose()`;
|
|
39
|
+
`StreamBuilder` manages its own.
|
|
40
|
+
- Guard `snapshot.connectionState` in a `FutureBuilder`/`StreamBuilder` before
|
|
41
|
+
reading `snapshot.data`.
|
|
72
42
|
|
|
73
43
|
## Anti-patterns to flag
|
|
74
44
|
|
|
75
|
-
- A `TextEditingController`/`AnimationController`/`StreamSubscription
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
times for reasons unrelated to data changing, so anything with a side
|
|
84
|
-
effect or real cost does not belong there.
|
|
85
|
-
- Mixing state-management approaches in the same feature (e.g. a
|
|
86
|
-
`Riverpod` provider read via `ref` next to an ad hoc
|
|
87
|
-
`InheritedWidget`/`setState` for the same piece of state) instead of
|
|
88
|
-
following whichever one the project has already standardized on.
|
|
45
|
+
- A `TextEditingController`/`AnimationController`/`StreamSubscription`/`FocusNode`
|
|
46
|
+
created in `initState` with no matching release in `dispose()`.
|
|
47
|
+
- `BuildContext` or `setState()` used after an `await` with no `context.mounted`/
|
|
48
|
+
`mounted` check immediately before.
|
|
49
|
+
- Business logic (network calls, parsing, validation) inside `build()` instead of
|
|
50
|
+
a controller/view-model/state object.
|
|
51
|
+
- Mixing state-management approaches in one feature (a `Riverpod` provider read
|
|
52
|
+
via `ref` next to an ad hoc `InheritedWidget`/`setState` for the same state).
|
|
@@ -7,85 +7,51 @@ metadata:
|
|
|
7
7
|
|
|
8
8
|
# Flutter/Dart security
|
|
9
9
|
|
|
10
|
-
Narrows `core-common-rules`'
|
|
11
|
-
specific risks and the safe APIs to use instead. Applies only to `*.dart`
|
|
12
|
-
files.
|
|
10
|
+
Narrows `core-common-rules`' security rules to Flutter/Dart risks (OWASP Mobile Top 10) and the safe API for each.
|
|
13
11
|
|
|
14
12
|
## Secret and credential storage
|
|
15
13
|
|
|
16
|
-
- Store a token, session cookie, refresh token
|
|
17
|
-
`flutter_secure_storage` (
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
- Never hard-code an API key, client secret, or signing credential as a
|
|
29
|
-
Dart string literal compiled into the app — every string in a release
|
|
30
|
-
build is recoverable from the compiled binary with straightforward
|
|
31
|
-
reverse-engineering tools. `--dart-define`/a build-time `.env` file is
|
|
32
|
-
NOT a way to keep a secret server-side — both are compiled into the
|
|
33
|
-
binary at build time exactly like a string literal and are just as
|
|
34
|
-
recoverable from the shipped artifact; they only avoid committing the
|
|
35
|
-
secret to source control, which is a different property. For a value
|
|
36
|
-
that must actually stay off the device, fetch it at runtime from a
|
|
37
|
-
backend-issued short-lived token or a secrets manager reached over an
|
|
38
|
-
authenticated network call — never bake it into the build at all.
|
|
14
|
+
- Store a token, session cookie, refresh token or other credential in
|
|
15
|
+
`flutter_secure_storage` (Keychain on iOS, Android Keystore on Android; check
|
|
16
|
+
the plugin's current backing implementation rather than assuming
|
|
17
|
+
`EncryptedSharedPreferences`, which Google no longer recommends for new Android
|
|
18
|
+
code), never in `shared_preferences`.
|
|
19
|
+
- `shared_preferences` stays fine for non-sensitive preferences (a theme choice,
|
|
20
|
+
a "seen onboarding" flag).
|
|
21
|
+
- Never hard-code an API key, client secret or signing credential as a Dart string
|
|
22
|
+
literal. `--dart-define` and a build-time `.env` file are compiled into the
|
|
23
|
+
binary like a literal; they only keep the secret out of source control. A value
|
|
24
|
+
that must stay off the device is fetched at runtime from a backend-issued
|
|
25
|
+
short-lived token or a secrets manager over an authenticated call.
|
|
39
26
|
|
|
40
27
|
## Network calls and certificate pinning
|
|
41
28
|
|
|
42
|
-
- Use `https://` for every network call
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
validated against a known pin, or a package such as
|
|
50
|
-
`http_certificate_pinning`/platform-native pinning) — but treat this as
|
|
51
|
-
a deliberate, project-level decision with a rotation plan, not a default
|
|
52
|
-
to apply to every request, since a mishandled pin update can lock out
|
|
53
|
-
legitimate traffic when a certificate rotates.
|
|
54
|
-
- Never override `badCertificateCallback` (or an equivalent HTTP client
|
|
55
|
-
hook) to unconditionally return `true` — that disables certificate
|
|
56
|
-
validation entirely for that client, the same failure class as Go's
|
|
57
|
-
`InsecureSkipVerify: true`, and is never appropriate outside a
|
|
58
|
-
short-lived local test.
|
|
29
|
+
- Use `https://` for every network call carrying user data, credentials or tokens.
|
|
30
|
+
- Certificate pinning (`HttpClient.badCertificateCallback` validated against a
|
|
31
|
+
known pin, `http_certificate_pinning`, or platform-native pinning) is a
|
|
32
|
+
deliberate project-level decision with a rotation plan for especially sensitive
|
|
33
|
+
data (payment, health, authentication), not a default for every request.
|
|
34
|
+
- Never override `badCertificateCallback` (or an equivalent hook) to return
|
|
35
|
+
`true` unconditionally, outside a short-lived local test.
|
|
59
36
|
|
|
60
37
|
## Platform channel and input validation
|
|
61
38
|
|
|
62
|
-
- Validate and sanitize any value crossing a `MethodChannel
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
a query.
|
|
69
|
-
- Encode structured data crossing a platform channel with the codec the
|
|
70
|
-
channel already uses (the default standard codec, or an explicit
|
|
71
|
-
`MessageCodec`) rather than hand-rolling string concatenation/parsing
|
|
72
|
-
across the channel boundary, which reintroduces the same injection and
|
|
73
|
-
parsing-ambiguity risks as building a query string by hand.
|
|
39
|
+
- Validate and sanitize any value crossing a `MethodChannel`/`EventChannel` in
|
|
40
|
+
either direction before using it to index a collection, build a file path or
|
|
41
|
+
construct a query.
|
|
42
|
+
- Encode structured data crossing a channel with the channel's codec (the
|
|
43
|
+
standard codec or an explicit `MessageCodec`), not hand-rolled string
|
|
44
|
+
concatenation/parsing.
|
|
74
45
|
|
|
75
46
|
## Local storage and logging
|
|
76
47
|
|
|
77
|
-
- Never write a secret, token
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
- A `WebView` rendering any content that includes user-controlled or
|
|
82
|
-
externally-fetched HTML must not run with JavaScript enabled on
|
|
83
|
-
untrusted content unless the content is sanitized first — the same XSS
|
|
84
|
-
risk class as an unescaped web template, just inside a native app.
|
|
48
|
+
- Never write a secret, token or PII value to `debugPrint`/`print` or any logging
|
|
49
|
+
sink that a release build ships enabled.
|
|
50
|
+
- A `WebView` rendering user-controlled or externally-fetched HTML must not run
|
|
51
|
+
JavaScript on untrusted content unless it is sanitized first.
|
|
85
52
|
|
|
86
53
|
## Dependency hygiene
|
|
87
54
|
|
|
88
|
-
- Run `flutter pub outdated` and review
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
adding it.
|
|
55
|
+
- Run `flutter pub outdated` and review the changelog/CVE history before a
|
|
56
|
+
major-version bump; use `dart pub deps` to see what a new transitive dependency
|
|
57
|
+
pulls in before adding it.
|
|
@@ -7,95 +7,63 @@ metadata:
|
|
|
7
7
|
|
|
8
8
|
# Flutter/Dart testing
|
|
9
9
|
|
|
10
|
-
Narrows `core-common-rules`'
|
|
11
|
-
`flutter_test`'s widget-test framework and `package:test`'s unit-test
|
|
12
|
-
conventions. Applies only to `*.dart` files.
|
|
10
|
+
Narrows `core-common-rules`' testing rules to `flutter_test` widget tests and `package:test` unit tests.
|
|
13
11
|
|
|
14
12
|
## Layout and naming
|
|
15
13
|
|
|
16
|
-
-
|
|
17
|
-
(`lib/order/order_service.dart`
|
|
18
|
-
|
|
19
|
-
- A
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
class/widget, matching whatever the project's existing suite already
|
|
25
|
-
does.
|
|
14
|
+
- Tests live under `test/`, mirroring `lib/`
|
|
15
|
+
(`lib/order/order_service.dart` -> `test/order/order_service_test.dart`); no
|
|
16
|
+
separate ad hoc fixture tree.
|
|
17
|
+
- A `testWidgets('<behavior it verifies>', ...)` description names observable
|
|
18
|
+
behavior (`'shows an error banner when submit fails'`), not an implementation
|
|
19
|
+
detail (`'calls setState'`).
|
|
20
|
+
- `group('OrderService', () { ... })` clusters cases for one class/widget,
|
|
21
|
+
matching the project's existing suite.
|
|
26
22
|
|
|
27
23
|
## Widget tests
|
|
28
24
|
|
|
29
|
-
- Build the widget
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
- Locate widgets with `find.byType`, `find.text`, `find.byKey`, or
|
|
35
|
-
`find.byIcon` — prefer `find.byKey` for a widget identified by role
|
|
36
|
-
rather than by its current text/type when either could plausibly change
|
|
25
|
+
- Build the widget with `tester.pumpWidget(...)` wrapped in the ancestors it
|
|
26
|
+
needs (`MaterialApp`/`CupertinoApp`, a `Localizations` scope, a
|
|
27
|
+
state-management provider), matching the app's real tree.
|
|
28
|
+
- Locate with `find.byType`, `find.text`, `find.byKey`, `find.byIcon`; prefer
|
|
29
|
+
`find.byKey` for a widget identified by role when its text/type could change
|
|
37
30
|
without the behavior changing.
|
|
38
|
-
-
|
|
39
|
-
or
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
frame that never stops changing, so a bounded `pump(Duration(...))` is
|
|
45
|
-
the correct tool there instead.
|
|
46
|
-
- Interact with `tester.tap(finder)`, `tester.enterText(finder, '...')`,
|
|
47
|
-
`tester.drag(finder, offset)`, each followed by a `pump()`/
|
|
48
|
-
`pumpAndSettle()` appropriate to what the interaction triggers, before
|
|
49
|
-
asserting on the result.
|
|
31
|
+
- `tester.pump()` advances one frame; `tester.pumpAndSettle()` waits for an
|
|
32
|
+
animation, transition or async operation to finish. Not `pumpAndSettle()` by
|
|
33
|
+
default: under a `Timer.periodic` or other endless animation it times out; use a
|
|
34
|
+
bounded `pump(Duration(...))` there.
|
|
35
|
+
- Interact with `tester.tap`, `tester.enterText`, `tester.drag`, each followed by
|
|
36
|
+
the `pump()`/`pumpAndSettle()` the interaction needs before asserting.
|
|
50
37
|
|
|
51
38
|
## Mocking the boundary, not the internals
|
|
52
39
|
|
|
53
|
-
- Mock at the external boundary
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
-
|
|
59
|
-
|
|
60
|
-
state) — mocking one layer too deep tests that the implementation calls
|
|
61
|
-
itself in a particular way, not that the widget/class actually produces
|
|
62
|
-
the right externally-observable behavior, and it breaks on every
|
|
63
|
-
internal refactor even when the behavior is unchanged.
|
|
64
|
-
- Verify a mocked dependency's interaction (`verify(() =>
|
|
65
|
-
mockRepository.fetchOrders()).called(1)`) only for calls that matter to
|
|
66
|
-
the behavior under test — do not over-verify every incidental call,
|
|
67
|
-
which turns the test into a change-detector for implementation details.
|
|
40
|
+
- Mock at the external boundary (repository, HTTP client, platform-channel
|
|
41
|
+
wrapper) defined as an abstract class, using `mocktail` (no code generation) or
|
|
42
|
+
`mockito` (code generation).
|
|
43
|
+
- Never mock a class's own internal collaborator (a private helper, a widget's
|
|
44
|
+
internal state).
|
|
45
|
+
- Verify a mocked interaction (`verify(() => mockRepository.fetchOrders()).called(1)`)
|
|
46
|
+
only for calls that matter to the behavior; do not over-verify incidental calls.
|
|
68
47
|
|
|
69
48
|
## Async state in widget tests
|
|
70
49
|
|
|
71
|
-
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
transition entirely.
|
|
78
|
-
- Never use `Future.delayed`/a real `Duration` wait inside a test to give
|
|
79
|
-
a mocked async call "enough time" to resolve — control the mock's
|
|
80
|
-
`Future` directly (a `Completer` the test completes explicitly, or a
|
|
81
|
-
mock configured to resolve immediately) and drive time forward with
|
|
82
|
-
`pump()`/`pumpAndSettle()`/`tester.pump(duration)` instead, so the test
|
|
83
|
-
is deterministic rather than timing-dependent.
|
|
50
|
+
- For state depending on a `Future`, `pump()` once for the loading state, then
|
|
51
|
+
`pump()`/`pumpAndSettle()` after the mocked `Future` resolves, asserting the
|
|
52
|
+
loading indicator is gone and the content is present.
|
|
53
|
+
- Never use `Future.delayed` or a real `Duration` wait in a test; control the
|
|
54
|
+
mock's `Future` (a `Completer` the test completes, or an immediately resolving
|
|
55
|
+
mock) and advance time with `pump()`/`pumpAndSettle()`/`tester.pump(duration)`.
|
|
84
56
|
|
|
85
57
|
## Fixtures and golden tests
|
|
86
58
|
|
|
87
|
-
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
add one where the project already has a golden-test setup and baseline
|
|
93
|
-
images checked in, and regenerate baselines deliberately (`flutter test
|
|
94
|
-
--update-goldens`), not as a side effect of an unrelated change.
|
|
59
|
+
- Fixtures (sample models, mock repository responses) live in `test/fixtures/` or
|
|
60
|
+
a per-feature helper file, matching the project; no second fixture convention.
|
|
61
|
+
- A golden-image test (`matchesGoldenFile`) is opt-in: add one only where the
|
|
62
|
+
project already has a golden setup and checked-in baselines, and regenerate
|
|
63
|
+
with `flutter test --update-goldens` deliberately, not as a side effect.
|
|
95
64
|
|
|
96
65
|
## Running and coverage
|
|
97
66
|
|
|
98
|
-
- Run `flutter test` (
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
weakening its `expect`/`find` assertion to make it pass.
|
|
67
|
+
- Run `flutter test` (`--coverage` when the project tracks coverage) before
|
|
68
|
+
reporting a testing task done; fix a failing test by correcting the test or its
|
|
69
|
+
fixture, not by weakening its `expect`/`find` assertion.
|
|
@@ -8,78 +8,57 @@ metadata:
|
|
|
8
8
|
# Go coding style
|
|
9
9
|
|
|
10
10
|
Narrows `core-common-rules`' stack-agnostic style rules to modern Go
|
|
11
|
-
(1.23-1.25) idiom
|
|
12
|
-
|
|
11
|
+
(1.23-1.25) idiom, following Effective Go and the Go Code Review Comments.
|
|
12
|
+
Applies only to `*.go` files.
|
|
13
13
|
|
|
14
14
|
## Naming and structure
|
|
15
15
|
|
|
16
|
-
- Package names are short, lowercase, no underscores
|
|
17
|
-
(`user`, not `
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
starts with an uppercase letter, unexported with lowercase.
|
|
21
|
-
- Keep `main` thin: business logic lives in packages under `internal/` (or
|
|
22
|
-
a library's own top-level packages), `cmd/<binary>/main.go` only wires
|
|
23
|
-
flags/config and calls into them.
|
|
24
|
-
- An identifier's name shrinks with its scope: a loop index is `i`, a
|
|
25
|
-
package-level exported function gets a full descriptive name.
|
|
16
|
+
- Package names are short, lowercase, no underscores; do not stutter the
|
|
17
|
+
package name in exported identifiers (`user.User`, not `user.UserAccount`).
|
|
18
|
+
- Keep `main` thin: logic lives in packages under `internal/`,
|
|
19
|
+
`cmd/<binary>/main.go` only wires flags/config.
|
|
26
20
|
|
|
27
21
|
## Interfaces and structs
|
|
28
22
|
|
|
29
|
-
- Accept interfaces, return structs:
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
-
|
|
34
|
-
|
|
35
|
-
one or two methods. A producer-side interface with only one
|
|
36
|
-
implementation is usually unnecessary indirection.
|
|
37
|
-
- Prefer a zero-value-useful struct (`var b bytes.Buffer` works with no
|
|
38
|
-
constructor) over requiring `New()` when the zero value is meaningful.
|
|
23
|
+
- Accept interfaces, return structs: parameters take the narrowest interface
|
|
24
|
+
the callee needs; a constructor returns the concrete `*Thing`.
|
|
25
|
+
- Define an interface at the consumer, one or two methods; a producer-side
|
|
26
|
+
interface with one implementation is unnecessary.
|
|
27
|
+
- Prefer a zero-value-useful struct over requiring `New()` when the zero
|
|
28
|
+
value is meaningful.
|
|
39
29
|
|
|
40
30
|
## Errors
|
|
41
31
|
|
|
42
|
-
- Every returned `error` is checked or
|
|
43
|
-
(`_ = f.Close() // best-effort`)
|
|
44
|
-
- Wrap with
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
named `Err<Reason>`; a custom error type implements `Error() string` and,
|
|
52
|
-
when it wraps another error, `Unwrap() error`.
|
|
32
|
+
- Every returned `error` is checked or visibly discarded
|
|
33
|
+
(`_ = f.Close() // best-effort`).
|
|
34
|
+
- Wrap with `fmt.Errorf("doing x: %w", err)`, not `%v`; wrap once per
|
|
35
|
+
meaningful layer, not at every call site.
|
|
36
|
+
- Compare with `errors.Is`/`errors.As`, never `err.Error() == "..."` or bare
|
|
37
|
+
`==` against a wrapped error.
|
|
38
|
+
- Sentinel errors are `var ErrNotFound = errors.New("...")`, named
|
|
39
|
+
`Err<Reason>`; a custom error type that wraps another implements
|
|
40
|
+
`Unwrap() error`.
|
|
53
41
|
|
|
54
42
|
## Concurrency and context
|
|
55
43
|
|
|
56
|
-
- `context.Context` is
|
|
57
|
-
|
|
58
|
-
- Every goroutine
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
path is a leak, not fire-and-forget.
|
|
63
|
-
- Check `ctx.Err()` / respect `ctx.Done()` in any loop or blocking call
|
|
64
|
-
that should stop when the caller cancels.
|
|
44
|
+
- `context.Context` is the first parameter, named `ctx`, never stored on a
|
|
45
|
+
struct field.
|
|
46
|
+
- Every goroutine has an owner that knows when it exits: `sync.WaitGroup`
|
|
47
|
+
(or `WaitGroup.Go`), `errgroup.Group`, or the `ctx` it was given.
|
|
48
|
+
- Respect `ctx.Done()`/`ctx.Err()` in any loop or blocking call that should
|
|
49
|
+
stop on cancel.
|
|
65
50
|
|
|
66
51
|
## Generics and modern idiom
|
|
67
52
|
|
|
68
|
-
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
- A `range-over-func` iterator (`func(yield func(T) bool)`) is fine for a
|
|
75
|
-
package's own lazy sequence API on Go 1.23+; do not introduce it purely
|
|
76
|
-
to look modern when a plain slice-returning function reads more clearly.
|
|
53
|
+
- A type parameter only when it removes real duplication; do not generify a
|
|
54
|
+
function with one concrete call site.
|
|
55
|
+
- `log/slog` for structured logging in new code, unless the project has
|
|
56
|
+
standardized on something else.
|
|
57
|
+
- A `range-over-func` iterator only for a package's own lazy sequence API on
|
|
58
|
+
Go 1.23+, not where a slice-returning function reads more clearly.
|
|
77
59
|
|
|
78
60
|
## Formatting and imports
|
|
79
61
|
|
|
80
|
-
- Format with `gofmt`/`goimports
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
- Group imports stdlib / third-party / local with a blank line between
|
|
84
|
-
groups — `goimports` does this automatically; run it instead of
|
|
85
|
-
hand-ordering.
|
|
62
|
+
- Format with `gofmt`/`goimports`; do not hand-format around a configured
|
|
63
|
+
formatter.
|
|
64
|
+
- Imports grouped stdlib / third-party / local.
|
|
@@ -8,58 +8,43 @@ metadata:
|
|
|
8
8
|
# Go patterns
|
|
9
9
|
|
|
10
10
|
Narrows `core-common-rules`' stack-agnostic design guidance to idiomatic
|
|
11
|
-
Go design
|
|
11
|
+
Go design (Effective Go, Go Proverbs). Applies only to `*.go` files.
|
|
12
12
|
|
|
13
13
|
## Module and package layout
|
|
14
14
|
|
|
15
|
-
- `cmd/<binary>/` holds one `main` package per executable;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
with the package that owns its behavior.
|
|
22
|
-
- Avoid import cycles by depth, not by breaking them with an `internal`
|
|
23
|
-
workaround package — if package A needs package B's type and B needs
|
|
24
|
-
A's, one of the two owns too much; extract the shared piece into a
|
|
25
|
-
third package both depend on.
|
|
15
|
+
- `cmd/<binary>/` holds one `main` package per executable; anything not a
|
|
16
|
+
public API surface goes under `internal/`.
|
|
17
|
+
- No shared-types-only packages ("models", "types", "common"); colocate a
|
|
18
|
+
type with the package that owns its behavior.
|
|
19
|
+
- Break an import cycle by extracting the shared piece into a third package,
|
|
20
|
+
not with an `internal` workaround package.
|
|
26
21
|
|
|
27
22
|
## Idiomatic concurrency patterns
|
|
28
23
|
|
|
29
|
-
- Fan-out/fan-in: bound
|
|
30
|
-
`
|
|
31
|
-
|
|
32
|
-
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
once; a `nil` channel blocks forever on send/receive, which is
|
|
40
|
-
occasionally the correct way to disable a `select` case.
|
|
24
|
+
- Fan-out/fan-in: bound concurrent workers (worker pool or
|
|
25
|
+
`errgroup`'s `SetLimit`); never one goroutine per item on an unbounded
|
|
26
|
+
source.
|
|
27
|
+
- `errgroup.Group` when goroutines share one cancellation and you need the
|
|
28
|
+
first error; plain `sync.WaitGroup` when you only need completion.
|
|
29
|
+
- Channels for signaling and handoff, mutexes for shared state; no
|
|
30
|
+
hand-rolled channel semaphore where `sync.Mutex` or `errgroup.SetLimit`
|
|
31
|
+
fits.
|
|
32
|
+
- Close a channel only from the sender, only once; a `nil` channel is a valid
|
|
33
|
+
way to disable a `select` case.
|
|
41
34
|
|
|
42
35
|
## Composition over inheritance
|
|
43
36
|
|
|
44
|
-
-
|
|
45
|
-
|
|
46
|
-
field plus delegation when you would otherwise promote methods the
|
|
47
|
-
caller should not see.
|
|
37
|
+
- Struct embedding only when the embedding type is a true superset of the
|
|
38
|
+
embedded one's API; otherwise an explicit field plus delegation.
|
|
48
39
|
- Functional options (`func WithTimeout(d time.Duration) Option`) for a
|
|
49
|
-
constructor with many optional parameters
|
|
50
|
-
positional signature or a half-filled config struct.
|
|
40
|
+
constructor with many optional parameters.
|
|
51
41
|
|
|
52
42
|
## Anti-patterns to flag
|
|
53
43
|
|
|
54
|
-
- A large `interface{}`/`any`-typed
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
-
|
|
58
|
-
|
|
59
|
-
-
|
|
60
|
-
|
|
61
|
-
clearer and avoids nil-pointer-dereference risk at the call site.
|
|
62
|
-
- Panic used for ordinary control flow (a missing map key, a failed
|
|
63
|
-
lookup); reserve `panic` for programmer errors that should crash during
|
|
64
|
-
development (a violated invariant, an unreachable `default` case), and
|
|
65
|
-
return an `error` for everything a caller could reasonably handle.
|
|
44
|
+
- A large `interface{}`/`any`-typed signature where a type parameter or
|
|
45
|
+
smaller concrete interface fits.
|
|
46
|
+
- A "god package" (`utils`, `helpers`, `common`).
|
|
47
|
+
- Returning a pointer solely to allow a `nil` "not found"; use `(T, bool)` or
|
|
48
|
+
a named error (`ErrNotFound`).
|
|
49
|
+
- `panic` for ordinary control flow; reserve it for violated invariants and
|
|
50
|
+
unreachable `default` cases, return an `error` otherwise.
|