@Test public void simple_issue() throws IOException { String line = "21:26 error Assignment operator must have exactly single space on both sides of it. operator-whitespace"; org.sonarsource.solidity.externalreport.ExternalIssue issue = new SoliumReportSensor().parse(line); assertThat(issue).isNotNull(); assertThat(issue.message).isEqualTo("Assignment operator must have exactly single space on both sides of it."); assertThat(issue.lineNumber).isEqualTo(21); assertThat(issue.ruleKey).isEqualTo("operator-whitespace"); assertThat(issue.type).isEqualTo(RuleType.BUG); line = "21:26 error Assignment operator must have exactly single space on both sides of it. security/no-block-members"; issue = new SoliumReportSensor().parse(line); assertThat(issue).isNotNull(); line = "21:26 warning Ensure that all import statements are on top of the file imports-on-top"; issue = new SoliumReportSensor().parse(line); assertThat(issue).isNotNull(); }
@Nullable @Override ExternalIssue parse(String line) { Matcher m = SOLIUM_SPECIAL_CHARACTERS.matcher(line); String cleanLine = m.replaceAll(""); Matcher fileMatcher = SOLIUM_FILE_REGEX.matcher(cleanLine); Matcher lineMatcher = SOLIUM_LINE_REGEX.matcher(cleanLine); if (fileMatcher.matches()) { String filename = fileMatcher.group("file"); return new ExternalIssue(LINTER_ID, null, null, filename, 0, "onlyfilename"); } else if (lineMatcher.matches()) { int lineNumber = Integer.parseInt(lineMatcher.group("line")); String issueType = lineMatcher.group("type").trim(); String message = lineMatcher.group("message").trim(); String issueKey = lineMatcher.group("key").trim(); if (SoliumKeyUtils.keyExists(issueKey)) { return new ExternalIssue(LINTER_ID, matchIssueToRuleType(issueType, issueKey), issueKey, null, lineNumber, message); } else { return null; } } else { LOG.debug(logPrefix() + "Unexpected line: " + line); } return null; }
SoliumReportSensor extends AbstractExternalReportSensor { @Nullable @Override ExternalIssue parse(String line) { Matcher m = SOLIUM_SPECIAL_CHARACTERS.matcher(line); String cleanLine = m.replaceAll(""); Matcher fileMatcher = SOLIUM_FILE_REGEX.matcher(cleanLine); Matcher lineMatcher = SOLIUM_LINE_REGEX.matcher(cleanLine); if (fileMatcher.matches()) { String filename = fileMatcher.group("file"); return new ExternalIssue(LINTER_ID, null, null, filename, 0, "onlyfilename"); } else if (lineMatcher.matches()) { int lineNumber = Integer.parseInt(lineMatcher.group("line")); String issueType = lineMatcher.group("type").trim(); String message = lineMatcher.group("message").trim(); String issueKey = lineMatcher.group("key").trim(); if (SoliumKeyUtils.keyExists(issueKey)) { return new ExternalIssue(LINTER_ID, matchIssueToRuleType(issueType, issueKey), issueKey, null, lineNumber, message); } else { return null; } } else { LOG.debug(logPrefix() + "Unexpected line: " + line); } return null; } }
SoliumReportSensor extends AbstractExternalReportSensor { @Nullable @Override ExternalIssue parse(String line) { Matcher m = SOLIUM_SPECIAL_CHARACTERS.matcher(line); String cleanLine = m.replaceAll(""); Matcher fileMatcher = SOLIUM_FILE_REGEX.matcher(cleanLine); Matcher lineMatcher = SOLIUM_LINE_REGEX.matcher(cleanLine); if (fileMatcher.matches()) { String filename = fileMatcher.group("file"); return new ExternalIssue(LINTER_ID, null, null, filename, 0, "onlyfilename"); } else if (lineMatcher.matches()) { int lineNumber = Integer.parseInt(lineMatcher.group("line")); String issueType = lineMatcher.group("type").trim(); String message = lineMatcher.group("message").trim(); String issueKey = lineMatcher.group("key").trim(); if (SoliumKeyUtils.keyExists(issueKey)) { return new ExternalIssue(LINTER_ID, matchIssueToRuleType(issueType, issueKey), issueKey, null, lineNumber, message); } else { return null; } } else { LOG.debug(logPrefix() + "Unexpected line: " + line); } return null; }  }
SoliumReportSensor extends AbstractExternalReportSensor { @Nullable @Override ExternalIssue parse(String line) { Matcher m = SOLIUM_SPECIAL_CHARACTERS.matcher(line); String cleanLine = m.replaceAll(""); Matcher fileMatcher = SOLIUM_FILE_REGEX.matcher(cleanLine); Matcher lineMatcher = SOLIUM_LINE_REGEX.matcher(cleanLine); if (fileMatcher.matches()) { String filename = fileMatcher.group("file"); return new ExternalIssue(LINTER_ID, null, null, filename, 0, "onlyfilename"); } else if (lineMatcher.matches()) { int lineNumber = Integer.parseInt(lineMatcher.group("line")); String issueType = lineMatcher.group("type").trim(); String message = lineMatcher.group("message").trim(); String issueKey = lineMatcher.group("key").trim(); if (SoliumKeyUtils.keyExists(issueKey)) { return new ExternalIssue(LINTER_ID, matchIssueToRuleType(issueType, issueKey), issueKey, null, lineNumber, message); } else { return null; } } else { LOG.debug(logPrefix() + "Unexpected line: " + line); } return null; }   }
SoliumReportSensor extends AbstractExternalReportSensor { @Nullable @Override ExternalIssue parse(String line) { Matcher m = SOLIUM_SPECIAL_CHARACTERS.matcher(line); String cleanLine = m.replaceAll(""); Matcher fileMatcher = SOLIUM_FILE_REGEX.matcher(cleanLine); Matcher lineMatcher = SOLIUM_LINE_REGEX.matcher(cleanLine); if (fileMatcher.matches()) { String filename = fileMatcher.group("file"); return new ExternalIssue(LINTER_ID, null, null, filename, 0, "onlyfilename"); } else if (lineMatcher.matches()) { int lineNumber = Integer.parseInt(lineMatcher.group("line")); String issueType = lineMatcher.group("type").trim(); String message = lineMatcher.group("message").trim(); String issueKey = lineMatcher.group("key").trim(); if (SoliumKeyUtils.keyExists(issueKey)) { return new ExternalIssue(LINTER_ID, matchIssueToRuleType(issueType, issueKey), issueKey, null, lineNumber, message); } else { return null; } } else { LOG.debug(logPrefix() + "Unexpected line: " + line); } return null; }   static final String PROPERTY_KEY; static final String LINTER_NAME; static final String LINTER_ID; }