From 90e7e321d1c1e3d39583f73b8ac3ca319f029c05 Mon Sep 17 00:00:00 2001 From: Devansu Yadav Date: Thu, 19 Jan 2023 21:38:24 +0530 Subject: [PATCH] feat(eslint-plugin): new prefer-docusaurus-heading rule (#8384) --- .eslintrc.js | 10 +++ .../src/components/HomepageFeatures/index.tsx | 3 +- .../classic-typescript/src/pages/index.tsx | 5 +- .../src/components/HomepageFeatures/index.js | 3 +- .../templates/classic/src/pages/index.js | 5 +- .../src/theme/BlogArchivePage/index.tsx | 9 ++- .../src/theme/BlogTagsListPage/index.tsx | 3 +- .../src/theme/BlogTagsPostsPage/index.tsx | 3 +- .../src/theme/DocCard/index.tsx | 8 ++- .../src/theme/DocTagDocListPage/index.tsx | 5 +- .../src/theme/DocTagsListPage/index.tsx | 3 +- .../src/theme/ErrorPageContent.tsx | 5 +- .../src/theme/NotFound/Content/index.tsx | 5 +- .../src/theme/TagsListByLetter/index.tsx | 6 +- .../src/theme/SearchPage/index.tsx | 8 +-- packages/eslint-plugin/src/index.ts | 2 + .../prefer-docusaurus-heading.test.ts | 69 +++++++++++++++++++ packages/eslint-plugin/src/rules/index.ts | 2 + .../src/rules/prefer-docusaurus-heading.ts | 46 +++++++++++++ .../_dogfooding/_pages tests/analytics.tsx | 3 +- .../_pages tests/error-boundary-tests.tsx | 4 +- .../docs/api/misc/eslint-plugin/README.mdx | 1 + .../prefer-docusaurus-heading.mdx | 31 +++++++++ website/src/components/Playground/index.tsx | 3 +- .../src/components/TeamProfileCards/index.tsx | 5 +- website/src/pages/index.tsx | 21 +++--- .../_components/ShowcaseCard/index.tsx | 5 +- website/src/pages/showcase/index.tsx | 19 ++--- website/src/pages/versions.tsx | 4 +- .../theme/ChangelogList/Header/index.tsx | 5 +- website/src/theme/Admonition/Types.tsx | 5 +- 31 files changed, 254 insertions(+), 52 deletions(-) create mode 100644 packages/eslint-plugin/src/rules/__tests__/prefer-docusaurus-heading.test.ts create mode 100644 packages/eslint-plugin/src/rules/prefer-docusaurus-heading.ts create mode 100644 website/docs/api/misc/eslint-plugin/prefer-docusaurus-heading.mdx diff --git a/.eslintrc.js b/.eslintrc.js index 56851d0247c3..1acb68f82e64 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -375,6 +375,7 @@ module.exports = { '@typescript-eslint/no-unused-vars': [ERROR, {ignoreRestSiblings: true}], '@typescript-eslint/prefer-optional-chain': ERROR, '@docusaurus/no-html-links': ERROR, + '@docusaurus/prefer-docusaurus-heading': ERROR, '@docusaurus/no-untranslated-text': [ WARNING, { @@ -495,5 +496,14 @@ module.exports = { files: ['packages/eslint-plugin/**/*.{js,ts}'], extends: ['plugin:eslint-plugin/recommended'], }, + { + files: [ + 'packages/docusaurus-plugin-debug/**', + 'packages/docusaurus/src/**', + ], + rules: { + '@docusaurus/prefer-docusaurus-heading': OFF, + }, + }, ], }; diff --git a/packages/create-docusaurus/templates/classic-typescript/src/components/HomepageFeatures/index.tsx b/packages/create-docusaurus/templates/classic-typescript/src/components/HomepageFeatures/index.tsx index 91ef4601d2fc..75cd587bb065 100644 --- a/packages/create-docusaurus/templates/classic-typescript/src/components/HomepageFeatures/index.tsx +++ b/packages/create-docusaurus/templates/classic-typescript/src/components/HomepageFeatures/index.tsx @@ -1,5 +1,6 @@ import React from 'react'; import clsx from 'clsx'; +import Heading from '@theme/Heading'; import styles from './styles.module.css'; type FeatureItem = { @@ -48,7 +49,7 @@ function Feature({title, Svg, description}: FeatureItem) {
-

{title}

+ {title}

{description}

diff --git a/packages/create-docusaurus/templates/classic-typescript/src/pages/index.tsx b/packages/create-docusaurus/templates/classic-typescript/src/pages/index.tsx index 305139fba009..056c3d953b76 100644 --- a/packages/create-docusaurus/templates/classic-typescript/src/pages/index.tsx +++ b/packages/create-docusaurus/templates/classic-typescript/src/pages/index.tsx @@ -4,6 +4,7 @@ import Link from '@docusaurus/Link'; import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; import Layout from '@theme/Layout'; import HomepageFeatures from '@site/src/components/HomepageFeatures'; +import Heading from '@theme/Heading'; import styles from './index.module.css'; @@ -12,7 +13,9 @@ function HomepageHeader() { return (
-

{siteConfig.title}

+ + {siteConfig.title} +

{siteConfig.tagline}

-

{title}

+ {title}

{description}

diff --git a/packages/create-docusaurus/templates/classic/src/pages/index.js b/packages/create-docusaurus/templates/classic/src/pages/index.js index affcd9099c28..282c3fad6020 100644 --- a/packages/create-docusaurus/templates/classic/src/pages/index.js +++ b/packages/create-docusaurus/templates/classic/src/pages/index.js @@ -5,6 +5,7 @@ import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; import Layout from '@theme/Layout'; import HomepageFeatures from '@site/src/components/HomepageFeatures'; +import Heading from '@theme/Heading'; import styles from './index.module.css'; function HomepageHeader() { @@ -12,7 +13,9 @@ function HomepageHeader() { return (
-

{siteConfig.title}

+ + {siteConfig.title} +

{siteConfig.tagline}

-

{year}

+ + {year} +