@doubleloop-io/oxlint-plugin-effect 0.1.0 → 0.1.2
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/CHANGELOG.md +22 -1
- package/README.md +17 -200
- package/dist/rules/no-inline-yield-star.js +63 -14
- package/docs/user-guide/README.md +24 -0
- package/docs/user-guide/alongside-effect-tsgo.md +23 -0
- package/docs/user-guide/common-limits.md +10 -0
- package/docs/user-guide/configuration.md +43 -0
- package/docs/user-guide/default-configuration.md +88 -0
- package/docs/user-guide/installation.md +12 -0
- package/docs/user-guide/rules/adapter-import-boundary.md +27 -0
- package/docs/user-guide/rules/all-errors-handled-at-boundary.md +30 -0
- package/docs/user-guide/rules/anti-slop-no-manual-effect-error-tag.md +26 -0
- package/docs/user-guide/rules/anti-slop-no-service-constructor-imports.md +32 -0
- package/docs/user-guide/rules/anti-slop-prefer-effect-match.md +30 -0
- package/docs/user-guide/rules/exported-schema-identifier.md +26 -0
- package/docs/user-guide/rules/no-asymmetric-match-handlers.md +30 -0
- package/docs/user-guide/rules/no-effect-promise.md +26 -0
- package/docs/user-guide/rules/no-effect-return-type.md +29 -0
- package/docs/user-guide/rules/no-inline-schema-codec.md +26 -0
- package/docs/user-guide/rules/no-inline-yield-star.md +29 -0
- package/docs/user-guide/rules/no-manual-discriminant-comparison.md +36 -0
- package/docs/user-guide/rules/no-manual-discriminant-construction.md +32 -0
- package/docs/user-guide/rules/no-nested-match.md +44 -0
- package/docs/user-guide/rules/no-parameterless-catch-all.md +28 -0
- package/docs/user-guide/rules/no-provide-on-definition.md +27 -0
- package/docs/user-guide/rules/no-throw-or-primitive-failure.md +34 -0
- package/docs/user-guide/rules/no-transport-types-in-generator.md +41 -0
- package/docs/user-guide/rules/no-yielded-match.md +35 -0
- package/docs/user-guide/rules/prefer-effect-fn.md +31 -0
- package/docs/user-guide/rules/prefer-effect-vitest.md +30 -0
- package/docs/user-guide/rules/provide-named-layer.md +27 -0
- package/docs/user-guide/rules/redacted-secret-names.md +31 -0
- package/docs/user-guide/rules/run-only-in-runner.md +32 -0
- package/docs/user-guide/rules/service-built-with-of.md +36 -0
- package/docs/user-guide/rules/service-key-matches-name.md +29 -0
- package/docs/user-guide/rules/service-port-shape-only.md +27 -0
- package/docs/user-guide/rules/single-style-per-function.md +36 -0
- package/docs/user-guide/rules/split-success-path-from-error-handling.md +37 -0
- package/docs/user-guide/rules/try-object-form.md +27 -0
- package/docs/user-guide/rules/untraced-recursion.md +31 -0
- package/docs/user-guide/rules.md +26 -0
- package/docs/user-guide/shared-settings.md +65 -0
- package/docs/user-guide/troubleshooting.md +30 -0
- package/docs/user-guide/versioning.md +8 -0
- package/package.json +14 -9
- package/RULES.md +0 -1056
package/RULES.md
DELETED
|
@@ -1,1056 +0,0 @@
|
|
|
1
|
-
# `@doubleloop-io/oxlint-plugin-effect` rules
|
|
2
|
-
|
|
3
|
-
The plugin's 31 rules.
|
|
4
|
-
|
|
5
|
-
## Rules index
|
|
6
|
-
|
|
7
|
-
| Group | Rule |
|
|
8
|
-
| --------------------------------------------------- | --------------------------------------------------------------------------------------- |
|
|
9
|
-
| [Error channel](#error-channel) | [`no-throw-or-primitive-failure`](#no-throw-or-primitive-failure) |
|
|
10
|
-
| | [`try-object-form`](#try-object-form) |
|
|
11
|
-
| | [`no-effect-promise`](#no-effect-promise) |
|
|
12
|
-
| | [`no-parameterless-catch-all`](#no-parameterless-catch-all) |
|
|
13
|
-
| | [`split-success-path-from-error-handling`](#split-success-path-from-error-handling) |
|
|
14
|
-
| | [`anti-slop-no-manual-effect-error-tag`](#anti-slop-no-manual-effect-error-tag) |
|
|
15
|
-
| [Tagged values](#tagged-values) | [`no-manual-discriminant-comparison`](#no-manual-discriminant-comparison) |
|
|
16
|
-
| | [`no-manual-discriminant-construction`](#no-manual-discriminant-construction) |
|
|
17
|
-
| [Services and Layers](#services-and-layers) | [`service-port-shape-only`](#service-port-shape-only) |
|
|
18
|
-
| | [`service-key-matches-name`](#service-key-matches-name) |
|
|
19
|
-
| | [`service-built-with-of`](#service-built-with-of) |
|
|
20
|
-
| | [`provide-named-layer`](#provide-named-layer) |
|
|
21
|
-
| | [`no-provide-on-definition`](#no-provide-on-definition) |
|
|
22
|
-
| | [`anti-slop-no-service-constructor-imports`](#anti-slop-no-service-constructor-imports) |
|
|
23
|
-
| [Runtime and entry point](#runtime-and-entry-point) | [`run-only-in-runner`](#run-only-in-runner) |
|
|
24
|
-
| | [`prefer-effect-vitest`](#prefer-effect-vitest) |
|
|
25
|
-
| | [`all-errors-handled-at-boundary`](#all-errors-handled-at-boundary) |
|
|
26
|
-
| [Design and boundaries](#design-and-boundaries) | [`adapter-import-boundary`](#adapter-import-boundary) |
|
|
27
|
-
| | [`no-transport-types-in-generator`](#no-transport-types-in-generator) |
|
|
28
|
-
| [Effectful functions](#effectful-functions) | [`prefer-effect-fn`](#prefer-effect-fn) |
|
|
29
|
-
| | [`untraced-recursion`](#untraced-recursion) |
|
|
30
|
-
| | [`single-style-per-function`](#single-style-per-function) |
|
|
31
|
-
| [Code shape](#code-shape) | [`no-nested-match`](#no-nested-match) |
|
|
32
|
-
| | [`no-yielded-match`](#no-yielded-match) |
|
|
33
|
-
| | [`no-inline-yield-star`](#no-inline-yield-star) |
|
|
34
|
-
| | [`no-effect-return-type`](#no-effect-return-type) |
|
|
35
|
-
| | [`no-asymmetric-match-handlers`](#no-asymmetric-match-handlers) |
|
|
36
|
-
| | [`anti-slop-prefer-effect-match`](#anti-slop-prefer-effect-match) |
|
|
37
|
-
| [Schema](#schema) | [`exported-schema-identifier`](#exported-schema-identifier) |
|
|
38
|
-
| | [`no-inline-schema-codec`](#no-inline-schema-codec) |
|
|
39
|
-
| [Config and secrets](#config-and-secrets) | [`redacted-secret-names`](#redacted-secret-names) |
|
|
40
|
-
|
|
41
|
-
The `all` preset enables them all at `warn`.
|
|
42
|
-
|
|
43
|
-
## Common limits
|
|
44
|
-
|
|
45
|
-
- **Syntax only**: no rule uses type information. Only two rules look past the file: [`adapter-import-boundary`](#adapter-import-boundary), to find which directories are adapters, and [`prefer-effect-vitest`](#prefer-effect-vitest), to find whether `@effect/vitest` is installed.
|
|
46
|
-
- **Literal names**: `Effect.gen` is recognized, `import { Effect as E }` or `import * as L from "effect/Layer"` slip through. On code that uses aliases, silence is not compliance.
|
|
47
|
-
- **Effect 4**: the rules are written against v4. Where a v3 API has the same intent, they recognize its v3 name too (`catchAll`, `Either`, `Context.Tag`, `Config.redacted`, …), and the Trigger names it.
|
|
48
|
-
|
|
49
|
-
## Shared settings
|
|
50
|
-
|
|
51
|
-
What describes the project rather than a rule is declared once, under `settings["dl-effect"]` in the oxlint config, and read by every rule that needs it. A value **replaces** the default (it does not extend it). An unknown key or a value that is not an array of strings stops the lint with an error. File globs are matched against the path relative to oxlint's working directory, with `/` on every platform.
|
|
52
|
-
|
|
53
|
-
- **`entryFiles`**
|
|
54
|
-
- used by:
|
|
55
|
-
- [`run-only-in-runner`](#run-only-in-runner)
|
|
56
|
-
- [`adapter-import-boundary`](#adapter-import-boundary)
|
|
57
|
-
- default: `**/main.ts`, `**/cli.ts`, `**/bin/**`. `index.ts` is excluded on purpose: it is usually a barrel, and exempting it would let adapters reach the rest of the application through re-exports.
|
|
58
|
-
- **`testFiles`**
|
|
59
|
-
- used by:
|
|
60
|
-
- [`run-only-in-runner`](#run-only-in-runner), [`adapter-import-boundary`](#adapter-import-boundary), [`no-effect-promise`](#no-effect-promise), [`provide-named-layer`](#provide-named-layer), [`no-provide-on-definition`](#no-provide-on-definition), [`split-success-path-from-error-handling`](#split-success-path-from-error-handling), [`all-errors-handled-at-boundary`](#all-errors-handled-at-boundary), [`anti-slop-no-service-constructor-imports`](#anti-slop-no-service-constructor-imports): skip test files
|
|
61
|
-
- [`no-throw-or-primitive-failure`](#no-throw-or-primitive-failure): skips only primitive failures there
|
|
62
|
-
- [`single-style-per-function`](#single-style-per-function): treats their helpers like tests
|
|
63
|
-
- [`prefer-effect-vitest`](#prefer-effect-vitest): checks only them
|
|
64
|
-
- default: `**/*.test.*`, `**/*.spec.*`, `**/__tests__/**`, `**/test/**`, `**/tests/**`. A helper directory such as `src/testing/` does not count as tests: it is support code.
|
|
65
|
-
- **`discriminants`**
|
|
66
|
-
- used by:
|
|
67
|
-
- [`no-manual-discriminant-comparison`](#no-manual-discriminant-comparison)
|
|
68
|
-
- [`no-manual-discriminant-construction`](#no-manual-discriminant-construction)
|
|
69
|
-
- default: `_tag`. Add the fields your unions discriminate on (`type`, `kind`).
|
|
70
|
-
|
|
71
|
-
The file defaults come from a Node CLI. On another layout (Next.js, a monorepo) they must be reconfigured before reading the warnings:
|
|
72
|
-
|
|
73
|
-
```ts
|
|
74
|
-
export default defineConfig({
|
|
75
|
-
extends: [dlEffectAll],
|
|
76
|
-
settings: {
|
|
77
|
-
"dl-effect": { entryFiles: ["apps/web/src/app/**/route.ts", "apps/web/src/runtime.ts"] },
|
|
78
|
-
},
|
|
79
|
-
})
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
Settings are not inherited from a preset in `extends` and cannot go in `overrides`: for a value that differs by group of files, override the rules instead.
|
|
83
|
-
|
|
84
|
-
## Error channel
|
|
85
|
-
|
|
86
|
-
### `no-throw-or-primitive-failure`
|
|
87
|
-
|
|
88
|
-
<sup>[↑ rules index](#rules-index)</sup>
|
|
89
|
-
|
|
90
|
-
**Intent**: an expected failure is a tagged error, never a thrown or primitive value.
|
|
91
|
-
|
|
92
|
-
```ts
|
|
93
|
-
// no
|
|
94
|
-
Effect.gen(function* () {
|
|
95
|
-
if (tab === undefined) throw new Error("tab not found")
|
|
96
|
-
})
|
|
97
|
-
Effect.fail("tab not found")
|
|
98
|
-
|
|
99
|
-
// yes
|
|
100
|
-
export class SheetTabNotFoundError extends Schema.TaggedError<SheetTabNotFoundError>()(
|
|
101
|
-
"SheetTabNotFoundError",
|
|
102
|
-
{ spreadsheetId: Schema.String, message: Schema.String },
|
|
103
|
-
) {}
|
|
104
|
-
|
|
105
|
-
Effect.fail(new SheetTabNotFoundError({ spreadsheetId, message: "tab not found" }))
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
**Trigger**: a `throw` directly inside a generator passed to `Effect.gen`/`Effect.fn`; `Effect.fail` with a literal or a template.
|
|
109
|
-
|
|
110
|
-
**Exemptions and blind spots**: `Effect.fail` with a literal in test files, where a synthetic failure feeds code generic over the error; a `throw` in a test generator is still reported. A `throw` inside a nested callback. `Effect.fail(new Error(…))` and `class X extends Error`: see `global-error-in-effect-failure` and `extends-native-error` (effecttsgo).
|
|
111
|
-
|
|
112
|
-
**Why**: the typed error channel discriminates only on tags. A `throw` in the generator becomes a defect, outside the error channel.
|
|
113
|
-
|
|
114
|
-
**Options**:
|
|
115
|
-
|
|
116
|
-
- `testFiles`: shared setting, see [Shared settings](#shared-settings).
|
|
117
|
-
|
|
118
|
-
**Fix**: none
|
|
119
|
-
|
|
120
|
-
### `try-object-form`
|
|
121
|
-
|
|
122
|
-
<sup>[↑ rules index](#rules-index)</sup>
|
|
123
|
-
|
|
124
|
-
**Intent**: `Effect.try` and `Effect.tryPromise` take `{ try, catch }`, with `catch` producing a tagged error.
|
|
125
|
-
|
|
126
|
-
```ts
|
|
127
|
-
// no
|
|
128
|
-
Effect.tryPromise(() => api.spreadsheets.get({ spreadsheetId }))
|
|
129
|
-
|
|
130
|
-
// yes
|
|
131
|
-
Effect.tryPromise({
|
|
132
|
-
try: () => api.spreadsheets.get({ spreadsheetId }),
|
|
133
|
-
catch: toSheetError(spreadsheetId),
|
|
134
|
-
})
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
**Trigger**: `Effect.try` and `Effect.tryPromise` whose argument is not an object literal.
|
|
138
|
-
|
|
139
|
-
**Exemptions and blind spots**: an options object held in a variable is reported too.
|
|
140
|
-
|
|
141
|
-
**Why**: the thunk form types the error as `Cause.UnknownError` (`UnknownException` in v3), which no caller can handle by tag.
|
|
142
|
-
|
|
143
|
-
**Options**: none
|
|
144
|
-
|
|
145
|
-
**Fix**: none
|
|
146
|
-
|
|
147
|
-
### `no-effect-promise`
|
|
148
|
-
|
|
149
|
-
<sup>[↑ rules index](#rules-index)</sup>
|
|
150
|
-
|
|
151
|
-
**Intent**: a promise that can reject is lifted with [`Effect.tryPromise`](#try-object-form), not `Effect.promise`.
|
|
152
|
-
|
|
153
|
-
```ts
|
|
154
|
-
// no
|
|
155
|
-
Effect.promise(() => client.connect())
|
|
156
|
-
|
|
157
|
-
// yes
|
|
158
|
-
Effect.tryPromise({ try: () => client.connect(), catch: toConnectionError })
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
**Trigger**: `Effect.promise` outside the release step of `acquireRelease`, `acquireUseRelease` and `addFinalizer`.
|
|
162
|
-
|
|
163
|
-
**Exemptions and blind spots**: the release step, where a promise that cannot reject is the normal case. Test files, where a rejection during setup is a broken test and the defect fails it with the cause. Elsewhere, a promise that truly cannot reject must be suppressed by hand.
|
|
164
|
-
|
|
165
|
-
**Why**: `Effect.promise` turns a rejection into a defect.
|
|
166
|
-
|
|
167
|
-
**Options**:
|
|
168
|
-
|
|
169
|
-
- `testFiles`: shared setting, see [Shared settings](#shared-settings).
|
|
170
|
-
|
|
171
|
-
**Fix**: none
|
|
172
|
-
|
|
173
|
-
### `no-parameterless-catch-all`
|
|
174
|
-
|
|
175
|
-
<sup>[↑ rules index](#rules-index)</sup>
|
|
176
|
-
|
|
177
|
-
**Intent**: errors are caught by tag; a fallback that ignores the error is spelled `orElseSucceed`/`orElse`, never a catch-all with an ignored parameter.
|
|
178
|
-
|
|
179
|
-
```ts
|
|
180
|
-
// no
|
|
181
|
-
Effect.catch(() => Effect.succeed(fallback))
|
|
182
|
-
|
|
183
|
-
// yes
|
|
184
|
-
Effect.catchTag("AgentTimeout", () => Effect.succeed(skip))
|
|
185
|
-
Effect.catchTag(["ParseError", "ReservedPortError"], () => Effect.succeed(3000))
|
|
186
|
-
|
|
187
|
-
// yes: every failure truly means the same fallback
|
|
188
|
-
Effect.orElseSucceed(() => fallback)
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
**Trigger**: `Effect.catch`, `catchAll`, `catchCause` and `catchEager` with a parameterless handler.
|
|
192
|
-
|
|
193
|
-
**Exemptions and blind spots**: a catch-all that discriminates on `_tag` by hand: see [`anti-slop-no-manual-effect-error-tag`](#anti-slop-no-manual-effect-error-tag), and `catch-all-to-map-error`, `catch-all-tag-dispatch-to-catch-tag` and `catch-to-ignore` (effecttsgo).
|
|
194
|
-
|
|
195
|
-
**Why**: a catch-all that ignores its parameter also swallows the errors added later, which `catchTag` would leave visible in the type.
|
|
196
|
-
|
|
197
|
-
**Options**: none
|
|
198
|
-
|
|
199
|
-
**Fix**: none
|
|
200
|
-
|
|
201
|
-
### `split-success-path-from-error-handling`
|
|
202
|
-
|
|
203
|
-
<sup>[↑ rules index](#rules-index)</sup>
|
|
204
|
-
|
|
205
|
-
**Intent**: the generator holds only the happy path; error handling lives in the second argument of `Effect.fn`.
|
|
206
|
-
|
|
207
|
-
```ts
|
|
208
|
-
// no
|
|
209
|
-
function* () {
|
|
210
|
-
const x = yield* fetchThing.pipe(Effect.catchTag("NotFound", () => Effect.succeed(fallback)))
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// yes: naming the error or giving an alternative is not handling
|
|
214
|
-
function* () {
|
|
215
|
-
const x = yield* fetchThing.pipe(Effect.orElseSucceed(() => fallback))
|
|
216
|
-
const y = yield* decode(raw).pipe(Effect.mapError((error) => new BadRequest({ message: error.message })))
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// yes: translation in the second argument, which also receives the original arguments
|
|
220
|
-
const createEvent = Effect.fn("events.create")(
|
|
221
|
-
function* (request: Request) { /* success only */ },
|
|
222
|
-
(effect, request) => effect.pipe(Effect.catchTags({ BadRequest: (e) => refused(400, e.message) })),
|
|
223
|
-
)
|
|
224
|
-
```
|
|
225
|
-
|
|
226
|
-
**Trigger**: inside a generator passed to `Effect.gen`/`Effect.fn`, callbacks passed to `Effect.*` combinators included, calls to `Effect.catch*` (`catch`, `catchAll`, `catchTag`, `catchTags`, `catchIf`, `catchCause`, `catchDefect`, `catchReason`, …), `either`, `result`, `exit`, `match*` and `sandbox`.
|
|
227
|
-
|
|
228
|
-
**Exemptions and blind spots**: pipeables of a nested `Effect.fn`. Handlers inside the callback of an iteration (`forEach`, `filter`, `reduce`, `partition`, `validate`, `findFirst`, …): they handle each element on its own, and in the pipeables the first failure would stop the rest. Functions the generator only defines, such as an `HttpApiBuilder` handler or a service method: they are programs of their own. Test files, where the failure is the outcome under observation (`yield* Effect.result(op)` then `expect`). A `catch`, `catchTag`, `catchTags`, `catchIf` or `catchFilter` whose handlers only die (`Effect.die` passed directly or as the sole return): it is a selective `orDie`, declaring the case untracked rather than handling it; a die behind a wrapper or a condition is still reported. A `.pipe(Effect.catch…)` appended to an `Effect.gen` escapes; [`prefer-effect-fn`](#prefer-effect-fn) closes that gap.
|
|
229
|
-
|
|
230
|
-
**Why**: translation becomes a single exhaustive point instead of catches scattered along the flow.
|
|
231
|
-
|
|
232
|
-
**Options**:
|
|
233
|
-
|
|
234
|
-
- `testFiles`: shared setting, see [Shared settings](#shared-settings).
|
|
235
|
-
|
|
236
|
-
**Fix**: none
|
|
237
|
-
|
|
238
|
-
### `anti-slop-no-manual-effect-error-tag`
|
|
239
|
-
|
|
240
|
-
<sup>[↑ rules index](#rules-index)</sup>
|
|
241
|
-
|
|
242
|
-
**Intent**: a catch handler does not discriminate errors by `_tag`; `catchTag` and `catchReason` do.
|
|
243
|
-
|
|
244
|
-
```ts
|
|
245
|
-
// no
|
|
246
|
-
program.pipe(Effect.catch((error) => (error._tag === "NotFound" ? recover : Effect.fail(error))))
|
|
247
|
-
|
|
248
|
-
// yes
|
|
249
|
-
program.pipe(Effect.catchTag("NotFound", () => recover))
|
|
250
|
-
```
|
|
251
|
-
|
|
252
|
-
**Trigger**: an equality comparison between `_tag` (or `reason._tag`) and a string literal, or a `switch` on `_tag`, whose nearest enclosing function is a handler passed to `Effect.catch`, `catchAll` or `catchIf`. On `reason._tag` the message proposes `Effect.catchReason(s)`.
|
|
253
|
-
|
|
254
|
-
**Exemptions and blind spots**: handlers of other combinators (`catchTag`, `catchCause`, `mapError`), and `_tag` checks in a function nested inside the handler. Outside these handlers the same checks belong to [`no-manual-discriminant-comparison`](#no-manual-discriminant-comparison): the two never fire on the same node.
|
|
255
|
-
|
|
256
|
-
**Why**: a hand-written dispatch keeps the caught errors in the type even when handled, and silently misses tags added later.
|
|
257
|
-
|
|
258
|
-
**Options**: none
|
|
259
|
-
|
|
260
|
-
**Fix**: none
|
|
261
|
-
|
|
262
|
-
## Tagged values
|
|
263
|
-
|
|
264
|
-
### `no-manual-discriminant-comparison`
|
|
265
|
-
|
|
266
|
-
<sup>[↑ rules index](#rules-index)</sup>
|
|
267
|
-
|
|
268
|
-
**Intent**: branching on a union's discriminant goes through an exhaustive match, never through comparisons or `switch`.
|
|
269
|
-
|
|
270
|
-
```ts
|
|
271
|
-
// no
|
|
272
|
-
switch (event._tag) {
|
|
273
|
-
case "Created":
|
|
274
|
-
return onCreated(event)
|
|
275
|
-
case "Deleted":
|
|
276
|
-
return onDeleted(event)
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
// yes
|
|
280
|
-
Match.value(event).pipe(Match.tagsExhaustive({ Created: onCreated, Deleted: onDeleted }))
|
|
281
|
-
|
|
282
|
-
// yes, with `discriminants: ["_tag", "type"]`
|
|
283
|
-
Match.value(payment).pipe(
|
|
284
|
-
Match.discriminatorsExhaustive("type")({ card: fromCard, transfer: fromTransfer }),
|
|
285
|
-
)
|
|
286
|
-
```
|
|
287
|
-
|
|
288
|
-
**Trigger**: an equality comparison between a discriminant (also `["type"]`) and a string literal, or a `switch` on a discriminant. The discriminants are the names in `discriminants`.
|
|
289
|
-
|
|
290
|
-
**Exemptions and blind spots**: comparisons against a variable rather than a literal. On `_tag`, the handlers covered by [`anti-slop-no-manual-effect-error-tag`](#anti-slop-no-manual-effect-error-tag): the two never fire on the same node. Guard clauses such as `if (x.type === "a") return …` fire too; on `_tag` use `Predicate.isTagged`. A `_tag` compared with a variant of Effect's own types (`Success`/`Failure` of `Result` and `Exit`, `Left`/`Right`, `Some`/`None`) is reported with their refinement as the remedy, such as `Result.isFailure`: those types cannot gain a variant; a `switch` is reported as usual. An exhaustive ts-pattern match is an equally valid remedy. A name added to `discriminants` also fires on objects outside closed unions (DOM events, external payloads): the list is a choice of the codebase.
|
|
291
|
-
|
|
292
|
-
**Why**: `Match.tagsExhaustive`, `Match.discriminatorsExhaustive` and `$match` fail to compile when a variant is added; a comparison or a `switch` does not.
|
|
293
|
-
|
|
294
|
-
**Options**:
|
|
295
|
-
|
|
296
|
-
- `discriminants`: shared setting, see [Shared settings](#shared-settings).
|
|
297
|
-
|
|
298
|
-
**Fix**: none
|
|
299
|
-
|
|
300
|
-
### `no-manual-discriminant-construction`
|
|
301
|
-
|
|
302
|
-
<sup>[↑ rules index](#rules-index)</sup>
|
|
303
|
-
|
|
304
|
-
**Intent**: a union's variant is built by its constructor, never as an object literal with the discriminant.
|
|
305
|
-
|
|
306
|
-
```ts
|
|
307
|
-
// no
|
|
308
|
-
const error = { _tag: "NotFound", id }
|
|
309
|
-
|
|
310
|
-
// yes
|
|
311
|
-
const error = new NotFound({ id })
|
|
312
|
-
|
|
313
|
-
// no, with `discriminants: ["_tag", "eventType"]`
|
|
314
|
-
const event = { eventType: "PaymentStarted", id, payment }
|
|
315
|
-
|
|
316
|
-
// yes
|
|
317
|
-
const event = PaymentStartedEvent.make({ id, payment })
|
|
318
|
-
```
|
|
319
|
-
|
|
320
|
-
**Trigger**: an object literal with a discriminant property (also `"type"` or `["type"]`) whose value is a string literal. The discriminants are the names in `discriminants`.
|
|
321
|
-
|
|
322
|
-
**Exemptions and blind spots**: values that are not literals (`"Ready" as const` included). Literals that are patterns or raw input, also nested: the arguments of `Match.when`, `Match.not`, of `.with(…)` on a ts-pattern `match(…)` chain, the expected value of an `expect(…)` matcher or `expect.*` helper, the input of `Schema.decode*(X)(…)`/`Schema.encode*(X)(…)`, the argument of `JSON.stringify`, and an argument whose parameter is annotated `unknown` in a function declared in the same file (a fake API's raw body). Transport payloads written as literals fire, as does raw data passed to an imported function or through a variable, and a name added to `discriminants` fires on objects outside closed unions: the list is a choice of the codebase. See `schema-struct-with-tag` (effecttsgo) for `Schema.Struct` with a `_tag` field.
|
|
323
|
-
|
|
324
|
-
**Why**: a literal skips the constructor, so it carries none of the class's prototype, equality or validation, and drifts silently when the type changes.
|
|
325
|
-
|
|
326
|
-
**Options**:
|
|
327
|
-
|
|
328
|
-
- `discriminants`: shared setting, see [Shared settings](#shared-settings).
|
|
329
|
-
|
|
330
|
-
**Fix**: none
|
|
331
|
-
|
|
332
|
-
## Services and Layers
|
|
333
|
-
|
|
334
|
-
### `service-port-shape-only`
|
|
335
|
-
|
|
336
|
-
<sup>[↑ rules index](#rules-index)</sup>
|
|
337
|
-
|
|
338
|
-
**Intent**: a port is a shape-only `Context.Service` (v3: `Context.Tag`), with no implementation attached.
|
|
339
|
-
|
|
340
|
-
```ts
|
|
341
|
-
// no
|
|
342
|
-
class Agent extends Context.Service<Agent, Shape>()("app/Agent", { make: makeAgent }) {}
|
|
343
|
-
|
|
344
|
-
// yes
|
|
345
|
-
export class Agent extends Context.Service<
|
|
346
|
-
Agent,
|
|
347
|
-
{ readonly search: (name: string) => Effect.Effect<RaceCard, AgentError> }
|
|
348
|
-
>()("app/agent/Agent") {}
|
|
349
|
-
```
|
|
350
|
-
|
|
351
|
-
**Trigger**: the second argument of `Context.Service<…>()(id, opts)`; a `static layer`, `static Default` or `static Live` member on a `Context.Service` or v3 `Context.Tag(id)<…>()` class; any `Effect.Service`.
|
|
352
|
-
|
|
353
|
-
**Exemptions and blind spots**: a `Context.Service` or v3 `Context.GenericTag` assigned to a variable is not seen: see `service-not-as-class` (effecttsgo). Statics with other names slip through.
|
|
354
|
-
|
|
355
|
-
**Why**: `make` and a static layer tie the port to a default implementation, while the port must stay a contract any adapter can satisfy. It is a convention, not Effect's idiom: Effect's own docs put `static readonly layer` on the service.
|
|
356
|
-
|
|
357
|
-
**Options**: none
|
|
358
|
-
|
|
359
|
-
**Fix**: none
|
|
360
|
-
|
|
361
|
-
### `service-key-matches-name`
|
|
362
|
-
|
|
363
|
-
<sup>[↑ rules index](#rules-index)</sup>
|
|
364
|
-
|
|
365
|
-
**Intent**: a service's key is its class name, alone or after a path prefix.
|
|
366
|
-
|
|
367
|
-
```ts
|
|
368
|
-
// no
|
|
369
|
-
export class GeocodingApis extends Context.Service<GeocodingApis, Shape>()("GeocodingAPIs") {}
|
|
370
|
-
|
|
371
|
-
// yes
|
|
372
|
-
export class GeocodingApis extends Context.Service<GeocodingApis, Shape>()("GeocodingApis") {}
|
|
373
|
-
|
|
374
|
-
// yes
|
|
375
|
-
export class GeocodingApis extends Context.Service<GeocodingApis, Shape>()(
|
|
376
|
-
"app/geo/GeocodingApis",
|
|
377
|
-
) {}
|
|
378
|
-
```
|
|
379
|
-
|
|
380
|
-
**Trigger**: `class X extends Context.Service<…>()("key")`, or the v3 `Context.Tag("key")<…>()` and `Effect.Service<X>()("key", …)`, with a literal key that is neither `"X"` nor ends with `"/X"`.
|
|
381
|
-
|
|
382
|
-
**Exemptions and blind spots**: keys that are not literals (variables, templates with expressions). A `Context.Service` assigned to a variable is not seen: see `service-not-as-class` (effecttsgo). `deterministic-keys` (effecttsgo) with the `default` or `package-identifier` formula produces keys this rule accepts; with `default-hashed` the two contradict each other: enable only one.
|
|
383
|
-
|
|
384
|
-
**Why**: the key is the service's identity in errors, traces and `Context` lookups; a key that drifts from the name, as after a rename, makes it hard to find the class behind a message.
|
|
385
|
-
|
|
386
|
-
**Options**: none
|
|
387
|
-
|
|
388
|
-
**Fix**: suggestion that replaces the last segment of the key with the class name
|
|
389
|
-
|
|
390
|
-
### `service-built-with-of`
|
|
391
|
-
|
|
392
|
-
<sup>[↑ rules index](#rules-index)</sup>
|
|
393
|
-
|
|
394
|
-
**Intent**: the service a Layer provides is built with `Tag.of({…})`, not a bare object literal.
|
|
395
|
-
|
|
396
|
-
```ts
|
|
397
|
-
// no
|
|
398
|
-
export const RepoLive = Layer.effect(
|
|
399
|
-
Repo,
|
|
400
|
-
Effect.gen(function* () {
|
|
401
|
-
const db = yield* Database
|
|
402
|
-
return { find: (id: RepoId) => db.get(id) }
|
|
403
|
-
}),
|
|
404
|
-
)
|
|
405
|
-
|
|
406
|
-
// yes
|
|
407
|
-
export const RepoLive = Layer.effect(
|
|
408
|
-
Repo,
|
|
409
|
-
Effect.gen(function* () {
|
|
410
|
-
const db = yield* Database
|
|
411
|
-
return Repo.of({ find: (id: RepoId) => db.get(id) })
|
|
412
|
-
}),
|
|
413
|
-
)
|
|
414
|
-
```
|
|
415
|
-
|
|
416
|
-
**Trigger**: an object literal passed as the value of `Layer.succeed(T, {…})`, returned by the function of `Layer.sync(T, () => ({…}))`, or returned by a top-level `return {…}` of the generator of `Layer.effect(T, Effect.gen(…))` or `Layer.scoped`; the curried `Layer.succeed(T)(…)` forms too.
|
|
417
|
-
|
|
418
|
-
**Exemptions and blind spots**: a named factory (`Layer.sync(Repo, makeRepo)`) and a variable (`Layer.succeed(Repo, repo)`) are not inspected; `return` inside an `if` or a nested block, `Effect.gen(…).pipe(Layer.effect(T))` and generators other than `Effect.gen` slip through.
|
|
419
|
-
|
|
420
|
-
**Why**: `T.of` names the service the object implements and keeps it checked against the shape if the literal moves out of the Layer; one form for every Layer.
|
|
421
|
-
|
|
422
|
-
**Options**: none
|
|
423
|
-
|
|
424
|
-
**Fix**: suggestion that wraps the literal in `T.of(…)`
|
|
425
|
-
|
|
426
|
-
### `provide-named-layer`
|
|
427
|
-
|
|
428
|
-
<sup>[↑ rules index](#rules-index)</sup>
|
|
429
|
-
|
|
430
|
-
**Intent**: `Effect.provide` receives a named Layer, never an inline composition.
|
|
431
|
-
|
|
432
|
-
```ts
|
|
433
|
-
// no
|
|
434
|
-
printMissing.pipe(Effect.provide(Layer.mergeAll(FileRaceList.layer, GoogleSheet.readerLayer)))
|
|
435
|
-
|
|
436
|
-
// yes: the Layer is named in the entry point, provided in the dispatch
|
|
437
|
-
const missingLayer = Layer.mergeAll(FileRaceList.layer, GoogleSheet.readerLayer)
|
|
438
|
-
Missing: () => printMissing.pipe(Effect.provide(missingLayer)),
|
|
439
|
-
```
|
|
440
|
-
|
|
441
|
-
**Trigger**: an `Effect.provide` argument composed inline: `Layer.*(…)`, a ternary, an `&&`/`||`, a `match`/`$match`.
|
|
442
|
-
|
|
443
|
-
**Exemptions and blind spots**: test files, where different fakes per test are idiomatic. Where `provide` sits (outside the entry point) needs types: see `strict-effect-provide` (effecttsgo).
|
|
444
|
-
|
|
445
|
-
**Why**: an inline Layer cannot be reused and hides which adapters a branch chooses. When branches need different Layers, there is one `provide` per branch, all in the dispatch: a single Layer with every service would build adapters the command does not use.
|
|
446
|
-
|
|
447
|
-
**Options**:
|
|
448
|
-
|
|
449
|
-
- `testFiles`: shared setting, see [Shared settings](#shared-settings).
|
|
450
|
-
|
|
451
|
-
**Fix**: none
|
|
452
|
-
|
|
453
|
-
### `no-provide-on-definition`
|
|
454
|
-
|
|
455
|
-
<sup>[↑ rules index](#rules-index)</sup>
|
|
456
|
-
|
|
457
|
-
**Intent**: a program does not provide its own Layers; its caller does.
|
|
458
|
-
|
|
459
|
-
```ts
|
|
460
|
-
// no
|
|
461
|
-
const printMissing = Effect.gen(function* () { … }).pipe(Effect.provide(missingLayer))
|
|
462
|
-
|
|
463
|
-
// yes: the program stays unprovided, its caller provides
|
|
464
|
-
const printMissing = Effect.gen(function* () { … })
|
|
465
|
-
Missing: () => printMissing.pipe(Effect.provide(missingLayer)),
|
|
466
|
-
```
|
|
467
|
-
|
|
468
|
-
**Trigger**: `Effect.provide` applied to `Effect.gen(…)` or to `Effect.fn(…)(…)`, in all three forms: with `.pipe`, as an `Effect.fn` pipeable, data-first.
|
|
469
|
-
|
|
470
|
-
**Exemptions and blind spots**: test files. A program passed directly to `Effect.run*`, also through `.pipe(…)` or data-first `Effect.*` combinators (`Effect.runPromise(Effect.gen(…).pipe(Effect.provide(layer), Effect.result))`): it is already being dispatched; through any other function it is still reported. A context captured in an enclosing generator with `const ctx = yield* Effect.context<R>()` (also followed by `.pipe(…)`) and handed back to a method of the Layer being built: the caller chose the adapters when it built the Layer. A context obtained through a helper (`yield* contextWithoutSpan()`) is still reported. `provide` on a named program is allowed; `strict-effect-provide` (effecttsgo) reports it too.
|
|
471
|
-
|
|
472
|
-
**Why**: a program that provides its own Layers can no longer be wired to different adapters by its caller.
|
|
473
|
-
|
|
474
|
-
**Options**:
|
|
475
|
-
|
|
476
|
-
- `testFiles`: shared setting, see [Shared settings](#shared-settings).
|
|
477
|
-
|
|
478
|
-
**Fix**: none
|
|
479
|
-
|
|
480
|
-
### `anti-slop-no-service-constructor-imports`
|
|
481
|
-
|
|
482
|
-
<sup>[↑ rules index](#rules-index)</sup>
|
|
483
|
-
|
|
484
|
-
**Intent**: runtime code obtains a service from its Layer, never by calling its `make…` constructor.
|
|
485
|
-
|
|
486
|
-
```ts
|
|
487
|
-
// no: in src/runtime.ts
|
|
488
|
-
import { makeIssueService } from "./issue-service.ts"
|
|
489
|
-
|
|
490
|
-
// yes
|
|
491
|
-
import { IssueService } from "./issue-service.ts"
|
|
492
|
-
|
|
493
|
-
Effect.gen(function* () {
|
|
494
|
-
const issues = yield* IssueService
|
|
495
|
-
})
|
|
496
|
-
```
|
|
497
|
-
|
|
498
|
-
**Trigger**: a named import of `make` followed by an uppercase letter (`makeIssueService`, also when renamed) from a relative module.
|
|
499
|
-
|
|
500
|
-
**Exemptions and blind spots**: test files, which build services from their constructors to inject fakes. Non-relative imports (packages, path aliases), namespace and default imports, and constructors with another prefix slip through. The same import can also fire [`adapter-import-boundary`](#adapter-import-boundary).
|
|
501
|
-
|
|
502
|
-
**Why**: calling the constructor wires its dependencies by hand, and its requirements stop propagating to the composition root.
|
|
503
|
-
|
|
504
|
-
**Options**:
|
|
505
|
-
|
|
506
|
-
- `testFiles`: shared setting, see [Shared settings](#shared-settings).
|
|
507
|
-
|
|
508
|
-
**Fix**: none
|
|
509
|
-
|
|
510
|
-
## Runtime and entry point
|
|
511
|
-
|
|
512
|
-
### `run-only-in-runner`
|
|
513
|
-
|
|
514
|
-
<sup>[↑ rules index](#rules-index)</sup>
|
|
515
|
-
|
|
516
|
-
**Intent**: Effects run only in the program's runner, the entry point.
|
|
517
|
-
|
|
518
|
-
```ts
|
|
519
|
-
// no
|
|
520
|
-
export const check = () => Effect.runPromise(pingDb(url))
|
|
521
|
-
|
|
522
|
-
// yes: in main.ts
|
|
523
|
-
NodeRuntime.runMain(
|
|
524
|
-
run(process.argv.slice(2)).pipe(Effect.provide(NodeServices.layer)) satisfies Effect.Effect<
|
|
525
|
-
void,
|
|
526
|
-
never
|
|
527
|
-
>,
|
|
528
|
-
)
|
|
529
|
-
```
|
|
530
|
-
|
|
531
|
-
**Trigger**: every reference, not just calls, to `Effect.run*`, `NodeRuntime.runMain`, `BunRuntime.runMain` and `ManagedRuntime.make` outside entry files.
|
|
532
|
-
|
|
533
|
-
**Exemptions and blind spots**: test files, checked by [`prefer-effect-vitest`](#prefer-effect-vitest) instead.
|
|
534
|
-
|
|
535
|
-
**Why**: logger, Layers and defect handling are configured in one place.
|
|
536
|
-
|
|
537
|
-
**Options**:
|
|
538
|
-
|
|
539
|
-
- `entryFiles`: shared setting, see [Shared settings](#shared-settings).
|
|
540
|
-
- `testFiles`: shared setting, see [Shared settings](#shared-settings).
|
|
541
|
-
|
|
542
|
-
**Fix**: none
|
|
543
|
-
|
|
544
|
-
### `prefer-effect-vitest`
|
|
545
|
-
|
|
546
|
-
<sup>[↑ rules index](#rules-index)</sup>
|
|
547
|
-
|
|
548
|
-
**Intent**: tests hand their Effects to `@effect/vitest` instead of running them.
|
|
549
|
-
|
|
550
|
-
```ts
|
|
551
|
-
// no
|
|
552
|
-
test("…", async () => {
|
|
553
|
-
await Effect.runPromise(authorize({ role: "Manager" }))
|
|
554
|
-
})
|
|
555
|
-
|
|
556
|
-
// yes: fakes as Layers
|
|
557
|
-
import { effect } from "@effect/vitest"
|
|
558
|
-
|
|
559
|
-
effect("…", () => authorize({ role: "Manager" }).pipe(Effect.provide(sheetWith(row))))
|
|
560
|
-
```
|
|
561
|
-
|
|
562
|
-
**Trigger**: the same references as [`run-only-in-runner`](#run-only-in-runner), inside test files only.
|
|
563
|
-
|
|
564
|
-
**Exemptions and blind spots**: projects where `@effect/vitest` cannot be found in a `node_modules` from the test file up, since the remedy is out of reach there; scattered runs in their tests go unreported. Every file outside `testFiles`, test helpers such as `src/testing/` included.
|
|
565
|
-
|
|
566
|
-
**Why**: the test runtime brings `TestClock` and a scope per test, and fixtures provided as Layers replace services where the code reads them.
|
|
567
|
-
|
|
568
|
-
**Options**:
|
|
569
|
-
|
|
570
|
-
- `testFiles`: shared setting, see [Shared settings](#shared-settings).
|
|
571
|
-
|
|
572
|
-
**Fix**: none
|
|
573
|
-
|
|
574
|
-
### `all-errors-handled-at-boundary`
|
|
575
|
-
|
|
576
|
-
<sup>[↑ rules index](#rules-index)</sup>
|
|
577
|
-
|
|
578
|
-
**Intent**: the entry point runs an Effect whose error channel is closed to `never`.
|
|
579
|
-
|
|
580
|
-
```ts
|
|
581
|
-
// no
|
|
582
|
-
export const POST = (request: Request) => Effect.runPromise(createEvent(request))
|
|
583
|
-
|
|
584
|
-
// yes: in an entry file
|
|
585
|
-
export const POST = (request: Request) =>
|
|
586
|
-
Effect.runPromise(createEvent(request) satisfies Effect.Effect<Response, never>)
|
|
587
|
-
|
|
588
|
-
// yes: a typed helper
|
|
589
|
-
const runBoundary = (effect: Effect.Effect<Response, never, never>) => Effect.runPromise(effect)
|
|
590
|
-
```
|
|
591
|
-
|
|
592
|
-
**Trigger**: `Effect.runPromise`, `runSync`, `runFork` and `runCallback` whose argument is not `… satisfies Effect.Effect<A, never>`, a parameter declared with that type, or a program ending in `Effect.result`/`Effect.exit`, or the v3 `Effect.either` (`Effect.result(program)`, `program.pipe(…, Effect.result)`).
|
|
593
|
-
|
|
594
|
-
**Exemptions and blind spots**: the `*Exit` variants, which return failures as values; `NodeRuntime.runMain`/`BunRuntime.runMain`, which log the Cause and exit with code 1, the right outcome for a process that cannot start; runners inside an `async` function that renders JSX itself, a Server Component, which hands failures to React rather than to an HTTP response; test files, where a rejected run fails the test with the error. The rule checks the shape; `tsc` gives the guarantee.
|
|
595
|
-
|
|
596
|
-
**Why**: `Effect.runPromise` turns any error left over into a rejected promise, a generic 500. With `never`, a new untranslated error does not compile, and `R = never` forces all Layers to be provided.
|
|
597
|
-
|
|
598
|
-
**Options**:
|
|
599
|
-
|
|
600
|
-
- `testFiles`: shared setting, see [Shared settings](#shared-settings).
|
|
601
|
-
|
|
602
|
-
**Fix**: none
|
|
603
|
-
|
|
604
|
-
## Design and boundaries
|
|
605
|
-
|
|
606
|
-
### `adapter-import-boundary`
|
|
607
|
-
|
|
608
|
-
<sup>[↑ rules index](#rules-index)</sup>
|
|
609
|
-
|
|
610
|
-
**Intent**: domain code and other adapters do not import an adapter; only entry files choose it.
|
|
611
|
-
|
|
612
|
-
```ts
|
|
613
|
-
// no: in src/orders/place-order.ts
|
|
614
|
-
import { GoogleCalendar } from "../calendar/google/GoogleCalendar.ts"
|
|
615
|
-
|
|
616
|
-
// yes: depend on the port, main.ts provides GoogleCalendar.layer
|
|
617
|
-
import { Calendar } from "../calendar/Calendar.ts"
|
|
618
|
-
```
|
|
619
|
-
|
|
620
|
-
**Trigger**: a relative import of a file in another directory that is an adapter: one of its `.ts` files (tests excluded) builds a `Layer` with `Layer.effect`, `succeed`, `sync`, `scoped`, `effectContext`, `unwrap`, `mock` and similar, or declares a v3 `Effect.Service`, which always carries its implementation. Composition alone (`mergeAll`, `provide`, `merge`) does not make an adapter.
|
|
621
|
-
|
|
622
|
-
**Exemptions and blind spots**: entry files, where adapters are chosen, and test files, which compose the Layers they exercise. Non-relative imports (path aliases such as `@/calendar/google`) and directory imports through an `index.ts` (`"../google"`) slip through. On a layout other than one directory per adapter, check what it reports before trusting it. Infrastructure requirements in the port's `R` channel need types: see `leaking-requirements` (effecttsgo).
|
|
623
|
-
|
|
624
|
-
**Why**: the adapter can be replaced without touching its consumers.
|
|
625
|
-
|
|
626
|
-
**Options**:
|
|
627
|
-
|
|
628
|
-
- `entryFiles`: shared setting, see [Shared settings](#shared-settings).
|
|
629
|
-
- `testFiles`: shared setting, see [Shared settings](#shared-settings).
|
|
630
|
-
|
|
631
|
-
**Fix**: none
|
|
632
|
-
|
|
633
|
-
### `no-transport-types-in-generator`
|
|
634
|
-
|
|
635
|
-
<sup>[↑ rules index](#rules-index)</sup>
|
|
636
|
-
|
|
637
|
-
**Intent**: the generator returns a domain value; conversion to a transport type happens in the second argument of `Effect.fn`.
|
|
638
|
-
|
|
639
|
-
```ts
|
|
640
|
-
// no: an error branch inside the happy path
|
|
641
|
-
function* (request: Request) {
|
|
642
|
-
const credential = yield* sessionCredential
|
|
643
|
-
if (credential === undefined) return Response.redirect(new URL("/login", origin), 303)
|
|
644
|
-
// …
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
// yes
|
|
648
|
-
const createEvent = Effect.fn("events.create")(
|
|
649
|
-
function* (request: Request) {
|
|
650
|
-
const credential = yield* sessionCredential // fails with Unauthenticated
|
|
651
|
-
const submission = yield* form(request)
|
|
652
|
-
return yield* apiCreateEvent(credential, submission)
|
|
653
|
-
},
|
|
654
|
-
(effect, request) =>
|
|
655
|
-
effect.pipe(
|
|
656
|
-
Effect.map((created) => Response.redirect(eventUrl(request, created), 303)),
|
|
657
|
-
Effect.catchTags({ Unauthenticated: () => Effect.succeed(toLogin(request)) }),
|
|
658
|
-
),
|
|
659
|
-
)
|
|
660
|
-
```
|
|
661
|
-
|
|
662
|
-
**Trigger**: `new T(…)`, `T.method(…)` and `T(…)` inside an Effect generator, callbacks passed to `Effect.*` combinators included, when `T` is a transport type.
|
|
663
|
-
|
|
664
|
-
**Exemptions and blind spots**: pipeables of `Effect.fn`, where the conversion must live. Functions the generator only defines, such as an HTTP handler it registers. `return yield* new Unauthenticated(…)` is a declared failure. An early `return` of a domain value that actually signals an error is indistinguishable from a success.
|
|
665
|
-
|
|
666
|
-
**Why**: an early `return new Response(…)` on the happy path is an error branch disguised as success, and escapes exhaustive translation.
|
|
667
|
-
|
|
668
|
-
**Options**:
|
|
669
|
-
|
|
670
|
-
- `transportTypes`: default `["Response", "NextResponse"]`, replaced by the configured list. Add your own transport DTOs.
|
|
671
|
-
|
|
672
|
-
**Fix**: none
|
|
673
|
-
|
|
674
|
-
## Effectful functions
|
|
675
|
-
|
|
676
|
-
### `prefer-effect-fn`
|
|
677
|
-
|
|
678
|
-
<sup>[↑ rules index](#rules-index)</sup>
|
|
679
|
-
|
|
680
|
-
**Intent**: an effectful function is `Effect.fn("name")`, and a named effect value has a span.
|
|
681
|
-
|
|
682
|
-
```ts
|
|
683
|
-
// no
|
|
684
|
-
const outcomeFor = (name: string) => Effect.gen(function* () { … }).pipe(Effect.catch(toFailed))
|
|
685
|
-
const refresh = Effect.gen(function* () { … })
|
|
686
|
-
|
|
687
|
-
// yes: extra combinators as arguments, not .pipe
|
|
688
|
-
const outcomeFor = Effect.fn("outcomeFor")(function* (name: string) { … }, Effect.catch(toFailed))
|
|
689
|
-
const refresh = Effect.gen(function* () { … }).pipe(Effect.withSpan("refresh"))
|
|
690
|
-
```
|
|
691
|
-
|
|
692
|
-
**Trigger**:
|
|
693
|
-
|
|
694
|
-
- a declared function, a variable or an object member that only returns `Effect.gen(…)`, even with `.pipe`;
|
|
695
|
-
- a variable or an object member whose value is `Effect.gen(…)` without `Effect.withSpan` in its `.pipe`;
|
|
696
|
-
- `Effect.fn(body)` without a name;
|
|
697
|
-
- `.pipe` on `Effect.fn(…)(…)`.
|
|
698
|
-
|
|
699
|
-
**Exemptions and blind spots**: `Effect.gen` inline as an argument (`Layer.effect(Tag, Effect.gen(…))`, `Stream.unwrap`, callbacks, `it.effect`). Recursive functions: see [`untraced-recursion`](#untraced-recursion).
|
|
700
|
-
|
|
701
|
-
**Why**: named stack traces and spans without wrapper functions. Combinators passed as arguments run inside the function's span and receive its arguments: `(effect, name) => effect.pipe(…)`.
|
|
702
|
-
|
|
703
|
-
**Options**: none
|
|
704
|
-
|
|
705
|
-
**Fix**: none
|
|
706
|
-
|
|
707
|
-
### `untraced-recursion`
|
|
708
|
-
|
|
709
|
-
<sup>[↑ rules index](#rules-index)</sup>
|
|
710
|
-
|
|
711
|
-
**Intent**: a recursive effectful function uses `Effect.fnUntraced`; the entry point that starts the recursion is traced.
|
|
712
|
-
|
|
713
|
-
```ts
|
|
714
|
-
// no
|
|
715
|
-
const walk = Effect.fn("walk")(function* (node: Node) {
|
|
716
|
-
for (const child of node.children) yield* walk(child)
|
|
717
|
-
})
|
|
718
|
-
|
|
719
|
-
// yes
|
|
720
|
-
const walk = Effect.fnUntraced(function* (node: Node) {
|
|
721
|
-
for (const child of node.children) yield* walk(child)
|
|
722
|
-
})
|
|
723
|
-
export const scan = Effect.fn("scan")(function* (root: Node) {
|
|
724
|
-
return yield* walk(root)
|
|
725
|
-
})
|
|
726
|
-
```
|
|
727
|
-
|
|
728
|
-
**Trigger**: an `Effect.fn` assigned to a variable that its own body calls again, even by passing it as a callback.
|
|
729
|
-
|
|
730
|
-
**Exemptions and blind spots**: mutual recursion, recursion in pipeables.
|
|
731
|
-
|
|
732
|
-
**Why**: with `Effect.fn` every level opens a span nested in the previous one.
|
|
733
|
-
|
|
734
|
-
**Options**: none
|
|
735
|
-
|
|
736
|
-
**Fix**: none
|
|
737
|
-
|
|
738
|
-
### `single-style-per-function`
|
|
739
|
-
|
|
740
|
-
<sup>[↑ rules index](#rules-index)</sup>
|
|
741
|
-
|
|
742
|
-
**Intent**: a function is entirely Effect or not Effect at all.
|
|
743
|
-
|
|
744
|
-
```ts
|
|
745
|
-
// no
|
|
746
|
-
export const POST = async (request: Request) => {
|
|
747
|
-
const form = await request.formData()
|
|
748
|
-
const created = await Effect.runPromise(Effect.result(createEvent(form)))
|
|
749
|
-
// …
|
|
750
|
-
}
|
|
751
|
-
|
|
752
|
-
// yes: promises lifted with Effect.tryPromise
|
|
753
|
-
const createEvent = Effect.fn("events.create")(function* (request: Request) {
|
|
754
|
-
const form = yield* Effect.tryPromise({
|
|
755
|
-
try: () => request.formData(),
|
|
756
|
-
catch: () => new BadRequest({ message: "invalid form data" }),
|
|
757
|
-
})
|
|
758
|
-
// …
|
|
759
|
-
})
|
|
760
|
-
```
|
|
761
|
-
|
|
762
|
-
**Trigger**: `async`, `await` and `.then(` in a function that builds Effects: an Effect generator, or a function using an `Effect.*` member. A `test`/`it` callback (`.only`, `.each(…)` and the like included) or a `beforeAll`/`afterAll`/`beforeEach`/`afterEach` hook, and in test files any other function except an Effect generator, is reported once, on the function, when more than one of its `await`s, or any `.then(`, involves Effect: has an `Effect.*` member in its expression, nested callbacks and `Effect.run*` included.
|
|
763
|
-
|
|
764
|
-
**Exemptions and blind spots**: `Effect.run*` alone does not make a function effectful: it is how an async boundary hands over to Effect, and where it may appear is decided by [`run-only-in-runner`](#run-only-in-runner). An `async` function that renders JSX itself, not only in nested callbacks, is a Server Component: how it turns failures into UI is left to the application. A test, hook or test helper may await promise-based fixtures (a container, an identity provider), then one Effect program, and assert on its result. A step that reaches Effect only through a helper (`await run(seed)`) is not counted.
|
|
765
|
-
|
|
766
|
-
**Why**: errors travel on two channels, exceptions and Effect, and neither sees them all.
|
|
767
|
-
|
|
768
|
-
**Options**:
|
|
769
|
-
|
|
770
|
-
- `testFiles`: shared setting, see [Shared settings](#shared-settings).
|
|
771
|
-
|
|
772
|
-
**Fix**: none
|
|
773
|
-
|
|
774
|
-
## Code shape
|
|
775
|
-
|
|
776
|
-
### `no-nested-match`
|
|
777
|
-
|
|
778
|
-
<sup>[↑ rules index](#rules-index)</sup>
|
|
779
|
-
|
|
780
|
-
**Intent**: a match handler contains neither another match nor a ternary.
|
|
781
|
-
|
|
782
|
-
```ts
|
|
783
|
-
// no
|
|
784
|
-
const run = (argv: ReadonlyArray<string>) =>
|
|
785
|
-
Result.match(parseArgs(argv), {
|
|
786
|
-
onFailure: usageError,
|
|
787
|
-
onSuccess: (command) =>
|
|
788
|
-
Option.match(command.only, { onNone: () => fillAll, onSome: fillOnly }),
|
|
789
|
-
})
|
|
790
|
-
|
|
791
|
-
// yes, outside a generator: a named handler
|
|
792
|
-
const fill = (command: CliCommand) =>
|
|
793
|
-
Option.match(command.only, { onNone: () => fillAll, onSome: fillOnly })
|
|
794
|
-
|
|
795
|
-
const run = (argv: ReadonlyArray<string>) =>
|
|
796
|
-
Result.match(parseArgs(argv), { onFailure: usageError, onSuccess: fill })
|
|
797
|
-
|
|
798
|
-
// yes, inside a generator: guard clauses
|
|
799
|
-
const run = Effect.fn("run")(function* (argv: ReadonlyArray<string>) {
|
|
800
|
-
const parsed = parseArgs(argv)
|
|
801
|
-
if (Result.isFailure(parsed)) return yield* usageError(parsed.failure)
|
|
802
|
-
|
|
803
|
-
const { only } = parsed.success
|
|
804
|
-
if (Option.isNone(only)) return yield* fillAll
|
|
805
|
-
|
|
806
|
-
return yield* fillOnly(only.value)
|
|
807
|
-
})
|
|
808
|
-
```
|
|
809
|
-
|
|
810
|
-
**Trigger**: a handler of `Option.match`, `Result.match`, `Exit.match`, `Either.match`, `$match` or `Match.valueTags` that is itself a data-last match (also `Match.type().pipe(…)` and `pipe(Match.type(), …)`), or that returns a match, a `Match.value(…).pipe(…)` or `pipe(Match.value(…), …)` chain or a ternary.
|
|
811
|
-
|
|
812
|
-
**Exemptions and blind spots**: `if` inside handlers, and whatever they return from inside an `if` or another nested block; the handlers of an outer `Match.value`/`Match.type` chain; matches nested deeper than the returned value, or assigned to a variable before being returned.
|
|
813
|
-
|
|
814
|
-
**Why**: two nested levels of choice hide which branch is the normal one.
|
|
815
|
-
|
|
816
|
-
**Options**: none
|
|
817
|
-
|
|
818
|
-
**Fix**: none
|
|
819
|
-
|
|
820
|
-
### `no-yielded-match`
|
|
821
|
-
|
|
822
|
-
<sup>[↑ rules index](#rules-index)</sup>
|
|
823
|
-
|
|
824
|
-
**Intent**: inside an Effect generator, return early on the empty or failed case instead of yielding a match.
|
|
825
|
-
|
|
826
|
-
```ts
|
|
827
|
-
// no
|
|
828
|
-
const save = Effect.fn("save")(function* (id: PolicyId) {
|
|
829
|
-
const found = yield* findPolicy(id)
|
|
830
|
-
return yield* Option.match(found, {
|
|
831
|
-
onNone: () => register(id),
|
|
832
|
-
onSome: (policy) => update(policy),
|
|
833
|
-
})
|
|
834
|
-
})
|
|
835
|
-
|
|
836
|
-
// yes
|
|
837
|
-
const save = Effect.fn("save")(function* (id: PolicyId) {
|
|
838
|
-
const found = yield* findPolicy(id)
|
|
839
|
-
if (Option.isNone(found)) return yield* register(id)
|
|
840
|
-
|
|
841
|
-
return yield* update(found.value)
|
|
842
|
-
})
|
|
843
|
-
```
|
|
844
|
-
|
|
845
|
-
**Trigger**: `yield*` of `Option.match(x, {…})` or `Result.match(x, {…})` (v3: `Either.match`), or of a `x.pipe(…)`/`pipe(x, …)` ending in one of them, in the generator of `Effect.gen` or `Effect.fn`.
|
|
846
|
-
|
|
847
|
-
**Exemptions and blind spots**: an `Option.match` with `onNone` → `Effect.fail(…)` and `onSome` → `Effect.succeed`: see `option-match-to-from-option` (effecttsgo). A handler that `no-nested-match` reports. Matches not yielded directly (assigned first, or inside `Effect.flatMap`) slip through.
|
|
848
|
-
|
|
849
|
-
**Why**: the match splits the generator into two equal-weight branches; a guard clause leaves one main path of `yield*`.
|
|
850
|
-
|
|
851
|
-
**Options**: none
|
|
852
|
-
|
|
853
|
-
**Fix**: none
|
|
854
|
-
|
|
855
|
-
### `no-inline-yield-star`
|
|
856
|
-
|
|
857
|
-
<sup>[↑ rules index](#rules-index)</sup>
|
|
858
|
-
|
|
859
|
-
**Intent**: a `yield*` result is bound to a `const` before being used.
|
|
860
|
-
|
|
861
|
-
```ts
|
|
862
|
-
// no
|
|
863
|
-
function* () {
|
|
864
|
-
return yield* missingIn(yield* readSheet())
|
|
865
|
-
}
|
|
866
|
-
|
|
867
|
-
// yes
|
|
868
|
-
function* () {
|
|
869
|
-
const sheet = yield* readSheet()
|
|
870
|
-
return yield* missingIn(sheet)
|
|
871
|
-
}
|
|
872
|
-
```
|
|
873
|
-
|
|
874
|
-
**Trigger**: a `yield*` whose result is used inside a larger expression: argument, operand, member, property, template.
|
|
875
|
-
|
|
876
|
-
**Exemptions and blind spots**: a `yield*` that is the whole value of a statement (`yield* x`, `return yield* x`, `if (yield* x)`, `for (… of yield* x)`), a declaration or an assignment. Also the whole branch of a ternary, or the right operand of `&&`/`||`/`??`, in one of those positions (`const a = cached ?? (yield* x)`): binding first would run the effect unconditionally. The autofix extracts every nested `yield*` into `const`s, innermost first, named after the argument's last identifier without a verb prefix (`readSheet()` → `sheet`). There is no autofix when moving the effect could change when or how often it runs: branches of a ternary or `&&`/`||`/`??` inside a larger expression, optional chaining, `while`/`for` conditions, statements without braces, another call evaluated before the `yield*`.
|
|
877
|
-
|
|
878
|
-
**Why**: with several `yield*`s in one expression the order of effects can only be inferred from precedence. One `const` per effect makes the order the reading order and names the intermediate value.
|
|
879
|
-
|
|
880
|
-
**Options**: none
|
|
881
|
-
|
|
882
|
-
**Fix**: autofix
|
|
883
|
-
|
|
884
|
-
### `no-effect-return-type`
|
|
885
|
-
|
|
886
|
-
<sup>[↑ rules index](#rules-index)</sup>
|
|
887
|
-
|
|
888
|
-
**Intent**: `Effect`, `Stream` and `Layer` return types are inferred, not annotated, except on exported declarations.
|
|
889
|
-
|
|
890
|
-
```ts
|
|
891
|
-
// no
|
|
892
|
-
(effect, name): Effect.Effect<RaceFillResult, never, Agent | SheetReader | SheetWriter> =>
|
|
893
|
-
|
|
894
|
-
// yes
|
|
895
|
-
(effect, name) =>
|
|
896
|
-
|
|
897
|
-
// yes: an exported declaration keeps its annotation as a contract
|
|
898
|
-
export const findPrice = (id: PriceId): Effect.Effect<Price, PriceNotFound> =>
|
|
899
|
-
```
|
|
900
|
-
|
|
901
|
-
**Trigger**: `Effect.Effect`, `Stream.Stream` or `Layer.Layer` in an annotated return type, even nested (`Option.Option<Effect.Effect<…>>`, a function returning an `Effect`).
|
|
902
|
-
|
|
903
|
-
**Exemptions and blind spots**: module-level declarations with `export` (`export const`, `export function`, `export default`), unless `checkExported` is on; methods of an exported object, functions an exported function returns, and `export { f }` lists are still checked. Recursion, and returns of different shapes that need unifying (`Effect.succeed` and `Effect.fail`), recognized from the shape of the `return`s. An `import type { Effect }` used as `Effect<…>` slips through.
|
|
904
|
-
|
|
905
|
-
**Why**: the error and requirement channels collect what comes from everything the function calls; an error or a service added deep down would change every caller's annotation. An exported signature is the module's contract, like a named type: there the annotation makes such a change visible where it is published. To check a returned object against a named type, annotate the callback that builds it (`Effect.map(CurrentSession, (session): OrganizationContext => ({ … }))`) or use `satisfies`.
|
|
906
|
-
|
|
907
|
-
**Options**:
|
|
908
|
-
|
|
909
|
-
- `checkExported`: default `false`. Also checks exported declarations.
|
|
910
|
-
|
|
911
|
-
**Fix**: suggestion that removes the annotation
|
|
912
|
-
|
|
913
|
-
### `no-asymmetric-match-handlers`
|
|
914
|
-
|
|
915
|
-
<sup>[↑ rules index](#rules-index)</sup>
|
|
916
|
-
|
|
917
|
-
**Intent**: if one match handler delegates to a named function, the others do too.
|
|
918
|
-
|
|
919
|
-
```ts
|
|
920
|
-
// no
|
|
921
|
-
Option.match(only, {
|
|
922
|
-
onNone: () => missingIn(sheet),
|
|
923
|
-
onSome: Effect.fn("onlyCandidate")(function* (name: string) { … }),
|
|
924
|
-
})
|
|
925
|
-
|
|
926
|
-
// yes
|
|
927
|
-
Option.match(only, {
|
|
928
|
-
onNone: () => missingIn(sheet),
|
|
929
|
-
onSome: (name) => onlyCandidate(sheet, name),
|
|
930
|
-
})
|
|
931
|
-
```
|
|
932
|
-
|
|
933
|
-
**Trigger**: on the same matches as [`no-nested-match`](#no-nested-match), a handler with an inline body next to one that delegates. A handler delegates if it is a reference, a call, or a function returning only a call; it is inline if it has multiple statements, is a generator, or builds an `Effect.fn`/`Effect.gen`.
|
|
934
|
-
|
|
935
|
-
**Exemptions and blind spots**: returned literals, templates, arrays and objects are values and count on neither side.
|
|
936
|
-
|
|
937
|
-
**Why**: a branch saying _what_ next to one showing _how_ forces the reader to switch level halfway through the choice.
|
|
938
|
-
|
|
939
|
-
**Options**: none
|
|
940
|
-
|
|
941
|
-
**Fix**: none
|
|
942
|
-
|
|
943
|
-
### `anti-slop-prefer-effect-match`
|
|
944
|
-
|
|
945
|
-
<sup>[↑ rules index](#rules-index)</sup>
|
|
946
|
-
|
|
947
|
-
**Intent**: a choice among several literal values of the same expression is a `Match`, not a chain of ternaries.
|
|
948
|
-
|
|
949
|
-
```ts
|
|
950
|
-
// no
|
|
951
|
-
const label = kind === "a" ? "A" : kind === "b" ? "B" : "Other"
|
|
952
|
-
|
|
953
|
-
// yes
|
|
954
|
-
const label = Match.value(kind).pipe(
|
|
955
|
-
Match.when("a", () => "A"),
|
|
956
|
-
Match.when("b", () => "B"),
|
|
957
|
-
Match.orElse(() => "Other"),
|
|
958
|
-
)
|
|
959
|
-
```
|
|
960
|
-
|
|
961
|
-
**Trigger**: a ternary chain of at least two levels where every condition compares the same expression, by source text, with a literal (`==`, `===`, `!=`, `!==`).
|
|
962
|
-
|
|
963
|
-
**Exemptions and blind spots**: a single ternary, chains comparing different expressions, and the same expression written differently (`a.b` vs `a["b"]`). A chain returned by a match handler also fires [`no-nested-match`](#no-nested-match): extract the handler first, since a `Match.value` left inside it fires `no-nested-match` again.
|
|
964
|
-
|
|
965
|
-
**Why**: a ternary chain hides which value is the fallback and cannot be made exhaustive.
|
|
966
|
-
|
|
967
|
-
**Options**: none
|
|
968
|
-
|
|
969
|
-
**Fix**: none
|
|
970
|
-
|
|
971
|
-
## Schema
|
|
972
|
-
|
|
973
|
-
### `exported-schema-identifier`
|
|
974
|
-
|
|
975
|
-
<sup>[↑ rules index](#rules-index)</sup>
|
|
976
|
-
|
|
977
|
-
**Intent**: an exported schema carries an `identifier` equal to its name.
|
|
978
|
-
|
|
979
|
-
```ts
|
|
980
|
-
// no
|
|
981
|
-
export const EventBusEvents = Schema.Union([Created, Deleted])
|
|
982
|
-
|
|
983
|
-
// yes
|
|
984
|
-
export const EventBusEvents = Schema.Union([Created, Deleted]).annotate({
|
|
985
|
-
identifier: "EventBusEvents",
|
|
986
|
-
})
|
|
987
|
-
```
|
|
988
|
-
|
|
989
|
-
**Trigger**: `export const X = Schema.Struct(…)`, `Schema.Union(…)` or `Schema.Array(…)`, also followed by `.pipe(…)`, `.annotate(…)` or `.check(…)`, with no `identifier` in a `.annotate(…)` or `Schema.annotate(…)` of the chain (v3: `annotations`), or with a literal `identifier` other than `"X"`.
|
|
990
|
-
|
|
991
|
-
**Exemptions and blind spots**: non-exported schemas (fragments reused through `.fields`), and `Schema.Class` and `Schema.TaggedError`, which carry the name already. A computed `identifier` is not compared. Other constructors (`Schema.TaggedStruct`, `Schema.Literals`, …), `export { X }` lists and chains through other methods slip through. An exported fragment reused only through `.fields` fires too, although the annotation does not reach the schemas that spread it: export the plain fields object instead (`export const BaseFields = { … }`).
|
|
992
|
-
|
|
993
|
-
**Why**: without an `identifier`, decoding errors, JSON Schema and arbitraries describe the schema by its structure instead of its name.
|
|
994
|
-
|
|
995
|
-
**Options**: none
|
|
996
|
-
|
|
997
|
-
**Fix**: suggestion that corrects the `identifier`, or two that add it, `v3:` with `.annotations(…)` and `v4:` with `.annotate(…)`
|
|
998
|
-
|
|
999
|
-
### `no-inline-schema-codec`
|
|
1000
|
-
|
|
1001
|
-
<sup>[↑ rules index](#rules-index)</sup>
|
|
1002
|
-
|
|
1003
|
-
**Intent**: a decoder or encoder is a named module-level constant, not built and applied inline.
|
|
1004
|
-
|
|
1005
|
-
```ts
|
|
1006
|
-
// no
|
|
1007
|
-
const toPayment = (raw: unknown) => Schema.decodeUnknownSync(PaymentResponse)(raw)
|
|
1008
|
-
|
|
1009
|
-
// yes
|
|
1010
|
-
const decodePaymentResponse = Schema.decodeUnknownSync(PaymentResponse)
|
|
1011
|
-
|
|
1012
|
-
const toPayment = (raw: unknown) => decodePaymentResponse(raw)
|
|
1013
|
-
```
|
|
1014
|
-
|
|
1015
|
-
**Trigger**: an immediate application `Schema.decode*(X)(input)` or `Schema.encode*(X)(input)` (the `Effect`, `Exit`, `Option`, `Promise`, `Result` and `Sync` variants, `Unknown` included) inside a function, test callbacks included.
|
|
1016
|
-
|
|
1017
|
-
**Exemptions and blind spots**: module scope, and the generator of `Layer.effect(T, Effect.gen(…))` or `Layer.effect(T)(Effect.gen(…))` (also `Layer.scoped`), which run once; functions nested in that generator, such as the service methods, are checked. Codecs built inside a function and applied later (`const decode = Schema.decodeUnknownEffect(X)`), codecs passed as callbacks (`Effect.flatMap(Schema.decodeUnknownEffect(X))`) and a Layer built through `.pipe(Layer.effect(T))` slip through. Whether the codec should be synchronous is not this rule's concern: see `schema-sync` (effecttsgo).
|
|
1018
|
-
|
|
1019
|
-
**Why**: a named codec says what it decodes at the call site and is built once, instead of at every call.
|
|
1020
|
-
|
|
1021
|
-
**Options**: none
|
|
1022
|
-
|
|
1023
|
-
**Fix**: none
|
|
1024
|
-
|
|
1025
|
-
## Config and secrets
|
|
1026
|
-
|
|
1027
|
-
### `redacted-secret-names`
|
|
1028
|
-
|
|
1029
|
-
<sup>[↑ rules index](#rules-index)</sup>
|
|
1030
|
-
|
|
1031
|
-
**Intent**: a secret read from config or declared in a schema is `Redacted`.
|
|
1032
|
-
|
|
1033
|
-
```ts
|
|
1034
|
-
// no
|
|
1035
|
-
serviceAccount: Config.schema(NonBlank, "GOOGLE_SERVICE_ACCOUNT_JSON")
|
|
1036
|
-
const Session = Schema.Struct({ userId: UserId, accessToken: Schema.String })
|
|
1037
|
-
|
|
1038
|
-
// yes
|
|
1039
|
-
serviceAccount: Config.schema(Schema.Redacted(NonBlank), "GOOGLE_SERVICE_ACCOUNT_JSON")
|
|
1040
|
-
const Session = Schema.Struct({ userId: UserId, accessToken: Schema.Redacted(Schema.String) })
|
|
1041
|
-
```
|
|
1042
|
-
|
|
1043
|
-
**Trigger**:
|
|
1044
|
-
|
|
1045
|
-
- a literal name read with `Config.*` that ends with `KEY`, `SECRET`, `TOKEN`, `PASSWORD`, `CREDENTIAL`, `CREDENTIALS` or `_JSON` (service account keys often travel as inline JSON), when it does not go through `Config.Redacted`, the v3 `Config.redacted` (also wrapping a config, `Config.redacted(Config.string(name))`), or `Config.schema(Schema.Redacted…(…), name)`;
|
|
1046
|
-
- a field of `Schema.Struct({…})` or `Schema.Class<X>("X")({…})` whose name is a `secretFields` entry or ends with it capitalized (`password` matches `dbPassword`), declared with a `Schema.*` constant such as `Schema.String`, also through `.pipe(…)`, `.check(…)`, `.annotate(…)`/`.annotations(…)` or `Schema.optional`/`optionalKey`/`optionalWith`/`NullOr`/`UndefinedOr`/`NullishOr`, with no `Schema.Redacted…` along the way.
|
|
1047
|
-
|
|
1048
|
-
**Exemptions and blind spots**: a naming heuristic: secrets with other names slip through, non-secrets with these names must be suppressed. Fields declared with a named schema (`accessToken: AccessToken`) are not inspected; other constructors (`Schema.TaggedClass`, `Schema.TaggedStruct`, …) are not seen. `process.env` read outside `Config`: see `process-env` and `process-env-in-effect` (effecttsgo).
|
|
1049
|
-
|
|
1050
|
-
**Why**: a `Redacted` value does not end up in logs or `toString`.
|
|
1051
|
-
|
|
1052
|
-
**Options**:
|
|
1053
|
-
|
|
1054
|
-
- `secretFields`: default `["password", "secret", "apiKey", "accessToken", "refreshToken", "idToken"]` (no generic `token`), replaced by the configured list. `Config` names are fixed.
|
|
1055
|
-
|
|
1056
|
-
**Fix**: none
|