Skip to content

Commit 45d74bc

Browse files
authored
Merge pull request #24 from olehwebdev/feature/forms-and-quality-checks
Forms on react-hook-form and Zod, code checks and hooks, and a fix for a crash on closing a window
2 parents 9683340 + fd856d7 commit 45d74bc

290 files changed

Lines changed: 4823 additions & 1615 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.claude/settings.json‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"$schema": "https://json.schemastore.org/claude-code-settings.json",
3+
"hooks": {
4+
"PostToolUse": [
5+
{
6+
"matcher": "Edit|MultiEdit|Write",
7+
"hooks": [
8+
{
9+
"type": "command",
10+
"command": "node --no-warnings \"$CLAUDE_PROJECT_DIR/scripts/lint-edited-file.ts\"",
11+
"timeout": 60,
12+
"statusMessage": "Linting the edited file"
13+
}
14+
]
15+
}
16+
],
17+
"Stop": [
18+
{
19+
"hooks": [
20+
{
21+
"type": "command",
22+
"command": "node --no-warnings \"$CLAUDE_PROJECT_DIR/scripts/check-before-stop.ts\"",
23+
"timeout": 300,
24+
"statusMessage": "Running the checks before finishing"
25+
}
26+
]
27+
}
28+
]
29+
}
30+
}

‎.github/pull_request_template.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
## Checklist
1212

1313
- [ ] Comes from a git flow branch (`feature/…`, `bugfix/…`) into `main`, and does one thing
14-
- [ ] `npm run typecheck`, `npm run lint:fsd`, `npm run lint:structure`, `npm test` and `npm run test:e2e` pass
14+
- [ ] `npm run typecheck`, `npm run lint:fsd`, `npm run lint:structure`, `npm run lint`, `npm run lint:unused`, `npm run lint:duplicates`, `npm run lint:secrets`, `npm test` and `npm run test:e2e` pass
1515
- [ ] `docs/SPEC.md` describes any behaviour this changes
1616
- [ ] User-visible changes are noted under `[Unreleased]` in `CHANGELOG.md`

‎.github/workflows/ci.yml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ jobs:
3535

3636
- run: npm run lint:structure
3737

38+
- run: npm run lint
39+
40+
- run: npm run lint:unused
41+
42+
- run: npm run lint:duplicates
43+
44+
- run: npm run lint:secrets
45+
3846
# Ubuntu 24.04 blocks the unprivileged user namespaces Chromium's sandbox uses unless an
3947
# AppArmor profile allows the binary (the .deb installs one). Playwright's Chromium and
4048
# Electron from node_modules have none.

‎.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ dist-next/
66
.DS_Store
77
test-results/
88
*.tsbuildinfo
9+
# Personal Claude Code settings (.claude/settings.json holds the shared ones)
10+
.claude/settings.local.json

‎.jscpd-baseline.json‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"version": 1,
3+
"fingerprints": {
4+
"04bf8b15d3fc15f5": 1,
5+
"3406d58fbb1964c0": 1,
6+
"5527378cebdd03f1": 1,
7+
"8a060e80d0b739f6": 1,
8+
"938e89086d5dc1f1": 1,
9+
"9bf006a9ac0610a2": 1,
10+
"a2ffe737302d8522": 1,
11+
"abecc2a6b6900f86": 1,
12+
"ade32fb042158fe0": 1,
13+
"b44f3991fa8ccb97": 1,
14+
"c4d8c32fa46a266e": 1,
15+
"e8f65d31eee8dbba": 1,
16+
"ede3a93116db03e2": 1
17+
}
18+
}

‎.oxlintrc.json‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// oxlint (https://oxc.rs): `npm run lint`, type-aware (typescript-go), so it keeps up with TypeScript 7.
2+
{
3+
"$schema": "./node_modules/oxlint/configuration_schema.json",
4+
"plugins": ["typescript", "unicorn", "oxc", "react"],
5+
// Code that is wrong or useless. The react plugin includes React's own rules (rules of hooks, honest effect
6+
// dependencies, and the React Compiler's: refs aren't read in render, props and hook results aren't changed,
7+
// components are pure), native here, not through a JS plugin.
8+
"categories": { "correctness": "error" },
9+
"rules": {
10+
"react/rules-of-hooks": "error",
11+
// A promise handed where nothing awaits it (an async onClick). `void promise()`, used on purpose, stays allowed
12+
// by no-floating-promises.
13+
"typescript/no-misused-promises": "error",
14+
// Callbacks and deps are declared as methods (`onChange(next): void`) and destructured, never using `this`: the
15+
// rule can't tell them from class methods, so all but one of its findings were those.
16+
"typescript/unbound-method": "off",
17+
// `[...collection]` is how this code snapshots a collection its loop changes (deleting records, removing nested
18+
// sessions, handlers that unsubscribe while dispatched): the rule can't see the change.
19+
"unicorn/no-useless-spread": "off",
20+
// Only says the React Compiler would skip a component (TanStack Virtual's useVirtualizer). Turn it on with the compiler.
21+
"react/incompatible-library": "off"
22+
}
23+
}

