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
b7eeb6c5
Unverified
Commit
b7eeb6c5
authored
Dec 07, 2021
by
Bryan Smith
Committed by
GitHub
Dec 07, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix crash in no-page-custom-font eslint rule when default export is unnamed. (#32251)
fixes #32250
parent
836334e7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
10 deletions
+29
-10
no-page-custom-font.js
packages/eslint-plugin-next/lib/rules/no-page-custom-font.js
+12
-8
no-page-custom-font.test.ts
test/unit/eslint-plugin-next/no-page-custom-font.test.ts
+17
-2
No files found.
packages/eslint-plugin-next/lib/rules/no-page-custom-font.js
View file @
b7eeb6c5
...
...
@@ -24,7 +24,7 @@ module.exports = {
page
.
startsWith
(
`
${
posix
.
sep
}
_document`
)
let
documentImportName
let
localDefaultExport
Name
let
localDefaultExport
Id
let
exportDeclarationType
return
{
...
...
@@ -43,7 +43,7 @@ module.exports = {
exportDeclarationType
=
node
.
declaration
.
type
if
(
node
.
declaration
.
type
===
'FunctionDeclaration'
)
{
localDefaultExport
Name
=
node
.
declaration
.
id
.
name
localDefaultExport
Id
=
node
.
declaration
.
id
return
}
...
...
@@ -52,7 +52,7 @@ module.exports = {
node
.
declaration
.
superClass
&&
node
.
declaration
.
superClass
.
name
===
documentImportName
)
{
localDefaultExport
Name
=
node
.
declaration
.
id
.
name
localDefaultExport
Id
=
node
.
declaration
.
id
}
},
...
...
@@ -66,7 +66,7 @@ module.exports = {
// if `export default <name>` is further down within the file after the
// currently traversed component, then `localDefaultExportName` will
// still be undefined
if
(
!
localDefaultExport
Name
)
{
if
(
!
localDefaultExport
Id
)
{
// find the top level of the module
const
program
=
ancestors
.
find
(
(
ancestor
)
=>
ancestor
.
type
===
'Program'
...
...
@@ -74,7 +74,7 @@ module.exports = {
// go over each token to find the combination of `export default <name>`
for
(
let
i
=
0
;
i
<=
program
.
tokens
.
length
-
1
;
i
++
)
{
if
(
localDefaultExport
Name
)
{
if
(
localDefaultExport
Id
)
{
break
}
...
...
@@ -91,7 +91,7 @@ module.exports = {
const
maybeIdentifier
=
program
.
tokens
[
i
+
2
]
if
(
maybeIdentifier
&&
maybeIdentifier
.
type
===
'Identifier'
)
{
localDefaultExport
Name
=
maybeIdentifier
.
value
localDefaultExport
Id
=
{
name
:
maybeIdentifier
.
value
}
}
}
}
...
...
@@ -112,13 +112,13 @@ module.exports = {
if
(
exportDeclarationType
===
'FunctionDeclaration'
)
{
return
(
ancestor
.
type
===
exportDeclarationType
&&
ancestor
.
id
.
name
===
localDefaultExportName
isIdentifierMatch
(
ancestor
.
id
,
localDefaultExportId
)
)
}
// function ...() {} export default ...
// class ... extends ...; export default ...
return
ancestor
.
id
&&
ancestor
.
id
.
name
===
localDefaultExportName
return
isIdentifierMatch
(
ancestor
.
id
,
localDefaultExportId
)
})
// file starts with _document and this <link /> is within the default export
...
...
@@ -153,3 +153,7 @@ module.exports = {
}
},
}
function
isIdentifierMatch
(
id1
,
id2
)
{
return
(
id1
===
null
&&
id2
===
null
)
||
(
id1
&&
id2
&&
id1
.
name
===
id2
.
name
)
}
test/unit/eslint-plugin-next/no-page-custom-font.test.ts
View file @
b7eeb6c5
...
...
@@ -105,10 +105,25 @@ ruleTester.run('no-page-custom-font', rule, {
);
}
}
export default MyDocument;`
,
filename
,
},
{
code
:
`export default function() {
return (
<Html>
<Head>
<link
href="https://fonts.googleapis.com/css2?family=Krona+One&display=swap"
rel="stylesheet"
/>
</Head>
</Html>
)
}`
,
filename
,
},
],
invalid
:
[
...
...
@@ -153,7 +168,7 @@ ruleTester.run('no-page-custom-font', rule, {
<link
href="https://fonts.googleapis.com/css2?family=Open+Sans"
rel="stylesheet"
/>
/>
</>
)
}
...
...
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