Review generated type coverage runner

from Type coverage
TypeScript 6 advanced 6 min 4 issues to find

Review this generated coverage runner before it is added to CI.

Read an untrusted JSON configuration, validate it, run type coverage once for the project without a shell, enforce the configured minimum, and report failure reliably.

TypeScript
import { exec } from "node:child_process";

type Config = {
  project: string;
  files: string[];
  minimum: number;
};

function check(configText: string): void {
  const config = JSON.parse(configText) as Config;
  for (const file of config.files) {
    const command = `npx type-coverage -p ${config.project} -- ${file}`;
    exec(command, (error, stdout) => {
      const match: any = stdout.match(/([0-9.]+)%/);
      const percent = Number(match[1]);
      console.log(`${file}: ${percent} >= ${config.minimum}`);
      if (error) process.exitCode = 1;
    });
  }
}

check(process.argv[2]!);

generated code is illustrative, not from any one model

Open in playground
Report an error