Skip to content
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

Merged
merged 6 commits into from
Jan 9, 2018

Conversation

Arcanemagus
Copy link
Contributor

@Arcanemagus Arcanemagus commented Jan 8, 2018

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 of no-self-import, which was previously doc.

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 to first's documentation that can be changed.

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.
@Arcanemagus
Copy link
Contributor Author

Build failures look to be "normal" (AppVeyor), or related to network timeouts on Travis CI (#2428.5, #2428.6, #2428.13).

Copy link
Member

@ljharb ljharb left a 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!

@@ -1,8 +1,12 @@
import Exports from '../ExportMap'

const ruleDocsUrl = 'https://github.com/benmosher/eslint-plugin-import/tree/master/docs/rules'
Copy link
Member

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?

Copy link
Contributor

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

Copy link
Contributor Author

@Arcanemagus Arcanemagus Jan 8, 2018

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`.
@Arcanemagus
Copy link
Contributor Author

Updated, let me know if there are any other changes 😉.

const newMeta = Object.assign({}, first.meta, {
deprecated: true,
docs: {
url: `${ruleDocsUrl}/7b25c1cb95ee18acc1531002fd343e1e6031f9ed/docs/rules/imports-first.md`,
Copy link
Member

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?

Copy link
Contributor Author

@Arcanemagus Arcanemagus Jan 8, 2018

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.

Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@coveralls
Copy link

coveralls commented Jan 8, 2018

Coverage Status

Coverage decreased (-1.1%) to 95.061% when pulling a56c1c0 on Arcanemagus:rules-docs-url into 0d44914 on benmosher:master.

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.
@ljharb ljharb added the docs label Jan 8, 2018
@coveralls
Copy link

coveralls commented Jan 8, 2018

Coverage Status

Coverage increased (+0.02%) to 96.23% when pulling f12b6d0 on Arcanemagus:rules-docs-url into 0d44914 on benmosher:master.

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`
Copy link
Contributor

@j-f1 j-f1 Jan 8, 2018

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.

Copy link
Contributor Author

@Arcanemagus Arcanemagus Jan 8, 2018

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".
@coveralls
Copy link

coveralls commented Jan 9, 2018

Coverage Status

Coverage increased (+0.01%) to 96.225% when pulling c05cddb on Arcanemagus:rules-docs-url into 0d44914 on benmosher:master.

@coveralls
Copy link

coveralls commented Jan 9, 2018

Coverage Status

Coverage increased (+0.02%) to 96.23% when pulling f12b6d0 on Arcanemagus:rules-docs-url into 0d44914 on benmosher:master.

2 similar comments
@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 96.23% when pulling f12b6d0 on Arcanemagus:rules-docs-url into 0d44914 on benmosher:master.

@coveralls
Copy link

coveralls commented Jan 9, 2018

Coverage Status

Coverage increased (+0.02%) to 96.23% when pulling f12b6d0 on Arcanemagus:rules-docs-url into 0d44914 on benmosher:master.

@coveralls
Copy link

coveralls commented Jan 9, 2018

Coverage Status

Coverage increased (+0.01%) to 96.225% when pulling c05cddb on Arcanemagus:rules-docs-url into 0d44914 on benmosher:master.

1 similar comment
@coveralls
Copy link

coveralls commented Jan 9, 2018

Coverage Status

Coverage increased (+0.01%) to 96.225% when pulling c05cddb on Arcanemagus:rules-docs-url into 0d44914 on benmosher:master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

4 participants