diff --git a/src/main/java/se/bjurr/violations/lib/parsers/YAMLlintParser.java b/src/main/java/se/bjurr/violations/lib/parsers/YAMLlintParser.java index 757917e5..a67da927 100644 --- a/src/main/java/se/bjurr/violations/lib/parsers/YAMLlintParser.java +++ b/src/main/java/se/bjurr/violations/lib/parsers/YAMLlintParser.java @@ -20,49 +20,51 @@ * */ public class YAMLlintParser implements ViolationsParser { - @Override - public List parseReportOutput(final String string) throws Exception { - List violations = new ArrayList<>(); - List> partsPerLine = - getLines(string, "([^:]*):(\\d+):(\\d+):\\s?\\[(error|warning)\\]\\s?([\\w\\s]+)\\s?\\(([\\w\\s]+)\\)"); - for (List parts : partsPerLine) { - String filename = parts.get(1); - Integer line = parseInt(parts.get(2)); - Integer column = parseInt(parts.get(3)); - String severity = parts.get(4); - String message = parts.get(5); - String rule = parts.get(6); - violations.add( // - violationBuilder() // - .setParser(YAMLLINT) // - .setStartLine(line) // - .setColumn(column) // - .setFile(filename) // - .setSeverity(toSeverity(severity)) // - .setMessage(message) // - .setRule(rule) // - .build() // - ); - } - return violations; + @Override + public List parseReportOutput(final String string) throws Exception { + List violations = new ArrayList<>(); + List> partsPerLine = + getLines( + string, + "([^:]*):(\\d+):(\\d+):\\s?\\[(error|warning)\\]\\s?([\\w\\s\\d:]+)\\s?\\(([^\\)]+)\\)"); + for (List parts : partsPerLine) { + String filename = parts.get(1).trim(); + Integer line = parseInt(parts.get(2)); + Integer column = parseInt(parts.get(3)); + String severity = parts.get(4).trim(); + String message = parts.get(5).trim(); + String rule = parts.get(6).trim(); + violations.add( // + violationBuilder() // + .setParser(YAMLLINT) // + .setStartLine(line) // + .setColumn(column) // + .setFile(filename) // + .setSeverity(toSeverity(severity)) // + .setMessage(message) // + .setRule(rule) // + .build() // + ); } + return violations; + } - /** - * - * - *
-     * The different message types are:
-     * warning, for non critical syntax errors
-     * error, for more serious syntax problem
-     * 
- */ - public SEVERITY toSeverity(final String severity) { - if (severity.equalsIgnoreCase("error")) { - return ERROR; - } - if (severity.equalsIgnoreCase("warning")) { - return WARN; - } - return INFO; + /** + * + * + *
+   * The different message types are:
+   * warning, for non critical syntax errors
+   * error, for more serious syntax problem
+   * 
+ */ + public SEVERITY toSeverity(final String severity) { + if (severity.equalsIgnoreCase("error")) { + return ERROR; } + if (severity.equalsIgnoreCase("warning")) { + return WARN; + } + return INFO; + } } diff --git a/src/test/java/se/bjurr/violations/lib/YAMLlintTest.java b/src/test/java/se/bjurr/violations/lib/YAMLlintTest.java index e916e4a6..1f55ba65 100644 --- a/src/test/java/se/bjurr/violations/lib/YAMLlintTest.java +++ b/src/test/java/se/bjurr/violations/lib/YAMLlintTest.java @@ -5,7 +5,6 @@ import static se.bjurr.violations.lib.ViolationsApi.violationsApi; import static se.bjurr.violations.lib.model.SEVERITY.ERROR; 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.YAMLLINT; import java.util.List; @@ -13,34 +12,36 @@ import se.bjurr.violations.lib.model.Violation; public class YAMLlintTest { - @Test - public void testThatViolationsCanBeParsed() { - final String rootFolder = getRootFolder(); + @Test + public void testThatViolationsCanBeParsed() { + final String rootFolder = getRootFolder(); - final List actual = - violationsApi() // - .withPattern(".*/yamllint/.*\\.txt$") // - .inFolder(rootFolder) // - .findAll(YAMLLINT) // - .violations(); + final List actual = + violationsApi() // + .withPattern(".*/yamllint/.*\\.txt$") // + .inFolder(rootFolder) // + .findAll(YAMLLINT) // + .violations(); - assertThat(actual) // - .hasSize(3); + final Violation violation0 = actual.get(0); + assertThat(violation0.getMessage()) // + .isEqualTo("missing starting space in comment"); + assertThat(violation0.getFile()) // + .isEqualTo("file.yml"); + assertThat(violation0.getSeverity()) // + .isEqualTo(WARN); + assertThat(violation0.getRule()) // + .isEqualTo("comments"); - assertThat(actual.get(0).getMessage()) // - .isEqualTo("missing starting space in comment (comments)"); - assertThat(actual.get(0).getFile()) // - .isEqualTo("file.yml"); - assertThat(actual.get(0).getSeverity()) // - .isEqualTo(WARN); - assertThat(actual.get(0).getRule()) // - .isEqualTo("comments"); + final Violation violation1 = actual.get(1); + assertThat(violation1.getMessage()) // + .isEqualTo("trailing spaces"); + assertThat(violation1.getFile()) // + .isEqualTo("test/file.yml"); + assertThat(violation1.getSeverity()) // + .isEqualTo(ERROR); - assertThat(actual.get(1).getMessage()) // - .isEqualTo("trailing spaces"); - assertThat(actual.get(1).getFile()) // - .isEqualTo("test/file.yml"); - assertThat(actual.get(1รง).getSeverity()) // - .isEqualTo(ERROR); - } + assertThat(actual) // + .hasSize(3); + } }