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
ce4f1e88
Unverified
Commit
ce4f1e88
authored
Jun 18, 2021
by
Houssein Djirdeh
Committed by
GitHub
Jun 18, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[ESLint] Adds `--quiet` flag, TypeScript resolver and bug fixes (#26280)
parent
b4e0eb0b
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
56 additions
and
14 deletions
+56
-14
index.js
packages/eslint-config-next/index.js
+3
-0
package.json
packages/eslint-config-next/package.json
+1
-0
link-passhref.js
packages/eslint-plugin-next/lib/rules/link-passhref.js
+1
-3
next-lint.ts
packages/next/cli/next-lint.ts
+8
-4
runLintCheck.ts
packages/next/lib/eslint/runLintCheck.ts
+8
-5
.eslintrc
test/integration/eslint/custom-config/.eslintrc
+1
-1
index.js
test/integration/eslint/custom-config/pages/index.js
+1
-0
index.test.js
test/integration/eslint/test/index.test.js
+22
-1
yarn.lock
yarn.lock
+11
-0
No files found.
packages/eslint-config-next/index.js
View file @
ce4f1e88
...
...
@@ -58,6 +58,9 @@ module.exports = {
[
require
.
resolve
(
'eslint-import-resolver-node'
)]:
{
extensions
:
[
'.js'
,
'.jsx'
,
'.ts'
,
'.tsx'
],
},
[
require
.
resolve
(
'eslint-import-resolver-typescript'
)]:
{
alwaysTryTypes
:
true
,
},
},
},
}
packages/eslint-config-next/package.json
View file @
ce4f1e88
...
...
@@ -13,6 +13,7 @@
"@rushstack/eslint-patch"
:
"^1.0.6"
,
"@typescript-eslint/parser"
:
"^4.20.0"
,
"eslint-import-resolver-node"
:
"^0.3.4"
,
"eslint-import-resolver-typescript"
:
"^2.4.0"
,
"eslint-plugin-import"
:
"^2.22.1"
,
"eslint-plugin-jsx-a11y"
:
"^6.4.1"
,
"eslint-plugin-react"
:
"^7.23.1"
,
...
...
packages/eslint-plugin-next/lib/rules/link-passhref.js
View file @
ce4f1e88
...
...
@@ -44,9 +44,7 @@ module.exports = {
const
hasAnchorChild
=
children
.
some
(
(
attr
)
=>
attr
.
type
===
'JSXElement'
&&
attr
.
openingElement
.
name
.
name
===
'a'
&&
attr
.
closingElement
.
name
.
name
===
'a'
attr
.
type
===
'JSXElement'
&&
attr
.
openingElement
.
name
.
name
===
'a'
)
if
(
!
hasAnchorChild
&&
!
hasPassHref
)
{
...
...
packages/next/cli/next-lint.ts
View file @
ce4f1e88
...
...
@@ -28,7 +28,6 @@ const eslintOptions = (args: arg.Spec) => ({
args
[
'--report-unused-disable-directives'
]
||
null
,
cache
:
args
[
'--cache'
]
??
false
,
cacheLocation
:
args
[
'--cache-location'
]
||
'.eslintcache'
,
cacheStrategy
:
args
[
'--cache-strategy'
]
||
'metadata'
,
errorOnUnmatchedPattern
:
!
Boolean
(
args
[
'--no-error-on-unmatched-pattern'
]),
})
...
...
@@ -55,11 +54,11 @@ const nextLint: cliCommand = (argv) => {
'--fix-type'
:
[
String
],
'--ignore-path'
:
String
,
'--no-ignore'
:
Boolean
,
'--quiet'
:
Boolean
,
'--no-inline-config'
:
Boolean
,
'--report-unused-disable-directives'
:
String
,
'--cache'
:
Boolean
,
'--cache-location'
:
String
,
'--cache-strategy'
:
String
,
'--no-error-on-unmatched-pattern'
:
Boolean
,
// Aliases
...
...
@@ -107,6 +106,9 @@ const nextLint: cliCommand = (argv) => {
--ignore-path path::String Specify path of ignore file
--no-ignore Disable use of ignore files and patterns
Handling warnings:
--quiet Report errors only - default: false
Inline configuration comments:
--no-inline-config Prevent comments from changing config or rules
--report-unused-disable-directives Adds reported errors for unused eslint-disable directives ("error" | "warn" | "off")
...
...
@@ -114,7 +116,6 @@ const nextLint: cliCommand = (argv) => {
Caching:
--cache Only check changed files - default: false
--cache-location path::String Path to the cache file or directory - default: .eslintcache
--cache-strategy String Strategy to use for detecting changed files - either: metadata or content - default: metadata
Miscellaneous:
--no-error-on-unmatched-pattern Prevent errors when pattern is unmatched - default: false
...
...
@@ -140,7 +141,10 @@ const nextLint: cliCommand = (argv) => {
},
[]
)
runLintCheck
(
baseDir
,
lintDirs
,
false
,
eslintOptions
(
args
))
const
reportErrorsOnly
=
Boolean
(
args
[
'--quiet'
])
runLintCheck
(
baseDir
,
lintDirs
,
false
,
eslintOptions
(
args
),
reportErrorsOnly
)
.
then
(
async
(
lintResults
)
=>
{
const
lintOutput
=
typeof
lintResults
===
'string'
?
lintResults
:
lintResults
?.
output
...
...
packages/next/lib/eslint/runLintCheck.ts
View file @
ce4f1e88
...
...
@@ -28,7 +28,8 @@ async function lint(
lintDirs
:
string
[],
eslintrcFile
:
string
|
null
,
pkgJsonPath
:
string
|
null
,
eslintOptions
:
any
=
null
eslintOptions
:
any
=
null
,
reportErrorsOnly
:
boolean
=
false
):
Promise
<
|
string
|
null
...
...
@@ -59,7 +60,6 @@ async function lint(
'error'
)}
- ESLint class not found. Please upgrade to ESLint version 7 or later`
}
let
options
:
any
=
{
useEslintrc
:
true
,
baseConfig
:
{},
...
...
@@ -110,8 +110,9 @@ async function lint(
}
const
lintStart
=
process
.
hrtime
()
cons
t
results
=
await
eslint
.
lintFiles
(
lintDirs
)
le
t
results
=
await
eslint
.
lintFiles
(
lintDirs
)
if
(
options
.
fix
)
await
ESLint
.
outputFixes
(
results
)
if
(
reportErrorsOnly
)
results
=
await
ESLint
.
getErrorResults
(
results
)
// Only return errors if --quiet flag is used
const
formattedResult
=
formatResults
(
baseDir
,
results
)
const
lintEnd
=
process
.
hrtime
(
lintStart
)
...
...
@@ -141,7 +142,8 @@ export async function runLintCheck(
baseDir
:
string
,
lintDirs
:
string
[],
lintDuringBuild
:
boolean
=
false
,
eslintOptions
:
any
=
null
eslintOptions
:
any
=
null
,
reportErrorsOnly
:
boolean
=
false
):
ReturnType
<
typeof
lint
>
{
try
{
// Find user's .eslintrc file
...
...
@@ -202,7 +204,8 @@ export async function runLintCheck(
lintDirs
,
eslintrcFile
,
pkgJsonPath
,
eslintOptions
eslintOptions
,
reportErrorsOnly
)
}
catch
(
err
)
{
throw
err
...
...
test/integration/eslint/custom-config/.eslintrc
View file @
ce4f1e88
...
...
@@ -3,6 +3,6 @@
"root": true,
"rules": {
"@next/next/no-html-link-for-pages": 0,
"@next/next/no-sync-scripts":
2
"@next/next/no-sync-scripts":
1
}
}
test/integration/eslint/custom-config/pages/index.js
View file @
ce4f1e88
const
Home
=
()
=>
(
<
div
>
<
p
>
Home
<
/p
>
<
script
src
=
"https://example.com"
/>
/* Badly formatted comment */
<
/div
>
)
...
...
test/integration/eslint/test/index.test.js
View file @
ce4f1e88
...
...
@@ -41,6 +41,9 @@ describe('ESLint', () => {
})
const
output
=
stdout
+
stderr
expect
(
output
).
toContain
(
'Warning: External synchronous scripts are forbidden'
)
expect
(
output
).
toContain
(
'Error: Comments inside children section of tag should be placed inside braces'
)
...
...
@@ -75,7 +78,7 @@ describe('ESLint', () => {
)
})
test
.
only
(
'invalid eslint version'
,
async
()
=>
{
test
(
'invalid eslint version'
,
async
()
=>
{
const
{
stdout
,
stderr
}
=
await
nextBuild
(
dirInvalidEslintVersion
,
[],
{
stdout
:
true
,
stderr
:
true
,
...
...
@@ -115,6 +118,9 @@ describe('ESLint', () => {
})
const
output
=
stdout
+
stderr
expect
(
output
).
toContain
(
'Warning: External synchronous scripts are forbidden'
)
expect
(
output
).
toContain
(
'Error: Comments inside children section of tag should be placed inside braces'
)
...
...
@@ -167,5 +173,20 @@ describe('ESLint', () => {
}
}
})
test
(
'quiet flag suppresses warnings and only reports errors'
,
async
()
=>
{
const
{
stdout
,
stderr
}
=
await
nextLint
(
dirCustomConfig
,
[
'--quiet'
],
{
stdout
:
true
,
stderr
:
true
,
})
const
output
=
stdout
+
stderr
expect
(
output
).
toContain
(
'Error: Comments inside children section of tag should be placed inside braces'
)
expect
(
output
).
not
.
toContain
(
'Warning: External synchronous scripts are forbidden'
)
})
})
})
yarn.lock
View file @
ce4f1e88
...
...
@@ -7991,6 +7991,17 @@ eslint-import-resolver-node@^0.3.4:
debug "^2.6.9"
resolve "^1.13.1"
eslint-import-resolver-typescript@^2.4.0:
version "2.4.0"
resolved "https://registry.yarnpkg.com/eslint-import-resolver-typescript/-/eslint-import-resolver-typescript-2.4.0.tgz#ec1e7063ebe807f0362a7320543aaed6fe1100e1"
integrity sha512-useJKURidCcldRLCNKWemr1fFQL1SzB3G4a0li6lFGvlc5xGe1hY343bvG07cbpCzPuM/lK19FIJB3XGFSkplA==
dependencies:
debug "^4.1.1"
glob "^7.1.6"
is-glob "^4.0.1"
resolve "^1.17.0"
tsconfig-paths "^3.9.0"
eslint-module-utils@^2.6.0:
version "2.6.0"
resolved "https://registry.yarnpkg.com/eslint-module-utils/-/eslint-module-utils-2.6.0.tgz#579ebd094f56af7797d19c9866c9c9486629bfa6"
...
...
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