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