Skip to content

Commit

Permalink
Correcting YAMLLint #42
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Sep 15, 2018
1 parent 146e31f commit fd4e6df
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 70 deletions.
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-bin.zip
84 changes: 42 additions & 42 deletions src/main/java/se/bjurr/violations/lib/parsers/YAMLlintParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,49 +20,49 @@
* </code>
*/
public class YAMLlintParser implements ViolationsParser {
@Override
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)\\]\\s?([\\w\\s]+)\\s?\\(([\\w\\s]+)\\)");
for (List<String> 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<Violation> parseReportOutput(final String string) throws Exception {
List<Violation> violations = new ArrayList<>();
List<List<String>> partsPerLine =
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();
violations.add( //
violationBuilder() //
.setParser(YAMLLINT) //
.setStartLine(line) //
.setColumn(column) //
.setFile(filename) //
.setSeverity(toSeverity(severity)) //
.setMessage(message) //
.setRule(rule) //
.build() //
);
}
return violations;
}

/**
*
*
* <pre>
* The different message types are:
* warning, for non critical syntax errors
* error, for more serious syntax problem
* </pre>
*/
public SEVERITY toSeverity(final String severity) {
if (severity.equalsIgnoreCase("error")) {
return ERROR;
}
if (severity.equalsIgnoreCase("warning")) {
return WARN;
}
return INFO;
/**
*
*
* <pre>
* The different message types are:
* warning, for non critical syntax errors
* error, for more serious syntax problem
* </pre>
*/
public SEVERITY toSeverity(final String severity) {
if (severity.equalsIgnoreCase("error")) {
return ERROR;
}
if (severity.equalsIgnoreCase("warning")) {
return WARN;
}
return INFO;
}
}
55 changes: 28 additions & 27 deletions src/test/java/se/bjurr/violations/lib/YAMLlintTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,43 @@
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;
import org.junit.Test;
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<Violation> actual =
violationsApi() //
.withPattern(".*/yamllint/.*\\.txt$") //
.inFolder(rootFolder) //
.findAll(YAMLLINT) //
.violations();
final List<Violation> 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);
}
}

0 comments on commit fd4e6df

Please sign in to comment.