com.cj.jshintmojo.reporter.JSLintReporter Maven / Gradle / Ivy
package com.cj.jshintmojo.reporter;
import java.util.Arrays;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import com.cj.jshintmojo.cache.Result;
import com.cj.jshintmojo.jshint.JSHint;
/**
* JSLint style xml reporter class.
*/
public class JSLintReporter implements JSHintReporter {
/**
* format type of this reporter.
*/
public static final String FORMAT = "jslint";
@Override
public String report(Map results) {
if(results == null){
return "";
}
StringBuilder buf = new StringBuilder();
buf.append("\n");
buf.append("\n");
String[] files = results.keySet().toArray(new String[0]);
Arrays.sort(files);
for(String file : files){
Result result = results.get(file);
buf.append("\t\n");
for(JSHint.Error issue : result.errors){
buf.append(String.format("\t\t \n");
}
buf.append("\t \n");
}
buf.append(" \n");
return buf.toString();
}
private String encode(String str) {
if(str == null){
return "";
}
return str
.replaceAll("&", "&")
.replaceAll("\"", """)
.replaceAll("'", "'")
.replaceAll("<", "<")
.replaceAll(">", ">");
}
}