This repository has been archived by the owner on Jul 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds support for tslint 4.0.0's new (fixed!) output format, and definitions for more rules introduced in the past while. Fixes long tslint output on Linux being truncated (merged issue69 branch). Fixes #67, #69, #70
- Loading branch information
1 parent
4c93d89
commit 35918a9
Showing
12 changed files
with
399 additions
and
480 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
package com.pablissimo.sonar; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import com.pablissimo.sonar.model.TsLintIssue; | ||
|
||
public interface TsLintParser { | ||
TsLintIssue[][] parse(String toParse); | ||
Map<String, List<TsLintIssue>> parse(List<String> rawOutputBatches); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,56 @@ | ||
package com.pablissimo.sonar; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
import com.pablissimo.sonar.model.TsLintIssue; | ||
|
||
public class TsLintParserImpl implements TsLintParser { | ||
public TsLintIssue[][] parse(String toParse) { | ||
private static final Logger LOG = LoggerFactory.getLogger(TsLintParserImpl.class); | ||
|
||
public Map<String, List<TsLintIssue>> parse(List<String> toParse) { | ||
GsonBuilder builder = new GsonBuilder(); | ||
Gson gson = builder.create(); | ||
|
||
List<TsLintIssue> allIssues = new ArrayList<TsLintIssue>(); | ||
|
||
for (String batch : toParse) { | ||
TsLintIssue[] batchIssues = gson.fromJson(getFixedUpOutput(batch), TsLintIssue[].class); | ||
for (TsLintIssue batchIssue : batchIssues) { | ||
allIssues.add(batchIssue); | ||
} | ||
} | ||
|
||
return gson.fromJson(toParse, TsLintIssue[][].class); | ||
// Remap by filename | ||
Map<String, List<TsLintIssue>> toReturn = new HashMap<String, List<TsLintIssue>>(); | ||
for (TsLintIssue issue : allIssues) { | ||
List<TsLintIssue> issuesByFile = toReturn.get(issue.getName()); | ||
if (issuesByFile == null) { | ||
issuesByFile = new ArrayList<TsLintIssue>(); | ||
toReturn.put(issue.getName(), issuesByFile); | ||
} | ||
|
||
issuesByFile.add(issue); | ||
} | ||
|
||
return toReturn; | ||
} | ||
|
||
private String getFixedUpOutput(String toParse) { | ||
if (toParse.contains("][")) { | ||
// Pre 4.0.0-versions of TsLint return nonsense for its JSON output | ||
// when faced with multiple files so we need to fix it up before we | ||
// do anything else | ||
return toParse.replaceAll("\\]\\[", ","); | ||
} | ||
|
||
return toParse; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.