@Test public void test_issues() throws IOException { SensorContextTester context = SoliumTestHelper.createContext(7, 2); context.settings().setProperty(SoliumReportSensor.PROPERTY_KEY, REPORT_BASE_PATH.resolve("test-report1.out").toString()); List<ExternalIssue> externalIssues = SoliumTestHelper.executeSensor(new SoliumReportSensor(), context); assertThat(externalIssues).isNotEmpty(); ExternalIssue firstExternalIssue = externalIssues.get(0); assertThat(firstExternalIssue.ruleKey()).isEqualTo(RuleKey.parse("solium:security/no-block-members")); assertThat(firstExternalIssue.type()).isEqualTo(RuleType.CODE_SMELL); assertThat(firstExternalIssue.severity()).isEqualTo(Severity.MAJOR); assertThat(firstExternalIssue.primaryLocation().message()).isEqualTo("Avoid using 'now' (alias to 'block.timestamp')."); assertThat(firstExternalIssue.primaryLocation().textRange().start().line()).isEqualTo(6); }
@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; }