Skip to content

Commit 1e249b0

Browse files
refactor: use execFileSync in find-unused-diagnostic-messages script
Replaces execSync (shell string interpolation) with execFileSync (argument array) to avoid shell expansion entirely. diagName is derived from repo-controlled diagnostic identifiers so there is no practical injection risk, but the array form is the more idiomatic and robust Node.js pattern for invoking subprocesses. Also restores original CRLF line endings to avoid unrelated line-ending noise in the diff. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
1 parent 0d95912 commit 1e249b0

1 file changed

Lines changed: 31 additions & 31 deletions

File tree

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,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-
}
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

Comments
 (0)