Skip to content

Code standards

Every app turbobase apps init creates comes with @turbobase/code-standards, an open-source package (MIT, on npm) that checks your code the same way on every machine and formats it so nobody spends time on style. It is the same standard Turbobase’s own code is held to.

The checks look for the mistakes that compile, build and still break a screen:

  • a React hook called after an early return — the screen works until the record it was waiting for arrives, then crashes;
  • a promise nobody waited for, so an error is lost and a write can finish after the screen moved on;
  • an object with the same key written twice, where the first value is silently replaced;
  • code nothing uses any more, and the same block copied in two places inside your app.

Duplicates are counted inside your app only. Code that looks like another app’s is never a finding.

Command What it does
npm run check Reports every lint finding and every file not in the house format, and exits non-zero if there is one. Run it before you push.
npm run fix Applies every automatic fix and formats every file.

The house format is tabs, semicolons, single quotes and lines of up to 120 characters.

When Claude Code edits a file in your app, it is formatted straight away by a hook in .claude/settings.json. The hook uses the copy of the package installed in your project, never a download, and it never blocks an edit: before your first npm install it simply does nothing.

File What it holds
.oxlintrc.json The lint rules, extended from the package’s React profile.
oxfmt.config.ts The house format, re-exported from the package.
code-standards.json What counts as one unit for duplicates (your whole app) and which files are skipped.
code-standards.baseline.json The findings your app already had when it adopted the standard. A new app starts with an empty one. npm run check only fails on findings beyond it, and will not run without it.
knip.json Where the unused-code check starts looking: your app, plus your hooks, conduits and processes.

src/types.ts is skipped on purpose. turbobase project types writes it from your instance’s catalog and rewrites it every session, so a finding in it is not one you could fix. src/lib/turbobase.ts, the client your app talks to your instance through, is skipped for the same reason: it is ours, and an update replaces it.

After the first npm install, run npm run fix once to put every file in the house format; from then on npm run check passes until something new needs fixing.

The steps are in the release log, under For app developers — adopt these, and turbobase project adopt writes them into your project’s ADOPT.md, where Claude Code picks them up at the start of a session. In short:

  1. npm install -D @turbobase/code-standards.
  2. Add .oxlintrc.json, oxfmt.config.ts, code-standards.json and knip.json at the app’s root, as a new app has them, and remove baseUrl from your tsconfig.json.
  3. Add "check": "code-standards check" and "fix": "code-standards fix" to scripts in package.json. If you already have a check script, keep it and give these two other names.
  4. Run npm run fix once and commit the result on its own, so the formatting change is one commit you can skip past when reading history.
  5. Run npx code-standards baseline and commit code-standards.baseline.json. It records what your app already has, so the check passes today and fails only on something new.
  6. Run npm run check before every push. The baseline can only shrink: fix a finding, run baseline again, and commit the smaller file.