-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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(eslint-plugin): new prefer-docusaurus-heading rule #8384
Conversation
✅ [V2]Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site settings. |
⚡️ Lighthouse report for the deploy preview of this PR
|
@Josh-Cena no strong opinion but what's the motivation to force users to use Heading instead of h2? That looks like a valid thing to do to use a custom h2 (or any other level) in some cases. Is there a reason to handle h2 in a different way than any other heading level? Not against this rule but we probably need to think a bit deeper about what we are trying to prevent here, and also what should be the default experience. Note |
@slorber I do think this should not only apply to h2 though, but to all |
@Josh-Cena @slorber I agree that we should have this rule apply to all possible headings and in fact, I have already added an option PS: Just a heads up, I'll be able to continue my work on this PR after the 19th Dec, as I'd be unavailable due to my ongoing University exams 😅 |
We should probably not use and special edge case for h2, and just apply this to all headings by default. Eventually pass a list of headings to check as an option, but I really wonder who would use it 🤔 Do we want to make a special case for h1 @Josh-Cena ? In this case there's no anchor/id. |
@Josh-Cena @slorber Any updates on how I should proceed with this? What I mean is that, do we need to have any special cases for |
I think we can move on and apply the rule for all hX elements 👍 We'll add more options later if needed, once people come with a good use-case to explain why an option is needed |
2e06132
to
bf09d47
Compare
@slorber I have implemented the eslint rule without any options for now. For fixing all the eslint errors introduced due to this new rule, I have made use of I know the above question might be a bit naive, but from what I understand after digging through source code, all of the |
e351bf9
to
039cc45
Compare
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.
Almost LGTM thanks 👍
Some changes requested in comments
@Josh-Cena let me know if you want to review this
@@ -53,6 +53,7 @@ For more fine-grained control, you can also enable the plugin manually and confi | |||
| [`@docusaurus/no-untranslated-text`](./no-untranslated-text.mdx) | Enforce text labels in JSX to be wrapped by translate calls | | | |||
| [`@docusaurus/string-literal-i18n-messages`](./string-literal-i18n-messages.mdx) | Enforce translate APIs to be called on plain text labels | ✅ | | |||
| [`@docusaurus/no-html-links`](./no-html-links.mdx) | Ensures @docusaurus/Link is used instead of `<a>` tags | ✅ | | |||
| [`@docusaurus/prefer-docusaurus-heading`](./prefer-docusaurus-heading.mdx) | Ensures @theme/Heading is used instead of `<hn>` tags for headings | ✅ | |
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.
maybe prefer-theme-heading would be a more accurate rule name? (also maybe more confusing name?)
Any opinion @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.
Yeah, I agree prefer-theme-heading
sounds more accurate but doesn't docusaurus provide different themes containing the Heading
component?
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.
docusaurus core doesn't provide any heading for now, only the theme does.
But maybe we could have a core heading component later if we want to create a graph of pages + their respective headings or whatever. We can keep this name for now, it doesn't matter much 😅
packages/docusaurus-plugin-debug/src/theme/DebugConfig/index.tsx
Outdated
Show resolved
Hide resolved
packages/docusaurus-theme-classic/src/theme/BlogArchivePage/index.tsx
Outdated
Show resolved
Hide resolved
packages/docusaurus-theme-classic/src/theme/TagsListByLetter/index.tsx
Outdated
Show resolved
Hide resolved
9fd48c5
to
c01304d
Compare
@Josh-Cena @slorber Any updates from your end on the changes that I have made recently in this PR? |
Signed-off-by: Devansu <devansuyadav@gmail.com>
Signed-off-by: Devansu <devansuyadav@gmail.com>
Signed-off-by: Devansu <devansuyadav@gmail.com>
Signed-off-by: Devansu <devansuyadav@gmail.com>
Signed-off-by: Devansu <devansuyadav@gmail.com>
Signed-off-by: Devansu <devansuyadav@gmail.com>
Signed-off-by: Devansu <devansuyadav@gmail.com>
Signed-off-by: Devansu <devansuyadav@gmail.com>
b41c634
to
47c9b7a
Compare
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, LGTM 👍
@@ -53,6 +53,7 @@ For more fine-grained control, you can also enable the plugin manually and confi | |||
| [`@docusaurus/no-untranslated-text`](./no-untranslated-text.mdx) | Enforce text labels in JSX to be wrapped by translate calls | | | |||
| [`@docusaurus/string-literal-i18n-messages`](./string-literal-i18n-messages.mdx) | Enforce translate APIs to be called on plain text labels | ✅ | | |||
| [`@docusaurus/no-html-links`](./no-html-links.mdx) | Ensures @docusaurus/Link is used instead of `<a>` tags | ✅ | | |||
| [`@docusaurus/prefer-docusaurus-heading`](./prefer-docusaurus-heading.mdx) | Ensures @theme/Heading is used instead of `<hn>` tags for headings | ✅ | |
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.
docusaurus core doesn't provide any heading for now, only the theme does.
But maybe we could have a core heading component later if we want to create a graph of pages + their respective headings or whatever. We can keep this name for now, it doesn't matter much 😅
Pre-flight checklist
Motivation
Described in #6472. Basically, this plugin enforces the use of
@theme/Heading
component instead of<h2>
tags.Test Plan
Added Jest unit tests for this plugin.
Test links
Deploy preview: https://deploy-preview-8384--docusaurus-2.netlify.app/
Related issues/PRs
#6472
Comments