init
This commit is contained in:
39
linter/Linter.java
Normal file
39
linter/Linter.java
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user