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
Conversation
LGTM |
@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. |
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 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) { |
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.
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); |
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.
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; |
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.
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.
204fa5f
to
c92dbc9
Compare
LGTM |
@not-an-aardvark thanks for the prompt review! Made all the changes as suggested. About the initial usage of |
c92dbc9
to
59af1ee
Compare
LGTM |
Fair enough. The |
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.
LGTM. Thanks!
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.
Thanks, great job on this! LGTM
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 think we don't need Set
s. 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."; |
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 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); |
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 don't think we need to use Set
for both of them? Maybe we should do rules.get(ruleName).meta.docs.recommended
instead?
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.
Good point -- I suppose there's no need to do this in a separate loop.
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.
Gah, I just noticed that you actually requested adding Set
s. 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.
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 convinced by your argument and I agree that it's overkill. @wkurniawan07, apologies for the misleading review earlier.
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.
@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!
Also this should be |
59af1ee
to
aefbf32
Compare
LGTM |
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.
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."; |
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 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.";
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.
@alberto Done! 🙂
aefbf32
to
1dd0054
Compare
LGTM |
Thanks for all the support! I'll see if I can contribute to more issues. 🙂 |
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.