Skip to content
This repository has been archived by the owner on Jul 8, 2019. It is now read-only.

Commit

Permalink
Fixing most of the more straightforward code smells
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablissimo committed Feb 19, 2017
1 parent e450a62 commit adf4e59
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 12 deletions.
Expand Up @@ -133,7 +133,7 @@ public void execute(SensorContext ctx, Map<InputFile, Set<Integer>> nonCommentLi
Map<InputFile, Set<Integer>> nonCommentLineMap = nonCommentLineNumbersByFile;

if (nonCommentLineMap == null) {
nonCommentLineMap = new HashMap<InputFile, Set<Integer>>();
nonCommentLineMap = new HashMap<>();
}

if (isLCOVReportProvided(ctx)) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/pablissimo/sonar/TsLintParser.java
Expand Up @@ -5,6 +5,7 @@

import com.pablissimo.sonar.model.TsLintIssue;

@FunctionalInterface
public interface TsLintParser {
Map<String, List<TsLintIssue>> parse(List<String> rawOutputBatches);
}
9 changes: 5 additions & 4 deletions src/main/java/com/pablissimo/sonar/TsLintParserImpl.java
Expand Up @@ -12,12 +12,13 @@
import com.pablissimo.sonar.model.TsLintIssue;

@BatchSide
public class TsLintParserImpl implements TsLintParser {
public class TsLintParserImpl implements TsLintParser {
@Override
public Map<String, List<TsLintIssue>> parse(List<String> toParse) {
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();

List<TsLintIssue> allIssues = new ArrayList<TsLintIssue>();
List<TsLintIssue> allIssues = new ArrayList<>();

for (String batch : toParse) {
TsLintIssue[] batchIssues = gson.fromJson(getFixedUpOutput(batch), TsLintIssue[].class);
Expand All @@ -32,11 +33,11 @@ public Map<String, List<TsLintIssue>> parse(List<String> toParse) {
}

// Remap by filename
Map<String, List<TsLintIssue>> toReturn = new HashMap<String, List<TsLintIssue>>();
Map<String, List<TsLintIssue>> toReturn = new HashMap<>();
for (TsLintIssue issue : allIssues) {
List<TsLintIssue> issuesByFile = toReturn.get(issue.getName());
if (issuesByFile == null) {
issuesByFile = new ArrayList<TsLintIssue>();
issuesByFile = new ArrayList<>();
toReturn.put(issue.getName(), issuesByFile);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/pablissimo/sonar/TsLintSensor.java
Expand Up @@ -67,7 +67,7 @@ public void execute(SensorContext ctx) {
ruleNames.add(rule.ruleKey().rule());
}

List<String> paths = new ArrayList<String>();
List<String> paths = new ArrayList<>();

for (InputFile file : ctx.fileSystem().inputFiles(ctx.fileSystem().predicates().hasLanguage(TypeScriptLanguage.LANGUAGE_KEY))) {
if (shouldSkipFile(file.file(), skipTypeDefFiles)) {
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/com/pablissimo/sonar/TsRulesDefinition.java
Expand Up @@ -136,12 +136,7 @@ public static void loadRules(InputStream stream, List<TsLintRule> rulesCollectio
rulesCollection.add(tsRule);
}

Collections.sort(rulesCollection, new Comparator<TsLintRule>() {
@Override
public int compare(TsLintRule r1, TsLintRule r2) {
return r1.key.compareTo(r2.key);
}
});
Collections.sort(rulesCollection, (TsLintRule r1, TsLintRule r2) -> r1.key.compareTo(r2.key));
}

private void createRule(NewRepository repository, TsLintRule tsRule) {
Expand Down Expand Up @@ -190,6 +185,7 @@ private void createRule(NewRepository repository, TsLintRule tsRule) {
sonarRule.setType(type);
}

@Override
public void define(Context context) {
NewRepository repository =
context
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/pablissimo/sonar/TypeScriptLanguage.java
Expand Up @@ -12,6 +12,7 @@ public TypeScriptLanguage(){
super(LANGUAGE_KEY, LANGUAGE_NAME);
}

@Override
public String[] getFileSuffixes() {
return LANGUAGE_EXTENSIONS;
}
Expand Down

0 comments on commit adf4e59

Please sign in to comment.