Search in sources :

Example 1 with TextRange

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

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

the class ConnectedModeTest method canFetchHotspot.

@Test
public void canFetchHotspot() throws InvalidProtocolBufferException {
    assumeTrue("SonarQube should support opening security hotspots", ORCHESTRATOR.getServer().version().isGreaterThanOrEquals(8, 6));
    analyzeMavenProject(PROJECT_KEY_JAVA_HOTSPOT);
    var securityHotspotsService = new ServerApi(endpointParams(ORCHESTRATOR), sqHttpClient()).hotspot();
    var remoteHotspot = securityHotspotsService.fetch(new GetSecurityHotspotRequestParams(getFirstHotspotKey(PROJECT_KEY_JAVA_HOTSPOT), PROJECT_KEY_JAVA_HOTSPOT));
    assertThat(remoteHotspot).isNotEmpty();
    var actualHotspot = remoteHotspot.get();
    assertThat(actualHotspot.message).isEqualTo("Make sure using this hardcoded IP address is safe here.");
    assertThat(actualHotspot.filePath).isEqualTo("src/main/java/foo/Foo.java");
    assertThat(actualHotspot.textRange).isEqualToComparingFieldByField(new TextRange(5, 14, 5, 29));
    assertThat(actualHotspot.author).isEmpty();
    assertThat(actualHotspot.status).isEqualTo(ServerHotspot.Status.TO_REVIEW);
    assertThat(actualHotspot.resolution).isNull();
    assertThat(actualHotspot.rule.key).isEqualTo("java:S1313");
}
Also used : GetSecurityHotspotRequestParams(org.sonarsource.sonarlint.core.serverapi.hotspot.GetSecurityHotspotRequestParams) ServerApi(org.sonarsource.sonarlint.core.serverapi.ServerApi) TextRange(org.sonarsource.sonarlint.core.analysis.api.TextRange) Test(org.junit.Test)

Example 3 with TextRange

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

the class IssueStorePaths method toApiIssue.

public static ServerIssue toApiIssue(Sonarlint.ServerIssue pbIssue, String idePath) {
    var issue = new DefaultServerIssue();
    issue.setAssigneeLogin(pbIssue.getAssigneeLogin());
    issue.setLineHash(pbIssue.getLineHash());
    if (pbIssue.getPrimaryLocation().hasTextRange()) {
        var textRange = pbIssue.getPrimaryLocation().getTextRange();
        issue.setTextRange(new TextRange(textRange.getStartLine(), textRange.getStartLineOffset(), textRange.getEndLine(), textRange.getEndLineOffset()));
        issue.setCodeSnippet(trimToNull(pbIssue.getPrimaryLocation().getCodeSnippet()));
    }
    issue.setFilePath(idePath);
    issue.setMessage(pbIssue.getPrimaryLocation().getMsg());
    issue.setSeverity(pbIssue.getSeverity());
    issue.setType(pbIssue.getType());
    issue.setCreationDate(Instant.ofEpochMilli(pbIssue.getCreationDate()));
    issue.setResolution(pbIssue.getResolution());
    issue.setKey(pbIssue.getKey());
    issue.setRuleKey(pbIssue.getRuleRepository() + ":" + pbIssue.getRuleKey());
    for (Sonarlint.ServerIssue.Flow f : pbIssue.getFlowList()) {
        issue.getFlows().add(new DefaultServerFlow(f.getLocationList()));
    }
    return issue;
}
Also used : DefaultServerIssue(org.sonarsource.sonarlint.core.container.model.DefaultServerIssue) TextRange(org.sonarsource.sonarlint.core.analysis.api.TextRange) DefaultServerIssue(org.sonarsource.sonarlint.core.container.model.DefaultServerIssue) ServerIssue(org.sonarsource.sonarlint.core.client.api.connected.ServerIssue) DefaultServerFlow(org.sonarsource.sonarlint.core.container.model.DefaultServerFlow)

Aggregations

TextRange (org.sonarsource.sonarlint.core.analysis.api.TextRange)3 Test (org.junit.Test)1 Test (org.junit.jupiter.api.Test)1 Issue (org.sonarsource.sonarlint.core.analysis.api.Issue)1 ServerIssue (org.sonarsource.sonarlint.core.client.api.connected.ServerIssue)1 DefaultServerFlow (org.sonarsource.sonarlint.core.container.model.DefaultServerFlow)1 DefaultServerIssue (org.sonarsource.sonarlint.core.container.model.DefaultServerIssue)1 ServerApi (org.sonarsource.sonarlint.core.serverapi.ServerApi)1 GetSecurityHotspotRequestParams (org.sonarsource.sonarlint.core.serverapi.hotspot.GetSecurityHotspotRequestParams)1