use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile in project sonarlint-core by SonarSource.
the class StandaloneIssueMediumTest method supportJavaSuppressWarning.
@Test
public void supportJavaSuppressWarning() throws Exception {
ClientInputFile inputFile = prepareInputFile("Foo.java", "public class Foo {\n" + " @SuppressWarnings(\"squid:S106\")\n" + " public void foo() {\n" + " int x;\n" + " System.out.println(\"Foo\");\n" + " System.out.println(\"Foo\"); //NOSONAR\n" + " }\n" + "}", false);
final List<Issue> issues = new ArrayList<>();
sonarlint.analyze(new StandaloneAnalysisConfiguration(baseDir.toPath(), temp.newFolder().toPath(), Arrays.asList(inputFile), ImmutableMap.of()), issue -> issues.add(issue), null, null);
assertThat(issues).extracting("ruleKey", "startLine", "inputFile.path", "severity").containsOnly(tuple("squid:S1220", null, inputFile.getPath(), "MINOR"), tuple("squid:S1481", 4, inputFile.getPath(), "MINOR"));
}
use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile in project sonarlint-core by SonarSource.
the class StandaloneIssueMediumTest method simpleTypeScript.
@Test
public void simpleTypeScript() throws Exception {
RuleDetails ruleDetails = sonarlint.getRuleDetails("typescript:S1764");
assertThat(ruleDetails.getName()).isEqualTo("Identical expressions should not be used on both sides of a binary operator");
assertThat(ruleDetails.getLanguage()).isEqualTo("ts");
assertThat(ruleDetails.getSeverity()).isEqualTo("MAJOR");
assertThat(ruleDetails.getTags()).containsOnly("cert");
assertThat(ruleDetails.getHtmlDescription()).contains("<p>", "Using the same value on either side of a binary operator is almost always a mistake");
final File tsConfig = new File(baseDir, "tsconfig.json");
FileUtils.write(tsConfig, "{}", StandardCharsets.UTF_8);
ClientInputFile inputFile = prepareInputFile("foo.ts", "function foo() {\n" + " if(bar() && bar()) { return 42; }\n" + "}", false);
final List<Issue> issues = new ArrayList<>();
sonarlint.analyze(new StandaloneAnalysisConfiguration(baseDir.toPath(), temp.newFolder().toPath(), Arrays.asList(inputFile), ImmutableMap.of()), i -> issues.add(i), null, null);
assertThat(issues).extracting("ruleKey", "startLine", "inputFile.path").containsOnly(tuple("typescript:S1764", 2, inputFile.getPath()));
}
use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile in project sonarlint-core by SonarSource.
the class StandaloneIssueMediumTest method simpleJavaPomXml.
@Test
public void simpleJavaPomXml() throws Exception {
ClientInputFile inputFile = prepareInputFile("pom.xml", "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<project>\n" + " <modelVersion>4.0.0</modelVersion>\n" + " <groupId>com.foo</groupId>\n" + " <artifactId>bar</artifactId>\n" + " <version>${pom.version}</version>\n" + "</project>", false);
final List<Issue> issues = new ArrayList<>();
sonarlint.analyze(new StandaloneAnalysisConfiguration(baseDir.toPath(), temp.newFolder().toPath(), Arrays.asList(inputFile), ImmutableMap.of()), issue -> issues.add(issue), null, null);
assertThat(issues).extracting("ruleKey", "startLine", "inputFile.path", "severity").containsOnly(tuple("squid:S3421", 6, inputFile.getPath(), "MINOR"));
}
use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile in project sonarlint-core by SonarSource.
the class StandaloneIssueMediumTest method prepareInputFile.
private ClientInputFile prepareInputFile(String relativePath, String content, final boolean isTest, Charset encoding, @Nullable String language) throws IOException {
final File file = new File(baseDir, relativePath);
FileUtils.write(file, content, encoding);
ClientInputFile inputFile = new TestClientInputFile(file.toPath(), relativePath, isTest, encoding, language);
return inputFile;
}
use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile in project sonarlint-core by SonarSource.
the class StandaloneIssueMediumTest method simplePhp.
@Test
public void simplePhp() throws Exception {
ClientInputFile inputFile = prepareInputFile("foo.php", "<?php\n" + "function writeMsg($fname) {\n" + " $i = 0; // NOSONAR\n" + " echo \"Hello world!\";\n" + "}\n" + "?>", false);
final List<Issue> issues = new ArrayList<>();
sonarlint.analyze(new StandaloneAnalysisConfiguration(baseDir.toPath(), temp.newFolder().toPath(), Arrays.asList(inputFile), ImmutableMap.of()), issue -> issues.add(issue), null, null);
assertThat(issues).extracting("ruleKey", "startLine", "inputFile.path").containsOnly(tuple("php:S1172", 2, inputFile.getPath()));
}
Aggregations