Skip to content

Commit

Permalink
Fix direct link to a file
Browse files Browse the repository at this point in the history
The `/tree/` links are meant for directories, `/blob/` leads to an exact
file. This allowed a simplification of the `docsUrl` function since the
default branch can be treated as a "commit hash".
  • Loading branch information
Arcanemagus committed Jan 8, 2018
1 parent f12b6d0 commit c05cddb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
9 changes: 2 additions & 7 deletions src/docsUrl.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
const repoUrl = 'https://github.com/benmosher/eslint-plugin-import'

export default function docsUrl(ruleName, commitHash) {
let baseUrl = `${repoUrl}/tree/master/docs/rules`
if (commitHash) {
baseUrl = `${repoUrl}/blob/${commitHash}/docs/rules`
}

return `${baseUrl}/${ruleName}.md`
export default function docsUrl(ruleName, commitHash = 'master') {
return `${repoUrl}/blob/${commitHash}/docs/rules/${ruleName}.md`
}
2 changes: 1 addition & 1 deletion tests/src/core/docsUrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import docsUrl from '../../../src/docsUrl'

describe('docsUrl', function () {
it('returns the rule documentation URL when given a rule name', function () {
expect(docsUrl('foo')).to.equal('https://github.com/benmosher/eslint-plugin-import/tree/master/docs/rules/foo.md')
expect(docsUrl('foo')).to.equal('https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/foo.md')
})

it('supports an optional commit hash parameter', function () {
Expand Down

0 comments on commit c05cddb

Please sign in to comment.