Skip to content

Commit

Permalink
Changing rule format in PyLint to CODE(codeName)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Oct 25, 2016
1 parent 87ecb51 commit 2461870
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
28 changes: 15 additions & 13 deletions src/main/java/se/bjurr/violations/lib/parsers/PyLintParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,25 @@
public class PyLintParser implements ViolationsParser {

@Override
public List<Violation> parseFile(File file) throws Exception {
String string = Files.toString(file, UTF_8);
List<Violation> violations = newArrayList();
List<List<String>> partsPerLine = getLines(string, "([^:]*):(\\d+): \\[(\\D)(\\d*)\\(([^\\]]*)\\), ([^\\]]*)] (.*)");
for (List<String> parts : partsPerLine) {
String filename = parts.get(1);
Integer line = parseInt(parts.get(2));
String severity = parts.get(3);
String rule = parts.get(5);
String method = parts.get(6);
String message = parts.get(7);
public List<Violation> parseFile(final File file) throws Exception {
final String string = Files.toString(file, UTF_8);
final List<Violation> violations = newArrayList();
final List<List<String>> partsPerLine = getLines(string,
"([^:]*):(\\d+): \\[(\\D)(\\d*)\\(([^\\]]*)\\), ([^\\]]*)] (.*)");
for (final List<String> parts : partsPerLine) {
final String filename = parts.get(1);
final Integer line = parseInt(parts.get(2));
final String severity = parts.get(3);
final String ruleCode = parts.get(4);
final String rule = parts.get(5);
final String method = parts.get(6);
final String message = parts.get(7);
violations.add(//
violationBuilder()//
.setReporter(PYLINT)//
.setStartLine(line)//
.setFile(filename)//
.setRule(rule)//
.setRule(ruleCode + "(" + rule + ")")//
.setSeverity(toSeverity(severity))//
.setMessage(message)//
.setSpecific("method", method)//
Expand All @@ -64,7 +66,7 @@ public List<Violation> parseFile(File file) throws Exception {
* further processing.
* </pre>
*/
public SEVERITY toSeverity(String severity) {
public SEVERITY toSeverity(final String severity) {
if (severity.equalsIgnoreCase("E") || severity.equalsIgnoreCase("F")) {
return ERROR;
}
Expand Down
6 changes: 4 additions & 2 deletions src/test/java/se/bjurr/violations/lib/PyLintTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public class PyLintTest {

@Test
public void testThatViolationsCanBeParsed() {
String rootFolder = getRootFolder();
final String rootFolder = getRootFolder();

List<Violation> actual = violationsReporterApi() //
final List<Violation> actual = violationsReporterApi() //
.withPattern(".*/pylint/.*\\.txt$") //
.inFolder(rootFolder) //
.findAll(PYLINT) //
Expand All @@ -35,5 +35,7 @@ public void testThatViolationsCanBeParsed() {
.isEqualTo("Wrong continued indentation (add 1 space).");
assertThat(actual.get(0).getSeverity())//
.isEqualTo(INFO);
assertThat(actual.get(0).getRule().orNull())//
.isEqualTo("0330(bad-continuation)");
}
}

0 comments on commit 2461870

Please sign in to comment.