Skip to content

Commit 41dcad0

Browse files
author
Orta Therox
authoredAug 24, 2021
Adds a script for removing unused diagnostics (microsoft#44324)
* Adds a script for removing unused diagnostics * Accidentally deleted the wrong one
1 parent 7117f03 commit 41dcad0

File tree

2 files changed

+30
-196
lines changed

2 files changed

+30
-196
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// @ts-check
2+
// This file requires a modern version of node 14+, and grep to be available.
3+
4+
// node scripts/find-unused-diagnostic-messages.mjs
5+
import { readFileSync } from "fs";
6+
import {EOL} from "os";
7+
import { execSync } from "child_process";
8+
9+
const diags = readFileSync("src/compiler/diagnosticInformationMap.generated.ts", "utf8");
10+
const startOfDiags = diags.split("export const Diagnostics")[1];
11+
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+
} catch (error) {
21+
missingNames.push(diagName);
22+
process.stdout.write("x");
23+
}
24+
});
25+
26+
if (missingNames.length) {
27+
process.exitCode = 1;
28+
console.log("Could not find usage of these diagnostics in the codebase:");
29+
console.log(missingNames);
30+
}

0 commit comments

Comments
 (0)
Please sign in to comment.