Skip to content
Permalink
Browse files
Remove 'async' dependency, used only in errorCheck.ts, modernize file (
  • Loading branch information
jakebailey committed Sep 23, 2022
1 parent c6bef3f commit f16ca7dd364e57ee7ce337f987b20dbc1e34941f
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 83 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

@@ -40,7 +40,6 @@
],
"devDependencies": {
"@octokit/rest": "latest",
"@types/async": "latest",
"@types/chai": "latest",
"@types/fs-extra": "^9.0.13",
"@types/glob": "latest",
@@ -62,7 +61,6 @@
"@typescript-eslint/eslint-plugin": "^5.33.1",
"@typescript-eslint/parser": "^5.33.1",
"@typescript-eslint/utils": "^5.33.1",
"async": "latest",
"azure-devops-node-api": "^11.2.0",
"chai": "latest",
"chalk": "^4.1.2",
@@ -1,12 +1,12 @@
import * as fs from "fs";
import * as async from "async";
import * as glob from "glob";
import * as fsPromises from "fs/promises";
import * as _glob from "glob";
import * as util from "util";

fs.readFile("src/compiler/diagnosticMessages.json", "utf-8", (err, data) => {
if (err) {
throw err;
}
const glob = util.promisify(_glob);

async function checkErrorBaselines() {
const data = await fsPromises.readFile("src/compiler/diagnosticMessages.json", "utf-8");
const messages = JSON.parse(data);
const keys = Object.keys(messages);
console.log("Loaded " + keys.length + " errors");
@@ -18,39 +18,35 @@ fs.readFile("src/compiler/diagnosticMessages.json", "utf-8", (err, data) => {
const errRegex = /\(\d+,\d+\): error TS([^:]+):/g;
const baseDir = "tests/baselines/reference/";

fs.readdir(baseDir, (err, files) => {
files = files.filter(f => f.indexOf(".errors.txt") > 0);
const tasks: ((callback: () => void) => void)[] = [];
files.forEach(f => tasks.push(done => {
fs.readFile(baseDir + f, "utf-8", (err, baseline) => {
if (err) throw err;

let g: RegExpExecArray | null;
while (g = errRegex.exec(baseline)) {
const errCode = +g[1];
const msg = keys.filter(k => messages[k].code === errCode)[0];
messages[msg].seen = true;
}

done();
});
}));

async.parallelLimit(tasks, 25, done => {
console.log("== List of errors not present in baselines ==");
let count = 0;
for (const k of keys) {
if (messages[k].seen !== true) {
console.log(k);
count++;
}
const files = (await fsPromises.readdir(baseDir)).filter(f => f.endsWith(".errors.txt"));

files.forEach(f => {
fs.readFile(baseDir + f, "utf-8", (err, baseline) => {
if (err) throw err;

let g: RegExpExecArray | null;
while (g = errRegex.exec(baseline)) {
const errCode = +g[1];
const msg = keys.filter(k => messages[k].code === errCode)[0];
messages[msg].seen = true;
}
console.log(count + " of " + keys.length + " errors are not in baselines");
});
});
});

fs.readFile("src/compiler/diagnosticInformationMap.generated.ts", "utf-8", (err, data) => {
console.log("== List of errors not present in baselines ==");
let count = 0;
for (const k of keys) {
if (messages[k].seen !== true) {
console.log(k);
count++;
}
}
console.log(count + " of " + keys.length + " errors are not in baselines");
}

async function checkSourceFiles() {
const data = await fsPromises.readFile("src/compiler/diagnosticInformationMap.generated.ts", "utf-8");

const errorRegexp = /\s(\w+): \{ code/g;
const errorNames: string[] = [];
let errMatch: RegExpExecArray | null;
@@ -59,27 +55,33 @@ fs.readFile("src/compiler/diagnosticInformationMap.generated.ts", "utf-8", (err,
}

let allSrc = "";
glob("./src/**/*.ts", {}, (err, files) => {
console.log("Reading " + files.length + " source files");
for (const file of files) {
if (file.indexOf("diagnosticInformationMap.generated.ts") > 0) {
continue;
}

const src = fs.readFileSync(file, "utf-8");
allSrc = allSrc + src;
const files = await glob("./src/**/*.ts");
console.log("Reading " + files.length + " source files");
for (const file of files) {
if (file.indexOf("diagnosticInformationMap.generated.ts") > 0) {
continue;
}

console.log("Consumed " + allSrc.length + " characters of source");
const src = fs.readFileSync(file, "utf-8");
allSrc = allSrc + src;
}

console.log("Consumed " + allSrc.length + " characters of source");

let count = 0;
console.log("== List of errors not used in source ==");
for (const errName of errorNames) {
if (allSrc.indexOf(errName) < 0) {
console.log(errName);
count++;
}
let count = 0;
console.log("== List of errors not used in source ==");
for (const errName of errorNames) {
if (allSrc.indexOf(errName) < 0) {
console.log(errName);
count++;
}
console.log(count + " of " + errorNames.length + " errors are not used in source");
});
});
}
console.log(count + " of " + errorNames.length + " errors are not used in source");
}

async function main() {
await checkErrorBaselines();
await checkSourceFiles();
}

main();

0 comments on commit f16ca7d

Please sign in to comment.