Unverified Commit 32f0c9a4 authored by Yamagishi Kazutoshi's avatar Yamagishi Kazutoshi Committed by GitHub

Support ESLint v8 (#29865)

Co-authored-by: 's avatarMichaël De Boey <info@michaeldeboey.be>
Co-authored-by: 's avatarTim Neutkens <tim@timneutkens.nl>
parent a39a8969
...@@ -229,7 +229,7 @@ export async function createApp({ ...@@ -229,7 +229,7 @@ export async function createApp({
/** /**
* Default devDependencies. * Default devDependencies.
*/ */
const devDependencies = ['eslint@7', 'eslint-config-next'] const devDependencies = ['eslint', 'eslint-config-next']
/** /**
* TypeScript projects will have type definitions and other devDependencies. * TypeScript projects will have type definitions and other devDependencies.
*/ */
......
...@@ -10,17 +10,17 @@ ...@@ -10,17 +10,17 @@
}, },
"dependencies": { "dependencies": {
"@next/eslint-plugin-next": "12.0.4", "@next/eslint-plugin-next": "12.0.4",
"@rushstack/eslint-patch": "^1.0.6", "@rushstack/eslint-patch": "^1.0.8",
"@typescript-eslint/parser": "^4.20.0", "@typescript-eslint/parser": "^5.0.0",
"eslint-import-resolver-node": "^0.3.4", "eslint-import-resolver-node": "^0.3.4",
"eslint-import-resolver-typescript": "^2.4.0", "eslint-import-resolver-typescript": "^2.4.0",
"eslint-plugin-import": "^2.22.1", "eslint-plugin-import": "^2.25.2",
"eslint-plugin-jsx-a11y": "^6.4.1", "eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-react": "^7.23.1", "eslint-plugin-react": "^7.27.0",
"eslint-plugin-react-hooks": "^4.2.0" "eslint-plugin-react-hooks": "^4.3.0"
}, },
"peerDependencies": { "peerDependencies": {
"eslint": "^7.23.0", "eslint": "^7.23.0 || ^8.0.0",
"next": ">=10.2.0", "next": ">=10.2.0",
"typescript": ">=3.3.1" "typescript": ">=3.3.1"
}, },
......
module.exports=(()=>{var r={192:(r,e,t)=>{var s=t(622);r.exports=function(r,e){if(e){var t=e.map(function(e){return s.resolve(r,e)})}else{var t=r}var n=t.slice(1).reduce(function(r,e){if(!e.match(/^([A-Za-z]:)?\/|\\/)){throw new Error("relative path without a basedir")}var t=e.split(/\/+|\\+/);for(var s=0;r[s]===t[s]&&s<Math.min(r.length,t.length);s++);return r.slice(0,s)},t[0].split(/\/+|\\+/));return n.length>1?n.join("/"):"/"}},293:(r,e,t)=>{"use strict";const s=t(747);const n=t(622);const{promisify:o}=t(669);const c=t(519);const i=c.satisfies(process.version,">=10.12.0");const a=r=>{if(process.platform==="win32"){const e=/[<>:"|?*]/.test(r.replace(n.parse(r).root,""));if(e){const e=new Error(`Path contains invalid characters: ${r}`);e.code="EINVAL";throw e}}};const u=r=>{const e={mode:511&~process.umask(),fs:s};return{...e,...r}};const d=r=>{const e=new Error(`operation not permitted, mkdir '${r}'`);e.code="EPERM";e.errno=-4048;e.path=r;e.syscall="mkdir";return e};const f=async(r,e)=>{a(r);e=u(e);const t=o(e.fs.mkdir);const c=o(e.fs.stat);if(i&&e.fs.mkdir===s.mkdir){const s=n.resolve(r);await t(s,{mode:e.mode,recursive:true});return s}const f=async r=>{try{await t(r,e.mode);return r}catch(e){if(e.code==="EPERM"){throw e}if(e.code==="ENOENT"){if(n.dirname(r)===r){throw d(r)}if(e.message.includes("null bytes")){throw e}await f(n.dirname(r));return f(r)}try{const t=await c(r);if(!t.isDirectory()){throw new Error("The path is not a directory")}}catch(r){throw e}return r}};return f(n.resolve(r))};r.exports=f;r.exports.sync=((r,e)=>{a(r);e=u(e);if(i&&e.fs.mkdirSync===s.mkdirSync){const t=n.resolve(r);s.mkdirSync(t,{mode:e.mode,recursive:true});return t}const t=r=>{try{e.fs.mkdirSync(r,e.mode)}catch(s){if(s.code==="EPERM"){throw s}if(s.code==="ENOENT"){if(n.dirname(r)===r){throw d(r)}if(s.message.includes("null bytes")){throw s}t(n.dirname(r));return t(r)}try{if(!e.fs.statSync(r).isDirectory()){throw new Error("The path is not a directory")}}catch(r){throw s}}return r};return t(n.resolve(r))})},477:(r,e,t)=>{"use strict";const s=t(622);const n=t(442);const o=async r=>{const e=await n("package.json",{cwd:r});return e&&s.dirname(e)};r.exports=o;r.exports.default=o;r.exports.sync=(r=>{const e=n.sync("package.json",{cwd:r});return e&&s.dirname(e)})},281:(r,e,t)=>{"use strict";const s=t(622);const n=t(747);const o=t(192);const c=t(477);const i=t(293);const{env:a,cwd:u}=process;const d=r=>{try{n.accessSync(r,n.constants.W_OK);return true}catch(r){return false}};function useDirectory(r,e){if(e.create){i.sync(r)}if(e.thunk){return(...e)=>s.join(r,...e)}return r}function getNodeModuleDirectory(r){const e=s.join(r,"node_modules");if(!d(e)&&(n.existsSync(e)||!d(s.join(r)))){return}return e}r.exports=((r={})=>{if(a.CACHE_DIR&&!["true","false","1","0"].includes(a.CACHE_DIR)){return useDirectory(s.join(a.CACHE_DIR,"find-cache-dir"),r)}let{cwd:e=u()}=r;if(r.files){e=o(e,r.files)}e=c.sync(e);if(!e){return}const t=getNodeModuleDirectory(e);if(!t){return undefined}return useDirectory(s.join(e,"node_modules",".cache",r.name),r)})},747:r=>{"use strict";r.exports=require("fs")},442:r=>{"use strict";r.exports=require("next/dist/compiled/find-up")},519:r=>{"use strict";r.exports=require("next/dist/compiled/semver")},622:r=>{"use strict";r.exports=require("path")},669:r=>{"use strict";r.exports=require("util")}};var e={};function __nccwpck_require__(t){if(e[t]){return e[t].exports}var s=e[t]={exports:{}};var n=true;try{r[t](s,s.exports,__nccwpck_require__);n=false}finally{if(n)delete e[t]}return s.exports}__nccwpck_require__.ab=__dirname+"/";return __nccwpck_require__(281)})(); module.exports=(()=>{var r={192:(r,e,t)=>{var s=t(622);r.exports=function(r,e){if(e){var t=e.map(function(e){return s.resolve(r,e)})}else{var t=r}var n=t.slice(1).reduce(function(r,e){if(!e.match(/^([A-Za-z]:)?\/|\\/)){throw new Error("relative path without a basedir")}var t=e.split(/\/+|\\+/);for(var s=0;r[s]===t[s]&&s<Math.min(r.length,t.length);s++);return r.slice(0,s)},t[0].split(/\/+|\\+/));return n.length>1?n.join("/"):"/"}},293:(r,e,t)=>{"use strict";const s=t(747);const n=t(622);const{promisify:o}=t(669);const c=t(519);const i=c.satisfies(process.version,">=10.12.0");const a=r=>{if(process.platform==="win32"){const e=/[<>:"|?*]/.test(r.replace(n.parse(r).root,""));if(e){const e=new Error(`Path contains invalid characters: ${r}`);e.code="EINVAL";throw e}}};const u=r=>{const e={mode:511&~process.umask(),fs:s};return{...e,...r}};const d=r=>{const e=new Error(`operation not permitted, mkdir '${r}'`);e.code="EPERM";e.errno=-4048;e.path=r;e.syscall="mkdir";return e};const f=async(r,e)=>{a(r);e=u(e);const t=o(e.fs.mkdir);const c=o(e.fs.stat);if(i&&e.fs.mkdir===s.mkdir){const s=n.resolve(r);await t(s,{mode:e.mode,recursive:true});return s}const f=async r=>{try{await t(r,e.mode);return r}catch(e){if(e.code==="EPERM"){throw e}if(e.code==="ENOENT"){if(n.dirname(r)===r){throw d(r)}if(e.message.includes("null bytes")){throw e}await f(n.dirname(r));return f(r)}try{const t=await c(r);if(!t.isDirectory()){throw new Error("The path is not a directory")}}catch(r){throw e}return r}};return f(n.resolve(r))};r.exports=f;r.exports.sync=((r,e)=>{a(r);e=u(e);if(i&&e.fs.mkdirSync===s.mkdirSync){const t=n.resolve(r);s.mkdirSync(t,{mode:e.mode,recursive:true});return t}const t=r=>{try{e.fs.mkdirSync(r,e.mode)}catch(s){if(s.code==="EPERM"){throw s}if(s.code==="ENOENT"){if(n.dirname(r)===r){throw d(r)}if(s.message.includes("null bytes")){throw s}t(n.dirname(r));return t(r)}try{if(!e.fs.statSync(r).isDirectory()){throw new Error("The path is not a directory")}}catch(r){throw s}}return r};return t(n.resolve(r))})},281:(r,e,t)=>{"use strict";const s=t(622);const n=t(747);const o=t(192);const c=t(98);const i=t(293);const{env:a,cwd:u}=process;const d=r=>{try{n.accessSync(r,n.constants.W_OK);return true}catch(r){return false}};function useDirectory(r,e){if(e.create){i.sync(r)}if(e.thunk){return(...e)=>s.join(r,...e)}return r}function getNodeModuleDirectory(r){const e=s.join(r,"node_modules");if(!d(e)&&(n.existsSync(e)||!d(s.join(r)))){return}return e}r.exports=((r={})=>{if(a.CACHE_DIR&&!["true","false","1","0"].includes(a.CACHE_DIR)){return useDirectory(s.join(a.CACHE_DIR,"find-cache-dir"),r)}let{cwd:e=u()}=r;if(r.files){e=o(e,r.files)}e=c.sync(e);if(!e){return}const t=getNodeModuleDirectory(e);if(!t){return undefined}return useDirectory(s.join(e,"node_modules",".cache",r.name),r)})},98:(r,e,t)=>{"use strict";const s=t(622);const n=t(442);const o=async r=>{const e=await n("package.json",{cwd:r});return e&&s.dirname(e)};r.exports=o;r.exports.default=o;r.exports.sync=(r=>{const e=n.sync("package.json",{cwd:r});return e&&s.dirname(e)})},747:r=>{"use strict";r.exports=require("fs")},442:r=>{"use strict";r.exports=require("next/dist/compiled/find-up")},519:r=>{"use strict";r.exports=require("next/dist/compiled/semver")},622:r=>{"use strict";r.exports=require("path")},669:r=>{"use strict";r.exports=require("util")}};var e={};function __nccwpck_require__(t){if(e[t]){return e[t].exports}var s=e[t]={exports:{}};var n=true;try{r[t](s,s.exports,__nccwpck_require__);n=false}finally{if(n)delete e[t]}return s.exports}__nccwpck_require__.ab=__dirname+"/";return __nccwpck_require__(281)})();
\ No newline at end of file \ No newline at end of file
...@@ -94,8 +94,8 @@ async function lint( ...@@ -94,8 +94,8 @@ async function lint(
lintDuringBuild ? ' in order to run during builds:' : ':' lintDuringBuild ? ' in order to run during builds:' : ':'
} ${chalk.bold.cyan( } ${chalk.bold.cyan(
(await isYarn(baseDir)) (await isYarn(baseDir))
? 'yarn add --dev eslint@"<8.0.0"' // TODO: Remove @"<8.0.0" when ESLint v8 is supported https://github.com/vercel/next.js/pull/29865 ? 'yarn add --dev eslint'
: 'npm install --save-dev eslint@"<8.0.0"' // TODO: Remove @"<8.0.0" when ESLint v8 is supported https://github.com/vercel/next.js/pull/29865 : 'npm install --save-dev eslint'
)}` )}`
) )
return null return null
...@@ -111,16 +111,7 @@ async function lint( ...@@ -111,16 +111,7 @@ async function lint(
'error' 'error'
)} - Your project has an older version of ESLint installed${ )} - Your project has an older version of ESLint installed${
eslintVersion ? ' (' + eslintVersion + ')' : '' eslintVersion ? ' (' + eslintVersion + ')' : ''
}. Please upgrade to ESLint version 7` }. Please upgrade to ESLint version 7 or above`
} else if (semver.gte(eslintVersion, '8.0.0')) {
// TODO: Remove this check when ESLint v8 is supported https://github.com/vercel/next.js/pull/29865
return `${chalk.red('error')} - ESLint version ${
eslintVersion ? eslintVersion : '8'
} is not yet supported. Please downgrade to version 7 for the meantime: ${chalk.bold.cyan(
(await isYarn(baseDir))
? 'yarn remove eslint && yarn add --dev eslint@"<8.0.0"'
: 'npm uninstall eslint && npm install --save-dev eslint@"<8.0.0"'
)}`
} }
let options: any = { let options: any = {
......
{
"name": "eslint",
"main": "./lib/api.js",
"version": "8.0.1"
}
const Home = () => (
<div>
<p>Home</p>
/* Badly formatted comment */
</div>
)
export default Home
...@@ -25,10 +25,6 @@ const dirInvalidOlderEslintVersion = join( ...@@ -25,10 +25,6 @@ const dirInvalidOlderEslintVersion = join(
__dirname, __dirname,
'../invalid-eslint-version' '../invalid-eslint-version'
) )
const dirInvalidNewerEslintVersion = join(
__dirname,
'../invalid-newer-eslint-version'
)
const dirMaxWarnings = join(__dirname, '../max-warnings') const dirMaxWarnings = join(__dirname, '../max-warnings')
const dirEmptyDirectory = join(__dirname, '../empty-directory') const dirEmptyDirectory = join(__dirname, '../empty-directory')
const dirEslintIgnore = join(__dirname, '../eslint-ignore') const dirEslintIgnore = join(__dirname, '../eslint-ignore')
...@@ -115,24 +111,6 @@ describe('ESLint', () => { ...@@ -115,24 +111,6 @@ describe('ESLint', () => {
) )
}) })
// TODO: Remove this test when ESLint v8 is supported https://github.com/vercel/next.js/pull/29865
test('invalid newer eslint version', async () => {
const { stdout, stderr } = await nextBuild(
dirInvalidNewerEslintVersion,
[],
{
stdout: true,
stderr: true,
}
)
const output = stdout + stderr
console.log(output)
expect(output).toContain(
'ESLint version 8.0.1 is not yet supported. Please downgrade to version 7 for the meantime'
)
})
test('empty directories do not fail the build', async () => { test('empty directories do not fail the build', async () => {
const { stdout, stderr } = await nextBuild(dirEmptyDirectory, [], { const { stdout, stderr } = await nextBuild(dirEmptyDirectory, [], {
stdout: true, stdout: true,
......
...@@ -519,7 +519,10 @@ describe('Telemetry CLI', () => { ...@@ -519,7 +519,10 @@ describe('Telemetry CLI', () => {
}) })
it('emits telemetry for lint during build', async () => { it('emits telemetry for lint during build', async () => {
await fs.writeFile(path.join(appDir, '.eslintrc'), `{ "extends": "next" }`) await fs.writeFile(
path.join(appDir, '.eslintrc'),
`{ "root": true, "extends": "next" }`
)
const { stderr } = await nextBuild(appDir, [], { const { stderr } = await nextBuild(appDir, [], {
stderr: true, stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 }, env: { NEXT_TELEMETRY_DEBUG: 1 },
...@@ -541,7 +544,10 @@ describe('Telemetry CLI', () => { ...@@ -541,7 +544,10 @@ describe('Telemetry CLI', () => {
}) })
it('emits telemetry for `next lint`', async () => { it('emits telemetry for `next lint`', async () => {
await fs.writeFile(path.join(appDir, '.eslintrc'), `{ "extends": "next" }`) await fs.writeFile(
path.join(appDir, '.eslintrc'),
`{ "root": true, "extends": "next" }`
)
const { stderr } = await nextLint(appDir, [], { const { stderr } = await nextLint(appDir, [], {
stderr: true, stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 }, env: { NEXT_TELEMETRY_DEBUG: 1 },
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment