use of org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration 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.standalone.StandaloneAnalysisConfiguration 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.standalone.StandaloneAnalysisConfiguration 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()));
}
use of org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration in project sonarlint-core by SonarSource.
the class StandaloneIssueMediumTest method concurrentAnalysis.
@Test
public void concurrentAnalysis() throws Throwable {
final ClientInputFile inputFile = prepareInputFile("Foo.java", "public class Foo {\n" + " public void foo() {\n" + " int x;\n" + " System.out.println(\"Foo\");\n" + " System.out.println(\"Foo\"); //NOSONAR\n" + " }\n" + "}", false);
final Path workDir = temp.newFolder().toPath();
int parallelExecutions = 4;
ExecutorService executor = Executors.newFixedThreadPool(parallelExecutions);
List<Future<?>> results = new ArrayList<>();
for (int i = 0; i < parallelExecutions; i++) {
Runnable worker = new Runnable() {
@Override
public void run() {
sonarlint.analyze(new StandaloneAnalysisConfiguration(baseDir.toPath(), workDir, Arrays.asList(inputFile), ImmutableMap.of()), issue -> {
}, null, null);
}
};
results.add(executor.submit(worker));
}
executor.shutdown();
while (!executor.isTerminated()) {
}
for (Future<?> future : results) {
try {
future.get();
} catch (ExecutionException e) {
throw e.getCause();
}
}
}
use of org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration in project sonarlint-core by SonarSource.
the class StandaloneNoPluginMediumTest method dont_fail_if_no_plugin.
@Test
public void dont_fail_if_no_plugin() throws Exception {
ClientInputFile inputFile = prepareInputFile("foo.js", "function foo() {var x;}", false);
AnalysisResults results = sonarlint.analyze(new StandaloneAnalysisConfiguration(baseDir.toPath(), temp.newFolder().toPath(), Arrays.asList(inputFile), ImmutableMap.<String, String>of()), i -> {
}, null, null);
assertThat(results.fileCount()).isEqualTo(1);
assertThat(logs.get(Level.WARN)).contains("No analyzers installed");
}
Aggregations