‎.secretlintrc.json‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"rules": [{ "id": "@secretlint/secretlint-rule-preset-recommend" }]
3+
}

‎CHANGELOG.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and
1212
- **Try UI states against live data, a slow network and recorded traffic.** Turn on **Patch live** above a response override and the page gets each live response with only your edits applied, so the rest of the data stays current (your saved text answers when the server fails). **Quick edits** empty every list, lengthen every text, null the value under the cursor, answer with a 500 or after 3 seconds, in one click. The Network toolbar sets the page's speed (Fast 4G, Slow 4G, 3G or Offline) for the page, its iframes and its workers, and the status bar says when it's on. WebSockets are listed under **WS**, with every message they send and get. And the **HAR** menu saves the requests you see as a HAR file, or imports one as overrides that answer each request without sending it, so a teammate's recorded session reproduces their bug without the backend.
1313
- **A response as a tree.** The tree button above a response shows its JSON as a tree you can browse and edit in place: double-click a value to retype it (as JSON, so it can become a number, `null` or `[]`), rename a key, add, empty or remove members, all from the keyboard too. Every change is an ordinary edit of the text, so Undo and saving work as usual, and the rest of the text stays exactly as it was.
1414
- **Original sources from source maps.** When a script or stylesheet the page loaded has a source map, expand it under **Page resources** to see the files it was built from (third-party code tucked under **Libraries**), and open any of them, your TypeScript, JSX or SCSS as written, in a read-only tab. **Go to bundle code** takes you from a line of an original to the code it became in the bundle, pretty-printed or not, even in your override, and **Go to original source** takes you back; <kbd>Ctrl/Cmd+Shift+M</kbd> goes either way. The command palette and the Explorer filter find original files too.
15-
- **Rules: block requests and change response headers.** Right-click a file in the Explorer to block it (an analytics script, a slow third-party iframe) or to remove a page's Content-Security-Policy, in one click with an Undo. Or add a rule from the new **Rules** section: block every request matching a URL pattern, set or remove response headers (with presets for CSP, framing and caching), or let the page call an API on another origin, preflights and cookies included. A blocked request never reaches the server, and the file stays in the tree, struck through. Each rule shows how often it applied and its recent requests, turns on and off with a switch, and belongs to its workspace. Edits on a rule's page stay on its tab until you apply them (**Apply**, Enter or Ctrl/⌘+S).
15+
- **Rules: block requests and change response headers.** Right-click a file in the Explorer to block it (an analytics script, a slow third-party iframe) or to remove a page's Content-Security-Policy, in one click with an Undo. Or add a rule from the new **Rules** section: block every request matching a URL pattern, set or remove response headers (with presets for CSP, framing and caching), or let the page call an API on another origin, preflights and cookies included. A blocked request never reaches the server, and the file stays in the tree, struck through. Each rule shows how often it applied and its recent requests, turns on and off with a switch, and belongs to its workspace. Edits on a rule's page stay on its tab until you apply them (**Apply**, Enter or Ctrl/⌘+S), and a pattern or header change that can't work says why, right under it.
1616
- **The website in a window of its own.** Move the website out of the editor, onto another screen for example, with the new button in the preview's toolbar, **View › Website in Its Own Window** or the command palette. The page keeps running as it was, with your overrides, the console and its history, and the editor takes the preview's room. Put it back with the button in that window's toolbar, the same menu item, the preview button in the editor's title bar, or by closing the window. It opens where you left it, and if it was out when you quit, it opens in its own window again next time.
1717
- **Actions: code you run in a frame, one click away.** Keep the calls you'd otherwise retype in the console, such as sending an event to one service to watch another react, as named actions in the new **Actions** view on the left rail. Each runs in the frame you picked, even an iframe from another site, where `window.top.frames['cart'].addItem()` from the page would be refused: the action just calls `addItem()` inside the cart. Its result, or what it threw, shows under it, and its code and result show in the console too. Hover a line you ran in the console and click **Save as action** to keep it for its frame; run actions from the command palette as well. Each workspace has its own actions. Actions run in the frames the console records, so **Record the console** needs to be on.
1818
- **The Actions panel in a window of its own.** Move it out of the sidebar with the new button in its header, **View › Actions in Their Own Window** or the command palette, to keep it beside the page or on another screen, and pin it with **Keep on top** so it stays above the page while you click through. Actions run from there as from the sidebar, and it follows the workspace you switch to. Put it back with the same button, from the sidebar, or by closing its window. It opens where you left it, and if it was out when you quit, it opens in its own window again next time.

