Skip to content

Commit

Permalink
Fixed warnings (appending concatenated strings and sizing arrays prop…
Browse files Browse the repository at this point in the history
…erly on creation)
  • Loading branch information
SeanShubin committed Jan 26, 2015
1 parent 9c89b12 commit e6858d1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
8 changes: 5 additions & 3 deletions src/main/java/com/cj/jshintmojo/reporter/JSLintReporter.java
Expand Up @@ -2,6 +2,7 @@

import java.util.Arrays;
import java.util.Map;
import java.util.Set;

import org.apache.commons.lang.StringUtils;

Expand All @@ -26,16 +27,17 @@ public String report(Map<String, Result> results) {
StringBuilder buf = new StringBuilder();
buf.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
buf.append("<jslint>\n");
String[] files = results.keySet().toArray(new String[0]);
Set<String> strings = results.keySet();
String[] files = strings.toArray(new String[strings.size()]);
Arrays.sort(files);
for(String file : files){
Result result = results.get(file);
buf.append("\t<file name=\"" + result.path + "\">\n");
buf.append("\t<file name=\"").append(result.path).append("\">\n");
for(JSHint.Error issue : result.errors){
buf.append(String.format("\t\t<issue line=\"%d\" char=\"%d\" reason=\"%s\" evidence=\"%s\" ",
issue.line.intValue(), issue.character.intValue(), encode(issue.reason), encode(issue.evidence)));
if(StringUtils.isNotEmpty(issue.code)){
buf.append("severity=\"" + issue.code.charAt(0) + "\" ");
buf.append("severity=\"").append(issue.code.charAt(0)).append("\" ");
}
buf.append("/>\n");
}
Expand Down
19 changes: 11 additions & 8 deletions src/main/java/com/cj/jshintmojo/util/OptionsParser.java
@@ -1,5 +1,6 @@
package com.cj.jshintmojo.util;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -59,20 +60,22 @@ public static Set<String> extractOptions(byte[] configFileContentsBytes) {
}

/**
* @param configFileContentsBytes
* @param configFileContents
* JSON-like file contents
* @return set of JSHint allowed globals
*/
public static Set<String> extractGlobals(byte[] configFileContents) {
String withoutComments = removeComments(new String(configFileContents));
Matcher matcher = GLOBALS_PATTERN.matcher(withoutComments);
matcher.find();
String globalsCsv = matcher.group(1).replaceAll("\\s", "").replaceAll("\"", "");
if(matcher.find()) {
String globalsCsv = matcher.group(1).replaceAll("\\s", "").replaceAll("\"", "");

Set<String> globalsSet = new HashSet<String>();
for (String global : globalsCsv.split(",")) {
globalsSet.add(global);
}
return globalsSet;
Set<String> globalsSet = new HashSet<String>();
Collections.addAll(globalsSet, globalsCsv.split(","));
return globalsSet;
} else {
throw new RuntimeException(String.format(
"Unable to find pattern '%s' in text '%s'", GLOBALS_PATTERN, withoutComments));
}
}
}

0 comments on commit e6858d1

Please sign in to comment.