diff --git a/analyzer-rubocop/src/main/java/io/codety/scanner/analyzer/rubocop/RubocopAnalyzerConverter.java b/analyzer-rubocop/src/main/java/io/codety/scanner/analyzer/rubocop/RubocopAnalyzerConverter.java index 56f4c6b..ebf638d 100644 --- a/analyzer-rubocop/src/main/java/io/codety/scanner/analyzer/rubocop/RubocopAnalyzerConverter.java +++ b/analyzer-rubocop/src/main/java/io/codety/scanner/analyzer/rubocop/RubocopAnalyzerConverter.java @@ -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; @@ -39,10 +40,11 @@ public static List 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())); diff --git a/scanner-common/src/main/java/io/codety/scanner/util/StringUtil.java b/scanner-common/src/main/java/io/codety/scanner/util/StringUtil.java index 9f9ac49..5872a73 100644 --- a/scanner-common/src/main/java/io/codety/scanner/util/StringUtil.java +++ b/scanner-common/src/main/java/io/codety/scanner/util/StringUtil.java @@ -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(); + + } + }