-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add URL to rule documentation to the metadata #998
Conversation
ESLint v4.15.0 added an official location for rules to store a URL to their documentation in the rule metadata in eslint/eslint#9788. This adds the URL to all the existing rules so anything consuming them can know where their documentation is without having to resort to external packages to guess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
definitely don't worry about the travis timeouts, they're having trouble this week.
Thanks!
src/rules/default.js
Outdated
@@ -1,8 +1,12 @@ | |||
import Exports from '../ExportMap' | |||
|
|||
const ruleDocsUrl = 'https://github.com/benmosher/eslint-plugin-import/tree/master/docs/rules' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we import this from somewhere rather than repeating it everywhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe something like docsUrl('rule-name')
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, can do that for everything other than imports-first
, since it needs a specific blob.
I didn't really like how this was fitting in the style here which is why I explicitly called it out as something to look at 😉.
Move the common string of the URL to a function that is called. Note that `imports-first` still has a fully defined URL in the rule file as the documentation for that rule requires a specific blob id since it has been deleted on `master`.
Updated, let me know if there are any other changes 😉. |
src/rules/imports-first.js
Outdated
const newMeta = Object.assign({}, first.meta, { | ||
deprecated: true, | ||
docs: { | ||
url: `${ruleDocsUrl}/7b25c1cb95ee18acc1531002fd343e1e6031f9ed/docs/rules/imports-first.md`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm confused, why does this one have a sha but the others don't? could it be an optional second argument passed to docsUrl
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rule was deprecated / renamed in 8e35cd9, however the documentation was directly renamed, leaving nothing in it's place. The straight mapping used elsewhere can't be used here because of this.
An alternative here would be to simply point this rule at first
's documentation, as outlined in the PR description.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we modify docsUrl
to take an optional second argument that defaults to master
but can be overridden to this sha?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The URL's are slightly different, but sure I can fix it to that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gave the function an optional second parameter, added tests for it, and used it for imports-first
.
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.
src/docsUrl.js
Outdated
const repoUrl = 'https://github.com/benmosher/eslint-plugin-import' | ||
|
||
export default function docsUrl(ruleName, commitHash) { | ||
let baseUrl = `${repoUrl}/tree/master/docs/rules` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be blob/master
, too. tree
is used for directories, while blob
is used for files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, it looks like this is a pretty common mistake since GitHub automatically redirects the wrong link, but you are absolutely correct.
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".
ESLint v4.15.0 added an official location for rules to store a URL to their documentation in the rule metadata in eslint/eslint#9788. This adds the URL to all the existing rules so anything consuming them can
know where their documentation is without having to resort to external packages to guess.
This also fixes the
docs
property ofno-self-import
, which was previouslydoc
.I'm not sure I like how the URL's are being defined here to fit within the 99 character line length limit, if you would like me to move the
ruleDocsUrl
to a single file that they all import, or alternatively do something like eslint-community/eslint-plugin-eslint-plugin@eb207d0, just let me know!Note:
imports-first
has a slightly different format since the documentation for this deprecated rule was removed. If you want that to instead point tofirst
's documentation that can be changed.