Search in sources :

Example 16 with ClientInputFile

use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile in project sonarlint-core by SonarSource.

the class StandaloneIssueMediumTest method simpleJavaWithBytecode.

@Test
public void simpleJavaWithBytecode() throws Exception {
    ClientInputFile inputFile = TestUtils.createInputFile(new File("src/test/projects/java-with-bytecode/src/Foo.java").getAbsoluteFile().toPath(), "src/Foo.java", false);
    final List<Issue> issues = new ArrayList<>();
    sonarlint.analyze(new StandaloneAnalysisConfiguration(baseDir.toPath(), temp.newFolder().toPath(), Arrays.asList(inputFile), ImmutableMap.of("sonar.java.binaries", new File("src/test/projects/java-with-bytecode/bin").getAbsolutePath())), issue -> issues.add(issue), null, null);
    assertThat(issues).extracting("ruleKey", "startLine", "inputFile.path").containsOnly(tuple("squid:S106", 5, inputFile.getPath()), tuple("squid:S1220", null, inputFile.getPath()), tuple("squid:UnusedPrivateMethod", 8, inputFile.getPath()), tuple("squid:S1186", 8, 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) 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 17 with ClientInputFile

use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile 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 18 with ClientInputFile

use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile 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 19 with ClientInputFile

use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile 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 20 with ClientInputFile

use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile 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)

Aggregations

ClientInputFile (org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile)72 Test (org.junit.Test)45 Issue (org.sonarsource.sonarlint.core.client.api.common.analysis.Issue)36 ArrayList (java.util.ArrayList)30 StandaloneAnalysisConfiguration (org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration)25 TestClientInputFile (org.sonarsource.sonarlint.core.TestClientInputFile)19 File (java.io.File)14 ConnectedAnalysisConfiguration (org.sonarsource.sonarlint.core.client.api.connected.ConnectedAnalysisConfiguration)9 Path (java.nio.file.Path)8 HashMap (java.util.HashMap)7 AnalysisResults (org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults)7 LinkedList (java.util.LinkedList)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 Collection (java.util.Collection)4 AccessToken (com.intellij.openapi.application.AccessToken)3 Logger (com.intellij.openapi.diagnostic.Logger)3 RangeMarker (com.intellij.openapi.editor.RangeMarker)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3 Project (com.intellij.openapi.project.Project)3 PsiFile (com.intellij.psi.PsiFile)3