40 lines
1.1 KiB
Java
40 lines
1.1 KiB
Java
// 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;
|
|
}
|
|
}
|