From c1c05c67407bafb4a3ffa42c7522d7791027d95e Mon Sep 17 00:00:00 2001 From: Stoyan Delev Date: Tue, 1 Feb 2022 12:30:52 +0200 Subject: [PATCH] fix eslint link-passhref rule --- .../lib/rules/link-passhref.js | 2 +- .../eslint-plugin-next/link-passhref.test.ts | 37 +++++++++++++++++-- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/packages/eslint-plugin-next/lib/rules/link-passhref.js b/packages/eslint-plugin-next/lib/rules/link-passhref.js index 44f233395144d59..97c13029aff944c 100644 --- a/packages/eslint-plugin-next/lib/rules/link-passhref.js +++ b/packages/eslint-plugin-next/lib/rules/link-passhref.js @@ -23,7 +23,7 @@ module.exports = { }, JSXOpeningElement(node) { - if (node.name.name !== 'Link' || node.name.name !== linkImport) { + if (node.name.name !== linkImport) { return } diff --git a/test/unit/eslint-plugin-next/link-passhref.test.ts b/test/unit/eslint-plugin-next/link-passhref.test.ts index 6c864a879d621df..6b8f3668edf0f51 100644 --- a/test/unit/eslint-plugin-next/link-passhref.test.ts +++ b/test/unit/eslint-plugin-next/link-passhref.test.ts @@ -14,17 +14,23 @@ const ruleTester = new RuleTester() ruleTester.run('link-passhref', rule, { valid: [ - `export const Home = () => ( + ` + import Link from 'next/link' + export const Home = () => ( )`, - `export const Home = () => ( + ` + import Link from 'next/link' + export const Home = () => ( Test )`, - `export const Home = () => ( + ` + import Link from 'next/link' + export const Home = () => ( Test @@ -37,6 +43,14 @@ ruleTester.run('link-passhref', rule, { )`, + + ` + import NextLink from 'next/link' + export const Home = () => ( + + Test + + )`, ], invalid: [ @@ -57,6 +71,23 @@ ruleTester.run('link-passhref', rule, { }, ], }, + { + code: ` + import NextLink from 'next/link' + + export const Home = () => ( + + Test + + )`, + errors: [ + { + message: + 'passHref is missing. See: https://nextjs.org/docs/messages/link-passhref', + type: 'JSXOpeningElement', + }, + ], + }, { code: ` import Link from 'next/link'