]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9749 Order secondary locations markers by line
authorStas Vilchik <stas.vilchik@sonarsource.com>
Tue, 10 Oct 2017 09:27:50 +0000 (11:27 +0200)
committerStas Vilchik <stas.vilchik@sonarsource.com>
Wed, 11 Oct 2017 10:02:21 +0000 (12:02 +0200)
server/sonar-web/src/main/js/helpers/__tests__/issues-test.ts
server/sonar-web/src/main/js/helpers/issues.ts

index 034fcb4a916e5ee7018d07554d4625c4a73e2580..90a80fd6f3694ca6b59ecc1f45125617f654b4ee 100644 (file)
@@ -31,7 +31,7 @@ it('should populate comments data', () => {
   const issue = {
     comments: [
       {
-        createdAt: '2017-04-11T10:38:09+0200',
+        createdAt: '2017-04-11T10:38:090200',
         htmlText: 'comment!',
         key: 'AVtcKbZkQmGLa7yW8J71',
         login: 'admin',
@@ -47,7 +47,7 @@ it('should populate comments data', () => {
       authorAvatar: 'c1244e6857f7be3dc4549d9e9d51c631',
       authorLogin: 'admin',
       authorName: 'Admin Admin',
-      createdAt: '2017-04-11T10:38:09+0200',
+      createdAt: '2017-04-11T10:38:090200',
       htmlText: 'comment!',
       key: 'AVtcKbZkQmGLa7yW8J71',
       login: undefined,
@@ -56,3 +56,20 @@ it('should populate comments data', () => {
     }
   ]);
 });
+
+it('orders secondary locations', () => {
+  const issue = {
+    flows: [
+      { locations: [{ textRange: { startLine: 68, startOffset: 5, endLine: 68, endOffset: 7 } }] },
+      { locations: [{ textRange: { startLine: 43, startOffset: 8, endLine: 43, endOffset: 12 } }] },
+      { locations: [{ textRange: { startLine: 43, startOffset: 6, endLine: 43, endOffset: 8 } }] },
+      { locations: [{ textRange: { startLine: 70, startOffset: 12, endLine: 70, endOffset: 16 } }] }
+    ]
+  } as any;
+  expect(parseIssueFromResponse(issue).secondaryLocations).toEqual([
+    { textRange: { startLine: 43, startOffset: 6, endLine: 43, endOffset: 8 } },
+    { textRange: { startLine: 43, startOffset: 8, endLine: 43, endOffset: 12 } },
+    { textRange: { startLine: 68, startOffset: 5, endLine: 68, endOffset: 7 } },
+    { textRange: { startLine: 70, startOffset: 12, endLine: 70, endOffset: 16 } }
+  ]);
+});
index cce6a2adc494b6d856bb68064c0c2d5f525d5e58..efa8b272af6c8d22bb30bb2065f01ab66ccca1ca 100644 (file)
@@ -134,7 +134,7 @@ function reverseLocations(locations: FlowLocation[]): FlowLocation[] {
 
 function splitFlows(
   issue: RawIssue
-): { secondaryLocations: Array<FlowLocation>; flows: Array<Array<FlowLocation>> } {
+): { secondaryLocations: FlowLocation[]; flows: FlowLocation[][] } {
   const parsedFlows = (issue.flows || [])
     .filter(flow => flow.locations != null)
     .map(flow => flow.locations!.filter(location => location.textRange != null));
@@ -142,10 +142,18 @@ function splitFlows(
   const onlySecondaryLocations = parsedFlows.every(flow => flow.length === 1);
 
   return onlySecondaryLocations
-    ? { secondaryLocations: flatten(parsedFlows), flows: [] }
+    ? { secondaryLocations: orderLocations(flatten(parsedFlows)), flows: [] }
     : { secondaryLocations: [], flows: parsedFlows.map(reverseLocations) };
 }
 
+function orderLocations(locations: FlowLocation[]) {
+  return sortBy(
+    locations,
+    location => location.textRange && location.textRange.startLine,
+    location => location.textRange && location.textRange.startOffset
+  );
+}
+
 export function parseIssueFromResponse(
   issue: RawIssue,
   components?: Component[],