Skip to content

Commit

Permalink
update ruby analyzer.
Browse files Browse the repository at this point in the history
  • Loading branch information
catchcatchus authored and random1223 committed Sep 5, 2024
1 parent 96ed70e commit 1cd1bda
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.codety.scanner.analyzer.rubocop.dto.RubocopRoot;
import io.codety.scanner.reporter.dto.CodeAnalysisIssueDto;
import io.codety.scanner.util.JsonFactoryUtil;
import io.codety.scanner.util.StringUtil;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -39,10 +40,11 @@ public static List<CodeAnalysisIssueDto> convertResult(String errorOutput, Strin
String externalRuleId = rubocopOffense.getCop_name();
String[] split = externalRuleId.split("/");
String category = split[0].toLowerCase();
String issue = StringUtil.camelCaseSentencesToDashConnectedSentences(split[1].trim());
RubocopIssueLocation location = rubocopOffense.getLocation();
issueDto.setStartLineNumber(location.getStart_line());
issueDto.setEndLineNumber(location.getLast_line());
issueDto.setIssueCode(externalRuleId);
issueDto.setIssueCode(issue);
issueDto.setIssueCategory(category);
issueDto.setDescription(rubocopOffense.getMessage());
issueDto.setPriority(convertPriority(rubocopOffense.getSeverity()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,24 @@ public static String toCamelCaseWord(String str){

}

public static String camelCaseSentencesToDashConnectedSentences(String str){
if(str == null){
return str;
}

StringBuilder builder = new StringBuilder();
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
if(i == 0) {
builder.append(Character.toLowerCase(c));
}else if(Character.isUpperCase(c)){
builder.append("-").append(Character.toLowerCase(c));
}else{
builder.append(c);
}
}
return builder.toString();

}

}

0 comments on commit 1cd1bda

Please sign in to comment.