diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 17b6408e..35c3f1e4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -166,7 +166,8 @@ jobs: - run: python3 scripts/ci/check_orb.py # The workflows and actions: actionlint (with shellcheck on their scripts) and zizmor (.github/zizmor.yml, with its - # online audits: impostor commits, actions with known vulnerabilities); and secrets in the commits this push or pull + # online audits on pull requests: impostor commits, actions with known vulnerabilities); the Dockerfiles (hadolint); + # spelling (typos), JS/TS (oxlint) and shell scripts (ShellCheck); and secrets in the commits this push or pull # request adds (Betterleaks, .betterleaks.toml). mise.toml pins the tools, and the pre-commit hook runs the same ones. security: runs-on: ubuntu-latest @@ -178,8 +179,12 @@ jobs: fetch-depth: 0 - uses: jdx/mise-action@924e7c586e33d7d4bae9c14e26c5d22e2beb6e78 # v5.3.0 with: - install_args: actionlint shellcheck zizmor betterleaks hadolint + install_args: actionlint shellcheck zizmor betterleaks hadolint typos oxlint - run: actionlint + # Spelling (_typos.toml), JS/TS lint (.oxlintrc.json) and every shell script (scripts/ci/shellcheck.sh). + - run: typos + - run: oxlint --deny-warnings . + - run: scripts/ci/shellcheck.sh # The renderer's two warnings (a `cd` and a pipe in the PDFBox download step) wait for its next rebuild: any edit # to renderer.Dockerfile rebuilds the renderer image (its inputs hash), so it isn't touched for lint alone. - run: hadolint docker/app.Dockerfile && hadolint --ignore DL3003 --ignore DL4006 docker/renderer.Dockerfile diff --git a/.oxlintrc.json b/.oxlintrc.json new file mode 100644 index 00000000..50304a52 --- /dev/null +++ b/.oxlintrc.json @@ -0,0 +1,18 @@ +// oxlint (JS/TS lint), run by the pre-commit hook and CI's security job with --deny-warnings. Turn a rule off for a +// file here only with the reason beside it. +{ + "$schema": "https://raw.githubusercontent.com/oxc-project/oxc/main/npm/oxlint/configuration_schema.json", + "ignorePatterns": ["**/node_modules/**", "**/dist/**", "**/dist-ssr/**", "**/dist-site/**", "target/**", "tmp/**"], + "overrides": [ + { + // The URL checks reject control characters (\x00-\x20, \x7f) on purpose. + "files": ["clients/gallery/js/src/model.ts"], + "rules": { "no-control-regex": "off" } + }, + { + // Sprockets needs its manifest to exist; this example's has only a comment. + "files": ["clients/gallery/ruby/examples/rails/app/assets/config/manifest.js"], + "rules": { "unicorn/no-empty-file": "off" } + } + ] +} diff --git a/AGENTS.md b/AGENTS.md index d87444ca..be1727ba 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -18,8 +18,10 @@ design is in `docs/design.md`; read it before changing the architecture, and upd live in the clone's shared `.git/hooks`, so its worktrees all get them; `lefthook.yml` lists them). The pre-commit hook runs the formatters on the staged files and stages what they change. CI has no format check (Nathan, 5 Dec 2026, sc-9611), so a commit made without the hooks lands unformatted: never commit with `--no-verify`. -- **Workflows and secrets are checked** by CI's `security` job and the pre-commit hook: actionlint, zizmor and - Betterleaks (mise.toml pins them). Pin every action by commit SHA with its version in a comment (`pinact run` does +- **Workflows, secrets, spelling, JS/TS and shell scripts are checked** by CI's `security` job and the pre-commit + hook: actionlint, zizmor, Betterleaks, typos (`_typos.toml`), oxlint (`.oxlintrc.json`) and ShellCheck + (`scripts/ci/shellcheck.sh`); mise.toml pins them. Allow a word or turn a lint rule off for a file only in those + files, with the reason beside it. Pin every action by commit SHA with its version in a comment (`pinact run` does it). Ignore a zizmor finding only inline (`# zizmor: ignore[audit]`) with the reason beside it; allow a made-up value in `.betterleaks.toml` only with a description of what it is. A real secret that reached a commit is revoked, not allowlisted. diff --git a/_typos.toml b/_typos.toml new file mode 100644 index 00000000..e4e5afde --- /dev/null +++ b/_typos.toml @@ -0,0 +1,36 @@ +# typos (spelling), run by the pre-commit hook (`typos -w` fixes what it's sure of) and CI's security job. Allow a +# word here only with the reason beside it. + +[default] +extend-ignore-re = [ + # Misspelled on purpose: tests and docs that check an unknown setting or field is caught (envschema's "did you + # mean", visualci.yml's unknown fields). + "APP_S3_REGOIN", + "APP_WAITLSIT", + "MYAPP_DATABSE_POOL", + "\"thresold\"", + "\"thresold: ", + # Possessives in Rust identifiers (close_the_branchs_builds, each_repositorys_collaborators); still typos in prose. + "\\w+_(branchs|repositorys)_\\w+", +] + +[files] +# Binary files: typos skips them when it walks the tree, but checks (and -w rewrites) any file named on the command +# line unless it's excluded here (the hook passes --force-exclude). +extend-exclude = ["*.png", "*.jpg", "*.jpeg", "*.gif", "*.webp", "*.ico", "*.pdf", "*.woff", "*.woff2", "*.ttf", "*.otf", "*.zip", "*.gz"] + +[default.extend-identifiers] +# The plural of PNG, which typos splits into PN + Gs. +PNGs = "PNGs" +# A PDF dictionary key (/DecodeParms). +DecodeParms = "DecodeParms" + +[default.extend-words] +# Postgres's block range index. +brin = "brin" +# PDF's /FlateDecode compression. +flate = "flate" +# Test text: "café" with the accent escaped. +caf = "caf" +# A correct spelling too. +unparseable = "unparseable" diff --git a/lefthook.yml b/lefthook.yml index d57529f5..10b7de2f 100644 --- a/lefthook.yml +++ b/lefthook.yml @@ -4,7 +4,9 @@ # Formatters fix what they find and stage the result (stage_fixed). CI has no format gate: formatting is never a # reason for a red build (Nathan, 5 Dec 2026, sc-9611). pre-commit: - parallel: true + # One at a time: rustfmt and typos both rewrite staged files (and stage them), and two fixers on one file at once + # would lose an edit. The whole hook takes a few seconds. + parallel: false commands: # Each file through stdin: given a path, rustfmt also formats (and must parse) every module file it declares, so # a half-written unstaged module would be rewritten or would refuse the commit. `cat >` keeps the file's mode. @@ -12,6 +14,17 @@ pre-commit: glob: "*.rs" run: for f in {staged_files}; do rustfmt --emit stdout <"$f" >"$f.fmt" && cat "$f.fmt" >"$f"; s=$?; rm -f "$f.fmt"; [ $s = 0 ] || exit 1; done stage_fixed: true + # Spelling: fixes what it's sure of and stages it; anything else fails until fixed or allowed in _typos.toml. + # --force-exclude: typos checks (and -w rewrites) every file it's given by name, images included, unless excluded. + typos: + run: typos -w --force-exclude {staged_files} + stage_fixed: true + oxlint: + glob: "*.{js,mjs,cjs,jsx,ts,mts,cts,tsx,astro,vue,svelte}" + run: oxlint --deny-warnings {staged_files} + shellcheck: + glob: "{*.sh,scripts/*,scripts/**/*,**/bin/*}" + run: scripts/ci/shellcheck.sh {staged_files} # The workflows and actions: actionlint (with shellcheck on their scripts) and zizmor (.github/zizmor.yml). actionlint: glob: ".github/workflows/*.{yml,yaml}" diff --git a/mise.toml b/mise.toml index 17ddcdeb..a7396b97 100644 --- a/mise.toml +++ b/mise.toml @@ -10,3 +10,5 @@ betterleaks = "1.10.1" cargo-deny = "0.22.3" trivy = "0.77.0" hadolint = "2.15.1" +typos = "1.53.0" +oxlint = "1.96.0" diff --git a/scripts/ci/shellcheck.sh b/scripts/ci/shellcheck.sh new file mode 100755 index 00000000..9cdc8ee2 --- /dev/null +++ b/scripts/ci/shellcheck.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +# ShellCheck on every shell script in the repository (each tracked file whose first line is a sh/bash shebang, and +# every *.sh), at warning level and up. Run by CI's security job, and by the pre-commit hook on just the staged files it +# names (`scripts/ci/shellcheck.sh ...`). mise.toml pins ShellCheck. +# GitHub Actions' run: scripts are actionlint's (it runs ShellCheck on them), and the CircleCI orb's are +# scripts/ci/check_orb.py's. +set -euo pipefail +cd "$(git rev-parse --show-toplevel)" +files=() +while IFS= read -r -d '' f; do + [ -f "$f" ] || continue + case $f in + *.sh) files+=("$f") ;; + *) + first= + IFS= read -r first <"$f" || true + [[ $first =~ ^\#!.*[/\ ](bash|dash|sh)([[:space:]]|$) ]] && files+=("$f") + ;; + esac +done < <(if [ $# -gt 0 ]; then printf '%s\0' "$@"; else git ls-files -z; fi) +[ ${#files[@]} -gt 0 ] || exit 0 +shellcheck --severity=warning "${files[@]}" +echo "ShellCheck: ${#files[@]} scripts clean" diff --git a/scripts/ci/visual.sh b/scripts/ci/visual.sh index 0d3b8b3a..5e7d3cf3 100755 --- a/scripts/ci/visual.sh +++ b/scripts/ci/visual.sh @@ -112,7 +112,7 @@ EOF rm -f "$out/site/visualci.schema.json" fi # The link-preview cards the prerender drew (scripts/og.mjs), so a broken card template shows up in review. - rm -rf "$out/og" && cp -r "$root/frontend/dist/og" "$out/og" + rm -rf "$out/og" && cp -R "$root/frontend/dist/og" "$out/og" # Component snapshots, written fresh: the baselines are on VisualCI. cd "$root/frontend" find src -name __snapshots__ -type d -prune -exec rm -rf {} + diff --git a/scripts/on-dev b/scripts/on-dev index 79843d20..a99f020e 100755 --- a/scripts/on-dev +++ b/scripts/on-dev @@ -85,7 +85,7 @@ sync() { # app/build.rs lists the migrations when database/migrations changes, but rsync keeps a new file's old mtime, so cargo # would build the old list in: touch the folder when a migration was added or removed (not on every sync, which # would rebuild the app each time). - if printf '%s\n' "$changes" | grep -qE '^([<>]f\+{9}|\*deleting) +app/database/migrations/'; then + if grep -qE '^([<>]f\+{9}|\*deleting) +app/database/migrations/' <<<"$changes"; then ssh "$host" "touch '$remote/app/database/migrations'" fi } diff --git a/scripts/screenshots/lightbox.mjs b/scripts/screenshots/lightbox.mjs index 8123d5f5..0705a2d4 100644 --- a/scripts/screenshots/lightbox.mjs +++ b/scripts/screenshots/lightbox.mjs @@ -22,7 +22,7 @@ export async function checkLightbox(browser, base) { const ctx = await browser.newContext({ baseURL: base, viewport: { width: 1440, height: 900 }, deviceScaleFactor: 2 }) try { await ctx.route('https://app.visualci.com/g/**', async (route) => { - if (/-2x\.png$/.test(new URL(route.request().url()).pathname)) await new Promise((r) => setTimeout(r, SLOW_MS)) + if (new URL(route.request().url()).pathname.endsWith('-2x.png')) await new Promise((r) => setTimeout(r, SLOW_MS)) await route.fulfill({ status: 200, contentType: 'image/png', body: PNG }).catch(() => {}) }) const page = await ctx.newPage() @@ -48,7 +48,7 @@ export async function checkLightbox(browser, base) { await page .waitForFunction(() => { const img = document.querySelector('dialog.vg-box .vg-box-view img') - return img && img.complete && /-2x\.png$/.test(img.currentSrc) + return img && img.complete && img.currentSrc.endsWith('-2x.png') }, null, { timeout: SLOW_MS + 5000 }) .catch(async () => { throw new Error(`lightbox: opening "${first.title}": its image never showed (${JSON.stringify(await shown())})`)