Skip to content

Commit

Permalink
Avoiding faulty slash with CodeNarc #53
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Jan 14, 2019
1 parent 7c2be26 commit fa97ac8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,16 @@ public List<Violation> parseReportOutput(String string) throws Exception {
if (message == null) {
message = ruleName;
}
String fileString = null;
if (sourceDirectory == null || sourceDirectory.isEmpty()) {
fileString = path + "/" + name;
} else {
fileString = sourceDirectory + "/" + path + "/" + name;
}
final Violation violation =
violationBuilder() //
.setParser(CODENARC) //
.setFile((sourceDirectory + "/" + path + "/" + name).replace("//", "/")) //
.setFile(fileString.replace("//", "/")) //
.setMessage(message) //
.setRule(ruleName) //
.setSeverity(getSeverity(priority)) //
Expand Down
18 changes: 17 additions & 1 deletion src/test/java/se/bjurr/violations/lib/CodeNarcTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void testThatViolationsCanBeParsed() {
assertThat(violation0.getMessage()) //
.isEqualTo("In most cases, exceptions should not be caught and ignored (swallowed).");
assertThat(violation0.getFile()) //
.isEqualTo("/foo/bar/Test.groovy");
.isEqualTo("foo/bar/Test.groovy");
assertThat(violation0.getSeverity()) //
.isEqualTo(WARN);
assertThat(violation0.getRule()) //
Expand Down Expand Up @@ -75,4 +75,20 @@ public void testThatViolationsCanBeParsed2() {
assertThat(violation0.getEndLine()) //
.isEqualTo(184);
}

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

final List<Violation> actual =
violationsApi() //
.withPattern(".*/codenarc/CodeNarcXmlReport\\.xml$") //
.inFolder(rootFolder) //
.findAll(CODENARC) //
.violations();

final Violation violation0 = actual.get(0);
assertThat(violation0.getFile()) //
.isEqualTo("grails-app/controllers/LoginController.groovy");
}
}

0 comments on commit fa97ac8

Please sign in to comment.