Skip to content

Commit

Permalink
fix eslint link-passhref rule (#33857)
Browse files Browse the repository at this point in the history
  • Loading branch information
mutebg committed Feb 1, 2022
1 parent 3e60c23 commit a7793c7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/eslint-plugin-next/lib/rules/link-passhref.js
Expand Up @@ -23,7 +23,7 @@ module.exports = {
},

JSXOpeningElement(node) {
if (node.name.name !== 'Link' || node.name.name !== linkImport) {
if (node.name.name !== linkImport) {
return
}

Expand Down
37 changes: 34 additions & 3 deletions test/unit/eslint-plugin-next/link-passhref.test.ts
Expand Up @@ -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 = () => (
<Link href="/test"></Link>
)`,

`export const Home = () => (
`
import Link from 'next/link'
export const Home = () => (
<Link href="/test">
<a>Test</a>
</Link>
)`,

`export const Home = () => (
`
import Link from 'next/link'
export const Home = () => (
<Link href="/test" passHref>
<StyledLink>Test</StyledLink>
</Link>
Expand All @@ -37,6 +43,14 @@ ruleTester.run('link-passhref', rule, {
<MyButton />
</Link>
)`,

`
import NextLink from 'next/link'
export const Home = () => (
<NextLink href="/test" passHref>
<StyledLink>Test</StyledLink>
</NextLink>
)`,
],

invalid: [
Expand All @@ -57,6 +71,23 @@ ruleTester.run('link-passhref', rule, {
},
],
},
{
code: `
import NextLink from 'next/link'
export const Home = () => (
<NextLink href="/test">
<StyledLink>Test</StyledLink>
</NextLink>
)`,
errors: [
{
message:
'passHref is missing. See: https://nextjs.org/docs/messages/link-passhref',
type: 'JSXOpeningElement',
},
],
},
{
code: `
import Link from 'next/link'
Expand Down

0 comments on commit a7793c7

Please sign in to comment.