Search in sources :

Example 1 with Issue

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

the class DefaultClientIssueTests method transformIssue.

@Test
void transformIssue() {
    var currentFile = mock(InputComponent.class);
    var currentFileKey = "currentFileKey";
    when(currentFile.key()).thenReturn(currentFileKey);
    var anotherFile = mock(InputComponent.class);
    when(anotherFile.key()).thenReturn("anotherFileKey");
    textRange = new TextRange(1, 2, 2, 3);
    when(rule.getName()).thenReturn("name");
    when(rule.getType()).thenReturn("BUG");
    when(rule.getSeverity()).thenReturn("MAJOR");
    var issue = new Issue("rule:S123", "msg", textRange, clientInputFile, null, null);
    var underTest = new DefaultClientIssue(issue, rule);
    assertThat(underTest.getStartLine()).isEqualTo(1);
    assertThat(underTest.getStartLineOffset()).isEqualTo(2);
    assertThat(underTest.getEndLine()).isEqualTo(2);
    assertThat(underTest.getEndLineOffset()).isEqualTo(3);
    assertThat(underTest.getMessage()).isEqualTo("msg");
    assertThat(underTest.getSeverity()).isEqualTo("MAJOR");
    assertThat(underTest.getType()).isEqualTo("BUG");
    assertThat(underTest.getInputFile()).isEqualTo(clientInputFile);
}
Also used : Issue(org.sonarsource.sonarlint.core.analysis.api.Issue) TextRange(org.sonarsource.sonarlint.core.analysis.api.TextRange) Test(org.junit.jupiter.api.Test)

Example 2 with Issue

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

the class DefaultFilterableIssueTests method delegate_textRange_to_rawIssue.

@Test
void delegate_textRange_to_rawIssue() {
    TextRange textRange = new DefaultTextRange(new DefaultTextPointer(0, 1), new DefaultTextPointer(2, 3));
    var activeRule = mock(ActiveRuleAdapter.class);
    when(activeRule.ruleKey()).thenReturn(RuleKey.of("foo", "S123"));
    var rawIssue = new Issue(activeRule, null, textRange, null, null, null);
    FilterableIssue underTest = new DefaultFilterableIssue(rawIssue, mock(InputComponent.class));
    assertThat(underTest.textRange()).usingRecursiveComparison().isEqualTo(textRange);
}
Also used : InputComponent(org.sonar.api.batch.fs.InputComponent) FilterableIssue(org.sonar.api.scan.issue.filter.FilterableIssue) Issue(org.sonarsource.sonarlint.core.analysis.api.Issue) FilterableIssue(org.sonar.api.scan.issue.filter.FilterableIssue) DefaultTextRange(org.sonarsource.sonarlint.core.analysis.container.analysis.filesystem.DefaultTextRange) TextRange(org.sonar.api.batch.fs.TextRange) DefaultTextRange(org.sonarsource.sonarlint.core.analysis.container.analysis.filesystem.DefaultTextRange) DefaultTextPointer(org.sonarsource.sonarlint.core.analysis.container.analysis.filesystem.DefaultTextPointer) Test(org.junit.jupiter.api.Test)

Example 3 with Issue

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

Aggregations

Test (org.junit.jupiter.api.Test)3 Issue (org.sonarsource.sonarlint.core.analysis.api.Issue)3 ArrayList (java.util.ArrayList)1 InputComponent (org.sonar.api.batch.fs.InputComponent)1 TextRange (org.sonar.api.batch.fs.TextRange)1 FilterableIssue (org.sonar.api.scan.issue.filter.FilterableIssue)1 AnalysisConfiguration (org.sonarsource.sonarlint.core.analysis.api.AnalysisConfiguration)1 ClientInputFile (org.sonarsource.sonarlint.core.analysis.api.ClientInputFile)1 ClientModuleInfo (org.sonarsource.sonarlint.core.analysis.api.ClientModuleInfo)1 TextRange (org.sonarsource.sonarlint.core.analysis.api.TextRange)1 AnalyzeCommand (org.sonarsource.sonarlint.core.analysis.command.AnalyzeCommand)1 RegisterModuleCommand (org.sonarsource.sonarlint.core.analysis.command.RegisterModuleCommand)1 DefaultTextPointer (org.sonarsource.sonarlint.core.analysis.container.analysis.filesystem.DefaultTextPointer)1 DefaultTextRange (org.sonarsource.sonarlint.core.analysis.container.analysis.filesystem.DefaultTextRange)1 OnDiskTestClientInputFile (testutils.OnDiskTestClientInputFile)1