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

Build: display rules’ meta data in their docs (fixes #5774) #8127

Merged
merged 1 commit into from Feb 23, 2017

Conversation

wkurniawan07
Copy link
Contributor

What is the purpose of this pull request? (put an "X" next to item)

[X] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:

What changes did you make? (Give an overview)

Modified the generation of eslint.github.io website so that important rule metadata such as recommended and fixable are automatically appended to the documentation of each rule.

This removes the need to hard-code the "fixable" portion on all fixable rules.

Is there anything you'd like reviewers to focus on?

Nothing in particular.

@eslintbot
Copy link

LGTM

@mention-bot
Copy link

@wkurniawan07, thanks for your PR! By analyzing the history of the files in this pull request, we identified @not-an-aardvark, @madmed88 and @nzakas to be potential reviewers.

@wkurniawan07
Copy link
Contributor Author

Sample rule page (ran locally):
screen shot 2017-02-22 at 12 58 00 pm

Copy link
Member

@not-an-aardvark not-an-aardvark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! I just have a few suggestions.

This is reminding me that we should really add tests for some of the functionality in Makefile.js. But that doesn't have to be a part of this PR.

Makefile.js Outdated
const rule = require(filename);
const ruleName = path.basename(filename, ".js");

if (rule.meta.docs.recommended || false) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like you left a || false from debugging.

Makefile.js Outdated
const fixable = [];

find(path.join(process.cwd(), "/lib/rules/")).filter(fileType("js")).forEach(filename => {
const rule = require(filename);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to use require('.').linter.getRules() to get all the rules, instead of looking through the filesystem?

Makefile.js Outdated

// Find out if the rule requires a special docs portion (e.g. if it is recommended and/or fixable)
const isRecommended = recommended.indexOf(ruleName) >= 0;
const isFixable = fixable.indexOf(ruleName) >= 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't really matter since there are a fairly small number of rules, but it might be better to use a Set for recommended and fixable since we don't care about the ordering here.

@eslintbot
Copy link

LGTM

@wkurniawan07
Copy link
Contributor Author

@not-an-aardvark thanks for the prompt review! Made all the changes as suggested.

About the initial usage of find(path.join(...))... to find the rules in the file system, I actually followed the idea from this part of the very same file.

@eslintbot
Copy link

LGTM

@not-an-aardvark
Copy link
Member

About the initial usage of find(path.join(...))... to find the rules in the file system, I actually followed the idea from this part of the very same file.

Fair enough. The linter.getRules() API was only introduced recently, so we probably haven't taken full advantage of it everywhere yet.

Copy link
Member

@not-an-aardvark not-an-aardvark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

Copy link
Member

@vitorbal vitorbal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, great job on this! LGTM

Copy link
Member

@ilyavolodin ilyavolodin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need Sets. They just add new loop and consume more memory.

Makefile.js Outdated
}
});

const RECOMMENDED_TEXT = "\n\n(recommended) The `\"extends\": \"eslint:recommended\"` property in a configuration file enables this rule.";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should just append HTML directly, without having to use replace later? We currently replace (recommended) and (fixable) with markup in Jekyll. @eslint/eslint-team thoughts?

Makefile.js Outdated
if (path.dirname(filename).indexOf("rules") >= 0) {

// Find out if the rule requires a special docs portion (e.g. if it is recommended and/or fixable)
const isRecommended = recommended.has(ruleName);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to use Set for both of them? Maybe we should do rules.get(ruleName).meta.docs.recommended instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point -- I suppose there's no need to do this in a separate loop.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gah, I just noticed that you actually requested adding Sets. Sorry I didn't look at this earlier:-( I still think adding an extra loop and two new data structures that we are not going to use for anything else later is an overkill, but I guess I can live with this, if everyone else thinks that it's fine.

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 convinced by your argument and I agree that it's overkill. @wkurniawan07, apologies for the misleading review earlier.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@not-an-aardvark no worries, we all make mistakes sometimes.
@ilyavolodin will change as suggested, it does make the script a lot shorter as well!

@ilyavolodin ilyavolodin added accepted There is consensus among the team that this change meets the criteria for inclusion build This change relates to ESLint's build process enhancement This change enhances an existing feature of ESLint labels Feb 23, 2017
@ilyavolodin
Copy link
Member

Also this should be Build PR, not Docs, since it modifies build script.

@wkurniawan07 wkurniawan07 changed the title Docs: display rules’ meta data in their docs (fixes #5774) Build: display rules’ meta data in their docs (fixes #5774) Feb 23, 2017
@eslintbot
Copy link

LGTM

Copy link
Member

@ilyavolodin ilyavolodin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome. LGTM, thanks.

Makefile.js Outdated
const rules = require(".").linter.getRules();

const RECOMMENDED_TEXT = "\n\n(recommended) The `\"extends\": \"eslint:recommended\"` property in a configuration file enables this rule.";
const FIXABLE_TEXT = "\n\n(fixable) The `--fix` option on the [command line](../user-guide/command-line-interface#fix) automatically fixes problems reported by this rule.";
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 change the text to:

"\n\n(fixable) The --fix option on the command line can automatically fix some of the problems reported by this rule.";

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alberto Done! 🙂

@eslintbot
Copy link

LGTM

@alberto alberto merged commit cbd7ded into eslint:master Feb 23, 2017
@wkurniawan07
Copy link
Contributor Author

Thanks for all the support! I'll see if I can contribute to more issues. 🙂

@wkurniawan07 wkurniawan07 deleted the Issue5774 branch February 23, 2017 18:48
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion build This change relates to ESLint's build process enhancement This change enhances an existing feature of ESLint
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants