aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorJeremy Davis <jeremy.davis@sonarsource.com>2019-11-01 20:58:03 +0900
committerSonarTech <sonartech@sonarsource.com>2019-11-07 11:45:16 +0100
commit35f2d76d8dba2fed8cc7476dc2e3c90227667bd7 (patch)
tree7083316ed72c7f637617de0b69843281ab18c019 /server
parentfbcd0ca6d13677c26d38572e05f1518aa1d54f4f (diff)
downloadsonarqube-35f2d76d8dba2fed8cc7476dc2e3c90227667bd7.tar.gz
sonarqube-35f2d76d8dba2fed8cc7476dc2e3c90227667bd7.zip
SONAR-12601 Increase snippet merge threshold
Diffstat (limited to 'server')
-rw-r--r--server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/__tests__/ComponentSourceSnippetViewer-test.tsx20
-rw-r--r--server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/__tests__/utils-test.ts8
-rw-r--r--server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/utils.ts2
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/source/ws/IssueSnippetsAction.java6
4 files changed, 18 insertions, 18 deletions
diff --git a/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/__tests__/ComponentSourceSnippetViewer-test.tsx b/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/__tests__/ComponentSourceSnippetViewer-test.tsx
index a06177b9618..26807e530cf 100644
--- a/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/__tests__/ComponentSourceSnippetViewer-test.tsx
+++ b/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/__tests__/ComponentSourceSnippetViewer-test.tsx
@@ -60,16 +60,16 @@ it('should render correctly with secondary locations', () => {
}),
mockFlowLocation({
component: 'a',
- textRange: { startLine: 54, endLine: 54, startOffset: 0, endOffset: 0 }
+ textRange: { startLine: 74, endLine: 74, startOffset: 0, endOffset: 0 }
})
],
- ...mockSnippetsByComponent('a', [...range(2, 17), ...range(29, 39), ...range(49, 59)])
+ ...mockSnippetsByComponent('a', [...range(2, 17), ...range(29, 39), ...range(69, 79)])
};
const wrapper = shallowRender({ issue, snippetGroup });
expect(wrapper.state('snippets')).toHaveLength(3);
expect(wrapper.state('snippets')[0]).toEqual({ index: 0, start: 2, end: 16 });
expect(wrapper.state('snippets')[1]).toEqual({ index: 1, start: 29, end: 39 });
- expect(wrapper.state('snippets')[2]).toEqual({ index: 2, start: 49, end: 59 });
+ expect(wrapper.state('snippets')[2]).toEqual({ index: 2, start: 69, end: 79 });
});
it('should expand block', async () => {
@@ -77,20 +77,20 @@ it('should expand block', async () => {
Object.values(mockSnippetsByComponent('a', range(6, 59)).sources)
);
const issue = mockIssue(true, {
- textRange: { startLine: 64, endLine: 64, startOffset: 5, endOffset: 10 }
+ textRange: { startLine: 74, endLine: 74, startOffset: 5, endOffset: 10 }
});
const snippetGroup: T.SnippetGroup = {
locations: [
mockFlowLocation({
component: 'a',
- textRange: { startLine: 64, endLine: 64, startOffset: 0, endOffset: 0 }
+ textRange: { startLine: 74, endLine: 74, startOffset: 0, endOffset: 0 }
}),
mockFlowLocation({
component: 'a',
- textRange: { startLine: 87, endLine: 87, startOffset: 0, endOffset: 0 }
+ textRange: { startLine: 107, endLine: 107, startOffset: 0, endOffset: 0 }
})
],
- ...mockSnippetsByComponent('a', [...range(59, 73), ...range(82, 92)])
+ ...mockSnippetsByComponent('a', [...range(69, 83), ...range(102, 112)])
};
const wrapper = shallowRender({ issue, snippetGroup });
@@ -98,9 +98,9 @@ it('should expand block', async () => {
wrapper.instance().expandBlock(0, 'up');
await waitAndUpdate(wrapper);
- expect(getSources).toHaveBeenCalledWith({ from: 6, key: 'a', to: 58 });
+ expect(getSources).toHaveBeenCalledWith({ from: 9, key: 'a', to: 68 });
expect(wrapper.state('snippets')).toHaveLength(2);
- expect(wrapper.state('snippets')[0]).toEqual({ index: 0, start: 9, end: 73 });
+ expect(wrapper.state('snippets')[0]).toEqual({ index: 0, start: 19, end: 83 });
expect(Object.keys(wrapper.state('additionalLines'))).toHaveLength(53);
});
@@ -151,7 +151,7 @@ it('should get the right branch when expanding', async () => {
wrapper.instance().expandBlock(0, 'down');
await waitAndUpdate(wrapper);
- expect(getSources).toHaveBeenCalledWith({ branch: 'asdf', from: 8, key: 'a', to: 60 });
+ expect(getSources).toHaveBeenCalledWith({ branch: 'asdf', from: 8, key: 'a', to: 67 });
});
it('should handle correctly open/close issue', () => {
diff --git a/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/__tests__/utils-test.ts b/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/__tests__/utils-test.ts
index d76fdcdb501..825231cb690 100644
--- a/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/__tests__/utils-test.ts
+++ b/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/__tests__/utils-test.ts
@@ -152,10 +152,10 @@ describe('createSnippets', () => {
it("should prepend the issue's main location if necessary", () => {
const locations = [
mockFlowLocation({
- textRange: { startLine: 65, startOffset: 2, endLine: 65, endOffset: 3 }
+ textRange: { startLine: 85, startOffset: 2, endLine: 85, endOffset: 3 }
}),
mockFlowLocation({
- textRange: { startLine: 32, startOffset: 2, endLine: 32, endOffset: 3 }
+ textRange: { startLine: 42, startOffset: 2, endLine: 42, endOffset: 3 }
})
];
const results = createSnippets({
@@ -193,7 +193,7 @@ describe('expandSnippet', () => {
it('should merge snippets if necessary', () => {
const snippets = [
{ index: 1, start: 4, end: 14 },
- { index: 2, start: 72, end: 82 },
+ { index: 2, start: 82, end: 92 },
{ index: 3, start: 37, end: 47 }
];
@@ -201,7 +201,7 @@ describe('expandSnippet', () => {
expect(result).toHaveLength(3);
expect(result[0]).toEqual({ index: 1, start: 4, end: 64 });
- expect(result[1]).toEqual({ index: 2, start: 72, end: 82 });
+ expect(result[1]).toEqual({ index: 2, start: 82, end: 92 });
expect(result[2]).toEqual({ index: 3, start: 37, end: 47, toDelete: true });
});
});
diff --git a/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/utils.ts b/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/utils.ts
index f46b71e77a8..a73881a0204 100644
--- a/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/utils.ts
+++ b/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/utils.ts
@@ -19,7 +19,7 @@
*/
const LINES_ABOVE = 5;
const LINES_BELOW = 5;
-export const MERGE_DISTANCE = 4; // Merge if snippets are four lines away (separated by 3 lines) or fewer
+export const MERGE_DISTANCE = 11; // Merge if snippets are eleven lines away (separated by 10 lines) or fewer
export const LINES_BELOW_ISSUE = 9;
export const EXPAND_BY_LINES = 50;
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/source/ws/IssueSnippetsAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/source/ws/IssueSnippetsAction.java
index 9a3b8f4b4e2..8074133394e 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/source/ws/IssueSnippetsAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/source/ws/IssueSnippetsAction.java
@@ -167,14 +167,14 @@ public class IssueSnippetsAction implements SourcesWsAction {
TreeSet<Integer> lines = linesPerComponent.computeIfAbsent(componentUuid, c -> new TreeSet<>());
IntStream.rangeClosed(start, end).forEach(lines::add);
- // If two snippets in the same component are 3 lines apart of each other, include those 3 lines.
+ // If two snippets in the same component are 10 lines apart of each other, include those 10 lines.
Integer closestToStart = lines.lower(start);
- if (closestToStart != null && closestToStart >= start - 4) {
+ if (closestToStart != null && closestToStart >= start - 11) {
IntStream.range(closestToStart + 1, start).forEach(lines::add);
}
Integer closestToEnd = lines.higher(end);
- if (closestToEnd != null && closestToEnd <= end + 4) {
+ if (closestToEnd != null && closestToEnd <= end + 11) {
IntStream.range(end + 1, closestToEnd).forEach(lines::add);
}