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
8a37c2e3
Unverified
Commit
8a37c2e3
authored
Jul 22, 2024
by
darthmaim
Committed by
GitHub
Jul 22, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix `next lint` with async eslint-formatters (#67860)
parent
852092f2
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
6 deletions
+29
-6
customFormatter.ts
packages/next/src/lib/eslint/customFormatter.ts
+5
-5
runLintCheck.ts
packages/next/src/lib/eslint/runLintCheck.ts
+1
-1
format.js
test/integration/eslint/formatter-async/format.js
+7
-0
next-lint.test.js
test/integration/eslint/test/next-lint.test.js
+16
-0
No files found.
packages/next/src/lib/eslint/customFormatter.ts
View file @
8a37c2e3
...
@@ -94,16 +94,16 @@ function formatMessage(
...
@@ -94,16 +94,16 @@ function formatMessage(
return
output
return
output
}
}
export
function
formatResults
(
export
async
function
formatResults
(
baseDir
:
string
,
baseDir
:
string
,
results
:
LintResult
[],
results
:
LintResult
[],
format
:
(
r
:
LintResult
[])
=>
string
format
:
(
r
:
LintResult
[])
=>
string
|
Promise
<
string
>
):
{
):
Promise
<
{
output
:
string
output
:
string
outputWithMessages
:
string
outputWithMessages
:
string
totalNextPluginErrorCount
:
number
totalNextPluginErrorCount
:
number
totalNextPluginWarningCount
:
number
totalNextPluginWarningCount
:
number
}
{
}
>
{
let
totalNextPluginErrorCount
=
0
let
totalNextPluginErrorCount
=
0
let
totalNextPluginWarningCount
=
0
let
totalNextPluginWarningCount
=
0
let
resultsWithMessages
=
results
.
filter
(({
messages
})
=>
messages
?.
length
)
let
resultsWithMessages
=
results
.
filter
(({
messages
})
=>
messages
?.
length
)
...
@@ -117,7 +117,7 @@ export function formatResults(
...
@@ -117,7 +117,7 @@ export function formatResults(
// Use user defined formatter or Next.js's built-in custom formatter
// Use user defined formatter or Next.js's built-in custom formatter
const
output
=
format
const
output
=
format
?
format
(
resultsWithMessages
)
?
await
format
(
resultsWithMessages
)
:
resultsWithMessages
:
resultsWithMessages
.
map
(({
messages
,
filePath
})
=>
.
map
(({
messages
,
filePath
})
=>
formatMessage
(
baseDir
,
messages
,
filePath
)
formatMessage
(
baseDir
,
messages
,
filePath
)
...
...
packages/next/src/lib/eslint/runLintCheck.ts
View file @
8a37c2e3
...
@@ -229,7 +229,7 @@ async function lint(
...
@@ -229,7 +229,7 @@ async function lint(
if
(
reportErrorsOnly
)
results
=
await
ESLint
.
getErrorResults
(
results
)
// Only return errors if --quiet flag is used
if
(
reportErrorsOnly
)
results
=
await
ESLint
.
getErrorResults
(
results
)
// Only return errors if --quiet flag is used
if
(
formatter
)
selectedFormatter
=
await
eslint
.
loadFormatter
(
formatter
)
if
(
formatter
)
selectedFormatter
=
await
eslint
.
loadFormatter
(
formatter
)
const
formattedResult
=
formatResults
(
const
formattedResult
=
await
formatResults
(
baseDir
,
baseDir
,
results
,
results
,
selectedFormatter
?.
format
selectedFormatter
?.
format
...
...
test/integration/eslint/formatter-async/format.js
0 → 100644
View file @
8a37c2e3
module
.
exports
=
async
function
(
results
)
{
// wait 1ms
await
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
1
))
// return results as JSON
return
'Async results:
\
n'
+
JSON
.
stringify
(
results
)
}
test/integration/eslint/test/next-lint.test.js
View file @
8a37c2e3
...
@@ -27,6 +27,7 @@ const dirNoConfig = join(__dirname, '../no-config')
...
@@ -27,6 +27,7 @@ const dirNoConfig = join(__dirname, '../no-config')
const
dirFileLinting
=
join
(
__dirname
,
'../file-linting'
)
const
dirFileLinting
=
join
(
__dirname
,
'../file-linting'
)
const
mjsCjsLinting
=
join
(
__dirname
,
'../mjs-cjs-linting'
)
const
mjsCjsLinting
=
join
(
__dirname
,
'../mjs-cjs-linting'
)
const
dirTypescript
=
join
(
__dirname
,
'../with-typescript'
)
const
dirTypescript
=
join
(
__dirname
,
'../with-typescript'
)
const
formatterAsync
=
join
(
__dirname
,
'../formatter-async/format.js'
)
describe
(
'Next Lint'
,
()
=>
{
describe
(
'Next Lint'
,
()
=>
{
describe
(
'First Time Setup '
,
()
=>
{
describe
(
'First Time Setup '
,
()
=>
{
...
@@ -441,6 +442,21 @@ describe('Next Lint', () => {
...
@@ -441,6 +442,21 @@ describe('Next Lint', () => {
expect
(
stdout
).
toContain
(
'2 warnings found'
)
expect
(
stdout
).
toContain
(
'2 warnings found'
)
})
})
test
(
'format flag supports async formatters'
,
async
()
=>
{
const
{
stdout
,
stderr
}
=
await
nextLint
(
dirMaxWarnings
,
[
'-f'
,
formatterAsync
],
{
stdout
:
true
,
stderr
:
true
,
}
)
const
output
=
stdout
+
stderr
expect
(
output
).
toContain
(
'Async results:'
)
expect
(
stdout
).
toContain
(
'Synchronous scripts should not be used.'
)
})
test
(
'file flag can selectively lint only a single file'
,
async
()
=>
{
test
(
'file flag can selectively lint only a single file'
,
async
()
=>
{
const
{
stdout
,
stderr
}
=
await
nextLint
(
const
{
stdout
,
stderr
}
=
await
nextLint
(
dirFileLinting
,
dirFileLinting
,
...
...
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