Cotton code
77 lines · 3.1 KB · TypeScriptRaw
// Every workspace either runs ESLint or is on a list that says why not.//// `apps/cotton` had no `eslint.config.js` and no `lint` script, so// `turbo lint` skipped it and CI's lint step never read a line of ~30k lines// of TypeScript. Nothing announced that: a package with no lint script is// indistinguishable, to turbo, from one whose lint passed.//// This is a RATCHET, not a pass/fail on today's repo. Twelve packages are// genuinely unlinted right now and are listed below with the reason; the test// asserts the list is EXACT, so adding a package without lint fails here, and// removing a package's exemption without giving it lint fails here too. The// list can only shrink.import { readFileSync } from "node:fs";import { execFileSync } from "node:child_process";import path from "node:path";import { describe, expect, it } from "vitest";const ROOT = path.resolve(__dirname, "../..");/** * Workspaces that do not run ESLint, each with the reason it does not. * * Every entry is a gap, not a decision to be proud of: these are ordinary * TypeScript packages that would benefit from the same rules the linted ones * run. They are listed rather than fixed because each one surfaces its own * findings, and a config plus its findings is a PR per package — not a * footnote in someone else's. */const UNLINTED: Record<string, string> = {};function workspaces(): { dir: string; lint: boolean }[] {  return execFileSync("git", ["ls-files", "packages/*/package.json", "apps/*/package.json"], {    cwd: ROOT,    encoding: "utf8",  })    .split("\n")    .filter(Boolean)    .map((manifest) => {      const pkg = JSON.parse(readFileSync(path.join(ROOT, manifest), "utf8")) as {        scripts?: Record<string, string>;      };      return { dir: path.dirname(manifest), lint: typeof pkg.scripts?.lint === "string" };    });}describe("lint coverage", () => {  it("every workspace either has a `lint` script or a written reason it does not", () => {    const missing = workspaces()      .filter((w) => !w.lint && !(w.dir in UNLINTED))      .map((w) => w.dir);    expect(missing, "add a `lint` script, or add the package to UNLINTED with the reason").toEqual([]);  });  it("the exemption list holds no package that now lints — it can only shrink", () => {    const stale = workspaces()      .filter((w) => w.lint && w.dir in UNLINTED)      .map((w) => w.dir);    expect(stale, "these lint now: delete their UNLINTED entries").toEqual([]);  });  it("names no workspace that does not exist, so a rename cannot leave a hole behind", () => {    const dirs = new Set(workspaces().map((w) => w.dir));    expect(Object.keys(UNLINTED).filter((dir) => !dirs.has(dir))).toEqual([]);  });  it("gives every exemption a reason, never a bare entry", () => {    expect(Object.entries(UNLINTED).filter(([, why]) => why.trim().length < 10)).toEqual([]);  });  it("apps/cotton lints — the gap this guard was written for", () => {    const mac = workspaces().find((w) => w.dir === "apps/cotton");    expect(mac?.lint).toBe(true);    expect("apps/cotton" in UNLINTED).toBe(false);  });});