printScratchLint
uses node:fs
oxlint's findings in a scratch file, printed under its report; whether any is an error. Brief (TCM_BRIEF=1),
warnings are a count, and errors are shown.
import type { Codebase } from "#codebase/tcmts/cli/codebase"; import { lintScratch } from "#codebase/tcmts/cli/lint"; import { printIssue } from "#codebase/tcmts/cli/main"; import { dim } from "#codebase/tcmts/cli/style"; import fs from "node:fs"; export function printScratchLint( cb: Codebase, file: string, only?: { start: number; end: number }[], ): boolean { const text = fs.readFileSync(file, "utf8"); const issues = lintScratch(cb, file, text).filter( (i) => !only || only.some((r) => i.start >= r.start && i.start < r.end), ); if (!issues.length) return false; const brief = process.env.TCM_BRIEF === "1"; const shown = brief ? issues.filter((i) => i.severity === "error") : issues; const warnings = issues.length - shown.length; console.log( `\n ${dim("lint")}${warnings ? dim(` ${warnings} warning(s), not shown: \`tcm lint <namespace>\` lists them`) : ""}`, ); for (const i of shown) printIssue(text, i, " "); return issues.some((i) => i.severity === "error"); }