Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds a script for removing unused diagnostics #44324

Merged
merged 3 commits into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions scripts/find-unused-diganostic-messages.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// @ts-check
// This file requires a modern version of node 14+, and grep to be available.

// node scripts/find-unused-diagnostic-messages.mjs
import { readFileSync } from "fs";
import {EOL} from "os";
import { execSync } from "child_process";

const diags = readFileSync("src/compiler/diagnosticInformationMap.generated.ts", "utf8");
const startOfDiags = diags.split("export const Diagnostics")[1];

const missingNames = [];
startOfDiags.split(EOL).forEach(line => {
if (!line.includes(":")) return;
const diagName = line.split(":")[0].trim();

try {
execSync(`grep -rnw 'src' -e 'Diagnostics.${diagName}'`).toString();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's probably a platform-independent package on npm that does recursive file string search, although feature-detecting grep vs findstr would work too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wes thinks ripgrep ( https://www.npmjs.com/package/vscode-ripgrep ) should be a reasonable tradeoff here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid the offensive huge cost of this you could just grep all lines that include Diagnostics., print them to a temp file, then search through this file. Also, even if the names are well behaved, it would be better to add -F. Also, -n is redundant AFAICT.

(And doing it with a grep library seems like an overkill too...)

process.stdout.write(".");
} catch (error) {
missingNames.push(diagName);
process.stdout.write("x");
}
});

if (missingNames.length) {
process.exitCode = 1;
console.log("Could not find usage of these diagnostics in the codebase:");
console.log(missingNames);
}
Loading