Search in sources :

Example 16 with ClientInputFile

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

the class AnalysisEngineMediumTests method should_analyze_a_file_inside_a_module.

@Test
void should_analyze_a_file_inside_a_module(@TempDir Path baseDir) throws Exception {
    var content = "def foo():\n" + "  x = 9; # trailing comment\n";
    ClientInputFile inputFile = preparePythonInputFile(baseDir, content);
    AnalysisConfiguration analysisConfig = AnalysisConfiguration.builder().addInputFiles(inputFile).addActiveRules(trailingCommentRule()).setBaseDir(baseDir).build();
    List<Issue> issues = new ArrayList<>();
    analysisEngine.post(new RegisterModuleCommand(new ClientModuleInfo("moduleKey", aModuleFileSystem())), progressMonitor).get();
    analysisEngine.post(new AnalyzeCommand("moduleKey", analysisConfig, issues::add, null), progressMonitor).get();
    assertThat(issues).extracting("ruleKey", "message", "inputFile", "flows", "quickFixes", "textRange.startLine", "textRange.startLineOffset", "textRange.endLine", "textRange.endLineOffset").containsOnly(tuple("python:S139", "Move this trailing comment on the previous empty line.", inputFile, List.of(), List.of(), 2, 9, 2, 27));
}
Also used : Issue(org.sonarsource.sonarlint.core.analysis.api.Issue) AnalysisConfiguration(org.sonarsource.sonarlint.core.analysis.api.AnalysisConfiguration) ArrayList(java.util.ArrayList) ClientModuleInfo(org.sonarsource.sonarlint.core.analysis.api.ClientModuleInfo) OnDiskTestClientInputFile(testutils.OnDiskTestClientInputFile) ClientInputFile(org.sonarsource.sonarlint.core.analysis.api.ClientInputFile) RegisterModuleCommand(org.sonarsource.sonarlint.core.analysis.command.RegisterModuleCommand) AnalyzeCommand(org.sonarsource.sonarlint.core.analysis.command.AnalyzeCommand) Test(org.junit.jupiter.api.Test)

Example 17 with ClientInputFile

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

the class AbstractAnalysisConfiguration method generateToStringInputFiles.

protected void generateToStringInputFiles(StringBuilder sb) {
    sb.append("  inputFiles: [\n");
    for (ClientInputFile inputFile : inputFiles()) {
        sb.append("    ").append(inputFile.uri());
        sb.append(" (").append(getCharsetLabel(inputFile)).append(")");
        if (inputFile.isTest()) {
            sb.append(" [test]");
        }
        var language = inputFile.language();
        if (language != null) {
            sb.append(" [" + language.getLanguageKey() + "]");
        }
        sb.append("\n");
    }
    sb.append("  ]\n");
}
Also used : ClientInputFile(org.sonarsource.sonarlint.core.analysis.api.ClientInputFile)

Aggregations

ClientInputFile (org.sonarsource.sonarlint.core.analysis.api.ClientInputFile)17 Test (org.junit.jupiter.api.Test)16 OnDiskTestClientInputFile (testutils.OnDiskTestClientInputFile)14 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 InputFile (org.sonar.api.batch.fs.InputFile)4 InMemoryTestClientInputFile (testutils.InMemoryTestClientInputFile)4 File (java.io.File)3 Map (java.util.Map)3 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)3 RuleKey (org.sonarsource.sonarlint.core.client.api.common.RuleKey)3 Issue (org.sonarsource.sonarlint.core.client.api.common.analysis.Issue)3 IOException (java.io.IOException)2 Charset (java.nio.charset.Charset)2 StandardCharsets (java.nio.charset.StandardCharsets)2 Files (java.nio.file.Files)2 Path (java.nio.file.Path)2 Paths (java.nio.file.Paths)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2