Skip to content

Commit 19d4d0f

Browse files
authored
Merge pull request #3 from btravers/docs-sync-removed-tomatchable
docs: sync to shipped APIs + fix format pre-commit hook
2 parents 1e9d789 + 27555e7 commit 19d4d0f

4 files changed

Lines changed: 34 additions & 19 deletions

File tree

CLAUDE.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,19 @@ Never pull `ts-pattern` or `vitest` into core.
158158
a zero-dependency exhaustive fold whose handler object is
159159
`{ Ok, Defect } & { [K in E["_tag"]]: (e: Extract<E, {_tag: K}>) => R }`.
160160
3.**`packages/vitest`** — Done. Custom matchers `toBeOk`, `toBeOkWith`,
161-
`toBeErr`, `toBeErrTagged`, `toBeDefect`, registered via `expect.extend` and
162-
augmenting Vitest's `Matchers` interface. They detect a thenable `AsyncResult`
163-
and await internally, so a test reads `await expect(asyncResult).toBeOk()`
164-
(the required `await` is documented loudly — a forgotten one passes silently).
165-
4.**`packages/pattern`** — Done. Thin `ts-pattern` integration: `tag(t)`
166-
sugar (the `{ _tag: t }` pattern, narrowing to the variant + payload) and
167-
`toMatchable(result)` exposing the ok/err/defect channels as a `_kind`
168-
discriminated union. Kept small — the power is ts-pattern's; `matchTags`
169-
covers the everyday exhaustive case.
161+
`toBeErr`, `toBeErrTagged` (optional second arg also matches the tagged
162+
error's payload — exact for a plain object, partial for an asymmetric matcher
163+
like `expect.objectContaining`), `toBeDefect`, registered via `expect.extend`
164+
and augmenting Vitest's `Matchers` interface. They detect a thenable
165+
`AsyncResult` and await internally, so a test reads
166+
`await expect(asyncResult).toBeOk()` (the required `await` is documented loudly
167+
— a forgotten one passes silently).
168+
4.**`packages/pattern`** — Done. Because `Result` is a discriminated union
169+
(Thesis #1 / Public surface), `ts-pattern` matches it natively — this package
170+
is thin sugar: pattern constructors `P.ok`/`P.err`/`P.defect` (returning the
171+
`{ tag: … }` object patterns) plus `tag(t)` (the `{ _tag: t }` pattern,
172+
narrowing to the variant + payload). Kept small — the power is ts-pattern's;
173+
`matchTags` covers the everyday exhaustive case.
170174

171175
Also shipped: a root `README` + `LICENSE`, per-package READMEs, and the VitePress
172176
docs site (guide + generated API reference). **Remaining work is manual** and

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ defect, so the edge of your program needs a single `match` and no `try`/`catch`.
7575

7676
## Packages
7777

78-
| Package | Description |
79-
| ----------------------------------------- | ------------------------------------------------------------------------------------------ |
80-
| [`unthrown`](./packages/core) | The core `Result` / `AsyncResult`, interop, `TaggedError`, `matchTags`. Zero runtime deps. |
81-
| [`@unthrown/vitest`](./packages/vitest) | Vitest matchers: `toBeOk`, `toBeOkWith`, `toBeErr`, `toBeErrTagged`, `toBeDefect`. |
82-
| [`@unthrown/pattern`](./packages/pattern) | Thin `ts-pattern` integration: `toMatchable`, `tag`. |
78+
| Package | Description |
79+
| ----------------------------------------- | ---------------------------------------------------------------------------------------------- |
80+
| [`unthrown`](./packages/core) | The core `Result` / `AsyncResult`, interop, `TaggedError`, `matchTags`. Zero runtime deps. |
81+
| [`@unthrown/vitest`](./packages/vitest) | Vitest matchers: `toBeOk`, `toBeOkWith`, `toBeErr`, `toBeErrTagged`, `toBeDefect`. |
82+
| [`@unthrown/pattern`](./packages/pattern) | Thin `ts-pattern` sugar for the natively-matchable `Result`: `P.ok`/`P.err`/`P.defect`, `tag`. |
8383

8484
## Contributing
8585

docs/api/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ This reference is generated from the source with
1212
`matchTags`).
1313
- [**@unthrown/vitest**](./vitest/) — custom Vitest matchers (`toBeOk`,
1414
`toBeOkWith`, `toBeErr`, `toBeErrTagged`, `toBeDefect`).
15-
- [**@unthrown/pattern**](./pattern/)the thin `ts-pattern` integration
16-
(`toMatchable`, `tag`).
15+
- [**@unthrown/pattern**](./pattern/) — thin `ts-pattern` sugar for the
16+
natively-matchable `Result` (`P.ok`/`P.err`/`P.defect`, `tag`).

lefthook.yml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,23 @@ pre-commit:
22
parallel: true
33
commands:
44
format:
5-
glob: "**/*.{ts,tsx,js,jsx,json,yaml,yml,md}"
6-
exclude: "pnpm-lock.yaml"
5+
# `*.x` (not `**/*.x`): lefthook's `*` spans `/`, so this matches files at
6+
# ANY depth including the repo root. `**/*.x` requires a leading directory,
7+
# so root files (`CLAUDE.md`, `README.md`, root `*.json`) silently never
8+
# matched and were never formatted on commit.
9+
glob: "*.{ts,tsx,js,jsx,json,yaml,yml,md}"
10+
# Mirror oxfmt's `ignorePatterns` (generated docs/api + vitepress output):
11+
# handing oxfmt ONLY ignored files makes it exit non-zero, which would fail
12+
# a commit touching only those. Excluding them here skips the step instead.
13+
exclude:
14+
- "pnpm-lock.yaml"
15+
- "docs/api/*"
16+
- "docs/.vitepress/cache/*"
17+
- "docs/.vitepress/dist/*"
718
run: pnpm oxfmt {staged_files}
819
stage_fixed: true
920
lint:
10-
glob: "**/*.{ts,tsx,js,jsx}"
21+
glob: "*.{ts,tsx,js,jsx}"
1122
run: pnpm oxlint {staged_files}
1223

1324
commit-msg:

0 commit comments

Comments
 (0)