Skip to content

Commit

Permalink
fixed yamllint parser
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksei_Philippov committed Sep 17, 2018
1 parent d39b323 commit 8f804cf
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ It supports:
* [_Simian_](http://www.harukizaemon.com/simian/)
* [_StyleCop_](https://stylecop.codeplex.com/)
* [_XMLLint_](http://xmlsoft.org/xmllint.html)
* [_YAMLLint_](https://yamllint.readthedocs.io/en/stable/index.html)
* [_YAMLLint_](https://yamllint.readthedocs.io/en/stable/index.html) with `-f parsable`
* [_ZPTLint_](https://pypi.python.org/pypi/zptlint)

Example reports are available [in the test resources](https://github.com/tomasbjerre/violations-lib/tree/master/src/test/resources), examples of how to generate them are available [here](https://github.com/tomasbjerre/violations-test/blob/master/build.sh).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
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 static se.bjurr.violations.lib.util.Utils.isNullOrEmpty;
import static se.bjurr.violations.lib.util.ViolationParserUtils.getLines;

import java.util.ArrayList;
Expand All @@ -24,14 +25,17 @@ public class YAMLlintParser implements ViolationsParser {
public List<Violation> parseReportOutput(final String string) throws Exception {
List<Violation> violations = new ArrayList<>();
List<List<String>> partsPerLine =
getLines(string, "([^:]*):(\\d+):(\\d+):\\s?\\[(error|warning)\\]([^\\(]+)\\(([^\\)]+)\\)");
getLines(string, "([^:]*):(\\d+):(\\d+):\\s?\\[(error|warning)\\]([^\\(]+)(\\(([^\\)]+)\\))?");
for (List<String> 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();
String rule = null;
if (!isNullOrEmpty(parts.get(7))) {
rule = parts.get(7).trim();
}
violations.add( //
violationBuilder() //
.setParser(YAMLLINT) //
Expand Down
11 changes: 10 additions & 1 deletion src/test/java/se/bjurr/violations/lib/YAMLlintTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,16 @@ public void testThatViolationsCanBeParsed() {
assertThat(violation1.getSeverity()) //
.isEqualTo(ERROR);

final Violation violation2 = actual.get(3);
assertThat(violation2.getMessage()) //
.isEqualTo("syntax error: expected '<document start>', but found '<block mapping start>'");
assertThat(violation2.getFile()) //
.isEqualTo("./molecule-default/create.yml");
assertThat(violation2.getSeverity()) //
.isEqualTo(ERROR);
assertThat(violation2.getRule()).isEmpty();

assertThat(actual) //
.hasSize(3);
.hasSize(4);
}
}
3 changes: 2 additions & 1 deletion src/test/resources/yamllint/yamllint.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
file.yml:6:2: [warning] missing starting space in comment (comments)
test/file.yml:57:1: [error] trailing spaces (trailing-spaces)
file.yml:60:3: [error] wrong indentation: expected 4 but found 2 (indentation)
file.yml:60:3: [error] wrong indentation: expected 4 but found 2 (indentation)
./molecule-default/create.yml:117:89: [error] syntax error: expected '<document start>', but found '<block mapping start>'

0 comments on commit 8f804cf

Please sign in to comment.