1// This file requires a modern version of node 14+, and grep to be available. 2 3// node scripts/find-unused-diagnostic-messages.mjs 4import { readFileSync } from "fs"; 5import { EOL } from "os"; 6import { execSync } from "child_process"; 7 8const diags = readFileSync("src/compiler/diagnosticInformationMap.generated.ts", "utf8"); 9const startOfDiags = diags.split("export const Diagnostics")[1]; 10 11/** @type {string[]} */ 12const missingNames = []; 13startOfDiags.split(EOL).forEach(line => { 14 if (!line.includes(":")) return; 15 const diagName = line.split(":")[0].trim(); 16 17 try { 18 execSync(`grep -rnw 'src' -e 'Diagnostics.${diagName}'`).toString(); 19 process.stdout.write("."); 20 } 21 catch (error) { 22 missingNames.push(diagName); 23 process.stdout.write("x"); 24 } 25}); 26 27if (missingNames.length) { 28 process.exitCode = 1; 29 console.log("Could not find usage of these diagnostics in the codebase:"); 30 console.log(missingNames); 31} 32