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