-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0ae5e82
commit 1073e2a
Showing
11 changed files
with
3,797 additions
and
0 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
...er-rubocop/src/main/java/io/codety/scanner/analyzer/rubocop/RubocopAnalyzerConverter.java
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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package io.codety.scanner.analyzer.rubocop; | ||
|
||
import io.codety.scanner.analyzer.rubocop.dto.RubocopFile; | ||
import io.codety.scanner.analyzer.rubocop.dto.RubocopIssueLocation; | ||
import io.codety.scanner.analyzer.rubocop.dto.RubocopOffense; | ||
import io.codety.scanner.analyzer.rubocop.dto.RubocopRoot; | ||
import io.codety.scanner.reporter.dto.CodeAnalysisIssueDto; | ||
import io.codety.scanner.util.JsonFactoryUtil; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class RubocopAnalyzerConverter { | ||
public static List<CodeAnalysisIssueDto> convertResult(String errorOutput, String basePath) throws Exception { | ||
ArrayList<CodeAnalysisIssueDto> codeAnalysisIssueDtos = new ArrayList<>(); | ||
|
||
RubocopRoot rubocopRoot = JsonFactoryUtil.objectMapper.readValue(errorOutput, RubocopRoot.class); | ||
ArrayList<RubocopFile> files = rubocopRoot.getFiles(); | ||
if(files == null){ | ||
return codeAnalysisIssueDtos; | ||
} | ||
|
||
for(RubocopFile rubocopFile : files){ | ||
|
||
ArrayList<RubocopOffense> rubocopIssues = rubocopFile.getOffenses(); | ||
if(rubocopIssues == null || rubocopIssues.isEmpty()){ | ||
continue; | ||
} | ||
|
||
String path = rubocopFile.getPath(); | ||
if(path.startsWith(basePath)){ | ||
path = path.substring(basePath.length()+1); | ||
} | ||
|
||
|
||
for(RubocopOffense rubocopOffense : rubocopIssues){ | ||
CodeAnalysisIssueDto issueDto = new CodeAnalysisIssueDto(); | ||
|
||
String externalRuleId = rubocopOffense.getCop_name(); | ||
String[] split = externalRuleId.split("/"); | ||
String category = split[0].toLowerCase(); | ||
RubocopIssueLocation location = rubocopOffense.getLocation(); | ||
issueDto.setStartLineNumber(location.getStart_line()); | ||
issueDto.setEndLineNumber(location.getLast_line()); | ||
issueDto.setIssueCode(externalRuleId); | ||
issueDto.setIssueCategory(category); | ||
issueDto.setDescription(rubocopOffense.getMessage()); | ||
issueDto.setPriority(convertPriority(rubocopOffense.getSeverity())); | ||
issueDto.setFilePath(path); | ||
codeAnalysisIssueDtos.add(issueDto); | ||
} | ||
} | ||
|
||
|
||
return codeAnalysisIssueDtos; | ||
} | ||
|
||
private static Integer convertPriority(String severity) { | ||
Integer priority = 3; | ||
if(severity.equalsIgnoreCase("info")){ | ||
priority = 1; | ||
}else if(severity.equalsIgnoreCase("refactor")){ | ||
priority = 2; | ||
}else if(severity.equalsIgnoreCase("convention")){ | ||
priority = 2; | ||
}else if(severity.equalsIgnoreCase("warning")){ | ||
priority = 3; | ||
}else if(severity.equalsIgnoreCase("error")){ | ||
priority = 4; | ||
}else if(severity.equalsIgnoreCase("fatal")){ | ||
priority = 5; | ||
} | ||
return priority; | ||
} | ||
} |
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
29 changes: 29 additions & 0 deletions
29
analyzer-rubocop/src/main/java/io/codety/scanner/analyzer/rubocop/dto/RubocopFile.java
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.codety.scanner.analyzer.rubocop.dto; | ||
|
||
import java.util.ArrayList; | ||
|
||
// import com.fasterxml.jackson.databind.ObjectMapper; // version 2.11.1 | ||
// import com.fasterxml.jackson.annotation.JsonProperty; // version 2.11.1 | ||
/* ObjectMapper om = new ObjectMapper(); | ||
Root root = om.readValue(myJsonString, Root.class); */ | ||
public class RubocopFile { | ||
private String path; | ||
private ArrayList<RubocopOffense> offenses; | ||
|
||
public String getPath() { | ||
return path; | ||
} | ||
|
||
public void setPath(String path) { | ||
this.path = path; | ||
} | ||
|
||
public ArrayList<RubocopOffense> getOffenses() { | ||
return offenses; | ||
} | ||
|
||
public void setOffenses(ArrayList<RubocopOffense> offenses) { | ||
this.offenses = offenses; | ||
} | ||
} | ||
|
67 changes: 67 additions & 0 deletions
67
...er-rubocop/src/main/java/io/codety/scanner/analyzer/rubocop/dto/RubocopIssueLocation.java
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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package io.codety.scanner.analyzer.rubocop.dto; | ||
|
||
public class RubocopIssueLocation { | ||
private Integer start_line; | ||
private Integer start_column; | ||
private Integer last_line; | ||
private Integer last_column; | ||
private Integer length; | ||
private Integer line; | ||
private Integer column; | ||
|
||
public Integer getStart_line() { | ||
return start_line; | ||
} | ||
|
||
public void setStart_line(Integer start_line) { | ||
this.start_line = start_line; | ||
} | ||
|
||
public Integer getStart_column() { | ||
return start_column; | ||
} | ||
|
||
public void setStart_column(Integer start_column) { | ||
this.start_column = start_column; | ||
} | ||
|
||
public Integer getLast_line() { | ||
return last_line; | ||
} | ||
|
||
public void setLast_line(Integer last_line) { | ||
this.last_line = last_line; | ||
} | ||
|
||
public Integer getLast_column() { | ||
return last_column; | ||
} | ||
|
||
public void setLast_column(Integer last_column) { | ||
this.last_column = last_column; | ||
} | ||
|
||
public Integer getLength() { | ||
return length; | ||
} | ||
|
||
public void setLength(Integer length) { | ||
this.length = length; | ||
} | ||
|
||
public Integer getLine() { | ||
return line; | ||
} | ||
|
||
public void setLine(Integer line) { | ||
this.line = line; | ||
} | ||
|
||
public Integer getColumn() { | ||
return column; | ||
} | ||
|
||
public void setColumn(Integer column) { | ||
this.column = column; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
analyzer-rubocop/src/main/java/io/codety/scanner/analyzer/rubocop/dto/RubocopMetadata.java
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package io.codety.scanner.analyzer.rubocop.dto; | ||
|
||
public class RubocopMetadata { | ||
private String rubocop_version; | ||
private String ruby_engine; | ||
private String ruby_version; | ||
private String ruby_patchlevel; | ||
private String ruby_platform; | ||
|
||
public String getRubocop_version() { | ||
return rubocop_version; | ||
} | ||
|
||
public void setRubocop_version(String rubocop_version) { | ||
this.rubocop_version = rubocop_version; | ||
} | ||
|
||
public String getRuby_engine() { | ||
return ruby_engine; | ||
} | ||
|
||
public void setRuby_engine(String ruby_engine) { | ||
this.ruby_engine = ruby_engine; | ||
} | ||
|
||
public String getRuby_version() { | ||
return ruby_version; | ||
} | ||
|
||
public void setRuby_version(String ruby_version) { | ||
this.ruby_version = ruby_version; | ||
} | ||
|
||
public String getRuby_patchlevel() { | ||
return ruby_patchlevel; | ||
} | ||
|
||
public void setRuby_patchlevel(String ruby_patchlevel) { | ||
this.ruby_patchlevel = ruby_patchlevel; | ||
} | ||
|
||
public String getRuby_platform() { | ||
return ruby_platform; | ||
} | ||
|
||
public void setRuby_platform(String ruby_platform) { | ||
this.ruby_platform = ruby_platform; | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
analyzer-rubocop/src/main/java/io/codety/scanner/analyzer/rubocop/dto/RubocopOffense.java
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package io.codety.scanner.analyzer.rubocop.dto; | ||
|
||
public class RubocopOffense { | ||
private String severity; | ||
private String message; | ||
private String cop_name; | ||
private boolean corrected; | ||
private boolean correctable; | ||
private RubocopIssueLocation location; | ||
|
||
public String getSeverity() { | ||
return severity; | ||
} | ||
|
||
public void setSeverity(String severity) { | ||
this.severity = severity; | ||
} | ||
|
||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
public void setMessage(String message) { | ||
this.message = message; | ||
} | ||
|
||
public String getCop_name() { | ||
return cop_name; | ||
} | ||
|
||
public void setCop_name(String cop_name) { | ||
this.cop_name = cop_name; | ||
} | ||
|
||
public boolean isCorrected() { | ||
return corrected; | ||
} | ||
|
||
public void setCorrected(boolean corrected) { | ||
this.corrected = corrected; | ||
} | ||
|
||
public boolean isCorrectable() { | ||
return correctable; | ||
} | ||
|
||
public void setCorrectable(boolean correctable) { | ||
this.correctable = correctable; | ||
} | ||
|
||
public RubocopIssueLocation getLocation() { | ||
return location; | ||
} | ||
|
||
public void setLocation(RubocopIssueLocation location) { | ||
this.location = location; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
analyzer-rubocop/src/main/java/io/codety/scanner/analyzer/rubocop/dto/RubocopRoot.java
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package io.codety.scanner.analyzer.rubocop.dto; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class RubocopRoot { | ||
private RubocopMetadata metadata; | ||
private ArrayList<RubocopFile> files; | ||
private RubocopSummary summary; | ||
|
||
public RubocopMetadata getMetadata() { | ||
return metadata; | ||
} | ||
|
||
public void setMetadata(RubocopMetadata metadata) { | ||
this.metadata = metadata; | ||
} | ||
|
||
public ArrayList<RubocopFile> getFiles() { | ||
return files; | ||
} | ||
|
||
public void setFiles(ArrayList<RubocopFile> files) { | ||
this.files = files; | ||
} | ||
|
||
public RubocopSummary getSummary() { | ||
return summary; | ||
} | ||
|
||
public void setSummary(RubocopSummary summary) { | ||
this.summary = summary; | ||
} | ||
} |
Oops, something went wrong.