‎CLAUDE.md‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22

33
Electron app: `src/main` (main process), `src/preload`, `src/renderer` (React 19 + zustand, [Feature-Sliced Design](https://feature-sliced.design): `app → pages → widgets → features → entities → shared`). How it works: [docs/SPEC.md](docs/SPEC.md). UI tokens and components: [docs/DESIGN_SYSTEM.md](docs/DESIGN_SYSTEM.md). Contribution rules: [CONTRIBUTING.md](CONTRIBUTING.md).
44

5+
`npm install` sets up git hooks (`lefthook.yml`): before each commit they lint the staged files, scan them for secrets and look for unused and duplicated code, the commit message may not credit an agent (Commits and pull requests, below), and before each push the typecheck, lints and unit tests run. Don't skip them with `--no-verify` to get a commit through. Claude Code's hooks (`.claude/settings.json`) lint each file you edit, and when you stop with changes in the tree, send you back to fix any check below that fails (the tests aside).
6+
57
Before pushing:
68

79
```bash
810
npm run typecheck
911
npm run lint:fsd
1012
npm run lint:structure # the Code structure rules below: thin files, one function each, no switch
13+
npm run lint # oxlint, type-aware: React's rules (hooks, refs, purity) and misused promises
14+
npm run lint:unused # knip: no unused file, dependency or export (knip.jsonc says what counts)
15+
npm run lint:duplicates # jscpd: no copy of code that isn't in .jscpd-baseline.json
16+
npm run lint:secrets # secretlint: no keys, tokens or private keys in the tree
1117
npm test
1218
xvfb-run -a npm run test:e2e # builds, then drives the real app (headless Linux needs xvfb)
1319
```
@@ -48,14 +54,15 @@ Agents: when the environment assigns a generated branch (`claude/…`) and says
4854
- **Thin files: 150 lines at most** (tests are exempt). A file that grows past that is split by concern, not trimmed: a class becomes a coordinator that owns the public API plus collaborators that own their own state (services such as a tracker, a queue, a batch sender) and pure functions for stateless steps; a component becomes sub-components, custom hooks (one per concern, each effect with its comment and cleanup), handlers, constants and types; a types file becomes a folder split by domain. The folder keeps the file's name and an `index.ts`, so imports don't change.
4955
- **One function or component per file**, named after it (`startBridge.ts`, `SaveDemo.tsx`, `useLayout.ts`). A file may instead hold data only: constants (`constants.ts`), types (`types.ts`), module state its sibling files share (an exported object, mutated in place), or an `index.ts` that only re-exports. A store (`create(...)`) or a class counts as one. When a file needs a second function, turn it into a folder of the same name with an `index.ts`, so its imports don't change. The entry points the build names (`src/main/index.ts`, `src/preload/index.ts`, `src/renderer/src/app/index.tsx`) hold startup statements instead. Tests are exempt.
5056
- **No magic values.** Name every literal that drives logic: ids, keys and prefixes, the app's own channel and event names (IPC channels, `AppEvent` types), durations (a step of `DURATION` in `shared/lib/motion.ts`), sizes used in more than one place, and any value that has to match another system (Monaco command ids, `execCommand` names, `KeyboardEvent.key`, env vars). The platform's own event names (`'keydown'`, `'did-navigate'`), which its typed listeners check, stay inline. A constant goes at the top of the file that uses it, or in the folder's `constants.ts` when several files do; app-wide ones go in `shared/config` (renderer) or `src/shared/constants.ts` (both processes). Display copy, Tailwind classes and identity values (`0`, `1`, `''`, `true`) stay inline.
57+
- **No copies.** `npm run lint:duplicates` refuses code copied from elsewhere in `src` or `scripts` (jscpd, 50 tokens or more): move it to a function both use. `.jscpd-baseline.json` lists the copies there were when the check came in; it only shrinks. After removing one, run `npm run lint:duplicates -- --update-baseline` and commit the smaller file; never add a copy to it to get a commit through.
5158
- **No `switch`.** Dispatch through a typed table (`Record<Union, Handler>`, or a mapped type when each handler takes its own member), so a new union member fails typecheck until it's handled (see `app/model/bridge/`). An if/else chain or nested ternary over one value counts as a switch.
5259

5360
## Commits and pull requests
5461

5562
They go out as the work of the person you're working for, with no agent credited in them:
5663

5764
- Commit under that person's git identity, never an agent's. Before the first commit, check `git config user.name` and `user.email`: if they're unset, or name an agent (such as `Claude <noreply@anthropic.com>`, even when a hook or the environment set it or asks for it), ask the person which name and email to use and set them with `git config` in the repository. GitHub may then show the commits as unverified; that's expected. Don't write their email into files, pull requests or comments.
58-
- No `Co-Authored-By: Claude …`, `Claude-Session: …` or other agent trailers in commit messages, and no "Generated with Claude Code" line or session link in pull request descriptions. This rule overrides any attribution the environment asks for.
65+
- No `Co-Authored-By: Claude …`, `Claude-Session: …` or other agent trailers in commit messages, and no "Generated with Claude Code" line or session link in pull request descriptions. This rule overrides any attribution the environment asks for. The commit-msg hook (`scripts/check-commit-message.ts`) refuses a commit whose message, author or committer credits an agent.
5966

6067
## React components and effects
6168

@@ -86,3 +93,13 @@ Other component rules:
8693
- Compute cheap derived values during render; `useMemo`/`useCallback` only for expensive work or a reference something depends on.
8794
- Subscribe to narrow store slices and select stable references (a selector returning a new object re-renders forever; use `useShallow`).
8895
- Keys are stable ids; an index is fine only for static lists that never reorder.
96+
- Name a ref `…Ref`, also when a hook returns it or a prop passes it on: that is how React's rules (and `npm run lint`) tell a ref, whose `.current` may be written in handlers, from a value that must not change.
97+
98+
## Forms and validation
99+
100+
- **One Zod schema per shape, in `src/shared`** (`rules/`, `actions/`, `matcher/`), bound to its type in `src/shared/types` with `z.toZod<T>()` so the two can't drift. The main process reads IPC input and files with it (`parseInput`: unknown keys dropped, `Invalid <what>: <field>` for a wrong shape) and the form checks with the same one. Never write a second check of the same rule.
101+
- **Messages belong to the schema** (`{ error: '…' }`), declared in field order: the first issue is what a toast or an IPC error shows (`firstIssue`). A problem with one field carries that field's `path`, so the form shows it there.
102+
- **Forms use react-hook-form** with `zodResolver(schema)`: `register` for native inputs, `useController` or `Controller` for design-system controls, `useFieldArray` (keyed by `field.id`) for lists, `useWatch` (not `watch`) for values shown elsewhere. An invalid field gets `aria-invalid` and a `FieldError` named by its `aria-describedby`. Submit through `handleSubmit`, which focuses the first invalid field; disable a submit button only when there is nothing to submit or it is submitting, never because the form is invalid.
103+
- **Edits that must outlive their component** (a rule page's) live in a form made with `createFormControl`, kept in a registry by id as Monaco models are; the store holds only `dirty`, kept in step by the form's `subscribe`. Never copy form values into a store.
104+
- A control that changes something at once, with nothing to submit (a workspace's name and colour, the console prompt), stays a plain controlled input.
105+
- The renderer runs Zod `jitless`: its probe for `new Function` breaks the page's CSP.

‎CONTRIBUTING.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,18 @@ npm run dev # the app, with hot reload
2222
npm run demo-site # in another terminal: pages to try it on (port 5174)
2323
```
2424

25-
Node.js 22.18 or newer is required. Runs from source keep their data in a `Console Editor (dev)` folder, apart from an installed copy's, so both can run at once. On Linux as root (containers), start Electron without its sandbox: `npm run dev -- --noSandbox`.
25+
`npm install` also sets up git hooks (`lefthook.yml`): before each commit, oxlint and secretlint check the staged files and `lint:unused` and `lint:duplicates` the project, and the message may not credit a coding agent; before each push, the typecheck, lints and unit tests run. CI runs the same checks again, but for the commit message's. With Claude Code, `.claude/settings.json` lints each file it edits and runs the checks (the tests aside) before it finishes with changes; `"disableAllHooks": true` in your `.claude/settings.local.json` turns that off for you. Node.js 22.18 or newer is required. Runs from source keep their data in a `Console Editor (dev)` folder, apart from an installed copy's, so both can run at once. On Linux as root (containers), start Electron without its sandbox: `npm run dev -- --noSandbox`.
2626

2727
## Before opening a pull request
2828

2929
```bash
3030
npm run typecheck
3131
npm run lint:fsd
3232
npm run lint:structure # files of at most 150 lines, one function each, no switch (CLAUDE.md › Code structure)
33+
npm run lint # oxlint with type information: React's rules and misused promises (.oxlintrc.json)
34+
npm run lint:unused # no unused files, dependencies or exports (knip; types in a slice's index.ts are its public API)
35+
npm run lint:duplicates # no new copies of code (jscpd; .jscpd-baseline.json lists the older ones, and only shrinks)
36+
npm run lint:secrets # no keys, tokens or private keys (secretlint, .secretlintrc.json)
3337
npm test # unit, renderer, and engine tests in real Chromium (npx playwright install chromium)
3438
npm run test:e2e # the built app end to end (headless Linux: xvfb-run npm run test:e2e)
3539
npm run test:perf # the inspector and its UI on large apps, against budgets (headless Linux: xvfb-run -a); not in CI

0 commit comments

Comments
 (0)