-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_imports.ts
More file actions
62 lines (58 loc) · 1.27 KB
/
check_imports.ts
File metadata and controls
62 lines (58 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const entries = Deno.readDirSync("./");
let err = false;
let errCount = 0;
for (const entry of entries) {
if (!entry.isFile) {
continue;
}
const match = entry.name.match(/^([0-9])_([^\.]+)\.ts$/);
if (match == null) {
continue;
}
const level = Number(match[1]);
const dir = match[2];
try {
if (!Deno.statSync(dir).isDirectory) {
continue;
}
} catch (err) {
if (err instanceof Deno.errors.NotFound) {
continue;
} else {
throw err;
}
}
for (const entry of Deno.readDirSync(dir)) {
if (!entry.isFile || !entry.name.endsWith(".ts")) {
continue;
}
const contents = Deno.readTextFileSync(dir + "/" + entry.name);
for (const [i, line] of contents.split("\n").entries()) {
const llevel = Number(line.match(/"..\/([0-9])+/)?.[1]);
if (isNaN(llevel)) {
continue;
}
if (llevel > level) {
err = true;
console.error(
`${++errCount}.`,
dir + "/" + entry.name + ":" + (i + 1),
"|",
llevel,
">",
level,
);
}
}
}
}
console.error(
errCount == 0
? "No errors were found."
: errCount == 1
? "An error was found."
: `${errCount} errors were found.`,
);
if (err) {
Deno.exit(1);
}