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()));
}
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();
}
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()));
}
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()));
}
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"));
}
Aggregations