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

Make a distributed eslint plugin to enforce best Docusaurus practices #6472

Open
2 tasks done
Josh-Cena opened this issue Jan 26, 2022 · 13 comments
Open
2 tasks done

Make a distributed eslint plugin to enforce best Docusaurus practices #6472

Josh-Cena opened this issue Jan 26, 2022 · 13 comments
Labels
domain: dx feature good first issue status: accepting pr

Comments

@Josh-Cena
Copy link
Collaborator

@Josh-Cena Josh-Cena commented Jan 26, 2022

Have you read the Contributing Guidelines on issues?

Motivation

I realized there are a few text labels in our repo that are accidentally not translated. This has happened a few times in the past as well (see #4542). It would be interesting if we can make an eslint plugin with two rules:

  1. no-dynamic-i18n-messages: ensures that all translate calls are plain text labels
  2. no-untranslated-text: ensures all text labels in JSX are wrapped by translate calls (may have lots of false positives, but interesting to see how close we can get)

See https://docusaurus.io/docs/next/i18n/tutorial#translate-your-react-code for some documentation of the mental model of translate APIs.

We can publish this plugin as @docusaurus/eslint-plugin, so users can use this for themselves, as well as plugin/theme authors.

We may even ensure more best practices:

  • prefer-docusaurus-link: ensures @docusaurus/Link is used instead of a tags
  • prefer-ideal-image: ensures @theme/IdealImage is used instead of img tags
  • prefer-docusaurus-heading: ensures @theme/Heading is used instead of h2 tags
  • no-hardcoded-src: ensures all src attributes are either require or useBaseUrl
  • no-window-eq-undefined: forbid typeof window !== 'undefined' because this is not an adequate way to escape SSR

Self-service

  • I'd be willing to do some initial work on this proposal myself.
@Josh-Cena Josh-Cena added good first issue proposal status: accepting pr labels Jan 26, 2022
@slorber
Copy link
Collaborator

@slorber slorber commented Jan 27, 2022

yes we definitively want an eslint plugin 👍

@Josh-Cena Josh-Cena changed the title Make a distributed eslint plugin to check for i18n labels Make a distributed eslint plugin to enforce best Docusaurus practices Jan 27, 2022
@dave-sh
Copy link

@dave-sh dave-sh commented Jan 28, 2022

Hello can I be assigned this issue?

@Josh-Cena
Copy link
Collaborator Author

@Josh-Cena Josh-Cena commented Jan 29, 2022

@dave-sh Sure, please go ahead. You have a week to send your initial work. Good luck!

@Josh-Cena Josh-Cena added status: claimed and removed status: accepting pr labels Jan 29, 2022
@Josh-Cena Josh-Cena added feature and removed proposal labels Jan 31, 2022
@Josh-Cena
Copy link
Collaborator Author

@Josh-Cena Josh-Cena commented Feb 5, 2022

This issue is up for grabs again, since @dave-sh seems to be unavailable.

@Josh-Cena Josh-Cena added status: accepting pr and removed status: claimed labels Feb 5, 2022
@Ash-KODES
Copy link

@Ash-KODES Ash-KODES commented Feb 25, 2022

can I contribute to this?

@Josh-Cena
Copy link
Collaborator Author

@Josh-Cena Josh-Cena commented Feb 25, 2022

@Ash-KODES Sure—again, the work needed is given in the description. If you have any doubts, you can ask on the Discord server. You have a week to send your initial work. Good luck!

@Josh-Cena Josh-Cena added status: claimed and removed status: accepting pr labels Feb 25, 2022
@Josh-Cena Josh-Cena added status: accepting pr and removed status: claimed labels Mar 5, 2022
@Josh-Cena
Copy link
Collaborator Author

@Josh-Cena Josh-Cena commented Mar 5, 2022

Due to the unresponsive nature of these kinds of issues, if anyone wants to grab the issue, just send a PR directly. No need to ask for permissions.

@Josh-Cena Josh-Cena added the domain: dx label Mar 29, 2022
@alceil
Copy link

@alceil alceil commented Apr 1, 2022

I would like to take up this issue @Josh-Cena . I would require some pointers as well on solving this issue.

@Josh-Cena
Copy link
Collaborator Author

@Josh-Cena Josh-Cena commented Apr 1, 2022

@alceil This issue would require you to have some understanding in developing ESLing plugins, or at least working with ASTs in general. Are you looking for pointers on how to develop an ESLint plugin, or just how to translate my issue description into more concrete demand? I can elaborate on the latter, but probably not on the former.

@Josh-Cena
Copy link
Collaborator Author

@Josh-Cena Josh-Cena commented Apr 1, 2022

Also cc @armano2 not sure about your availability, but I guess you would like this? This issue would probably not be resolved in a while, so whenever you have time you can take a look

@alceil
Copy link

@alceil alceil commented Apr 1, 2022

I would like some pointer on developing eslint plugins. I can get it done @Josh-Cena . Also I would like to know more about the issue

@Josh-Cena
Copy link
Collaborator Author

@Josh-Cena Josh-Cena commented Apr 1, 2022

I don't have many good resources to share, but https://eslint.org/docs/developer-guide/working-with-plugins and other related docs there would be a good starting point. When I work on ESLint I also find the AST explorer quite useful (you should use the TS-ESLint parser + ESLint v8 Transform). The TS-ESLint playground is quite good as well, but since we don't use type-aware linting here, AST explorer should be more preferable since you can visualize fixers.

Now this issue does assume you have some understanding in ESLint (as I said), so I will not go through the 101s of working with ASTs or fixers. You can try to learn from the resources above—the API is quite straightforward (I'd say much better than Babel's, because the goal is much simpler).

@alceil
Copy link

@alceil alceil commented Apr 1, 2022

Okay got it @Josh-Cena

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain: dx feature good first issue status: accepting pr
Projects
None yet
Development

No branches or pull requests

5 participants