-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support optional commit hash argument to docsUrl and add tests
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
1 parent
3ea1050
commit 60335bb
Showing
2 changed files
with
21 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
}) | ||
}) |