Skip to content

Automate docs with eslint-doc-generator #1930

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

Merged
merged 2 commits into from
Oct 21, 2022

Conversation

bmish
Copy link
Contributor

@bmish bmish commented Oct 10, 2022

I built this CLI tool eslint-doc-generator for automating the generation of the README rules list and rule doc title/notices for ESLint plugins. It follows common documentation conventions from this and other top ESLint plugins and will help us standardize documentation across ESLint plugins (and generally improve the usability of our custom rules through better documentation and streamline the process of adding new rules).

This is a follow-up to the work I did to add the original notices in #1576. eslint-doc-generator is significantly more robust compared to the previous documentation generator script/tests which I have now removed. It has additional functionality (for example, the rules list legend is auto-generated, and the rules list will show additional columns of information when applicable) and 100% test coverage.

There are some discrepancies between the old docs and the new docs. Some of these are intentional and likely improvements. If you don't like any of the changes, let me know and I can tweak eslint-doc-generator or add a config option to support the desired behavior.

@bmish bmish added the docs label Oct 10, 2022
@bmish bmish force-pushed the eslint-doc-generator branch from 1fd5bd6 to 68a674c Compare October 10, 2022 02:33
@fisker
Copy link
Collaborator

fisker commented Oct 10, 2022

I slightly prefer to keep codes in scripts/, so we can tweak them anytime we want.

The only missing part is the rule title, it's easy to support, I planned to do that, but haven't got time.

@bmish
Copy link
Contributor Author

bmish commented Oct 10, 2022

I slightly prefer to keep codes in scripts/, so we can tweak them anytime we want.

It is true you can more-easily tweak the current in-house scripts. I'm hoping the benefits I described in the PR description will outweigh that downside, in addition to these selling points:

  • I plan to move eslint-doc-generator to @eslint-community sometime after reaching v1
  • eslint-doc-generator will be less likely to break vs. maintaining in-house scripts since it is fully unit tested, written in TypeScript, and will be adopted by / tested on many of the top ESLint plugins
  • eslint-doc-generator will be increasingly-configurable so many desired tweaks will be possible simply through a config option

The only missing part is the rule title, it's easy to support, I planned to do that, but haven't got time.

What do you mean the "rule title" is missing?

@fisker
Copy link
Collaborator

fisker commented Oct 10, 2022

What do you mean the "rule title" is missing?

I mean, currently, we are not auto-generating rule titles, but this PR did.

@fisker
Copy link
Collaborator

fisker commented Oct 10, 2022

I'll leave the decision to Sindre.

@@ -1,11 +1,10 @@
# Improve regexes by making them shorter, consistent, and safer

<!-- Do not manually modify RULE_NOTICE part. Run: `npm run generate-rule-notices` -->
Copy link
Owner

Choose a reason for hiding this comment

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

@bmish I think it may be smart to have a notice like this.

Maybe:

<!-- end rule header -->
<!-- DO NOT EDIT ANYTHING ABOVE HERE -->

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added those original warning comments back in. But they aren't managed by eslint-doc-generator as they are outside the managed area indicated by the <!-- end rule header --> comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Filed an issue to consider making this part of the standard comment marker: bmish/eslint-doc-generator#150

@sindresorhus
Copy link
Owner

I'm a big 👍 on this. I hope all ESLint plugins adopt this so we can get some universal consistency.

@sindresorhus
Copy link
Owner

sindresorhus commented Oct 10, 2022

You need to ensure the rule names have more space so less of them are word wrapped. See the difference between our and yours:

@sindresorhus
Copy link
Owner

Can you apply --rule-doc-section-include for the Fail and Pass sections?

@sindresorhus
Copy link
Owner

Would be nice if you could define the config in package.json instead of as CLI flags.

https://github.com/sindresorhus/pkg-conf or a similar package.

@sindresorhus
Copy link
Owner

The docs for --rule-doc-title-format should have an example for each style.

https://github.com/bmish/eslint-doc-generator#configuration-options

@bmish
Copy link
Contributor Author

bmish commented Oct 10, 2022

Thanks for the feedback! Will work on making the tweaks and responding in the next few days.

@bmish
Copy link
Contributor Author

bmish commented Oct 20, 2022

The docs for --rule-doc-title-format should have an example for each style.

bmish/eslint-doc-generator#configuration-options

Done. See: https://github.com/bmish/eslint-doc-generator#--rule-doc-title-format

Would be nice if you could define the config in package.json instead of as CLI flags.

sindresorhus/pkg-conf or a similar package.

Planned in bmish/eslint-doc-generator#95.

Can you apply --rule-doc-section-include for the Fail and Pass sections?

I wanted to use this but there isn't (yet) any way to opt out rules from that check which we need because of:

const RULES_WITHOUT_PASS_FAIL_SECTIONS = new Set([

You need to ensure the rule names have more space so less of them are word wrapped. See the difference between our and yours:

Fixed in bmish/eslint-doc-generator#148.

Also implemented a consolidated fixable/suggestions notice: bmish/eslint-doc-generator#149.

@sindresorhus all the critical feedback so far should be addressed. Please keep the feedback coming and let me know if you see any blockers.

@sindresorhus sindresorhus requested a review from fisker October 20, 2022 17:41
Copy link
Collaborator

@fisker fisker left a comment

Choose a reason for hiding this comment

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

One comment. #1930 (comment)

Co-authored-by: fisker Cheung <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants