This commit is contained in:
2026-03-18 00:39:22 -07:00
commit c699640518
27 changed files with 3576 additions and 0 deletions

39
linter/Linter.java Normal file
View File

@@ -0,0 +1,39 @@
// Nik Johnson
// 2-24-2024
// TA: Andy Ruan
import java.util.*;
import java.io.*;
// file-based linting object, linting based on checks defined in a list
public class Linter {
private List<Check> checks;
// constructor, takes list of checks to perform
public Linter(List<Check> checks) {
this.checks = checks;
}
// compile list of errors based on output of check classes
// takes filename to perform checks on
// return list of errors present in that file
public List<Error> lint(String fileName) throws FileNotFoundException {
File toBeChecked = new File(fileName);
Scanner fileScanner = new Scanner(toBeChecked);
List<Error> errors = new ArrayList<>();
int lineNumber = 1;
while (fileScanner.hasNext()) {
String line = fileScanner.nextLine();
for (Check check : checks) {
Optional<Error> error = check.lint(line, lineNumber);
if (error.isPresent()) {
errors.add(error.get());
}
}
lineNumber++;
}
fileScanner.close();
return errors;
}
}