-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f721255
commit fdbc050
Showing
8 changed files
with
168 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/main/java/se/bjurr/violations/lib/parsers/GoLintParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package se.bjurr.violations.lib.parsers; | ||
|
||
import static java.lang.Integer.parseInt; | ||
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.parsers.ViolationParserUtils.getLines; | ||
import static se.bjurr.violations.lib.reports.Reporter.GOLINT; | ||
import static se.bjurr.violations.lib.util.Utils.isNullOrEmpty; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import se.bjurr.violations.lib.model.SEVERITY; | ||
import se.bjurr.violations.lib.model.Violation; | ||
|
||
public class GoLintParser implements ViolationsParser { | ||
|
||
@Override | ||
public List<Violation> parseReportOutput(String reportContent) throws Exception { | ||
List<Violation> violations = new ArrayList<>(); | ||
List<List<String>> partsPerLine = getLines(reportContent, "^([^:]+?):(\\d*):?(\\d*?):?([^:]*?)?:? (.*)$"); | ||
for (List<String> parts : partsPerLine) { | ||
String fileName = parts.get(1); | ||
Integer lineNumber = 0; | ||
if (!parts.get(2).isEmpty()) { | ||
lineNumber = parseInt(parts.get(2)); | ||
} | ||
Integer columnNumber = 0; | ||
if (!parts.get(3).isEmpty()) { | ||
columnNumber = parseInt(parts.get(3)); | ||
} | ||
String severity = parts.get(4); | ||
String message = parts.get(5); | ||
violations.add(// | ||
violationBuilder()// | ||
.setReporter(GOLINT)// | ||
.setStartLine(lineNumber)// | ||
.setColumn(columnNumber)// | ||
.setFile(fileName)// | ||
.setSeverity(toSeverity(severity))// | ||
.setMessage(message)// | ||
.build()// | ||
); | ||
} | ||
return violations; | ||
} | ||
|
||
public SEVERITY toSeverity(String severity) { | ||
if (isNullOrEmpty(severity)) { | ||
return INFO; | ||
} | ||
if (severity.equalsIgnoreCase("error")) { | ||
return ERROR; | ||
} | ||
if (severity.equalsIgnoreCase("warning")) { | ||
return WARN; | ||
} | ||
return INFO; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package se.bjurr.violations.lib; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static se.bjurr.violations.lib.TestUtils.getRootFolder; | ||
import static se.bjurr.violations.lib.ViolationsReporterApi.violationsReporterApi; | ||
import static se.bjurr.violations.lib.model.SEVERITY.INFO; | ||
import static se.bjurr.violations.lib.model.SEVERITY.WARN; | ||
import static se.bjurr.violations.lib.reports.Reporter.GOLINT; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.Test; | ||
|
||
import se.bjurr.violations.lib.model.Violation; | ||
|
||
public class GoLintTest { | ||
|
||
@Test | ||
public void testThatGoLintViolationsCanBeParsed() { | ||
String rootFolder = getRootFolder(); | ||
|
||
List<Violation> actual = violationsReporterApi() // | ||
.withPattern(".*/golint/golint\\.txt$") // | ||
.inFolder(rootFolder) // | ||
.findAll(GOLINT) // | ||
.violations(); | ||
|
||
assertThat(actual)// | ||
.hasSize(7); | ||
|
||
assertThat(actual.get(0).getMessage())// | ||
.isEqualTo( | ||
"comment on exported type RestDataSource should be of the form \"RestDataSource ...\" (with optional leading article)"); | ||
assertThat(actual.get(0).getFile())// | ||
.isEqualTo("src/bla/bla/bla/dataSource.go"); | ||
assertThat(actual.get(0).getSeverity())// | ||
.isEqualTo(INFO); | ||
assertThat(actual.get(0).getRule().orNull())// | ||
.isEqualTo(null); | ||
assertThat(actual.get(0).getStartLine())// | ||
.isEqualTo(28); | ||
assertThat(actual.get(0).getEndLine())// | ||
.isEqualTo(28); | ||
|
||
assertThat(actual.get(2).getMessage())// | ||
.isEqualTo("declaration of err shadows declaration at journalevent.go:165: (vet shadow) "); | ||
assertThat(actual.get(2).getFile())// | ||
.isEqualTo("journalevent.go"); | ||
assertThat(actual.get(2).getSeverity())// | ||
.isEqualTo(WARN); | ||
assertThat(actual.get(2).getRule().orNull())// | ||
.isEqualTo(null); | ||
assertThat(actual.get(2).getStartLine())// | ||
.isEqualTo(182); | ||
assertThat(actual.get(2).getEndLine())// | ||
.isEqualTo(182); | ||
} | ||
|
||
@Test | ||
public void testThatGoVetViolationsCanBeParsed() { | ||
String rootFolder = getRootFolder(); | ||
|
||
List<Violation> actual = violationsReporterApi() // | ||
.withPattern(".*/golint/govet\\.txt$") // | ||
.inFolder(rootFolder) // | ||
.findAll(GOLINT) // | ||
.violations(); | ||
|
||
assertThat(actual)// | ||
.hasSize(1); | ||
|
||
assertThat(actual.get(0).getMessage())// | ||
.isEqualTo( | ||
"this is a message"); | ||
assertThat(actual.get(0).getFile())// | ||
.isEqualTo("my_file.go"); | ||
assertThat(actual.get(0).getSeverity())// | ||
.isEqualTo(INFO); | ||
assertThat(actual.get(0).getStartLine())// | ||
.isEqualTo(46); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
src/bla/bla/bla/dataSource.go:28:1: comment on exported type RestDataSource should be of the form "RestDataSource ..." (with optional leading article) | ||
journalevent.go:308:1:warning: exported function NewSendJournalEventJob should have comment or be unexported (golint) | ||
journalevent.go:182::warning: declaration of err shadows declaration at journalevent.go:165: (vet shadow) | ||
journalevent.go:::: testing1 | ||
journalevent.go::: testing2 | ||
journalevent.go:: testing3 | ||
journalevent.go: testing4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
my_file.go:46: this is a message | ||
exit status 1 |