From 18ae9e6ee7de16a91c4a2b2101a4bd8ff1d2a1d0 Mon Sep 17 00:00:00 2001 From: Bob Lannon Date: Tue, 27 Feb 2018 18:12:51 -0500 Subject: [PATCH 1/6] github link to typedef points to comment lines --- src/github.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/github.js b/src/github.js index 1a80cfffc..291275b13 100644 --- a/src/github.js +++ b/src/github.js @@ -21,15 +21,20 @@ module.exports = function(comment: Comment) { .join('/'); if (urlPrefix) { + let startLine; + let endLine; + + if (comment.kind == 'typedef') { + startLine = comment.loc.start.line; + endLine = comment.loc.end.line; + } else { + startLine = comment.context.loc.start.line; + endLine = comment.context.loc.end.line; + } + comment.context.github = { url: - urlPrefix + - fileRelativePath + - '#L' + - comment.context.loc.start.line + - '-' + - 'L' + - comment.context.loc.end.line, + urlPrefix + fileRelativePath + '#L' + startLine + '-' + 'L' + endLine, path: fileRelativePath }; } From 92e77e32361accfd2d9688254bb8fb5e1dd6c867 Mon Sep 17 00:00:00 2001 From: Bob Lannon Date: Tue, 27 Feb 2018 19:51:48 -0500 Subject: [PATCH 2/6] adding test for typedef github links --- __tests__/lib/github.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/__tests__/lib/github.js b/__tests__/lib/github.js index ce15eccde..6821cdf14 100644 --- a/__tests__/lib/github.js +++ b/__tests__/lib/github.js @@ -85,3 +85,29 @@ test('enterprise repository', function() { mock.restore(); }); + +test('typedef', function() { + mock(mockRepo.master); + + expect( + evaluate(function() { + /** + * A number, or a string containing a number. + * @typedef {(number|string)} NumberLike + */ + + /** + * get one + * @returns {number} one + */ + function getOne() { + return 1; + } + })[0].context.github + ).toEqual({ + path: 'index.js', + url: 'https://github.com/foo/bar/blob/this_is_the_sha/index.js#L1-L4' + }); + + mock.restore(); +}); From 2fa10bb2081d27eafaaf3b7116c5f84267da8f69 Mon Sep 17 00:00:00 2001 From: Bob Lannon Date: Tue, 27 Feb 2018 19:52:14 -0500 Subject: [PATCH 3/6] adding comment.loc for flow check --- declarations/comment.js | 1 + 1 file changed, 1 insertion(+) diff --git a/declarations/comment.js b/declarations/comment.js index 257dee204..24fb5ba64 100644 --- a/declarations/comment.js +++ b/declarations/comment.js @@ -106,6 +106,7 @@ type Comment = { type?: DoctrineType, context: CommentContext, + loc: CommentLoc, path?: Array<{ name: string, From a5e7e27b8046afab2467fdebcc1eba5d6ea3fbbf Mon Sep 17 00:00:00 2001 From: Bob Lannon Date: Tue, 27 Feb 2018 19:56:48 -0500 Subject: [PATCH 4/6] reverting to original formatting From 7ffef00918af56fee0b17c48adf184dc01a5ce9d Mon Sep 17 00:00:00 2001 From: Bob Lannon Date: Wed, 28 Feb 2018 11:24:18 -0500 Subject: [PATCH 5/6] use afterEach to restore mock even if tests fail --- __tests__/lib/github.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/__tests__/lib/github.js b/__tests__/lib/github.js index 6821cdf14..a91cd590c 100644 --- a/__tests__/lib/github.js +++ b/__tests__/lib/github.js @@ -25,6 +25,10 @@ function evaluate(fn) { ); } +afterEach(function() { + mock.restore(); +}); + test('github', function() { mock(mockRepo.master); @@ -42,8 +46,6 @@ test('github', function() { path: 'index.js', url: 'https://github.com/foo/bar/blob/this_is_the_sha/index.js#L6-L8' }); - - mock.restore(); }); test('malformed repository', function() { @@ -60,8 +62,6 @@ test('malformed repository', function() { } })[0].context.github ).toBe(undefined); - - mock.restore(); }); test('enterprise repository', function() { @@ -82,8 +82,6 @@ test('enterprise repository', function() { url: 'https://github.enterprise.com/foo/bar/blob/this_is_the_sha/index.js#L6-L8' }); - - mock.restore(); }); test('typedef', function() { @@ -108,6 +106,4 @@ test('typedef', function() { path: 'index.js', url: 'https://github.com/foo/bar/blob/this_is_the_sha/index.js#L1-L4' }); - - mock.restore(); }); From c36ab612d5d11fc15ddb08d9abce08afb39e58b7 Mon Sep 17 00:00:00 2001 From: Bob Lannon Date: Wed, 28 Feb 2018 11:25:09 -0500 Subject: [PATCH 6/6] fixing line numbers in expected value --- __tests__/lib/github.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/__tests__/lib/github.js b/__tests__/lib/github.js index a91cd590c..92968adcf 100644 --- a/__tests__/lib/github.js +++ b/__tests__/lib/github.js @@ -104,6 +104,6 @@ test('typedef', function() { })[0].context.github ).toEqual({ path: 'index.js', - url: 'https://github.com/foo/bar/blob/this_is_the_sha/index.js#L1-L4' + url: 'https://github.com/foo/bar/blob/this_is_the_sha/index.js#L2-L5' }); }); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy