From 61a385ebf2bc2d57074614160210530c7dfb04b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Mon, 13 May 2024 22:26:56 +0800 Subject: [PATCH] fix: use @eslint/compat to fix eslint v9 + react plugin (#113) * fix: use eslint v9 when choosing react fixes #106 * fix: use `--force` * chore: add a note * fix: ask installing eslint v8/v9 * chore: add more tests * fix: rm an unused assignment --- lib/config-generator.js | 54 ++++++++++++++----- lib/utils/npm-utils.js | 5 +- .../__snapshots__/config@eslint-config-airbnb | 5 +- .../config@eslint-config-airbnb-base | 5 +- .../config@eslint-config-standard | 5 +- .../config@eslint-config-standard-flat | 5 +- .../config@eslint-config-standard-flat2 | 5 +- tests/__snapshots__/config@eslint-config-xo | 5 +- .../problems-commonjs-none-javascript | 5 +- .../problems-commonjs-none-typescript | 5 +- .../problems-commonjs-react-typescript | 23 -------- .../problems-commonjs-vue-javascript | 5 +- .../problems-commonjs-vue-typescript | 5 +- .../problems-esm-none-javascript | 5 +- .../problems-esm-none-typescript | 5 +- ...> problems-esm-react-eslint8.x-javascript} | 7 ++- ...> problems-esm-react-eslint8.x-typescript} | 7 ++- ...> problems-esm-react-eslint9.x-javascript} | 13 +++-- ...> problems-esm-react-eslint9.x-typescript} | 13 +++-- .../__snapshots__/problems-esm-vue-javascript | 5 +- .../__snapshots__/problems-esm-vue-typescript | 5 +- .../problems-script-none-javascript | 5 +- .../problems-script-none-typescript | 5 +- .../problems-script-react-javascript | 20 ------- .../problems-script-vue-javascript | 5 +- .../problems-script-vue-typescript | 5 +- .../syntax-commonjs-none-javascript | 5 +- .../syntax-commonjs-none-typescript | 5 +- .../syntax-commonjs-react-typescript | 20 ------- .../syntax-commonjs-vue-javascript | 5 +- .../syntax-commonjs-vue-typescript | 5 +- .../__snapshots__/syntax-esm-none-javascript | 5 +- .../__snapshots__/syntax-esm-none-typescript | 5 +- ... => syntax-esm-react-eslint8.x-javascript} | 7 ++- ... => syntax-esm-react-eslint8.x-typescript} | 7 ++- ... => syntax-esm-react-eslint9.x-javascript} | 13 +++-- ... => syntax-esm-react-eslint9.x-typescript} | 13 +++-- tests/__snapshots__/syntax-esm-vue-javascript | 5 +- tests/__snapshots__/syntax-esm-vue-typescript | 5 +- .../syntax-script-none-javascript | 5 +- .../syntax-script-none-typescript | 5 +- .../syntax-script-react-javascript | 17 ------ .../syntax-script-vue-javascript | 5 +- .../syntax-script-vue-typescript | 5 +- tests/config-snapshots.spec.js | 13 ++++- 45 files changed, 232 insertions(+), 150 deletions(-) delete mode 100644 tests/__snapshots__/problems-commonjs-react-typescript rename tests/__snapshots__/{problems-esm-react-javascript => problems-esm-react-eslint8.x-javascript} (78%) rename tests/__snapshots__/{problems-esm-react-typescript => problems-esm-react-eslint8.x-typescript} (81%) rename tests/__snapshots__/{problems-commonjs-react-javascript => problems-esm-react-eslint9.x-javascript} (59%) rename tests/__snapshots__/{problems-script-react-typescript => problems-esm-react-eslint9.x-typescript} (65%) delete mode 100644 tests/__snapshots__/problems-script-react-javascript delete mode 100644 tests/__snapshots__/syntax-commonjs-react-typescript rename tests/__snapshots__/{syntax-esm-react-javascript => syntax-esm-react-eslint8.x-javascript} (73%) rename tests/__snapshots__/{syntax-esm-react-typescript => syntax-esm-react-eslint8.x-typescript} (78%) rename tests/__snapshots__/{syntax-commonjs-react-javascript => syntax-esm-react-eslint9.x-javascript} (53%) rename tests/__snapshots__/{syntax-script-react-typescript => syntax-esm-react-eslint9.x-typescript} (61%) delete mode 100644 tests/__snapshots__/syntax-script-react-javascript diff --git a/lib/config-generator.js b/lib/config-generator.js index 34dc37dc..eef19632 100644 --- a/lib/config-generator.js +++ b/lib/config-generator.js @@ -28,9 +28,10 @@ export class ConfigGenerator { this.packageJsonPath = options.packageJsonPath || findPackageJson(this.cwd); this.answers = options.answers || {}; this.result = { - devDependencies: [], + devDependencies: ["eslint@9.x"], configFilename: "eslint.config.js", - configContent: "" + configContent: "", + installFlags: ["-D"] }; } @@ -72,6 +73,19 @@ export class ConfigGenerator { { message: "None of these", name: "none" } ] }, + { + type: "select", + name: "eslintVersion", + message: "The React plugin doesn't officially support ESLint v9 yet. What would you like to do?", + initial: 0, + choices: [ + { message: "Install ESLint v9.x with compatibility utilities", name: "9.x" }, + { message: "Install ESLint v8.x", name: "8.x" } + ], + skip() { + return this.state.answers.framework !== "react"; + } + }, { type: "select", name: "language", @@ -166,9 +180,18 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug } if (this.answers.framework === "react") { - this.result.devDependencies.push("eslint-plugin-react"); - importContent += "import pluginReactConfig from \"eslint-plugin-react/configs/recommended.js\";\n"; - exportContent += " pluginReactConfig,\n"; + if (this.answers.eslintVersion === "9.x") { + this.result.devDependencies.push("eslint-plugin-react", "@eslint/compat"); + this.result.installFlags.push("--force"); + importContent += "import pluginReactConfig from \"eslint-plugin-react/configs/recommended.js\";\n"; + importContent += "import { fixupConfigRules } from \"@eslint/compat\";\n"; + exportContent += " ...fixupConfigRules(pluginReactConfig),\n"; + } else if (this.answers.eslintVersion === "8.x") { + this.result.devDependencies[0] = "eslint@8.x"; + this.result.devDependencies.push("eslint-plugin-react"); + importContent += "import pluginReactConfig from \"eslint-plugin-react/configs/recommended.js\";\n"; + exportContent += " pluginReactConfig,\n"; + } } if (this.answers.config) { const config = this.answers.config; @@ -179,7 +202,19 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug const peers = fetchPeerDependencies(config.packageName); if (peers !== null) { - this.result.devDependencies.push(...peers); + const eslintIndex = peers.findIndex(dep => (dep.startsWith("eslint@"))); + + if (eslintIndex === -1) { + // eslint is not in the peer dependencies + + this.result.devDependencies.push(...peers); + } else { + + // eslint is in the peer dependencies => overwrite eslint version + this.result.devDependencies[0] = peers[eslintIndex]; + peers.splice(eslintIndex, 1); + this.result.devDependencies.push(...peers); + } } if (config.type === "flat" || config.type === void 0) { @@ -198,11 +233,6 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug this.result.devDependencies.push("@eslint/eslintrc", "@eslint/js"); } - const hasEslint = this.result.devDependencies.some(dep => (/^eslint(@|$)/u.test(dep))); - - if (!hasEslint) { - this.result.devDependencies.push("eslint"); - } this.result.configContent = `${importContent} ${needCompatHelper ? helperContent : ""} export default [\n${exportContent}];`; @@ -238,7 +268,7 @@ export default [\n${exportContent}];`; })).packageManager; log.info("☕️Installing..."); - installSyncSaveDev(this.result.devDependencies, packageManager); + installSyncSaveDev(this.result.devDependencies, packageManager, this.result.installFlags); await writeFile(configPath, this.result.configContent); // import("eslint") won't work in some cases. diff --git a/lib/utils/npm-utils.js b/lib/utils/npm-utils.js index f8a4dd2c..84736cd4 100644 --- a/lib/utils/npm-utils.js +++ b/lib/utils/npm-utils.js @@ -47,12 +47,13 @@ function findPackageJson(startDir) { * Install node modules synchronously and save to devDependencies in package.json * @param {string|string[]} packages Node module or modules to install * @param {string} packageManager Package manager to use for installation. + * @param {string[]} installFlags Flags to pass to the package manager. * @returns {void} */ -function installSyncSaveDev(packages, packageManager = "npm") { +function installSyncSaveDev(packages, packageManager = "npm", installFlags = ["-D"]) { const packageList = Array.isArray(packages) ? packages : [packages]; const installCmd = packageManager === "yarn" ? "add" : "install"; - const installProcess = spawn.sync(packageManager, [installCmd, "-D"].concat(packageList), { stdio: "inherit" }); + const installProcess = spawn.sync(packageManager, [installCmd, ...installFlags].concat(packageList), { stdio: "inherit" }); const error = installProcess.error; if (error && error.code === "ENOENT") { diff --git a/tests/__snapshots__/config@eslint-config-airbnb b/tests/__snapshots__/config@eslint-config-airbnb index 8a37ae66..8e43ce63 100644 --- a/tests/__snapshots__/config@eslint-config-airbnb +++ b/tests/__snapshots__/config@eslint-config-airbnb @@ -15,8 +15,8 @@ export default [ ];", "configFilename": "eslint.config.mjs", "devDependencies": [ - "eslint-config-airbnb", "eslint@^7.32.0 || ^8.2.0", + "eslint-config-airbnb", "eslint-plugin-import@^2.25.3", "eslint-plugin-jsx-a11y@^6.5.1", "eslint-plugin-react@^7.28.0", @@ -24,4 +24,7 @@ export default [ "@eslint/eslintrc", "@eslint/js", ], + "installFlags": [ + "-D", + ], } \ No newline at end of file diff --git a/tests/__snapshots__/config@eslint-config-airbnb-base b/tests/__snapshots__/config@eslint-config-airbnb-base index 02abf191..a4525962 100644 --- a/tests/__snapshots__/config@eslint-config-airbnb-base +++ b/tests/__snapshots__/config@eslint-config-airbnb-base @@ -15,10 +15,13 @@ export default [ ];", "configFilename": "eslint.config.mjs", "devDependencies": [ - "eslint-config-airbnb-base", "eslint@^7.32.0 || ^8.2.0", + "eslint-config-airbnb-base", "eslint-plugin-import@^2.25.2", "@eslint/eslintrc", "@eslint/js", ], + "installFlags": [ + "-D", + ], } \ No newline at end of file diff --git a/tests/__snapshots__/config@eslint-config-standard b/tests/__snapshots__/config@eslint-config-standard index f16330bf..f58f0160 100644 --- a/tests/__snapshots__/config@eslint-config-standard +++ b/tests/__snapshots__/config@eslint-config-standard @@ -15,12 +15,15 @@ export default [ ];", "configFilename": "eslint.config.mjs", "devDependencies": [ - "eslint-config-standard", "eslint@^8.0.1", + "eslint-config-standard", "eslint-plugin-import@^2.25.2", "eslint-plugin-n@^15.0.0 || ^16.0.0 ", "eslint-plugin-promise@^6.0.0", "@eslint/eslintrc", "@eslint/js", ], + "installFlags": [ + "-D", + ], } \ No newline at end of file diff --git a/tests/__snapshots__/config@eslint-config-standard-flat b/tests/__snapshots__/config@eslint-config-standard-flat index 9b748c70..063f9df1 100644 --- a/tests/__snapshots__/config@eslint-config-standard-flat +++ b/tests/__snapshots__/config@eslint-config-standard-flat @@ -7,10 +7,13 @@ export default [ ];", "configFilename": "eslint.config.mjs", "devDependencies": [ - "eslint-config-standard", "eslint@^8.0.1", + "eslint-config-standard", "eslint-plugin-import@^2.25.2", "eslint-plugin-n@^15.0.0 || ^16.0.0 ", "eslint-plugin-promise@^6.0.0", ], + "installFlags": [ + "-D", + ], } \ No newline at end of file diff --git a/tests/__snapshots__/config@eslint-config-standard-flat2 b/tests/__snapshots__/config@eslint-config-standard-flat2 index 9b748c70..063f9df1 100644 --- a/tests/__snapshots__/config@eslint-config-standard-flat2 +++ b/tests/__snapshots__/config@eslint-config-standard-flat2 @@ -7,10 +7,13 @@ export default [ ];", "configFilename": "eslint.config.mjs", "devDependencies": [ - "eslint-config-standard", "eslint@^8.0.1", + "eslint-config-standard", "eslint-plugin-import@^2.25.2", "eslint-plugin-n@^15.0.0 || ^16.0.0 ", "eslint-plugin-promise@^6.0.0", ], + "installFlags": [ + "-D", + ], } \ No newline at end of file diff --git a/tests/__snapshots__/config@eslint-config-xo b/tests/__snapshots__/config@eslint-config-xo index d6d56931..0446f487 100644 --- a/tests/__snapshots__/config@eslint-config-xo +++ b/tests/__snapshots__/config@eslint-config-xo @@ -15,9 +15,12 @@ export default [ ];", "configFilename": "eslint.config.mjs", "devDependencies": [ - "eslint-config-xo", "eslint@>=8.56.0", + "eslint-config-xo", "@eslint/eslintrc", "@eslint/js", ], + "installFlags": [ + "-D", + ], } \ No newline at end of file diff --git a/tests/__snapshots__/problems-commonjs-none-javascript b/tests/__snapshots__/problems-commonjs-none-javascript index 7bbbcf4f..88bab91a 100644 --- a/tests/__snapshots__/problems-commonjs-none-javascript +++ b/tests/__snapshots__/problems-commonjs-none-javascript @@ -10,8 +10,11 @@ export default [ ];", "configFilename": "eslint.config.js", "devDependencies": [ + "eslint@9.x", "globals", "@eslint/js", - "eslint", + ], + "installFlags": [ + "-D", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problems-commonjs-none-typescript b/tests/__snapshots__/problems-commonjs-none-typescript index d93b4165..f271c29b 100644 --- a/tests/__snapshots__/problems-commonjs-none-typescript +++ b/tests/__snapshots__/problems-commonjs-none-typescript @@ -12,9 +12,12 @@ export default [ ];", "configFilename": "eslint.config.js", "devDependencies": [ + "eslint@9.x", "globals", "@eslint/js", "typescript-eslint", - "eslint", + ], + "installFlags": [ + "-D", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problems-commonjs-react-typescript b/tests/__snapshots__/problems-commonjs-react-typescript deleted file mode 100644 index 0ff88fe1..00000000 --- a/tests/__snapshots__/problems-commonjs-react-typescript +++ /dev/null @@ -1,23 +0,0 @@ -{ - "configContent": "import globals from "globals"; -import pluginJs from "@eslint/js"; -import tseslint from "typescript-eslint"; -import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; - - -export default [ - {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, - {languageOptions: { globals: {...globals.browser, ...globals.node} }}, - pluginJs.configs.recommended, - ...tseslint.configs.recommended, - pluginReactConfig, -];", - "configFilename": "eslint.config.js", - "devDependencies": [ - "globals", - "@eslint/js", - "typescript-eslint", - "eslint-plugin-react", - "eslint", - ], -} \ No newline at end of file diff --git a/tests/__snapshots__/problems-commonjs-vue-javascript b/tests/__snapshots__/problems-commonjs-vue-javascript index a925ee17..d774f7ec 100644 --- a/tests/__snapshots__/problems-commonjs-vue-javascript +++ b/tests/__snapshots__/problems-commonjs-vue-javascript @@ -12,9 +12,12 @@ export default [ ];", "configFilename": "eslint.config.js", "devDependencies": [ + "eslint@9.x", "globals", "@eslint/js", "eslint-plugin-vue", - "eslint", + ], + "installFlags": [ + "-D", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problems-commonjs-vue-typescript b/tests/__snapshots__/problems-commonjs-vue-typescript index db4688fd..7d28b52d 100644 --- a/tests/__snapshots__/problems-commonjs-vue-typescript +++ b/tests/__snapshots__/problems-commonjs-vue-typescript @@ -14,10 +14,13 @@ export default [ ];", "configFilename": "eslint.config.js", "devDependencies": [ + "eslint@9.x", "globals", "@eslint/js", "typescript-eslint", "eslint-plugin-vue", - "eslint", + ], + "installFlags": [ + "-D", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problems-esm-none-javascript b/tests/__snapshots__/problems-esm-none-javascript index e66bb2b5..a104c0e9 100644 --- a/tests/__snapshots__/problems-esm-none-javascript +++ b/tests/__snapshots__/problems-esm-none-javascript @@ -9,8 +9,11 @@ export default [ ];", "configFilename": "eslint.config.js", "devDependencies": [ + "eslint@9.x", "globals", "@eslint/js", - "eslint", + ], + "installFlags": [ + "-D", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problems-esm-none-typescript b/tests/__snapshots__/problems-esm-none-typescript index a3c753e5..7102cd7c 100644 --- a/tests/__snapshots__/problems-esm-none-typescript +++ b/tests/__snapshots__/problems-esm-none-typescript @@ -11,9 +11,12 @@ export default [ ];", "configFilename": "eslint.config.js", "devDependencies": [ + "eslint@9.x", "globals", "@eslint/js", "typescript-eslint", - "eslint", + ], + "installFlags": [ + "-D", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problems-esm-react-javascript b/tests/__snapshots__/problems-esm-react-eslint8.x-javascript similarity index 78% rename from tests/__snapshots__/problems-esm-react-javascript rename to tests/__snapshots__/problems-esm-react-eslint8.x-javascript index c844a1c5..c7dde98a 100644 --- a/tests/__snapshots__/problems-esm-react-javascript +++ b/tests/__snapshots__/problems-esm-react-eslint8.x-javascript @@ -5,15 +5,18 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [ - {languageOptions: { globals: {...globals.browser, ...globals.node} }}, + {languageOptions: { globals: globals.browser }}, pluginJs.configs.recommended, pluginReactConfig, ];", "configFilename": "eslint.config.js", "devDependencies": [ + "eslint@8.x", "globals", "@eslint/js", "eslint-plugin-react", - "eslint", + ], + "installFlags": [ + "-D", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problems-esm-react-typescript b/tests/__snapshots__/problems-esm-react-eslint8.x-typescript similarity index 81% rename from tests/__snapshots__/problems-esm-react-typescript rename to tests/__snapshots__/problems-esm-react-eslint8.x-typescript index 88981939..2d850447 100644 --- a/tests/__snapshots__/problems-esm-react-typescript +++ b/tests/__snapshots__/problems-esm-react-eslint8.x-typescript @@ -6,17 +6,20 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [ - {languageOptions: { globals: {...globals.browser, ...globals.node} }}, + {languageOptions: { globals: globals.browser }}, pluginJs.configs.recommended, ...tseslint.configs.recommended, pluginReactConfig, ];", "configFilename": "eslint.config.js", "devDependencies": [ + "eslint@8.x", "globals", "@eslint/js", "typescript-eslint", "eslint-plugin-react", - "eslint", + ], + "installFlags": [ + "-D", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problems-commonjs-react-javascript b/tests/__snapshots__/problems-esm-react-eslint9.x-javascript similarity index 59% rename from tests/__snapshots__/problems-commonjs-react-javascript rename to tests/__snapshots__/problems-esm-react-eslint9.x-javascript index ab27fb8f..efcf1803 100644 --- a/tests/__snapshots__/problems-commonjs-react-javascript +++ b/tests/__snapshots__/problems-esm-react-eslint9.x-javascript @@ -2,19 +2,24 @@ "configContent": "import globals from "globals"; import pluginJs from "@eslint/js"; import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; +import { fixupConfigRules } from "@eslint/compat"; export default [ - {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, - {languageOptions: { globals: {...globals.browser, ...globals.node} }}, + {languageOptions: { globals: globals.browser }}, pluginJs.configs.recommended, - pluginReactConfig, + ...fixupConfigRules(pluginReactConfig), ];", "configFilename": "eslint.config.js", "devDependencies": [ + "eslint@9.x", "globals", "@eslint/js", "eslint-plugin-react", - "eslint", + "@eslint/compat", + ], + "installFlags": [ + "-D", + "--force", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problems-script-react-typescript b/tests/__snapshots__/problems-esm-react-eslint9.x-typescript similarity index 65% rename from tests/__snapshots__/problems-script-react-typescript rename to tests/__snapshots__/problems-esm-react-eslint9.x-typescript index 2f744bf1..1a3caf6e 100644 --- a/tests/__snapshots__/problems-script-react-typescript +++ b/tests/__snapshots__/problems-esm-react-eslint9.x-typescript @@ -3,21 +3,26 @@ import pluginJs from "@eslint/js"; import tseslint from "typescript-eslint"; import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; +import { fixupConfigRules } from "@eslint/compat"; export default [ - {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, - {languageOptions: { globals: {...globals.browser, ...globals.node} }}, + {languageOptions: { globals: globals.browser }}, pluginJs.configs.recommended, ...tseslint.configs.recommended, - pluginReactConfig, + ...fixupConfigRules(pluginReactConfig), ];", "configFilename": "eslint.config.js", "devDependencies": [ + "eslint@9.x", "globals", "@eslint/js", "typescript-eslint", "eslint-plugin-react", - "eslint", + "@eslint/compat", + ], + "installFlags": [ + "-D", + "--force", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problems-esm-vue-javascript b/tests/__snapshots__/problems-esm-vue-javascript index 0555cc32..127e9de2 100644 --- a/tests/__snapshots__/problems-esm-vue-javascript +++ b/tests/__snapshots__/problems-esm-vue-javascript @@ -11,9 +11,12 @@ export default [ ];", "configFilename": "eslint.config.js", "devDependencies": [ + "eslint@9.x", "globals", "@eslint/js", "eslint-plugin-vue", - "eslint", + ], + "installFlags": [ + "-D", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problems-esm-vue-typescript b/tests/__snapshots__/problems-esm-vue-typescript index 3632511c..e8d0db42 100644 --- a/tests/__snapshots__/problems-esm-vue-typescript +++ b/tests/__snapshots__/problems-esm-vue-typescript @@ -13,10 +13,13 @@ export default [ ];", "configFilename": "eslint.config.js", "devDependencies": [ + "eslint@9.x", "globals", "@eslint/js", "typescript-eslint", "eslint-plugin-vue", - "eslint", + ], + "installFlags": [ + "-D", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problems-script-none-javascript b/tests/__snapshots__/problems-script-none-javascript index cd756b1f..85142146 100644 --- a/tests/__snapshots__/problems-script-none-javascript +++ b/tests/__snapshots__/problems-script-none-javascript @@ -10,8 +10,11 @@ export default [ ];", "configFilename": "eslint.config.js", "devDependencies": [ + "eslint@9.x", "globals", "@eslint/js", - "eslint", + ], + "installFlags": [ + "-D", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problems-script-none-typescript b/tests/__snapshots__/problems-script-none-typescript index a50b00fd..491f4eee 100644 --- a/tests/__snapshots__/problems-script-none-typescript +++ b/tests/__snapshots__/problems-script-none-typescript @@ -12,9 +12,12 @@ export default [ ];", "configFilename": "eslint.config.js", "devDependencies": [ + "eslint@9.x", "globals", "@eslint/js", "typescript-eslint", - "eslint", + ], + "installFlags": [ + "-D", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problems-script-react-javascript b/tests/__snapshots__/problems-script-react-javascript deleted file mode 100644 index b3001f7b..00000000 --- a/tests/__snapshots__/problems-script-react-javascript +++ /dev/null @@ -1,20 +0,0 @@ -{ - "configContent": "import globals from "globals"; -import pluginJs from "@eslint/js"; -import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; - - -export default [ - {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, - {languageOptions: { globals: {...globals.browser, ...globals.node} }}, - pluginJs.configs.recommended, - pluginReactConfig, -];", - "configFilename": "eslint.config.js", - "devDependencies": [ - "globals", - "@eslint/js", - "eslint-plugin-react", - "eslint", - ], -} \ No newline at end of file diff --git a/tests/__snapshots__/problems-script-vue-javascript b/tests/__snapshots__/problems-script-vue-javascript index 42f07b1b..ae430a21 100644 --- a/tests/__snapshots__/problems-script-vue-javascript +++ b/tests/__snapshots__/problems-script-vue-javascript @@ -12,9 +12,12 @@ export default [ ];", "configFilename": "eslint.config.js", "devDependencies": [ + "eslint@9.x", "globals", "@eslint/js", "eslint-plugin-vue", - "eslint", + ], + "installFlags": [ + "-D", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problems-script-vue-typescript b/tests/__snapshots__/problems-script-vue-typescript index 4a91e350..84370fa8 100644 --- a/tests/__snapshots__/problems-script-vue-typescript +++ b/tests/__snapshots__/problems-script-vue-typescript @@ -14,10 +14,13 @@ export default [ ];", "configFilename": "eslint.config.js", "devDependencies": [ + "eslint@9.x", "globals", "@eslint/js", "typescript-eslint", "eslint-plugin-vue", - "eslint", + ], + "installFlags": [ + "-D", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-commonjs-none-javascript b/tests/__snapshots__/syntax-commonjs-none-javascript index 6035d03a..3b801ad3 100644 --- a/tests/__snapshots__/syntax-commonjs-none-javascript +++ b/tests/__snapshots__/syntax-commonjs-none-javascript @@ -8,7 +8,10 @@ export default [ ];", "configFilename": "eslint.config.js", "devDependencies": [ + "eslint@9.x", "globals", - "eslint", + ], + "installFlags": [ + "-D", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-commonjs-none-typescript b/tests/__snapshots__/syntax-commonjs-none-typescript index 2afed03a..5c0f3a3f 100644 --- a/tests/__snapshots__/syntax-commonjs-none-typescript +++ b/tests/__snapshots__/syntax-commonjs-none-typescript @@ -10,8 +10,11 @@ export default [ ];", "configFilename": "eslint.config.js", "devDependencies": [ + "eslint@9.x", "globals", "typescript-eslint", - "eslint", + ], + "installFlags": [ + "-D", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-commonjs-react-typescript b/tests/__snapshots__/syntax-commonjs-react-typescript deleted file mode 100644 index 05dcabe1..00000000 --- a/tests/__snapshots__/syntax-commonjs-react-typescript +++ /dev/null @@ -1,20 +0,0 @@ -{ - "configContent": "import globals from "globals"; -import tseslint from "typescript-eslint"; -import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; - - -export default [ - {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, - {languageOptions: { globals: {...globals.browser, ...globals.node} }}, - ...tseslint.configs.recommended, - pluginReactConfig, -];", - "configFilename": "eslint.config.js", - "devDependencies": [ - "globals", - "typescript-eslint", - "eslint-plugin-react", - "eslint", - ], -} \ No newline at end of file diff --git a/tests/__snapshots__/syntax-commonjs-vue-javascript b/tests/__snapshots__/syntax-commonjs-vue-javascript index a66b850a..18c441d8 100644 --- a/tests/__snapshots__/syntax-commonjs-vue-javascript +++ b/tests/__snapshots__/syntax-commonjs-vue-javascript @@ -10,8 +10,11 @@ export default [ ];", "configFilename": "eslint.config.js", "devDependencies": [ + "eslint@9.x", "globals", "eslint-plugin-vue", - "eslint", + ], + "installFlags": [ + "-D", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-commonjs-vue-typescript b/tests/__snapshots__/syntax-commonjs-vue-typescript index 9222bc70..ad65bf00 100644 --- a/tests/__snapshots__/syntax-commonjs-vue-typescript +++ b/tests/__snapshots__/syntax-commonjs-vue-typescript @@ -12,9 +12,12 @@ export default [ ];", "configFilename": "eslint.config.js", "devDependencies": [ + "eslint@9.x", "globals", "typescript-eslint", "eslint-plugin-vue", - "eslint", + ], + "installFlags": [ + "-D", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-esm-none-javascript b/tests/__snapshots__/syntax-esm-none-javascript index 1e9a0e1f..ee6bfbed 100644 --- a/tests/__snapshots__/syntax-esm-none-javascript +++ b/tests/__snapshots__/syntax-esm-none-javascript @@ -7,7 +7,10 @@ export default [ ];", "configFilename": "eslint.config.js", "devDependencies": [ + "eslint@9.x", "globals", - "eslint", + ], + "installFlags": [ + "-D", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-esm-none-typescript b/tests/__snapshots__/syntax-esm-none-typescript index 3dc297b9..eacf9612 100644 --- a/tests/__snapshots__/syntax-esm-none-typescript +++ b/tests/__snapshots__/syntax-esm-none-typescript @@ -9,8 +9,11 @@ export default [ ];", "configFilename": "eslint.config.js", "devDependencies": [ + "eslint@9.x", "globals", "typescript-eslint", - "eslint", + ], + "installFlags": [ + "-D", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-esm-react-javascript b/tests/__snapshots__/syntax-esm-react-eslint8.x-javascript similarity index 73% rename from tests/__snapshots__/syntax-esm-react-javascript rename to tests/__snapshots__/syntax-esm-react-eslint8.x-javascript index d5b5aa43..558a41e0 100644 --- a/tests/__snapshots__/syntax-esm-react-javascript +++ b/tests/__snapshots__/syntax-esm-react-eslint8.x-javascript @@ -4,13 +4,16 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [ - {languageOptions: { globals: {...globals.browser, ...globals.node} }}, + {languageOptions: { globals: globals.browser }}, pluginReactConfig, ];", "configFilename": "eslint.config.js", "devDependencies": [ + "eslint@8.x", "globals", "eslint-plugin-react", - "eslint", + ], + "installFlags": [ + "-D", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-esm-react-typescript b/tests/__snapshots__/syntax-esm-react-eslint8.x-typescript similarity index 78% rename from tests/__snapshots__/syntax-esm-react-typescript rename to tests/__snapshots__/syntax-esm-react-eslint8.x-typescript index 04bdc76e..3d1bead6 100644 --- a/tests/__snapshots__/syntax-esm-react-typescript +++ b/tests/__snapshots__/syntax-esm-react-eslint8.x-typescript @@ -5,15 +5,18 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [ - {languageOptions: { globals: {...globals.browser, ...globals.node} }}, + {languageOptions: { globals: globals.browser }}, ...tseslint.configs.recommended, pluginReactConfig, ];", "configFilename": "eslint.config.js", "devDependencies": [ + "eslint@8.x", "globals", "typescript-eslint", "eslint-plugin-react", - "eslint", + ], + "installFlags": [ + "-D", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-commonjs-react-javascript b/tests/__snapshots__/syntax-esm-react-eslint9.x-javascript similarity index 53% rename from tests/__snapshots__/syntax-commonjs-react-javascript rename to tests/__snapshots__/syntax-esm-react-eslint9.x-javascript index 724bca5e..30938718 100644 --- a/tests/__snapshots__/syntax-commonjs-react-javascript +++ b/tests/__snapshots__/syntax-esm-react-eslint9.x-javascript @@ -1,17 +1,22 @@ { "configContent": "import globals from "globals"; import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; +import { fixupConfigRules } from "@eslint/compat"; export default [ - {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, - {languageOptions: { globals: {...globals.browser, ...globals.node} }}, - pluginReactConfig, + {languageOptions: { globals: globals.browser }}, + ...fixupConfigRules(pluginReactConfig), ];", "configFilename": "eslint.config.js", "devDependencies": [ + "eslint@9.x", "globals", "eslint-plugin-react", - "eslint", + "@eslint/compat", + ], + "installFlags": [ + "-D", + "--force", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-script-react-typescript b/tests/__snapshots__/syntax-esm-react-eslint9.x-typescript similarity index 61% rename from tests/__snapshots__/syntax-script-react-typescript rename to tests/__snapshots__/syntax-esm-react-eslint9.x-typescript index 1ae72f2d..a5fb880f 100644 --- a/tests/__snapshots__/syntax-script-react-typescript +++ b/tests/__snapshots__/syntax-esm-react-eslint9.x-typescript @@ -2,19 +2,24 @@ "configContent": "import globals from "globals"; import tseslint from "typescript-eslint"; import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; +import { fixupConfigRules } from "@eslint/compat"; export default [ - {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, - {languageOptions: { globals: {...globals.browser, ...globals.node} }}, + {languageOptions: { globals: globals.browser }}, ...tseslint.configs.recommended, - pluginReactConfig, + ...fixupConfigRules(pluginReactConfig), ];", "configFilename": "eslint.config.js", "devDependencies": [ + "eslint@9.x", "globals", "typescript-eslint", "eslint-plugin-react", - "eslint", + "@eslint/compat", + ], + "installFlags": [ + "-D", + "--force", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-esm-vue-javascript b/tests/__snapshots__/syntax-esm-vue-javascript index 00a8b838..ea7c0572 100644 --- a/tests/__snapshots__/syntax-esm-vue-javascript +++ b/tests/__snapshots__/syntax-esm-vue-javascript @@ -9,8 +9,11 @@ export default [ ];", "configFilename": "eslint.config.js", "devDependencies": [ + "eslint@9.x", "globals", "eslint-plugin-vue", - "eslint", + ], + "installFlags": [ + "-D", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-esm-vue-typescript b/tests/__snapshots__/syntax-esm-vue-typescript index 4fc0ce53..aa4e7fa5 100644 --- a/tests/__snapshots__/syntax-esm-vue-typescript +++ b/tests/__snapshots__/syntax-esm-vue-typescript @@ -11,9 +11,12 @@ export default [ ];", "configFilename": "eslint.config.js", "devDependencies": [ + "eslint@9.x", "globals", "typescript-eslint", "eslint-plugin-vue", - "eslint", + ], + "installFlags": [ + "-D", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-script-none-javascript b/tests/__snapshots__/syntax-script-none-javascript index 5fd05d01..8ed5c0cb 100644 --- a/tests/__snapshots__/syntax-script-none-javascript +++ b/tests/__snapshots__/syntax-script-none-javascript @@ -8,7 +8,10 @@ export default [ ];", "configFilename": "eslint.config.js", "devDependencies": [ + "eslint@9.x", "globals", - "eslint", + ], + "installFlags": [ + "-D", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-script-none-typescript b/tests/__snapshots__/syntax-script-none-typescript index 57c5d79b..a71843e7 100644 --- a/tests/__snapshots__/syntax-script-none-typescript +++ b/tests/__snapshots__/syntax-script-none-typescript @@ -10,8 +10,11 @@ export default [ ];", "configFilename": "eslint.config.js", "devDependencies": [ + "eslint@9.x", "globals", "typescript-eslint", - "eslint", + ], + "installFlags": [ + "-D", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-script-react-javascript b/tests/__snapshots__/syntax-script-react-javascript deleted file mode 100644 index 32b99533..00000000 --- a/tests/__snapshots__/syntax-script-react-javascript +++ /dev/null @@ -1,17 +0,0 @@ -{ - "configContent": "import globals from "globals"; -import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; - - -export default [ - {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, - {languageOptions: { globals: {...globals.browser, ...globals.node} }}, - pluginReactConfig, -];", - "configFilename": "eslint.config.js", - "devDependencies": [ - "globals", - "eslint-plugin-react", - "eslint", - ], -} \ No newline at end of file diff --git a/tests/__snapshots__/syntax-script-vue-javascript b/tests/__snapshots__/syntax-script-vue-javascript index e3502544..dcdb5f00 100644 --- a/tests/__snapshots__/syntax-script-vue-javascript +++ b/tests/__snapshots__/syntax-script-vue-javascript @@ -10,8 +10,11 @@ export default [ ];", "configFilename": "eslint.config.js", "devDependencies": [ + "eslint@9.x", "globals", "eslint-plugin-vue", - "eslint", + ], + "installFlags": [ + "-D", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-script-vue-typescript b/tests/__snapshots__/syntax-script-vue-typescript index 39b2f1eb..8518ee2c 100644 --- a/tests/__snapshots__/syntax-script-vue-typescript +++ b/tests/__snapshots__/syntax-script-vue-typescript @@ -12,9 +12,12 @@ export default [ ];", "configFilename": "eslint.config.js", "devDependencies": [ + "eslint@9.x", "globals", "typescript-eslint", "eslint-plugin-vue", - "eslint", + ], + "installFlags": [ + "-D", ], } \ No newline at end of file diff --git a/tests/config-snapshots.spec.js b/tests/config-snapshots.spec.js index 21507b9c..4ad5f440 100644 --- a/tests/config-snapshots.spec.js +++ b/tests/config-snapshots.spec.js @@ -18,12 +18,21 @@ describe("generate config for esm projects", () => { const choices = { purpose: ["syntax", "problems"], moduleType: ["esm", "commonjs", "script"], - framework: ["react", "vue", "none"], + framework: ["vue", "none"], language: ["javascript", "typescript"], env: ["browser", "node"] }; - const inputs = []; + const inputs = [ + { name: "syntax-esm-react-eslint8.x-javascript", answers: { purpose: "syntax", moduleType: "esm", framework: "react", eslintVersion: "8.x", language: "javascript", env: ["browser"] } }, + { name: "syntax-esm-react-eslint8.x-typescript", answers: { purpose: "syntax", moduleType: "esm", framework: "react", eslintVersion: "8.x", language: "typescript", env: ["browser"] } }, + { name: "syntax-esm-react-eslint9.x-javascript", answers: { purpose: "syntax", moduleType: "esm", framework: "react", eslintVersion: "9.x", language: "javascript", env: ["browser"] } }, + { name: "syntax-esm-react-eslint9.x-typescript", answers: { purpose: "syntax", moduleType: "esm", framework: "react", eslintVersion: "9.x", language: "typescript", env: ["browser"] } }, + { name: "problems-esm-react-eslint8.x-javascript", answers: { purpose: "problems", moduleType: "esm", framework: "react", eslintVersion: "8.x", language: "javascript", env: ["browser"] } }, + { name: "problems-esm-react-eslint8.x-typescript", answers: { purpose: "problems", moduleType: "esm", framework: "react", eslintVersion: "8.x", language: "typescript", env: ["browser"] } }, + { name: "problems-esm-react-eslint9.x-javascript", answers: { purpose: "problems", moduleType: "esm", framework: "react", eslintVersion: "9.x", language: "javascript", env: ["browser"] } }, + { name: "problems-esm-react-eslint9.x-typescript", answers: { purpose: "problems", moduleType: "esm", framework: "react", eslintVersion: "9.x", language: "typescript", env: ["browser"] } } + ]; // generate all possible combinations for (let i = 0; i < choices.purpose.length; i++) {