@evobug_com/safe-ts-skill 0.4.0 → 0.5.1
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/install.mjs +31 -7
- package/package.json +1 -1
- package/safe-ts-migrate/SKILL.md +80 -13
- package/safe-ts-migrate/references/architecture.md +10 -3
- package/safe-ts-migrate/references/census.md +31 -9
- package/safe-ts-migrate/references/escape-hatches.md +19 -9
- package/safe-ts-migrate/references/final-pass.md +7 -5
- package/safe-ts-migrate/references/fix-the-design.md +87 -0
- package/safe-ts-migrate/references/order-and-gates.md +9 -4
- package/safe-ts-migrate/references/patterns-core.md +1240 -85
- package/safe-ts-migrate/references/patterns-react.md +52 -16
- package/safe-ts-migrate/references/patterns-vue.md +98 -21
- package/safe-ts-migrate/references/review-checklist.md +7 -0
- package/safe-ts-migrate/references/templates.md +46 -21
- package/safe-ts-migrate/references/tool-gaps.md +284 -14
- package/safe-ts-migrate/scripts/census.mjs +343 -144
|
@@ -116,7 +116,9 @@ export function Name({ id }: { id: string }) {
|
|
|
116
116
|
|
|
117
117
|
A `let` at the top of a file is one value for every instance, every test and (with server
|
|
118
118
|
rendering) every request (`no-mutable-global`). Keep it in the component, in a common parent, or
|
|
119
|
-
in a context whose provider creates it.
|
|
119
|
+
in a context whose provider creates it. A module-level object is the same once a function changes
|
|
120
|
+
it, however it reaches it: destructured, iterated, or handed back by a getter (`getConfig().x = 1`,
|
|
121
|
+
across files too).
|
|
120
122
|
|
|
121
123
|
```tsx bad no-mutable-global
|
|
122
124
|
let clicks = 0;
|
|
@@ -169,13 +171,20 @@ export function TodoItem({ todo, onToggle }: { todo: Todo; onToggle: () => void
|
|
|
169
171
|
## A Result returned to React
|
|
170
172
|
|
|
171
173
|
React drops what a handler returns, so `onClick={archive}` with a `Result` loses the error
|
|
172
|
-
(`must-use-result`). The
|
|
174
|
+
(`must-use-result`). The component's state is one `Enum` that names every state, the first
|
|
175
|
+
included (`Ready`, `Refused` with a named error, `Archived`), and `<Match>` shows each: no `""`
|
|
176
|
+
for "no problem", no message built in the handler, and not an `Option` of the error, whose
|
|
177
|
+
`undefined` would mean both "not tried yet" and "archived".
|
|
173
178
|
|
|
174
179
|
```tsx bad must-use-result
|
|
180
|
+
import { constructors, type Enum } from "@evobug_com/safe-ts-std/enum";
|
|
175
181
|
import { err, type Result } from "@evobug_com/safe-ts-std/result";
|
|
176
182
|
|
|
177
|
-
|
|
178
|
-
|
|
183
|
+
type ArchiveError = Enum<{ NotDraft: {}; Locked: { by: string } }>;
|
|
184
|
+
const ArchiveError = constructors<ArchiveError>();
|
|
185
|
+
|
|
186
|
+
function archive(): Result<void, ArchiveError> {
|
|
187
|
+
return err(ArchiveError.Locked({ by: "Ada" }));
|
|
179
188
|
}
|
|
180
189
|
|
|
181
190
|
export function Toolbar() {
|
|
@@ -185,23 +194,43 @@ export function Toolbar() {
|
|
|
185
194
|
|
|
186
195
|
```tsx good
|
|
187
196
|
import { useState } from "react";
|
|
188
|
-
import {
|
|
197
|
+
import { constructors, type Enum } from "@evobug_com/safe-ts-std/enum";
|
|
198
|
+
import { err, isErr, type Result } from "@evobug_com/safe-ts-std/result";
|
|
199
|
+
import { Match } from "@evobug_com/safe-ts-react/match";
|
|
200
|
+
|
|
201
|
+
type ArchiveError = Enum<{ NotDraft: {}; Locked: { by: string } }>;
|
|
202
|
+
const ArchiveError = constructors<ArchiveError>();
|
|
189
203
|
|
|
190
|
-
|
|
191
|
-
|
|
204
|
+
type Archiving = Enum<{ Ready: {}; Refused: { error: ArchiveError }; Archived: {} }>;
|
|
205
|
+
const Archiving = constructors<Archiving>();
|
|
206
|
+
|
|
207
|
+
function archive(): Result<void, ArchiveError> {
|
|
208
|
+
return err(ArchiveError.Locked({ by: "Ada" }));
|
|
192
209
|
}
|
|
193
210
|
|
|
194
211
|
export function Toolbar() {
|
|
195
|
-
const [
|
|
212
|
+
const [state, setState] = useState<Archiving>(Archiving.Ready());
|
|
196
213
|
const onArchive = (): void => {
|
|
197
214
|
const archived = archive();
|
|
198
|
-
|
|
215
|
+
setState(isErr(archived) ? Archiving.Refused({ error: archived.error }) : Archiving.Archived());
|
|
199
216
|
};
|
|
217
|
+
const button = <button onClick={onArchive}>Archive</button>;
|
|
200
218
|
return (
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
{
|
|
204
|
-
|
|
219
|
+
<Match
|
|
220
|
+
on={state}
|
|
221
|
+
Ready={() => button}
|
|
222
|
+
Refused={({ error }) => (
|
|
223
|
+
<>
|
|
224
|
+
{button}
|
|
225
|
+
<Match
|
|
226
|
+
on={error}
|
|
227
|
+
NotDraft={() => <p>Only drafts can be archived.</p>}
|
|
228
|
+
Locked={({ by }) => <p>{by} is editing it.</p>}
|
|
229
|
+
/>
|
|
230
|
+
</>
|
|
231
|
+
)}
|
|
232
|
+
Archived={() => <p>Archived.</p>}
|
|
233
|
+
/>
|
|
205
234
|
);
|
|
206
235
|
}
|
|
207
236
|
```
|
|
@@ -209,7 +238,9 @@ export function Toolbar() {
|
|
|
209
238
|
## HTML from outside
|
|
210
239
|
|
|
211
240
|
`dangerouslySetInnerHTML` with text from a user or the network can run script
|
|
212
|
-
(`react-dangerous-html`). Render text; when it must be HTML,
|
|
241
|
+
(`react-dangerous-html`). Render text; when it must be HTML, go through the project's one
|
|
242
|
+
sanitizer, declared with `defineSanitizer` (`@evobug_com/safe-ts-std/html`): what it returns is
|
|
243
|
+
an `Html`, accepted by type. A known sanitizer called in the prop itself passes too.
|
|
213
244
|
React 19 neutralises `javascript:` URLs in `href`; on React 18, bind URLs from users through
|
|
214
245
|
`safeHref` from `@evobug_com/safe-ts-std/url`.
|
|
215
246
|
|
|
@@ -222,9 +253,14 @@ export function CommentView({ comment }: { comment: Comment }) {
|
|
|
222
253
|
```
|
|
223
254
|
|
|
224
255
|
```tsx good
|
|
225
|
-
|
|
256
|
+
import { defineSanitizer } from "@evobug_com/safe-ts-std/html";
|
|
257
|
+
|
|
258
|
+
declare const DOMPurify: { sanitize(html: string): string };
|
|
259
|
+
|
|
260
|
+
const sanitizeHtml = defineSanitizer((raw) => DOMPurify.sanitize(raw));
|
|
226
261
|
|
|
227
262
|
export function Article({ html }: { html: string }) {
|
|
228
|
-
|
|
263
|
+
const clean = sanitizeHtml(html);
|
|
264
|
+
return <div dangerouslySetInnerHTML={{ __html: clean }} />;
|
|
229
265
|
}
|
|
230
266
|
```
|
|
@@ -97,7 +97,8 @@ watch(() => props.id, (id) => run(id), { immediate: true });
|
|
|
97
97
|
- `abort()` stops a run in progress; `reset()` goes back to `Idle` from `Ready`, `Failed` or a
|
|
98
98
|
run in progress, and clears `panic`. Use `reset()` to dismiss an answer or an error.
|
|
99
99
|
- The work takes the task's `signal` and passes it to the request; with the idiomatic layer on,
|
|
100
|
-
`unused-task-signal` reports a task that never reads it
|
|
100
|
+
`unused-task-signal` reports a task that never reads it while calling something that could
|
|
101
|
+
take it (a navigation, which takes none, isn't reported).
|
|
101
102
|
- Write `<Match :value="...">`. The older `:on` still works at runtime but fails vue-tsc
|
|
102
103
|
(TS2345: Vue reads a prop named `on…` as an event listener).
|
|
103
104
|
|
|
@@ -108,11 +109,11 @@ failure has nowhere to go (`vue-ref-without-value`).
|
|
|
108
109
|
|
|
109
110
|
```vue bad vue-ref-without-value
|
|
110
111
|
<script setup lang="ts">
|
|
111
|
-
import { onMounted,
|
|
112
|
+
import { onMounted, shallowRef } from "vue";
|
|
112
113
|
import { isErr } from "@evobug_com/safe-ts-std/result";
|
|
113
114
|
import { fetchOrders, type Order } from "./api";
|
|
114
115
|
|
|
115
|
-
const orders =
|
|
116
|
+
const orders = shallowRef<readonly Order[]>();
|
|
116
117
|
|
|
117
118
|
onMounted(async () => {
|
|
118
119
|
const result = await fetchOrders();
|
|
@@ -161,7 +162,8 @@ the old list must stay on screen, keep the last answer next to the task.
|
|
|
161
162
|
```vue good
|
|
162
163
|
<script setup lang="ts">
|
|
163
164
|
import { onMounted, shallowRef, watch } from "vue";
|
|
164
|
-
import {
|
|
165
|
+
import { variant } from "@evobug_com/safe-ts-std/enum";
|
|
166
|
+
import { Match } from "@evobug_com/safe-ts-vue/match";
|
|
165
167
|
import { AsyncState } from "@evobug_com/safe-ts-vue/state";
|
|
166
168
|
import { useTask } from "@evobug_com/safe-ts-vue/task";
|
|
167
169
|
import { fetchOrders, type Order } from "./api";
|
|
@@ -178,8 +180,11 @@ onMounted(() => run());
|
|
|
178
180
|
</script>
|
|
179
181
|
|
|
180
182
|
<template>
|
|
181
|
-
<
|
|
182
|
-
|
|
183
|
+
<Match :value="state">
|
|
184
|
+
<template #Loading>Refreshing…</template>
|
|
185
|
+
<template #Failed>Couldn't refresh the orders.</template>
|
|
186
|
+
<template #_></template>
|
|
187
|
+
</Match>
|
|
183
188
|
<ul>
|
|
184
189
|
<li v-for="order in shown" :key="order.id">{{ order.total }}</li>
|
|
185
190
|
</ul>
|
|
@@ -221,7 +226,8 @@ async function save(): Promise<void> {
|
|
|
221
226
|
```vue good
|
|
222
227
|
<script setup lang="ts">
|
|
223
228
|
import { ref } from "vue";
|
|
224
|
-
import { is
|
|
229
|
+
import { is } from "@evobug_com/safe-ts-std/enum";
|
|
230
|
+
import { Match } from "@evobug_com/safe-ts-vue/match";
|
|
225
231
|
import { AsyncState } from "@evobug_com/safe-ts-vue/state";
|
|
226
232
|
import { useTask } from "@evobug_com/safe-ts-vue/task";
|
|
227
233
|
import { saveDraft } from "./api";
|
|
@@ -233,7 +239,10 @@ const { state: saving, run: save } = useTask((signal, draft: string) => saveDraf
|
|
|
233
239
|
<template>
|
|
234
240
|
<textarea v-model="text" />
|
|
235
241
|
<button :disabled="is(saving, AsyncState.Loading)" @click="save(text)">Save</button>
|
|
236
|
-
<
|
|
242
|
+
<Match :value="saving">
|
|
243
|
+
<template #Failed="{ error }">Couldn't save: {{ error.message }}</template>
|
|
244
|
+
<template #_></template>
|
|
245
|
+
</Match>
|
|
237
246
|
</template>
|
|
238
247
|
```
|
|
239
248
|
|
|
@@ -275,6 +284,31 @@ watch(() => props.id, (id) => run(id), { immediate: true });
|
|
|
275
284
|
</template>
|
|
276
285
|
```
|
|
277
286
|
|
|
287
|
+
```vue good
|
|
288
|
+
<script setup lang="ts">
|
|
289
|
+
import { watch } from "vue";
|
|
290
|
+
import { Match } from "@evobug_com/safe-ts-vue/match";
|
|
291
|
+
import { useTask } from "@evobug_com/safe-ts-vue/task";
|
|
292
|
+
import { fetchUser } from "./api";
|
|
293
|
+
|
|
294
|
+
const props = defineProps<{ id: string }>();
|
|
295
|
+
const { state, run } = useTask((signal, id: string) => fetchUser(id, signal));
|
|
296
|
+
|
|
297
|
+
watch(() => props.id, (id) => run(id), { immediate: true });
|
|
298
|
+
</script>
|
|
299
|
+
|
|
300
|
+
<template>
|
|
301
|
+
<Match :value="state">
|
|
302
|
+
<template #Idle></template>
|
|
303
|
+
<template #Loading>Loading…</template>
|
|
304
|
+
<template #Ready="{ value }">{{ value.name }}</template>
|
|
305
|
+
<template #Failed="{ error }">Couldn't load the user: {{ error.message }}</template>
|
|
306
|
+
</Match>
|
|
307
|
+
</template>
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
When every variant shows the same element with different text, `match` in a `computed`:
|
|
311
|
+
|
|
278
312
|
```vue good
|
|
279
313
|
<script setup lang="ts">
|
|
280
314
|
import { computed, watch } from "vue";
|
|
@@ -346,7 +380,9 @@ onMounted(() => input.value.focus());
|
|
|
346
380
|
A `ref` or `let` at the top of a composable file (or a plain `<script>` block) is one value for
|
|
347
381
|
every component and every test (`no-mutable-global`). `<script setup>` is per instance, so state
|
|
348
382
|
there is fine. For state many components share, the target is a Pinia setup store, or a
|
|
349
|
-
`createX()` provided at startup and read with `injectRequired` (Vue guide: State and props).
|
|
383
|
+
`createX()` provided at startup and read with `injectRequired` (Vue guide: State and props). A
|
|
384
|
+
module-level object is the same once a function changes it, however it reaches it: destructured,
|
|
385
|
+
iterated, or handed back by a getter (`getConfig().x = 1`, across files too).
|
|
350
386
|
|
|
351
387
|
```ts bad no-mutable-global
|
|
352
388
|
import { ref } from "vue";
|
|
@@ -380,7 +416,12 @@ export const useCounterStore = defineStore("counter", () => {
|
|
|
380
416
|
- A counter used to keep only the newest answer (`let latest = 0`, compared after an `await`)
|
|
381
417
|
is what `useTask` does: called in a setup store, a task belongs to the store's effect scope
|
|
382
418
|
and is aborted when the store is disposed. With the idiomatic layer on, `latest-wins-counter`
|
|
383
|
-
reports the hand-written counter, at module level or in a store's setup function.
|
|
419
|
+
reports the hand-written counter, at module level or in a store's setup function. Outside
|
|
420
|
+
Vue and React (a plain-DOM page, a worker), std's `latest(...)` (`@evobug_com/safe-ts-std/async`)
|
|
421
|
+
is the same without the state: each `run(...)` aborts the older run's `signal`, and an older
|
|
422
|
+
run resolves to `err(Superseded)`. Create it in the function that mounts the screen, with the
|
|
423
|
+
page's signal: a module-level one is one run in progress for every caller, and
|
|
424
|
+
`no-mutable-global` reports it.
|
|
384
425
|
- Readers outside components that imported the old module-level `ref` can read a module-level
|
|
385
426
|
`computed(() => useXStore().value)` bridge while they migrate (Vue guide: State and props).
|
|
386
427
|
- Two modules that must not import each other but need an event between them (a list that
|
|
@@ -521,16 +562,25 @@ written-out URL that `safeHref` would refuse (`safeHref('flow://watch')` without
|
|
|
521
562
|
## A Result returned to Vue
|
|
522
563
|
|
|
523
564
|
Vue drops what a handler returns, so `@click="publish"` with a `Result` loses the error
|
|
524
|
-
(`must-use-result`). The
|
|
565
|
+
(`must-use-result`). The component's state is one `Enum` that names every state, the first
|
|
566
|
+
included (`Editing`, `Rejected` with a named error, `Published`), and `<Match>` shows each: no
|
|
567
|
+
`""` for "no problem", no message built in the handler, and not an `Option` of the error,
|
|
568
|
+
whose `undefined` would mean both "not tried yet" and "published".
|
|
525
569
|
|
|
526
570
|
```vue bad must-use-result
|
|
527
571
|
<script setup lang="ts">
|
|
572
|
+
import { constructors, type Enum } from "@evobug_com/safe-ts-std/enum";
|
|
528
573
|
import { err, type Result } from "@evobug_com/safe-ts-std/result";
|
|
529
574
|
|
|
575
|
+
type PublishError = Enum<{ Empty: {}; TooLong: { max: number } }>;
|
|
576
|
+
const PublishError = constructors<PublishError>();
|
|
577
|
+
|
|
530
578
|
const props = defineProps<{ draft: string }>();
|
|
531
579
|
|
|
532
|
-
function publish(): Result<void,
|
|
533
|
-
|
|
580
|
+
function publish(): Result<void, PublishError> {
|
|
581
|
+
if (props.draft === "") return err(PublishError.Empty());
|
|
582
|
+
if (props.draft.length > 280) return err(PublishError.TooLong({ max: 280 }));
|
|
583
|
+
return undefined;
|
|
534
584
|
}
|
|
535
585
|
</script>
|
|
536
586
|
|
|
@@ -541,21 +591,48 @@ function publish(): Result<void, string> {
|
|
|
541
591
|
|
|
542
592
|
```vue good
|
|
543
593
|
<script setup lang="ts">
|
|
544
|
-
import {
|
|
545
|
-
import {
|
|
594
|
+
import { shallowRef } from "vue";
|
|
595
|
+
import { constructors, type Enum } from "@evobug_com/safe-ts-std/enum";
|
|
596
|
+
import { err, isErr, type Result } from "@evobug_com/safe-ts-std/result";
|
|
597
|
+
import { Match } from "@evobug_com/safe-ts-vue/match";
|
|
546
598
|
|
|
547
|
-
|
|
599
|
+
type PublishError = Enum<{ Empty: {}; TooLong: { max: number } }>;
|
|
600
|
+
const PublishError = constructors<PublishError>();
|
|
548
601
|
|
|
549
|
-
|
|
550
|
-
|
|
602
|
+
type Publishing = Enum<{ Editing: {}; Rejected: { error: PublishError }; Published: {} }>;
|
|
603
|
+
const Publishing = constructors<Publishing>();
|
|
604
|
+
|
|
605
|
+
const props = defineProps<{ draft: string }>();
|
|
606
|
+
const emit = defineEmits<{ publish: [text: string] }>();
|
|
607
|
+
const state = shallowRef<Publishing>(Publishing.Editing());
|
|
608
|
+
|
|
609
|
+
function publish(): Result<void, PublishError> {
|
|
610
|
+
if (props.draft === "") return err(PublishError.Empty());
|
|
611
|
+
if (props.draft.length > 280) return err(PublishError.TooLong({ max: 280 }));
|
|
612
|
+
emit("publish", props.draft);
|
|
613
|
+
return undefined;
|
|
551
614
|
}
|
|
552
615
|
|
|
553
|
-
|
|
616
|
+
function onPublish(): void {
|
|
617
|
+
const published = publish();
|
|
618
|
+
state.value = isErr(published) ? Publishing.Rejected({ error: published.error }) : Publishing.Published();
|
|
619
|
+
}
|
|
554
620
|
</script>
|
|
555
621
|
|
|
556
622
|
<template>
|
|
557
|
-
<
|
|
558
|
-
|
|
623
|
+
<Match :value="state">
|
|
624
|
+
<template #Editing>
|
|
625
|
+
<button @click="onPublish">Publish</button>
|
|
626
|
+
</template>
|
|
627
|
+
<template #Rejected="{ error }">
|
|
628
|
+
<button @click="onPublish">Publish</button>
|
|
629
|
+
<Match :value="error">
|
|
630
|
+
<template #Empty>Write something first.</template>
|
|
631
|
+
<template #TooLong="{ max }">Keep it under {{ max }} characters.</template>
|
|
632
|
+
</Match>
|
|
633
|
+
</template>
|
|
634
|
+
<template #Published>Published.</template>
|
|
635
|
+
</Match>
|
|
559
636
|
</template>
|
|
560
637
|
```
|
|
561
638
|
|
|
@@ -26,6 +26,13 @@ change can pass every gate and still be a minimal conversion.
|
|
|
26
26
|
|
|
27
27
|
## Architecture
|
|
28
28
|
|
|
29
|
+
- [ ] Findings were fixed at their cause ([fix-the-design.md](fix-the-design.md)): no guard,
|
|
30
|
+
default, `!` or extra branch at a reported line where a type, a single definition of the
|
|
31
|
+
set, a boundary parse or one owner of the state would rule the bug out. Each local fix
|
|
32
|
+
that remains has its reason in the hand-off report.
|
|
33
|
+
- [ ] A closed set that grew in this change (a new variant, phase, code or command) fails to
|
|
34
|
+
compile in every place that handles it: no `if` chain or `switch` on it ends in a silent
|
|
35
|
+
fallback.
|
|
29
36
|
- [ ] No new `loading` / `error` / `data` state: async work goes through `useTask`, shown with
|
|
30
37
|
`<Match>` or `match`.
|
|
31
38
|
- [ ] No `''`, `-1` or `0` meaning "none" or "no error"; no boolean sets that are one state.
|
|
@@ -26,25 +26,36 @@ prints it).
|
|
|
26
26
|
"strict": true,
|
|
27
27
|
"noUncheckedIndexedAccess": true,
|
|
28
28
|
"exactOptionalPropertyTypes": true,
|
|
29
|
-
// The prelude: Result, Option, q, match, ... without imports.
|
|
30
|
-
//
|
|
31
|
-
//
|
|
32
|
-
"
|
|
29
|
+
// The prelude: Result, Option, q, match, ... without imports. strict-lib: `unknown` where
|
|
30
|
+
// TypeScript's lib hands out `any` (JSON.parse, response.json(), Array.isArray, new Map()).
|
|
31
|
+
// Keep the entries the project already lists ("node", "vite/client"). With "typeRoots" set,
|
|
32
|
+
// add "node_modules" to it, or TypeScript can't find them (TS2688).
|
|
33
|
+
"types": ["@evobug_com/safe-ts-prelude", "@evobug_com/safe-ts-std/strict-lib"]
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
36
|
```
|
|
36
37
|
|
|
37
|
-
|
|
38
|
-
all read. Measure their error count first (`tsc --noEmit` with each
|
|
39
|
-
as part of the setup or the foundation step.
|
|
38
|
+
The flags and strict-lib go in from the first step, in the tsconfig that tsc, vue-tsc and a
|
|
39
|
+
type-aware oxlint all read. Measure their error count first (`tsc --noEmit` with each), and fix
|
|
40
|
+
those errors as part of the setup or the foundation step. strict-lib's errors are a value of
|
|
41
|
+
`JSON.parse`, `response.json()` or `Array.isArray` used unchecked: `validate<T>` in migrated
|
|
42
|
+
code; in a legacy file, the `any` written out (`const data: any = JSON.parse(raw)`) until it is
|
|
43
|
+
migrated. `safe-ts check` warns while the tsconfig doesn't load it, and for each of the flags
|
|
44
|
+
above left off (what each keeps true: docs/guide/adoption.md, "The tsconfig flags SAFE-TS relies
|
|
45
|
+
on").
|
|
46
|
+
|
|
47
|
+
For code Node runs itself (scripts, a server, `node --test`), its tsconfig also wants
|
|
48
|
+
`"verbatimModuleSyntax": true` and `"erasableSyntaxOnly": true`: Node's type stripping fails
|
|
49
|
+
to load a type imported without `type`, a parameter property, an `enum`. `safe-ts check`
|
|
50
|
+
doesn't ask for them.
|
|
40
51
|
|
|
41
52
|
## package.json
|
|
42
53
|
|
|
43
54
|
```jsonc
|
|
44
55
|
{
|
|
45
56
|
"scripts": {
|
|
46
|
-
"check:safe-ts": "safe-ts check src
|
|
47
|
-
"check:safe-ts:summary": "safe-ts check src
|
|
57
|
+
"check:safe-ts": "safe-ts check src --deny-warnings --baseline safe-ts-baseline.json",
|
|
58
|
+
"check:safe-ts:summary": "safe-ts check src --summary",
|
|
48
59
|
"check:architecture": "node scripts/census.mjs --baseline safe-ts-census.json",
|
|
49
60
|
"census": "node scripts/census.mjs"
|
|
50
61
|
},
|
|
@@ -57,11 +68,17 @@ as part of the setup or the foundation step.
|
|
|
57
68
|
```
|
|
58
69
|
|
|
59
70
|
- `safe-ts` is the command of `@evobug_com/safe-ts-native`, which the transform and the oxlint
|
|
60
|
-
plugin bring. Give `check` the
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
71
|
+
plugin bring. Give `check` the source directories: each file under one is an entry, so
|
|
72
|
+
tests, scripts and workers whose path is built at runtime are checked too
|
|
73
|
+
(`safe-ts check src scripts --deny-warnings`). With file entries instead (it follows relative
|
|
74
|
+
imports, tsconfig `paths` aliases, workspace packages, workers and `import()` from them), it
|
|
75
|
+
names the files under their directories that nothing reached, as warnings. Several apps in a
|
|
76
|
+
monorepo: all their directories or entries in one run.
|
|
77
|
+
- `--baseline safe-ts-baseline.json` fails the run when an escape hatch (`unsafe`, `trust`,
|
|
78
|
+
`@ts-expect-error`, ...), a weakened rule or setting (`infer`, `testRunners`, ...), a file not
|
|
79
|
+
checked, an unresolved import or a rule's warnings rose, or a setting got weaker than it was
|
|
80
|
+
(`"idiomatic"` off, a pack out of `"features"`). Write it with `--write-baseline safe-ts-baseline.json` in the setup
|
|
81
|
+
step, and again only for a reviewed exception.
|
|
65
82
|
- `--deny-warnings` makes warnings fail the run: the idiomatic rules and the cost rules are
|
|
66
83
|
warnings, and without it a run with only warnings exits 0. While an area burns a count down,
|
|
67
84
|
`--max-warnings <n>` holds it at `n`.
|
|
@@ -72,8 +89,8 @@ as part of the setup or the foundation step.
|
|
|
72
89
|
project (they import each other by relative path).
|
|
73
90
|
- Rule levels: `"rules": { "stable-shape": "error" }` and `"overrides": [{ "files":
|
|
74
91
|
["src/generated/**"], "rules": { "no-null": "off" } }]`. Each `"off"` or `"warn"` is an
|
|
75
|
-
exception in the architecture document
|
|
76
|
-
instead.
|
|
92
|
+
exception in the architecture document (`check` names each one, and `--baseline` fails on a
|
|
93
|
+
new one); a count to burn down is ratcheted by the census instead.
|
|
77
94
|
- Feature packs: the browser pack for browser code, `@evobug_com/safe-ts-feature-node` for Node,
|
|
78
95
|
and the packs for the libraries the code uses (Libraries and feature packs). A pack turns
|
|
79
96
|
each unhandled call of its library into a finding, so an existing app gains findings when one
|
|
@@ -182,7 +199,8 @@ changing code, and follow it over habits from other projects.
|
|
|
182
199
|
- Closed sets are `Enum`s with `constructors`; read them with `match`, `is`, `variant` (and
|
|
183
200
|
`<Match :value="...">` in templates). No raw `.tag ===`. No `''`, `-1` or `0` meaning "none".
|
|
184
201
|
- Outside data goes through `validate<T>` / `parseJson<T>` or a feature pack's safe version. No
|
|
185
|
-
`as
|
|
202
|
+
`as`, no hand-written `value is T` guards (`no-type-predicate`) and no overloads over a looser
|
|
203
|
+
implementation (`no-overload`). A trusted boundary inside the program is
|
|
186
204
|
`trust<T>(value)`, listed in the architecture document.
|
|
187
205
|
- Wire-keyed tables: `getOwn(table, key, fallback)`; a server field from a list that can grow is
|
|
188
206
|
`Open<K>`, read with `match` and `lookup`. Base64: `toBase64` / `fromBase64` (`btoa` only of
|
|
@@ -190,12 +208,13 @@ changing code, and follow it over habits from other projects.
|
|
|
190
208
|
- Request bodies that change a record are `Patch<T>` (`keep`, `clear`, a value).
|
|
191
209
|
- Markup is `Html` (from the sanitizer declared with `defineSanitizer` in <module>), URLs are
|
|
192
210
|
`SafeUrl` (from `safeHref`); never `as Html`. Test numbers and strings explicitly
|
|
193
|
-
(`count > 0`, `name !== ""`), not for truth
|
|
211
|
+
(`count > 0`, `name !== ""`), not for truth; a value that may be `undefined` gets both halves
|
|
212
|
+
(`name !== undefined && name !== ""`), never `name !== ""` alone.
|
|
194
213
|
- Optional keys under `exactOptionalPropertyTypes`: `...(x === undefined ? {} : { x })`.
|
|
195
214
|
- No module state: Pinia setup stores (Vue) or provided contexts.
|
|
196
215
|
- Escape hatches (`unsafe`, `unsafeAsync`, `panic`, `trust`, `LegacyNull`, `void`, casts,
|
|
197
|
-
`safe-ts-ignore`, legacy markers, rule levels) follow
|
|
198
|
-
a reason. A line that must stay as it is: `// safe-ts-ignore <rule>: <reason>`. A file not
|
|
216
|
+
`safe-ts-ignore`, `@ts-expect-error`, legacy markers, rule levels) follow
|
|
217
|
+
docs/safe-ts-architecture.md, each with a reason. Never `@ts-ignore` or `@ts-nocheck`. A line that must stay as it is: `// safe-ts-ignore <rule>: <reason>`. A file not
|
|
199
218
|
migrated yet: `// @safe-ts legacy`. Never a new one without a line in the exception list.
|
|
200
219
|
- Tests use `fixture`, `testDouble`, `unchecked` and `expectPresent` from
|
|
201
220
|
`@evobug_com/safe-ts-std/testing`, not casts.
|
|
@@ -220,7 +239,13 @@ changing code, and follow it over habits from other projects.
|
|
|
220
239
|
- features: useTask <n> → <n>, Enum ..., match ..., <Match> ..., q ...
|
|
221
240
|
- idiomatic findings: prefer-is-over-tag <n> → <n>, prefer-q ..., no-swallowed-error ..., ...
|
|
222
241
|
- escape hatches: unsafe <n> (each with its reason), panic <n>, trust <n>, LegacyNull <n>,
|
|
223
|
-
safe-ts-ignore <n>, void <n>, casts <n>
|
|
242
|
+
safe-ts-ignore <n>, @ts-expect-error <n>, void <n>, casts <n>; weakened: <none, or each>
|
|
243
|
+
|
|
244
|
+
## Causes removed
|
|
245
|
+
- <the class of bug>: <the design that rules it out> (cleared: <rule> <n>, <pattern> <n>)
|
|
246
|
+
e.g. "an empty id passed as a real one: `Option<UnitId>`, made only by `parseUnitId`
|
|
247
|
+
(cleared: strict-truthiness 14, empty-string-sentinel 9)"
|
|
248
|
+
- local fixes, each with why the cause is local: <file:line>: <why>
|
|
224
249
|
|
|
225
250
|
## Changed signatures (callers in other areas must be checked)
|
|
226
251
|
- `useIssueStore().rename`: now `Promise<Result<void, RequestError>>` (was rejecting)
|