forked from mkhan45/RustScript
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLinter.java
More file actions
Latest commit
58 lines (55 loc) · 1.5 KB
/
Copy pathLinter.java
File metadata and controls
58 lines (55 loc) · 1.5 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
importjava.io.File;
importjava.io.IOException;
importjava.nio.charset.StandardCharsets;
importjava.nio.file.Files;
importjava.nio.file.Paths;
importjava.util.Arrays;
importjava.util.List;
importcore.Parser;
publicclassLinter {
publicstaticvoidmain(String[] args) throwsException {
if (args.length == 0) {
System.out.println("Usage: Linter [file(s)]");
return;
}
run(Arrays.asList(args));
}
publicstaticvoidrun(List<String> files) {
System.out.println("Linting " + files.size() + " file(s)...");
intfailed = 0;
for (Stringfile : files) {
Filef = newFile(file);
if (!f.exists()) {
System.out.println("File '" + file + "' does not exist.");
return;
} elseif (f.isDirectory()) {
System.out.println("File '" + file + "' is a directory.");
return;
} elseif (!f.canRead()) {
System.out.println("File '" + file + "' is not readable.");
return;
}
Stringsource;
try {
source = Files.readString(Paths.get(file), StandardCharsets.UTF_8);
} catch (IOExceptione) {
e.printStackTrace();
continue;
}
try {
Parser.parseExprs(source);
} catch (Exceptione) {
System.out.println(String.format("""
Syntax error in '%s':
%s
""", file, e.getMessage()));
failed++;
}
}
if (failed == 0) {
System.out.println("All files passed!");
} else {
System.out.println("Found " + failed + " errors.");
}
}
}