se.bjurr.violations.lib.parsers.JSLintParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of violations-lib Show documentation
Show all versions of violations-lib Show documentation
Library for parsing report files from static code analyzis.
package se.bjurr.violations.lib.parsers;
import static se.bjurr.violations.lib.model.SEVERITY.ERROR;
import static se.bjurr.violations.lib.model.SEVERITY.INFO;
import static se.bjurr.violations.lib.model.SEVERITY.WARN;
import static se.bjurr.violations.lib.model.Violation.violationBuilder;
import static se.bjurr.violations.lib.reports.Parser.JSLINT;
import static se.bjurr.violations.lib.util.ViolationParserUtils.getAttribute;
import static se.bjurr.violations.lib.util.ViolationParserUtils.getChunks;
import static se.bjurr.violations.lib.util.ViolationParserUtils.getIntegerAttribute;
import java.util.ArrayList;
import java.util.List;
import se.bjurr.violations.lib.model.SEVERITY;
import se.bjurr.violations.lib.model.Violation;
public class JSLintParser implements ViolationsParser {
@Override
public List parseReportOutput(String string) throws Exception {
List violations = new ArrayList<>();
List files = getChunks(string, "");
for (String fileChunk : files) {
String filename = getAttribute(fileChunk, "name");
List issues = getChunks(fileChunk, " ");
for (String issueChunk : issues) {
Integer line = getIntegerAttribute(issueChunk, "line");
Integer charAttrib = getIntegerAttribute(issueChunk, "char");
String severity = getAttribute(issueChunk, "severity");
String reason = getAttribute(issueChunk, "reason").trim();
String evidence = getAttribute(issueChunk, "evidence").trim();
String message = reason + ": " + evidence;
violations.add( //
violationBuilder() //
.setParser(JSLINT) //
.setStartLine(line) //
.setColumn(charAttrib) //
.setFile(filename) //
.setSeverity(toSeverity(severity)) //
.setMessage(message) //
.build() //
);
}
}
return violations;
}
public SEVERITY toSeverity(String severity) {
if (severity.equalsIgnoreCase("E")) {
return ERROR;
}
if (severity.equalsIgnoreCase("W")) {
return WARN;
}
return INFO;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy