Skip to content

Commit

Permalink
SONAR-10489 stop filtering x-file locations in scanner
Browse files Browse the repository at this point in the history
  • Loading branch information
Stas Vilchik authored and SonarTech committed Mar 27, 2018
1 parent 16ae386 commit 139b2c9
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,6 @@ private static void applyFlows(int componentRef, ScannerReport.Issue.Builder bui
flowBuilder.clear();
for (org.sonar.api.batch.sensor.issue.IssueLocation location : flow.locations()) {
int locationComponentRef = ((DefaultInputComponent) location.inputComponent()).batchId();
if (locationComponentRef != componentRef) {
// Some analyzers are trying to report cross file secondary locations. The API was designed to support it, but server side is not
// ready to handle it (especially the UI)
// So let's skip them for now (SONAR-9929)
continue;
}
locationBuilder.clear();
locationBuilder.setComponentRef(locationComponentRef);
String message = location.message();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/
package org.sonar.scanner.issue;

import java.util.Arrays;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
Expand Down Expand Up @@ -183,28 +182,6 @@ public void use_rule_name_if_no_message() {
assertThat(argument.getValue().getMsg()).isEqualTo("Avoid Cycle");
}

// SONAR-9929 Filter secondary locations that are on different files
@Test
public void skip_cross_file_secondary_locations() {
ruleBuilder.add(SQUID_RULE_KEY).setName(SQUID_RULE_NAME);
activeRulesBuilder.create(SQUID_RULE_KEY).setSeverity(Severity.INFO).setName(SQUID_RULE_NAME).activate();
initModuleIssues();

DefaultIssue issue = new DefaultIssue()
.at(new DefaultIssueLocation().on(file).at(file.selectLine(3)).message("Foo"))
.forRule(SQUID_RULE_KEY)
.addFlow(Arrays.asList(new DefaultIssueLocation().on(file).at(file.selectLine(4)).message("Location 1"),
new DefaultIssueLocation().on(new TestInputFileBuilder("foo", "src/Foo2.php").initMetadata("Foo\nBar\nBiz\n").build()).at(file.selectLine(3)).message("Location outside")));
when(filters.accept(anyString(), any(ScannerReport.Issue.class))).thenReturn(true);

boolean added = moduleIssues.initAndAddIssue(issue);

assertThat(added).isTrue();
ArgumentCaptor<ScannerReport.Issue> argument = ArgumentCaptor.forClass(ScannerReport.Issue.class);
verify(reportPublisher.getWriter()).appendComponentIssue(eq(file.batchId()), argument.capture());
assertThat(argument.getValue().getFlow(0).getLocationList()).hasSize(1);
}

@Test
public void filter_issue() {
ruleBuilder.add(SQUID_RULE_KEY).setName(SQUID_RULE_NAME);
Expand Down

0 comments on commit 139b2c9

Please sign in to comment.