From 4a448773b6a393b2e9ac7b01486d2ff806b296a8 Mon Sep 17 00:00:00 2001 From: Viktor Malmedal <38523983+JohnVicke@users.noreply.github.com> Date: Wed, 14 Dec 2022 18:28:29 +0100 Subject: [PATCH] feat: add eslint plugin no-html-links (#8156) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Joshua Chen Co-authored-by: Viktor Malmedal Co-authored-by: sebastienlorber Co-authored-by: Sébastien Lorber --- .eslintrc.js | 1 + .../src/theme/EditThisPage/index.tsx | 9 +- .../src/theme/Heading/index.tsx | 7 +- .../src/theme/SkipToContent/index.tsx | 1 - .../src/theme/TOCItems/Tree.tsx | 7 +- .../src/utils/skipToContentUtils.tsx | 1 + .../src/theme/SearchPage/index.tsx | 8 +- .../docusaurus/src/client/exports/Link.tsx | 2 +- packages/eslint-plugin/src/index.ts | 2 + .../src/rules/__tests__/no-html-links.test.ts | 90 +++++++++++++++ packages/eslint-plugin/src/rules/index.ts | 2 + .../eslint-plugin/src/rules/no-html-links.ts | 103 ++++++++++++++++++ .../_pages tests/hydration-tests.tsx | 21 +--- website/docs/api/misc/eslint-plugin/README.md | 1 + .../api/misc/eslint-plugin/no-html-links.md | 45 ++++++++ website/src/components/HackerNewsIcon.tsx | 9 +- website/src/components/ProductHuntCard.tsx | 9 +- .../src/components/TeamProfileCards/index.tsx | 8 +- website/src/components/Tweet/index.tsx | 5 +- website/src/components/TweetQuote/index.tsx | 9 +- website/src/components/Versions.tsx | 5 +- website/src/pages/showcase/index.tsx | 9 +- website/src/pages/versions.tsx | 4 +- 23 files changed, 291 insertions(+), 67 deletions(-) create mode 100644 packages/eslint-plugin/src/rules/__tests__/no-html-links.test.ts create mode 100644 packages/eslint-plugin/src/rules/no-html-links.ts create mode 100644 website/docs/api/misc/eslint-plugin/no-html-links.md diff --git a/.eslintrc.js b/.eslintrc.js index c76cc234dc..56851d0247 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -374,6 +374,7 @@ module.exports = { // locals must be justified with a disable comment. '@typescript-eslint/no-unused-vars': [ERROR, {ignoreRestSiblings: true}], '@typescript-eslint/prefer-optional-chain': ERROR, + '@docusaurus/no-html-links': ERROR, '@docusaurus/no-untranslated-text': [ WARNING, { diff --git a/packages/docusaurus-theme-classic/src/theme/EditThisPage/index.tsx b/packages/docusaurus-theme-classic/src/theme/EditThisPage/index.tsx index ede0b5cbed..1fbfb173ab 100644 --- a/packages/docusaurus-theme-classic/src/theme/EditThisPage/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/EditThisPage/index.tsx @@ -8,22 +8,19 @@ import React from 'react'; import Translate from '@docusaurus/Translate'; import {ThemeClassNames} from '@docusaurus/theme-common'; +import Link from '@docusaurus/Link'; import IconEdit from '@theme/Icon/Edit'; import type {Props} from '@theme/EditThisPage'; export default function EditThisPage({editUrl}: Props): JSX.Element { return ( - + Edit this page - + ); } diff --git a/packages/docusaurus-theme-classic/src/theme/Heading/index.tsx b/packages/docusaurus-theme-classic/src/theme/Heading/index.tsx index 3bb3212855..00ef3f52da 100644 --- a/packages/docusaurus-theme-classic/src/theme/Heading/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/Heading/index.tsx @@ -9,6 +9,7 @@ import React from 'react'; import clsx from 'clsx'; import {translate} from '@docusaurus/Translate'; import {useThemeConfig} from '@docusaurus/theme-common'; +import Link from '@docusaurus/Link'; import type {Props} from '@theme/Heading'; import styles from './styles.module.css'; @@ -34,16 +35,16 @@ export default function Heading({as: As, id, ...props}: Props): JSX.Element { )} id={id}> {props.children} - ​ - + ); } diff --git a/packages/docusaurus-theme-classic/src/theme/SkipToContent/index.tsx b/packages/docusaurus-theme-classic/src/theme/SkipToContent/index.tsx index 0ae5c02a55..3200aeec72 100644 --- a/packages/docusaurus-theme-classic/src/theme/SkipToContent/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/SkipToContent/index.tsx @@ -7,7 +7,6 @@ import React from 'react'; import {SkipToContentLink} from '@docusaurus/theme-common'; - import styles from './styles.module.css'; export default function SkipToContent(): JSX.Element { diff --git a/packages/docusaurus-theme-classic/src/theme/TOCItems/Tree.tsx b/packages/docusaurus-theme-classic/src/theme/TOCItems/Tree.tsx index 04ab3fc93b..266feaba2c 100644 --- a/packages/docusaurus-theme-classic/src/theme/TOCItems/Tree.tsx +++ b/packages/docusaurus-theme-classic/src/theme/TOCItems/Tree.tsx @@ -6,6 +6,7 @@ */ import React from 'react'; +import Link from '@docusaurus/Link'; import type {Props} from '@theme/TOCItems/Tree'; // Recursive component rendering the toc tree @@ -22,12 +23,10 @@ function TOCItemTree({