-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
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
feat: Docusaurus ESLint plugin to enforce best Docusaurus practices #7206
Conversation
✅ [V2]Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site settings. |
⚡️ Lighthouse report for the changes in this PR:
Lighthouse ran on https://deploy-preview-7206--docusaurus-2.netlify.app/ |
At a glance, it looks much, much better than I could've imagined 👍 Thanks a bunch! I'll play with it later. |
node.children.every((child) => isTextLabelChild({child})); | ||
|
||
return { | ||
"JSXElement[openingElement.name.name='Translate']": (node) => { |
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 this is fine for now, but in the long term, we may need to first check the imported name because it may not be imported as Translate
(cf our translationExtractor
implementation). I'm not aware if we can let ESLint do a two-round traverse in an efficient way—I think people usually use Program:exit
?
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 really solid and it's already ready to be shipped IMO.
There are many useful extensions to make, but I think this will make a great initial kickstart.
packages/eslint-plugin/__tests__/lib/rules/no-dynamic-i18n-messages.test.js
Outdated
Show resolved
Hide resolved
const isMessageTypeValid = (type) => type === 'Literal'; | ||
|
||
const isNodeValid = (node) => | ||
node.children.every((child) => isTextLabelChild({child})); |
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 would be useful to add an option ignoreJSXAttributes
. We may want to flag <div aria-label="untranslated" />
as well. Doesn't have to be in this PR though
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 didn't understand that, could you provide an example usage of ignoreJSXAttributes
? Also what is the purpose of <div aria-label="untranslated" />
? Self-closing tags do not have children (excluding the children prop) therefore the current rules do not apply in this case, right ?
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.
Oh, sorry, wrong comment place. I was talking about no-untranslated-text
. There should be an option that turns on warning for JSX attributes like aria-label
as well, not just string literal children.
packages/docusaurus/src/client/exports/__tests__/Translate.test.tsx
Outdated
Show resolved
Hide resolved
packages/eslint-plugin/lib/rules/string-literal-i18n-messages.js
Outdated
Show resolved
Hide resolved
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 @elias-pap I'm sorry but this would probably take a bit longer than expected to be merged, because @slorber needs to review this as well, but he has limited availability. Luckily it doesn't touch existing code and should have very little merge conflict over time, so we'll probably go back to it in June, after 2.0 has been released. Thanks again!
- Reorder sidebar entries - Fix title size - Use Markdown file paths - Simplify relative links
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 is fully ready. @elias-pap There's no more feedback from my side. If @slorber manages to review this, we can merge it.
Great, thanks for the reviews @Josh-Cena. |
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, looks nice
As this is an optional plugin, not enabled by default the risk to merge this is quite low so we can give it a try 👍
website/docs/api/misc/eslint-plugin/string-literal-i18n-messages.md
Outdated
Show resolved
Hide resolved
Hold on—there are some minor issues. I would first fix all internal warnings and merge it no later than tomorrow. |
Will merge this soon. Thanks again @elias-pap much appreciated! It's caught a lot of issues in our own repo which I've just fixed. |
Motivation
Explained in the description of #6472
Have you read the Contributing Guidelines on pull requests?
Yes
Test Plan
Doc URL: https://deploy-preview-7206--docusaurus-2.netlify.app/docs/api/misc/@docusaurus/eslint-plugin/
Unit tests are included and integrated with existing jest setup.
Output of `yarn test eslint-plugin`
This is also dogfooded in our own monorepo.