Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
a7793c7a
Unverified
Commit
a7793c7a
authored
Feb 01, 2022
by
Stoyan Delev
Committed by
GitHub
Feb 01, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix eslint link-passhref rule (#33857)
parent
3e60c232
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
4 deletions
+35
-4
link-passhref.js
packages/eslint-plugin-next/lib/rules/link-passhref.js
+1
-1
link-passhref.test.ts
test/unit/eslint-plugin-next/link-passhref.test.ts
+34
-3
No files found.
packages/eslint-plugin-next/lib/rules/link-passhref.js
View file @
a7793c7a
...
@@ -23,7 +23,7 @@ module.exports = {
...
@@ -23,7 +23,7 @@ module.exports = {
},
},
JSXOpeningElement
(
node
)
{
JSXOpeningElement
(
node
)
{
if
(
node
.
name
.
name
!==
'Link'
||
node
.
name
.
name
!==
linkImport
)
{
if
(
node
.
name
.
name
!==
linkImport
)
{
return
return
}
}
...
...
test/unit/eslint-plugin-next/link-passhref.test.ts
View file @
a7793c7a
...
@@ -14,17 +14,23 @@ const ruleTester = new RuleTester()
...
@@ -14,17 +14,23 @@ const ruleTester = new RuleTester()
ruleTester
.
run
(
'link-passhref'
,
rule
,
{
ruleTester
.
run
(
'link-passhref'
,
rule
,
{
valid
:
[
valid
:
[
`export const Home = () => (
`
import Link from 'next/link'
export const Home = () => (
<Link href="/test"></Link>
<Link href="/test"></Link>
)`
,
)`
,
`export const Home = () => (
`
import Link from 'next/link'
export const Home = () => (
<Link href="/test">
<Link href="/test">
<a>Test</a>
<a>Test</a>
</Link>
</Link>
)`
,
)`
,
`export const Home = () => (
`
import Link from 'next/link'
export const Home = () => (
<Link href="/test" passHref>
<Link href="/test" passHref>
<StyledLink>Test</StyledLink>
<StyledLink>Test</StyledLink>
</Link>
</Link>
...
@@ -37,6 +43,14 @@ ruleTester.run('link-passhref', rule, {
...
@@ -37,6 +43,14 @@ ruleTester.run('link-passhref', rule, {
<MyButton />
<MyButton />
</Link>
</Link>
)`
,
)`
,
`
import NextLink from 'next/link'
export const Home = () => (
<NextLink href="/test" passHref>
<StyledLink>Test</StyledLink>
</NextLink>
)`
,
],
],
invalid
:
[
invalid
:
[
...
@@ -57,6 +71,23 @@ ruleTester.run('link-passhref', rule, {
...
@@ -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
:
`
code
:
`
import Link from 'next/link'
import Link from 'next/link'
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment