chore(lint): move the lint rules to ast-grep, set up Biome, and move to pnpm #10

Merged babariviere.com
targeting main from lint-tools
Merged opened by babariviere.com
targeting main from lint-tools

Summary #

One commit: the lint rules move from regexes in bash to ast-grep, Biome formats and lints the code, npm gives way to pnpm, and a test that broke just check on main gets a full snapshot.

+package.json          # pins @ast-grep/cli and @biomejs/biome (just install)
+pnpm-workspace.yaml   # the workspace: the lint tools and the Daemon
+app/pnpm-workspace.yaml, gallery/pnpm-workspace.yaml   # projects of their own, nodeLinker: hoisted
+sgconfig.yml          # .ts files read as TSX
+lint/rules/*.yml      # the 6 rules of scripts/lint.sh, one file each
+lint/tests/*-test.yml # good and bad samples for each rule
+biome.json            # 160 columns, recommended rules minus useTemplate
 scripts/lint.sh       # biome ci, ast-grep test, ast-grep scan, the geist check
 justfile              # pnpm everywhere, + fmt
 scripts/deploy.sh     # pnpm install for the App's copy, pnpm deploy --prod for the Daemon
just lint
  biome ci                         format, lint rules, order of imports
  ast-grep test                    each rule still finds its bad samples
  ast-grep scan                    the rules of DESIGN.md and ui/
  geist check                      App and gallery pin the same fonts
  • Rules now match code, not lines: a <Text> with class on its next line no longer slips through.
  • Biome is off for ui/icons.ts (copied from lucide), ui/theme.json and assets. useTemplate is off (the code joins strings with +), and useNodejsImportProtocol is off in the App, ui and the gallery (NSH's fs/promises and os are not Node's).
  • Biome's findings fixed: 2 unused imports, a comma operator in ListRows, ! in ReviewDiff, and a test regex whose . matched any character.

pnpm #

  • The workspace holds the lint tools (root package.json) and the Daemon. pnpm deploy --prod stages the Daemon's program for just deploy, with "files": ["src"].
  • The App and the gallery stay out of it. pnpm links packages to a store outside the app's folder, and nsh build refuses a font there ("is outside the app's directory"). So each is a pnpm project of its own, with nodeLinker: hoisted: plain folders, and the build works.
  • The .npmrc files' legacy-peer-deps becomes autoInstallPeers: false. allowBuilds lets only ast-grep run its install script.
  • On Linux, supportedArchitectures: { libc: [current, musl] } and publicHoistPattern install Biome's static musl build at the top of node_modules, so CI needs no extra step.

Evidence #

  • just lint on macOS: lint: ok.
  • In an x86 NixOS container, as CI runs it (nix-shell -p nodejs_22 pnpm just ripgrep bash ast-grep, pnpm 12.9.0): pnpm install --frozen-lockfile, just lint (lint: ok), the Daemon's type check, and the App's and the gallery's installs all pass.
  • just deploy's steps by hand: pnpm deploy --prod gives a Daemon whose modules load, and the App's copy installs and builds with nsh build. daemon/test/deploy.test.ts passes with a fake pnpm.
  • Every rule fires on a file with one violation of each, and the rules' samples pass:
app/zz.tsx:1:1: error[screens-no-nsh-base]
app/zz.tsx:2:17: error[screens-no-text-style]
app/zz.tsx:3:11: error[screens-no-badge]
app/zz.tsx:4:17: error[loader-spins]
app/zz.tsx:5:12: error[page-title]
app/zz.tsx:5:12: error[window-widths]
test result: ok. 6 passed; 0 failed;
  • just test: Daemon 38, App 25, gallery 15 pass.
  • just check passes. On main it failed on app/test/Chat.test.tsx:137, a snapshot without subscriptions: the test now starts from EMPTY_SNAPSHOT, as the others do.

Merge Danger #

Door: two-way

Blast Radius: CI

  • CI gets ast-grep from nixpkgs: the npm builds for Linux need a loader that NixOS has not, the musl one included. nixpkgs-unstable has the same 0.51.3. Biome comes from npm in its static musl build, at the pinned version. pnpm comes from nixpkgs (12.9.0).
  • just deploy now needs pnpm on the PATH, and says so when it is missing.
  • Biome reformats 35 files, so open branches conflict. Rebase, then run just fmt.
Commits 4

test(app): give the Markdown test a full snapshot
build: move from npm to pnpm, with a workspace for the lint tools and the Daemon
chore(lint): set up Biome, and format the code with it
chore(lint): move the lint rules to ast-grep
Sign up or Sign in to add to the discussion.