Skip to content

Commit

Permalink
Support optional commit hash argument to docsUrl and add tests
Browse files Browse the repository at this point in the history
Add an optional second argument to `docsUrl` specifying a commit hash
that, when specified, changes the returned URL to be specific to that
hash instead of directing to `master`.

Adds tests for `docsUrl` to ensure that it is operating as expected.
  • Loading branch information
Arcanemagus committed Jan 8, 2018
1 parent 3ea1050 commit 60335bb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/docsUrl.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
const ruleDocsUrl = 'https://github.com/benmosher/eslint-plugin-import/tree/master/docs/rules'
const repoUrl = 'https://github.com/benmosher/eslint-plugin-import'

export default function docsUrl(ruleName) {
return `${ruleDocsUrl}/${ruleName}.md`
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`
}
13 changes: 13 additions & 0 deletions tests/src/core/docsUrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { expect } from 'chai'

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')
})

it('supports an optional commit hash parameter', function () {
expect(docsUrl('foo', 'bar')).to.equal('https://github.com/benmosher/eslint-plugin-import/blob/bar/docs/rules/foo.md')
})
})

0 comments on commit 60335bb

Please sign in to comment.