Skip to content

Commit

Permalink
Handling css-lint reports where there are not line or evidence #11
Browse files Browse the repository at this point in the history
 * Also setting severity level for PyLint.
  • Loading branch information
tomasbjerre committed Oct 26, 2016
1 parent a7920c6 commit 35d5d33
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
12 changes: 6 additions & 6 deletions src/main/java/se/bjurr/violations/lib/parsers/CSSLintParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@
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.findAttribute;
import static se.bjurr.violations.lib.parsers.ViolationParserUtils.findIntegerAttribute;
import static se.bjurr.violations.lib.parsers.ViolationParserUtils.getAttribute;
import static se.bjurr.violations.lib.parsers.ViolationParserUtils.getChunks;
import static se.bjurr.violations.lib.parsers.ViolationParserUtils.getIntegerAttribute;
import static se.bjurr.violations.lib.reports.Reporter.CSSLINT;

import java.io.File;
import java.util.List;

import se.bjurr.violations.lib.model.SEVERITY;
import se.bjurr.violations.lib.model.Violation;

import com.google.common.base.Charsets;
import com.google.common.base.Optional;
import com.google.common.io.Files;

import se.bjurr.violations.lib.model.SEVERITY;
import se.bjurr.violations.lib.model.Violation;

public class CSSLintParser implements ViolationsParser {

@Override
Expand All @@ -32,12 +32,12 @@ public List<Violation> parseFile(File file) throws Exception {
String filename = getAttribute(fileChunk, "name");
List<String> issues = getChunks(fileChunk, "<issue", "/>");
for (String issueChunk : issues) {
Integer line = getIntegerAttribute(issueChunk, "line");
Integer line = findIntegerAttribute(issueChunk, "line").or(1);
Optional<Integer> charAttrib = findIntegerAttribute(issueChunk, "char");
String severity = getAttribute(issueChunk, "severity");

String message = getAttribute(issueChunk, "reason");
String evidence = getAttribute(issueChunk, "evidence").trim();
String evidence = findAttribute(issueChunk, "evidence").or("").trim();
violations.add(//
violationBuilder()//
.setReporter(CSSLINT)//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public List<Violation> parseFile(final File file) throws Exception {
.setReporter(PYLINT)//
.setStartLine(line)//
.setFile(filename)//
.setRule(ruleCode + "(" + rule + ")")//
.setRule(severity + ruleCode + "(" + rule + ")")//
.setSeverity(toSeverity(severity))//
.setMessage(message)//
.setSpecific("method", method)//
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/se/bjurr/violations/lib/CSSLintTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public void testThatViolationsCanBeParsed() {
.violations();

assertThat(actual)//
.containsExactly(//
.hasSize(6)//
.contains(//
violationBuilder()//
.setReporter(CSSLINT)//
.setFile("web/css-file.css")//
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/se/bjurr/violations/lib/PyLintTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ public void testThatViolationsCanBeParsed() {
assertThat(actual.get(0).getSeverity())//
.isEqualTo(INFO);
assertThat(actual.get(0).getRule().orNull())//
.isEqualTo("0330(bad-continuation)");
.isEqualTo("C0330(bad-continuation)");
}
}
7 changes: 7 additions & 0 deletions src/test/resources/csslint/csslint-no-line.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<csslint>
<file name="foo/bar/style.css>
<issue evidence="" reason="Too many !important declarations (38), try to use less than 10 to avoid specificity issues." severity="warning"/>
<issue evidence="" reason="Too many font-size declarations (35), abstraction needed." severity="warning"/>
<issue evidence="" reason="You have 5 h1s, 7 h2s, 5 h3s, 7 h4s, 2 h5s defined in this stylesheet." severity="warning"/>
</file>
</csslint>

0 comments on commit 35d5d33

Please sign in to comment.