use of org.sonarsource.sonarlint.core.client.api.common.RuleKey in project sonarlint-core by SonarSource.
the class StandaloneIssueMediumTests method simpleJavaWithIssueOnDir.
@Test
void simpleJavaWithIssueOnDir() throws Exception {
var inputFile = prepareInputFile("foo/Foo.java", "package foo;\n" + "public class Foo {\n" + "}", false);
final Collection<RuleKey> includedRules = singleton(new RuleKey("java", "S1228"));
final List<Issue> issues = new ArrayList<>();
sonarlint.analyze(StandaloneAnalysisConfiguration.builder().setBaseDir(baseDir.toPath()).addInputFile(inputFile).addIncludedRules(includedRules).build(), issues::add, null, null);
assertThat(issues).extracting(Issue::getRuleKey, Issue::getStartLine, i -> i.getInputFile() != null ? i.getInputFile().relativePath() : null, Issue::getSeverity).containsOnly(tuple("java:S2094", 2, "foo/Foo.java", "MINOR"), tuple("java:S1228", null, null, "MINOR"));
}
use of org.sonarsource.sonarlint.core.client.api.common.RuleKey in project sonarlint-core by SonarSource.
the class StandaloneIssueMediumTests method simpleJavaNoHotspots.
@Test
void simpleJavaNoHotspots() throws Exception {
assertThat(sonarlint.getAllRuleDetails()).extracting(RuleDetails::getKey).doesNotContain("java:S1313");
assertThat(sonarlint.getRuleDetails("java:S1313")).isEmpty();
var inputFile = prepareInputFile("foo/Foo.java", "package foo;\n" + "public class Foo {\n" + " String ip = \"192.168.12.42\"; // Hotspots should not be reported in SonarLint\n" + "}", false);
final List<Issue> issues = new ArrayList<>();
sonarlint.analyze(StandaloneAnalysisConfiguration.builder().setBaseDir(baseDir.toPath()).addInputFile(inputFile).addIncludedRule(new RuleKey("java", "S1313")).build(), issues::add, null, null);
assertThat(issues).isEmpty();
}
use of org.sonarsource.sonarlint.core.client.api.common.RuleKey in project sonarlint-core by SonarSource.
the class StandaloneIssueMediumTests method simpleJavaWithIncludedAndExcludedRules.
@Test
void simpleJavaWithIncludedAndExcludedRules() throws Exception {
var inputFile = prepareInputFile(A_JAVA_FILE_PATH, "import java.util.Optional;\n" + "public class Foo {\n" + " public void foo(Optional<String> name) { // for squid:S3553, not in Sonar Way\n" + " int x;\n" + " System.out.println(\"Foo\" + name.isPresent());\n" + " }\n" + "}", false);
// exclusion wins
final Collection<RuleKey> excludedRules = Collections.singleton(new RuleKey("squid", "S3553"));
final Collection<RuleKey> includedRules = Collections.singleton(new RuleKey("squid", "S3553"));
final List<Issue> issues = new ArrayList<>();
sonarlint.analyze(StandaloneAnalysisConfiguration.builder().setBaseDir(baseDir.toPath()).addInputFile(inputFile).addExcludedRules(excludedRules).addIncludedRules(includedRules).build(), issues::add, null, null);
assertThat(issues).extracting(Issue::getRuleKey, Issue::getStartLine, i -> i.getInputFile().relativePath(), Issue::getSeverity).containsOnly(tuple("java:S106", 5, A_JAVA_FILE_PATH, "MAJOR"), tuple("java:S1220", null, A_JAVA_FILE_PATH, "MINOR"), tuple("java:S1481", 4, A_JAVA_FILE_PATH, "MINOR"));
}
use of org.sonarsource.sonarlint.core.client.api.common.RuleKey in project sonarlint-core by SonarSource.
the class StandaloneIssueMediumTests method simpleJavaWithExcludedRulesUsingDeprecatedKey.
@Test
void simpleJavaWithExcludedRulesUsingDeprecatedKey() throws Exception {
var inputFile = prepareInputFile(A_JAVA_FILE_PATH, "public class Foo {\n" + " public void foo() {\n" + " int x;\n" + " System.out.println(\"Foo\");\n" + " }\n" + "}", false);
final Collection<RuleKey> excludedRules = singleton(new RuleKey("squid", "S106"));
List<String> logs = new ArrayList<>();
final List<Issue> issues = new ArrayList<>();
sonarlint.analyze(StandaloneAnalysisConfiguration.builder().setBaseDir(baseDir.toPath()).addInputFile(inputFile).addExcludedRules(excludedRules).build(), issues::add, (msg, lvl) -> logs.add(msg), null);
assertThat(issues).extracting(Issue::getRuleKey, Issue::getStartLine, i -> i.getInputFile().relativePath(), Issue::getSeverity).containsOnly(tuple("java:S1220", null, A_JAVA_FILE_PATH, "MINOR"), tuple("java:S1481", 3, A_JAVA_FILE_PATH, "MINOR"));
assertThat(logs).contains("Rule 'java:S106' was excluded using its deprecated key 'squid:S106'. Please fix your configuration.");
}
Aggregations