![JAR search and dependency download from the Maven repository](/logo.png)
com.cj.jshintmojo.reporter.CheckStyleReporter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jshint-maven-plugin Show documentation
Show all versions of jshint-maven-plugin Show documentation
a maven mojo that integrates the 'jshint' javascript preprocessor
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;
/**
* CheckStyle style xml reporter class.
*/
public class CheckStyleReporter implements JSHintReporter {
/**
* format type of this reporter.
*/
public static final String FORMAT = "checkstyle";
@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 error : result.errors){
buf.append(String.format("\t\t \n",
error.line.intValue(), error.character.intValue(), encode(error.reason), encode(error.code), severity(error.code)));
}
buf.append("\t \n");
}
buf.append(" \n");
return buf.toString();
}
private String severity(String errorCode) {
if(StringUtils.isNotEmpty(errorCode)){
switch(errorCode.charAt(0)){
case 'E':
return "error";
case 'I':
return "info";
case 'W':
default:
break;
}
}
return "warning";
}
private String encode(String str) {
if(str == null){
return "";
}
return str
.replaceAll("&", "&")
.replaceAll("\"", """)
.replaceAll("'", "'")
.replaceAll("<", "<")
.replaceAll(">", ">");
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy