Search in sources :

Example 6 with StandaloneAnalysisConfiguration

use of org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration in project sonarlint-core by SonarSource.

the class StandaloneIssueMediumTest method fileEncoding.

@Test
public void fileEncoding() throws IOException {
    ClientInputFile inputFile = prepareInputFile("foo.xoo", "function xoo() {\n" + "  var xoo1, xoo2;\n" + "  var xoo; //NOSONAR\n" + "}", false, StandardCharsets.UTF_16, null);
    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", "startLineOffset", "inputFile.path").containsOnly(tuple("xoo:HasTag", 1, 9, inputFile.getPath()), tuple("xoo:HasTag", 2, 6, inputFile.getPath()), tuple("xoo:HasTag", 2, 12, inputFile.getPath()));
}
Also used : Issue(org.sonarsource.sonarlint.core.client.api.common.analysis.Issue) ArrayList(java.util.ArrayList) StandaloneAnalysisConfiguration(org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) TestClientInputFile(org.sonarsource.sonarlint.core.TestClientInputFile) Test(org.junit.Test)

Example 7 with StandaloneAnalysisConfiguration

use of org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration in project sonarlint-core by SonarSource.

the class StandaloneIssueMediumTest method simpleJavaScript.

@Test
public void simpleJavaScript() throws Exception {
    RuleDetails ruleDetails = sonarlint.getRuleDetails("javascript:UnusedVariable");
    assertThat(ruleDetails.getName()).isEqualTo("Unused local variables and functions should be removed");
    assertThat(ruleDetails.getLanguage()).isEqualTo("js");
    assertThat(ruleDetails.getSeverity()).isEqualTo("MINOR");
    assertThat(ruleDetails.getTags()).containsOnly("unused");
    assertThat(ruleDetails.getHtmlDescription()).contains("<p>", "If a local variable or a local function is declared but not used");
    String content = "function foo() {\n" + "  var x;\n" + "  var y; //NOSONAR\n" + "}";
    ClientInputFile inputFile = prepareInputFile("foo.js", content, 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("javascript:UnusedVariable", 2, inputFile.getPath()));
    // SLCORE-160
    inputFile = prepareInputFile("node_modules/foo.js", content, false);
    issues.clear();
    sonarlint.analyze(new StandaloneAnalysisConfiguration(baseDir.toPath(), temp.newFolder().toPath(), Arrays.asList(inputFile), ImmutableMap.of()), i -> issues.add(i), null, null);
    assertThat(issues).isEmpty();
}
Also used : Issue(org.sonarsource.sonarlint.core.client.api.common.analysis.Issue) ArrayList(java.util.ArrayList) StandaloneAnalysisConfiguration(org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) TestClientInputFile(org.sonarsource.sonarlint.core.TestClientInputFile) RuleDetails(org.sonarsource.sonarlint.core.client.api.common.RuleDetails) Test(org.junit.Test)

Example 8 with StandaloneAnalysisConfiguration

use of org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration in project sonarlint-core by SonarSource.

the class StandaloneIssueMediumTest method analysisErrors.

@Test
public void analysisErrors() throws Exception {
    ClientInputFile inputFile = prepareInputFile("foo.xoo", "function foo() {\n" + "  var xoo;\n" + "  var y; //NOSONAR\n" + "}", false);
    prepareInputFile("foo.xoo.error", "1,2,error analysing\n2,3,error analysing", false);
    final List<Issue> issues = new ArrayList<>();
    AnalysisResults results = sonarlint.analyze(new StandaloneAnalysisConfiguration(baseDir.toPath(), temp.newFolder().toPath(), Arrays.asList(inputFile), ImmutableMap.of()), issue -> issues.add(issue), null, null);
    assertThat(results.failedAnalysisFiles()).containsExactly(inputFile);
    assertThat(issues).extracting("ruleKey", "startLine", "startLineOffset", "inputFile.path").containsOnly(tuple("xoo:HasTag", 2, 6, inputFile.getPath()));
}
Also used : Issue(org.sonarsource.sonarlint.core.client.api.common.analysis.Issue) AnalysisResults(org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults) ArrayList(java.util.ArrayList) StandaloneAnalysisConfiguration(org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) TestClientInputFile(org.sonarsource.sonarlint.core.TestClientInputFile) Test(org.junit.Test)

Example 9 with StandaloneAnalysisConfiguration

use of org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration in project sonarlint-core by SonarSource.

the class StandaloneIssueMediumTest method useRelativePathToEvaluatePathPatterns.

// SLCORE-162
@Test
public void useRelativePathToEvaluatePathPatterns() throws Exception {
    // Temporary file doesn't have the correct file suffix
    final File file = new File(baseDir, "foo.tmp");
    FileUtils.write(file, "def my_function(name):\n" + "    print \"Hello\"\n" + "    print \"world!\" # NOSONAR\n" + "\n", StandardCharsets.UTF_8);
    ClientInputFile inputFile = new TestClientInputFile(file.toPath(), "foo.py", false, StandardCharsets.UTF_8, null);
    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("python:PrintStatementUsage", 2, inputFile.getPath()));
}
Also used : Issue(org.sonarsource.sonarlint.core.client.api.common.analysis.Issue) ArrayList(java.util.ArrayList) StandaloneAnalysisConfiguration(org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) TestClientInputFile(org.sonarsource.sonarlint.core.TestClientInputFile) TestClientInputFile(org.sonarsource.sonarlint.core.TestClientInputFile) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) TestClientInputFile(org.sonarsource.sonarlint.core.TestClientInputFile) File(java.io.File) Test(org.junit.Test)

Example 10 with StandaloneAnalysisConfiguration

use of org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration 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"));
}
Also used : Issue(org.sonarsource.sonarlint.core.client.api.common.analysis.Issue) ArrayList(java.util.ArrayList) StandaloneAnalysisConfiguration(org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) TestClientInputFile(org.sonarsource.sonarlint.core.TestClientInputFile) Test(org.junit.Test)

Aggregations

StandaloneAnalysisConfiguration (org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration)27 ClientInputFile (org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile)25 ArrayList (java.util.ArrayList)23 Test (org.junit.Test)23 Issue (org.sonarsource.sonarlint.core.client.api.common.analysis.Issue)22 TestClientInputFile (org.sonarsource.sonarlint.core.TestClientInputFile)15 AnalysisResults (org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults)5 File (java.io.File)4 Path (java.nio.file.Path)3 HashMap (java.util.HashMap)2 RuleDetails (org.sonarsource.sonarlint.core.client.api.common.RuleDetails)2 URI (java.net.URI)1 LinkedList (java.util.LinkedList)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 PublishDiagnosticsParams (org.eclipse.lsp4j.PublishDiagnosticsParams)1 DefaultClientInputFile (org.sonarlint.daemon.model.DefaultClientInputFile)1 ProxyIssueListener (org.sonarlint.daemon.model.ProxyIssueListener)1 ProjectLogOutput (org.sonarlint.intellij.util.ProjectLogOutput)1