feat(eslint-plugin): new prefer-docusaurus-heading rule#8384
feat(eslint-plugin): new prefer-docusaurus-heading rule#8384slorber merged 8 commits intofacebook:mainfrom
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
slorber
left a comment
There was a problem hiding this comment.
Almost LGTM thanks 👍
Some changes requested in comments
@Josh-Cena let me know if you want to review this
| | [`@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.
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.
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.
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
| | [`@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.
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/Headingcomponent 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