From cc4d8a6951c5432fbe16e4565dd2aa6c65cc123f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Wed, 10 Jan 2024 14:41:45 +0800 Subject: [PATCH 01/41] feat!: support flat config --- .editorconfig | 8 + README.md | 15 +- bin/create-config.js | 30 +- eslint.config.js | 11 +- lib/config-generator.js | 253 +++++++ lib/init/config-file.js | 134 ---- lib/init/config-initializer.js | 631 ------------------ lib/{shared => utils}/logging.js | 0 lib/{init => utils}/npm-utils.js | 34 +- package.json | 20 +- .../problem-commonjs-none-javascript | 16 + .../problem-commonjs-none-typescript | 19 + .../problem-commonjs-react-javascript | 19 + .../problem-commonjs-react-typescript | 22 + .../problem-commonjs-vue-javascript | 22 + .../problem-commonjs-vue-typescript | 25 + .../__snapshots__/problem-esm-none-javascript | 16 + .../__snapshots__/problem-esm-none-typescript | 19 + .../problem-esm-react-javascript | 19 + .../problem-esm-react-typescript | 22 + .../__snapshots__/problem-esm-vue-javascript | 22 + .../__snapshots__/problem-esm-vue-typescript | 25 + .../problem-script-none-javascript | 16 + .../problem-script-none-typescript | 19 + .../problem-script-react-javascript | 19 + .../problem-script-react-typescript | 22 + .../problem-script-vue-javascript | 22 + .../problem-script-vue-typescript | 25 + .../style-esm-none-xo-javascript | 17 + .../style-esm-none-xo-typescript | 20 + .../syntax-commonjs-none-javascript | 13 + .../syntax-commonjs-none-typescript | 16 + .../syntax-commonjs-react-javascript | 16 + .../syntax-commonjs-react-typescript | 19 + .../syntax-commonjs-vue-javascript | 19 + .../syntax-commonjs-vue-typescript | 22 + .../__snapshots__/syntax-esm-none-javascript | 13 + .../__snapshots__/syntax-esm-none-typescript | 16 + .../__snapshots__/syntax-esm-react-javascript | 16 + .../__snapshots__/syntax-esm-react-typescript | 19 + tests/__snapshots__/syntax-esm-vue-javascript | 19 + tests/__snapshots__/syntax-esm-vue-typescript | 22 + .../syntax-script-none-javascript | 13 + .../syntax-script-none-typescript | 16 + .../syntax-script-react-javascript | 16 + .../syntax-script-react-typescript | 19 + .../syntax-script-vue-javascript | 19 + .../syntax-script-vue-typescript | 22 + tests/config-snapshots.spec.js | 95 +++ tests/fixtures/cjs-project/package.json | 6 + tests/fixtures/esm-project/package.json | 6 + tests/init/config-file.js | 145 ---- tests/init/config-initializer.js | 544 --------------- .../npm-utils.js => utils/npm-utils.spec.js} | 29 +- 54 files changed, 1167 insertions(+), 1515 deletions(-) create mode 100644 .editorconfig mode change 100644 => 100755 bin/create-config.js create mode 100644 lib/config-generator.js delete mode 100644 lib/init/config-file.js delete mode 100644 lib/init/config-initializer.js rename lib/{shared => utils}/logging.js (100%) rename lib/{init => utils}/npm-utils.js (87%) create mode 100644 tests/__snapshots__/problem-commonjs-none-javascript create mode 100644 tests/__snapshots__/problem-commonjs-none-typescript create mode 100644 tests/__snapshots__/problem-commonjs-react-javascript create mode 100644 tests/__snapshots__/problem-commonjs-react-typescript create mode 100644 tests/__snapshots__/problem-commonjs-vue-javascript create mode 100644 tests/__snapshots__/problem-commonjs-vue-typescript create mode 100644 tests/__snapshots__/problem-esm-none-javascript create mode 100644 tests/__snapshots__/problem-esm-none-typescript create mode 100644 tests/__snapshots__/problem-esm-react-javascript create mode 100644 tests/__snapshots__/problem-esm-react-typescript create mode 100644 tests/__snapshots__/problem-esm-vue-javascript create mode 100644 tests/__snapshots__/problem-esm-vue-typescript create mode 100644 tests/__snapshots__/problem-script-none-javascript create mode 100644 tests/__snapshots__/problem-script-none-typescript create mode 100644 tests/__snapshots__/problem-script-react-javascript create mode 100644 tests/__snapshots__/problem-script-react-typescript create mode 100644 tests/__snapshots__/problem-script-vue-javascript create mode 100644 tests/__snapshots__/problem-script-vue-typescript create mode 100644 tests/__snapshots__/style-esm-none-xo-javascript create mode 100644 tests/__snapshots__/style-esm-none-xo-typescript create mode 100644 tests/__snapshots__/syntax-commonjs-none-javascript create mode 100644 tests/__snapshots__/syntax-commonjs-none-typescript create mode 100644 tests/__snapshots__/syntax-commonjs-react-javascript create mode 100644 tests/__snapshots__/syntax-commonjs-react-typescript create mode 100644 tests/__snapshots__/syntax-commonjs-vue-javascript create mode 100644 tests/__snapshots__/syntax-commonjs-vue-typescript create mode 100644 tests/__snapshots__/syntax-esm-none-javascript create mode 100644 tests/__snapshots__/syntax-esm-none-typescript create mode 100644 tests/__snapshots__/syntax-esm-react-javascript create mode 100644 tests/__snapshots__/syntax-esm-react-typescript create mode 100644 tests/__snapshots__/syntax-esm-vue-javascript create mode 100644 tests/__snapshots__/syntax-esm-vue-typescript create mode 100644 tests/__snapshots__/syntax-script-none-javascript create mode 100644 tests/__snapshots__/syntax-script-none-typescript create mode 100644 tests/__snapshots__/syntax-script-react-javascript create mode 100644 tests/__snapshots__/syntax-script-react-typescript create mode 100644 tests/__snapshots__/syntax-script-vue-javascript create mode 100644 tests/__snapshots__/syntax-script-vue-typescript create mode 100644 tests/config-snapshots.spec.js create mode 100644 tests/fixtures/cjs-project/package.json create mode 100644 tests/fixtures/esm-project/package.json delete mode 100644 tests/init/config-file.js delete mode 100644 tests/init/config-initializer.js rename tests/{init/npm-utils.js => utils/npm-utils.spec.js} (93%) diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..2e62126f --- /dev/null +++ b/.editorconfig @@ -0,0 +1,8 @@ +root = true + +[*] +indent_style = space +indent_size = 4 +trim_trailing_whitespace = true +end_of_line = lf +insert_final_newline = true diff --git a/README.md b/README.md index 9e2e1dd0..7da4059b 100644 --- a/README.md +++ b/README.md @@ -21,22 +21,17 @@ npx @eslint/create-config If you want to use a specific shareable config that is hosted on npm, you can use the `--config` option and specify the package name: ```bash -# use `eslint-config-semistandard` shared config +# use `eslint-config-standard` shared config # npm 7+ -npm init @eslint/config -- --config semistandard - -# or (`eslint-config` prefix is optional) -npm init @eslint/config -- --config eslint-config-semistandard +npm init @eslint/config -- --config eslint-config-standard # ⚠️ npm 6.x no extra double-dash: -npm init @eslint/config --config semistandard +npm init @eslint/config --config eslint-config-standard ``` -The `--config` flag also supports passing in arrays: +To use an eslintrc-style shared config: ```bash -npm init @eslint/config -- --config semistandard,standard -# or -npm init @eslint/config -- --config semistandard --config standard +npm init @eslint/config -- --eslintrc --config eslint-config-standard ``` diff --git a/bin/create-config.js b/bin/create-config.js old mode 100644 new mode 100755 index 66ff533b..0e646316 --- a/bin/create-config.js +++ b/bin/create-config.js @@ -1,10 +1,30 @@ #!/usr/bin/env node /** - * @fileoverview Main CLI that is run via the eslint command. - * @author Nicholas C. Zakas + * @fileoverview Main CLI that is run via the `npm init @eslint/config` command. + * @author 唯然 */ -/* eslint no-console:off -- CLI */ -import { initializeConfig } from "../lib/init/config-initializer.js"; -initializeConfig(); +import { ConfigGenerator } from "../lib/config-generator.js"; +import process from "process"; +const argv = process.argv; + +const sharedConfigIndex = process.argv.indexOf("--config"); + +if (sharedConfigIndex === -1) { + const generator = new ConfigGenerator(); + + await generator.prompt(); + generator.calc(); + await generator.output(); +} else { + + // passed "--config" + const packageName = argv[sharedConfigIndex + 1]; + const type = argv.includes("--eslintrc") ? "eslintrc" : "flat"; + const answers = { purpose: "style", moduleType: "module", styleguide: { packageName, type } }; + const generator = new ConfigGenerator({ answers }); + + generator.calc(); + await generator.output(); +} diff --git a/eslint.config.js b/eslint.config.js index a8293635..b1544b43 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -1,5 +1,4 @@ import eslintConfigESLint from "eslint-config-eslint"; -import globals from "globals"; export default [ { @@ -8,13 +7,5 @@ export default [ "tests/fixtures/" ] }, - ...eslintConfigESLint, - { - files: ["tests/**"], - languageOptions: { - globals: { - ...globals.mocha - } - } - } + ...eslintConfigESLint ]; diff --git a/lib/config-generator.js b/lib/config-generator.js new file mode 100644 index 00000000..4e7b43e8 --- /dev/null +++ b/lib/config-generator.js @@ -0,0 +1,253 @@ +/** + * @fileoverview to generate config files. + * @author 唯然 + */ +import process from "process"; +import path from "path"; +import { spawnSync } from "child_process"; +import { writeFile } from "fs/promises"; +import enquirer from "enquirer"; +import { isPackageTypeModule, installSyncSaveDev, checkPackageJson, fetchPeerDependencies } from "./utils/npm-utils.js"; +import * as log from "./utils/logging.js"; + +/** + * Class representing a ConfigGenerator. + */ +export class ConfigGenerator { + + /** + * Create a ConfigGenerator. + * @param {Object} options The options for the ConfigGenerator. + * @param {string} options.cwd The current working directory. + * @param {Object} options.answers The answers provided by the user. + * @returns {ConfigGenerator} The ConfigGenerator instance. + */ + constructor(options = {}) { + this.cwd = options.cwd || process.cwd(); + this.answers = options.answers || {}; + this.result = { + devDependencies: ["eslint"], + configFilename: "eslint.config.js", + configContent: "" + }; + + const packageJsonExists = checkPackageJson(this.cwd); + + if (!packageJsonExists) { + throw new Error("A package.json file is necessary to initialize ESLint. Run `npm init` to create a package.json file and try again."); + } + } + + /** + * Prompt the user for input. + * @returns {void} + */ + async prompt() { + const questions = [ + { + type: "select", + name: "purpose", + message: "How would you like to use ESLint?", + initial: 1, + choices: [ + { message: "To check syntax only", name: "syntax" }, + { message: "To check syntax and find problems", name: "problems" }, + { message: "To check syntax, find problems, and enforce code style", name: "style" } + ] + }, + { + type: "select", + name: "moduleType", + message: "What type of modules does your project use?", + initial: 0, + choices: [ + { message: "JavaScript modules (import/export)", name: "esm" }, + { message: "CommonJS (require/exports)", name: "commonjs" }, + { message: "None of these", name: "none" } + ] + }, + { + type: "select", + name: "framework", + message: "Which framework does your project use?", + initial: 0, + choices: [ + { message: "React", name: "react" }, + { message: "Vue.js", name: "vue" }, + { message: "None of these", name: "none" } + ] + }, + { + type: "select", + name: "language", + message: "Does your project use TypeScript?", + choices: [ + { message: "No", name: "javascript" }, + { message: "Yes", name: "typescript" } + ], + initial: 0 + }, + { + type: "multiselect", + name: "env", + message: "Where does your code run?", + hint: "(Press to select, to toggle all, to invert selection)", + initial: 0, + choices: [ + { message: "Browser", name: "browser" }, + { message: "Node", name: "node" } + ] + } + ]; + + const answers = await enquirer.prompt(questions); + + Object.assign(this.answers, answers); + + if (answers.purpose === "style") { + + // TODO: need to specify the package version - they may export flat configs in the future. + const jsStyleGuides = [ + { message: "Airbnb: https://github.com/airbnb/javascript", name: "airbnb", value: { packageName: "eslint-config-airbnb", type: "eslintrc" } }, + { message: "Standard: https://github.com/standard/standard", name: "standard", value: { packageName: "eslint-config-standard", type: "eslintrc" } }, + { message: "XO: https://github.com/xojs/eslint-config-xo", name: "xo", value: { packageName: "eslint-config-xo", type: "eslintrc" } } + ]; + const tsStyleGuides = [ + { message: "Standard: https://github.com/standard/eslint-config-standard-with-typescript", name: "standard", value: { packageName: "eslint-config-standard-with-typescript", type: "eslintrc" } }, + { message: "XO: https://github.com/xojs/eslint-config-xo-typescript", name: "xo", value: { packageName: ["eslint-config-xo", "eslint-config-xo-typescript"], type: "eslintrc" } } + ]; + const choices = this.answers.language === "javascript" ? jsStyleGuides : tsStyleGuides; + const styleguideAnswer = await enquirer.prompt({ + type: "select", + name: "styleguide", + message: "Which style guide do you want to follow?", + choices, + result: choice => choices.find(it => it.name === choice).value + }); + + Object.assign(this.answers, styleguideAnswer); + } + } + + /** + * Calculate the configuration based on the user's answers. + * @returns {void} + */ + calc() { + const isModule = isPackageTypeModule(this.cwd); + + this.result.configFilename = isModule ? "eslint.config.js" : "eslint.config.mjs"; + + let importContent = ""; + let helperContent = ""; + let exportContent = ""; + let languageOptionsContent = ""; + + if (this.answers.purpose === "syntax") { + + // no need to install any plugin + } else if (this.answers.purpose === "problem") { + this.result.devDependencies.push("@eslint/js"); + importContent += "import pluginJs from \"@eslint/js\";\n"; + exportContent += " pluginJs.configs.recommended,\n"; + } else if (this.answers.purpose === "style") { + this.result.devDependencies.push(this.answers.styleguide.packageName, "@eslint/js"); + + // install peer dependencies - it's needed for most eslintrc-style shared configs. + const peers = fetchPeerDependencies(this.answers.styleguide.packageName); + + if (peers !== null) { + this.result.devDependencies.push(...peers); + } + + if (this.answers.styleguide.type === "flat" || this.answers.styleguide.type === void 0) { + importContent += `import styleGuide from "${this.answers.styleguide.packageName}";\n`; + exportContent += " styleGuide,\n"; + } else if (this.answers.styleguide.type === "eslintrc") { + + importContent += "import pluginJs from \"@eslint/js\";\n"; + importContent += "import path from \"path\";\nimport { fileURLToPath } from \"url\"\n;import { FlatCompat } from \"@eslint/eslintrc\";\n"; + helperContent ||= "// mimic CommonJS variables -- not needed if using CommonJS\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\nconst compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended});\n"; + + const extended = Array.isArray(this.answers.styleguide.packageName) + ? this.answers.styleguide.packageName + : [this.answers.styleguide.packageName]; + const extendedNames = extended.map(it => it.replace("eslint-config-", "")); + + exportContent += ` compat.extends("${extendedNames.join(", ")}"),\n`; + } + } + + if (this.answers.module === "commonjs") { + languageOptionsContent += "sourceType: \"commonjs\", "; + } + if (this.answers.env?.length > 0) { + this.result.devDependencies.push("globals"); + importContent += "import globals from \"globals\";\n"; + const envContent = { + browser: "globals: globals.browser", + node: "globals: globals.node", + "browser,node": "globals: {...globals.browser, ...globals.node}" + }; + + languageOptionsContent += `${envContent[this.answers.env.join(",")]}, `; + } + + + if (this.answers.language === "typescript") { + this.result.devDependencies.push("typescript-eslint"); + importContent += "import tseslint from \"typescript-eslint\";\n"; + exportContent += " tseslint.configs.recommended,\n"; + } + + if (this.answers.framework === "vue") { + + this.result.devDependencies.push("eslint-plugin-vue"); + + // importContent += "import pluginVue from \"eslint-plugin-vue\";\n"; + + // // TODO: there is a wip for flat support - https://github.com/vuejs/eslint-plugin-vue/pull/2319 + // exportContent += " pluginVue.configs[\"flat/essential\"],\n"; + + helperContent ||= "// mimic CommonJS variables -- not needed if using CommonJS\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\nconst compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended});\n"; + exportContent += " compat.extends(\"plugin:vue/vue3-essential\").map(config => ({files: [\"**/*.vue\"], ...config})),\n"; + } + + 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"; + } + + this.result.configContent = `${importContent}\n${helperContent}\nexport default [].concat(\n { languageOptions: {${languageOptionsContent}}},\n${exportContent});`; + } + + /** + * Output the configuration. + * @returns {void} + */ + async output() { + const packageManager = (await enquirer.prompt({ + type: "select", + name: "packageManager", + message: "Which package manager do you want to use?", + initial: 0, + choices: ["npm", "yarn", "pnpm", "bun"] + })).packageManager; + + installSyncSaveDev(this.result.devDependencies, packageManager); + + const configPath = path.join(this.cwd, this.result.configFilename); + + await writeFile(configPath, this.result.configContent); + + // import("eslint") won't work in some cases. + // refs: https://github.com/eslint/create-config/issues/8, https://github.com/eslint/create-config/issues/12 + const eslintBin = path.join(this.cwd, "./node_modules/.bin/eslint"); + const result = spawnSync(eslintBin, ["--fix", "--quiet", configPath], { encoding: "utf8" }); + + if (result.error || result.status !== 0) { + log.error("A config file was generated, but the config file itself may not follow your linting rules."); + } + } +} diff --git a/lib/init/config-file.js b/lib/init/config-file.js deleted file mode 100644 index e8ca0399..00000000 --- a/lib/init/config-file.js +++ /dev/null @@ -1,134 +0,0 @@ -/** - * @fileoverview Helper to locate and load configuration files. - * @author Nicholas C. Zakas - */ - - -//------------------------------------------------------------------------------ -// Requirements -//------------------------------------------------------------------------------ - -import fs from "fs"; -import path from "path"; -import stringify from "json-stable-stringify-without-jsonify"; -import debugEsm from "debug"; -import spawn from "cross-spawn"; -import * as log from "../shared/logging.js"; - -const debug = debugEsm("eslint:config-file"); -const cwd = process.cwd(); - -//------------------------------------------------------------------------------ -// Helpers -//------------------------------------------------------------------------------ - -/** - * Determines sort order for object keys for json-stable-stringify - * - * see: https://github.com/samn/json-stable-stringify#cmp - * @param {Object} a The first comparison object ({key: akey, value: avalue}) - * @param {Object} b The second comparison object ({key: bkey, value: bvalue}) - * @returns {number} 1 or -1, used in stringify cmp method - */ -function sortByKey(a, b) { - return a.key > b.key ? 1 : -1; -} - -//------------------------------------------------------------------------------ -// Private -//------------------------------------------------------------------------------ - -/** - * Writes a configuration file in JSON format. - * @param {Object} config The configuration object to write. - * @param {string} filePath The filename to write to. - * @returns {void} - * @private - */ -function writeJSONConfigFile(config, filePath) { - debug(`Writing JSON config file: ${filePath}`); - - const content = `${stringify(config, { cmp: sortByKey, space: 4 })}\n`; - - fs.writeFileSync(filePath, content, "utf8"); -} - -/** - * Writes a configuration file in YAML format. - * @param {Object} config The configuration object to write. - * @param {string} filePath The filename to write to. - * @returns {void} - * @private - */ -async function writeYAMLConfigFile(config, filePath) { - debug(`Writing YAML config file: ${filePath}`); - - // lazy load YAML to improve performance when not used - const yaml = await import("js-yaml"); - - const content = yaml.dump(config, { sortKeys: true }); - - fs.writeFileSync(filePath, content, "utf8"); -} - -/** - * Writes a configuration file in JavaScript format. - * @param {Object} config The configuration object to write. - * @param {string} filePath The filename to write to. - * @throws {Error} If an error occurs linting the config file contents. - * @returns {void} - * @private - */ -async function writeJSConfigFile(config, filePath) { - debug(`Writing JS config file: ${filePath}`); - - const stringifiedContent = `module.exports = ${stringify(config, { cmp: sortByKey, space: 4 })}\n`; - - fs.writeFileSync(filePath, stringifiedContent, "utf8"); - - // import("eslint") won't work in some cases. - // refs: https://github.com/eslint/create-config/issues/8, https://github.com/eslint/create-config/issues/12 - const eslintBin = path.join(cwd, "./node_modules/.bin/eslint"); - const result = spawn.sync(eslintBin, ["--fix", "--quiet", filePath], { encoding: "utf8" }); - - if (result.error || result.status !== 0) { - log.error("A config file was generated, but the config file itself may not follow your linting rules."); - } -} - -/** - * Writes a configuration file. - * @param {Object} config The configuration object to write. - * @param {string} filePath The filename to write to. - * @returns {void} - * @throws {Error} When an unknown file type is specified. - * @private - */ -async function write(config, filePath) { - switch (path.extname(filePath)) { - case ".js": - case ".cjs": - await writeJSConfigFile(config, filePath); - break; - - case ".json": - writeJSONConfigFile(config, filePath); - break; - - case ".yaml": - case ".yml": - await writeYAMLConfigFile(config, filePath); - break; - - default: - throw new Error("Can't write to unknown file type."); - } -} - -//------------------------------------------------------------------------------ -// Public Interface -//------------------------------------------------------------------------------ - -export { - write -}; diff --git a/lib/init/config-initializer.js b/lib/init/config-initializer.js deleted file mode 100644 index bbf12dbc..00000000 --- a/lib/init/config-initializer.js +++ /dev/null @@ -1,631 +0,0 @@ -/** - * @fileoverview Config initialization wizard. - * @author Ilya Volodin - */ - - -//------------------------------------------------------------------------------ -// Requirements -//------------------------------------------------------------------------------ - -import path from "path"; -import fs from "fs"; -import enquirer from "enquirer"; -import semver from "semver"; -import { Legacy } from "@eslint/eslintrc"; -import { info } from "../shared/logging.js"; -import * as ConfigFile from "./config-file.js"; -import * as npmUtils from "./npm-utils.js"; -import mri from "mri"; - -const { ConfigOps, naming, ModuleResolver } = Legacy; - -//------------------------------------------------------------------------------ -// Private -//------------------------------------------------------------------------------ - -/** - * check if the package.type === "module" - * @returns {boolean} return true if the package.type === "module" - */ -function isPackageTypeModule() { - const pkgJSONPath = npmUtils.findPackageJson(); - - if (pkgJSONPath) { - const pkgJSONContents = JSON.parse(fs.readFileSync(pkgJSONPath, "utf8")); - - if (pkgJSONContents.type === "module") { - return true; - } - } - - return false; -} - -/* istanbul ignore next: hard to test fs function */ -/** - * Create .eslintrc file in the current working directory - * @param {Object} config object that contains user's answers - * @param {string} format The file format to write to. - * @returns {void} - */ -async function writeFile(config, format) { - - // default is .js - let extname = ".js"; - - if (format === "YAML") { - extname = ".yml"; - } else if (format === "JSON") { - extname = ".json"; - } else if (format === "JavaScript") { - if (isPackageTypeModule()) { - extname = ".cjs"; - } - } - - delete config.installedESLint; - - await ConfigFile.write(config, `./.eslintrc${extname}`); - info(`Successfully created .eslintrc${extname} file in ${process.cwd()}`); -} - -/** - * Get the peer dependencies of the given module. - * This adds the gotten value to cache at the first time, then reuses it. - * In a process, this function is called twice, but `npmUtils.fetchPeerDependencies` needs to access network which is relatively slow. - * @param {string} moduleName The module name to get. - * @returns {Object} The peer dependencies of the given module. - * This object is the object of `peerDependencies` field of `package.json`. - * Returns null if npm was not found. - */ -function getPeerDependencies(moduleName) { - let result = getPeerDependencies.cache.get(moduleName); - - if (!result) { - info(`Checking peerDependencies of ${moduleName}`); - - result = npmUtils.fetchPeerDependencies(moduleName); - getPeerDependencies.cache.set(moduleName, result); - } - - return result; -} -getPeerDependencies.cache = new Map(); - -/** - * Return necessary plugins, configs, parsers, etc. based on the config - * @param {Object} config config object - * @param {boolean} [installESLint=true] If `false` is given, it does not install eslint. - * @returns {string[]} An array of modules to be installed. - */ -function getModulesList(config, installESLint) { - const modules = {}; - - // Create a list of modules which should be installed based on config - if (config.plugins) { - for (const plugin of config.plugins) { - const moduleName = naming.normalizePackageName(plugin, "eslint-plugin"); - - modules[moduleName] = "latest"; - } - } - - const extendList = []; - const overrides = config.overrides || []; - - for (const item of [config, ...overrides]) { - if (typeof item.extends === "string") { - extendList.push(item.extends); - } else if (Array.isArray(item.extends)) { - extendList.push(...item.extends); - } - } - - for (const extend of extendList) { - if (extend.startsWith("eslint:") || extend.startsWith("plugin:")) { - continue; - } - const moduleName = naming.normalizePackageName(extend, "eslint-config"); - - modules[moduleName] = "latest"; - Object.assign( - modules, - getPeerDependencies(`${moduleName}@latest`) - ); - } - - const parser = config.parser || (config.parserOptions && config.parserOptions.parser); - - if (parser) { - modules[parser] = "latest"; - } - - if (installESLint === false) { - delete modules.eslint; - } else { - const installStatus = npmUtils.checkDevDeps(["eslint"]); - - // Mark to show messages if it's new installation of eslint. - if (installStatus.eslint === false) { - info("Local ESLint installation not found."); - modules.eslint = modules.eslint || "latest"; - config.installedESLint = true; - } - } - - return Object.keys(modules).map(name => `${name}@${modules[name]}`); -} - -/** - * process user's answers and create config object - * @param {Object} answers answers received from enquirer - * @returns {Object} config object - */ -function processAnswers(answers) { - const config = { - rules: {}, - env: {}, - parserOptions: {}, - extends: [], - plugins: [], - overrides: [] - }; - - config.parserOptions.ecmaVersion = "latest"; - config.env.es2021 = true; - - if (answers.format === "JavaScript") { - config.overrides.push({ - files: [".eslintrc.{js,cjs}"], - parserOptions: { sourceType: "script" }, - env: { node: true } - }); - } - - // set the module type - if (answers.moduleType === "esm") { - config.parserOptions.sourceType = "module"; - } else if (answers.moduleType === "commonjs") { - config.env.commonjs = true; - } - - // add in browser and node environments if necessary - answers.env.forEach(env => { - config.env[env] = true; - }); - - // if answers.source == "guide", the ts supports should be in the shared config. - if (answers.typescript && answers.source !== "guide") { - - // .vue files should be parsed by vue-eslint-parser. - // https://eslint.vuejs.org/user-guide/#how-to-use-a-custom-parser - if (answers.framework === "vue") { - config.parserOptions.parser = "@typescript-eslint/parser"; - } else { - config.parser = "@typescript-eslint/parser"; - } - - config.plugins.push("@typescript-eslint"); - } - - // set config.extends based the selected guide - if (answers.source === "guide") { - if (answers.styleguide === "airbnb" && answers.framework !== "react") { - config.extends.push("airbnb-base"); - } else if (answers.styleguide === "xo-typescript") { - config.extends.push("xo"); - config.overrides.push({ - files: ["*.ts", "*.tsx"], - extends: ["xo-typescript"] - }); - } else { - config.extends.push(answers.styleguide); - } - } - - // setup rules based on problems/style enforcement preferences - if (answers.purpose === "problems") { - config.extends.unshift("eslint:recommended"); - } else if (answers.purpose === "style") { - if (answers.source === "prompt") { - config.extends.unshift("eslint:recommended"); - config.rules.indent = ["error", answers.indent]; - config.rules.quotes = ["error", answers.quotes]; - config.rules["linebreak-style"] = ["error", answers.linebreak]; - config.rules.semi = ["error", answers.semi ? "always" : "never"]; - } - } - if (answers.typescript && config.extends.includes("eslint:recommended")) { - config.extends.push("plugin:@typescript-eslint/recommended"); - } - - // add in library information - // The configuration of the framework plugins should be placed at the end of extends. - if (answers.framework === "react" && answers.styleguide !== "airbnb") { - config.plugins.push("react"); - config.extends.push("plugin:react/recommended"); - } else if (answers.framework === "vue") { - config.plugins.push("vue"); - config.extends.push("plugin:vue/vue3-essential"); - } - - // normalize extends - if (config.extends.length === 0) { - delete config.extends; - } else if (config.extends.length === 1) { - config.extends = config.extends[0]; - } - if (config.overrides.length === 0) { - delete config.overrides; - } - if (config.plugins.length === 0) { - delete config.plugins; - } - - ConfigOps.normalizeToStrings(config); - return config; -} - -/** - * Get the version of the local ESLint. - * @returns {string|null} The version. If the local ESLint was not found, returns null. - */ -function getLocalESLintVersion() { - try { - const eslintPkgPath = path.join(ModuleResolver.resolve("eslint/package.json", path.join(process.cwd(), "__placeholder__.js"))); - const eslintPkg = JSON.parse(fs.readFileSync(eslintPkgPath, "utf8")); - - return eslintPkg.version || null; - } catch { - return null; - } -} - -/** - * Get the shareable config name of the chosen style guide. - * @param {Object} answers The answers object. - * @returns {string} The shareable config name. - */ -function getStyleGuideName(answers) { - if (answers.styleguide === "airbnb" && answers.framework !== "react") { - return "airbnb-base"; - } - return answers.styleguide; -} - -/** - * Check whether the local ESLint version conflicts with the required version of the chosen shareable config. - * @param {Object} answers The answers object. - * @returns {boolean} `true` if the local ESLint is found then it conflicts with the required version of the chosen shareable config. - */ -function hasESLintVersionConflict(answers) { - - // Get the local ESLint version. - const localESLintVersion = getLocalESLintVersion(); - - if (!localESLintVersion) { - return false; - } - - // Get the required range of ESLint version. - const configName = getStyleGuideName(answers); - const moduleName = `eslint-config-${configName}@latest`; - const peerDependencies = getPeerDependencies(moduleName) || {}; - const requiredESLintVersionRange = peerDependencies.eslint; - - if (!requiredESLintVersionRange) { - return false; - } - - answers.localESLintVersion = localESLintVersion; - answers.requiredESLintVersionRange = requiredESLintVersionRange; - - // Check the version. - if (semver.satisfies(localESLintVersion, requiredESLintVersionRange)) { - answers.installESLint = false; - return false; - } - - return true; -} - -/** - * Install modules. - * @param {string[]} modules Modules to be installed. - * @param {string} packageManager Package manager to use for installation. - * @returns {void} - */ -function installModules(modules, packageManager) { - info(`Installing ${modules.join(", ")}`); - npmUtils.installSyncSaveDev(modules, packageManager); -} - -/* istanbul ignore next: no need to test enquirer */ -/** - * Ask user to install modules. - * @param {string[]} modules Array of modules to be installed. - * @returns {Promise} Answer that indicates if user wants to install. - */ -function askInstallModules(modules) { - - // If no modules, do nothing. - if (modules.length === 0) { - return Promise.resolve(); - } - - info("The config that you've selected requires the following dependencies:\n"); - info(modules.join(" ")); - return enquirer.prompt([ - { - type: "toggle", - name: "executeInstallation", - message: "Would you like to install them now?", - enabled: "Yes", - disabled: "No", - initial: 1, - skip() { - return !modules.length; - }, - result(input) { - return this.skipped ? null : input; - } - }, - { - type: "select", - name: "packageManager", - message: "Which package manager do you want to use?", - initial: 0, - choices: ["npm", "yarn", "pnpm", "bun"], - skip() { - return !this.state.answers.executeInstallation; - } - } - ]).then(({ executeInstallation, packageManager }) => { - if (executeInstallation) { - installModules(modules, packageManager); - } - }); -} - -/* istanbul ignore next: no need to test enquirer */ -/** - * Ask use a few questions on command prompt - * @returns {Promise} The promise with the result of the prompt - * @throws {Error} If `package.json` file doesn't exist. - */ -function promptUser() { - const packageJsonExists = npmUtils.checkPackageJson(); - - if (!packageJsonExists) { - throw new Error("A package.json file is necessary to initialize ESLint. Run `npm init` to create a package.json file and try again."); - } - - const styleGuides = []; - - return enquirer.prompt([ - { - type: "select", - name: "purpose", - message: "How would you like to use ESLint?", - - // The returned number matches the name value of nth in the choices array. - initial: 1, - choices: [ - { message: "To check syntax only", name: "syntax" }, - { message: "To check syntax and find problems", name: "problems" }, - { message: "To check syntax, find problems, and enforce code style", name: "style" } - ] - }, - { - type: "select", - name: "moduleType", - message: "What type of modules does your project use?", - initial: 0, - choices: [ - { message: "JavaScript modules (import/export)", name: "esm" }, - { message: "CommonJS (require/exports)", name: "commonjs" }, - { message: "None of these", name: "none" } - ] - }, - { - type: "select", - name: "framework", - message: "Which framework does your project use?", - initial: 0, - choices: [ - { message: "React", name: "react" }, - { message: "Vue.js", name: "vue" }, - { message: "None of these", name: "none" } - ] - }, - { - type: "toggle", - name: "typescript", - message: "Does your project use TypeScript?", - enabled: "Yes", - disabled: "No", - initial: 0, - result(val) { - if (val) { - - // remove airbnb/google javascript style guide, as they do not support ts - styleGuides.push( - { message: "Standard: https://github.com/standard/eslint-config-standard-with-typescript", name: "standard-with-typescript" }, - { message: "XO: https://github.com/xojs/eslint-config-xo-typescript", name: "xo-typescript" } - ); - } else { - styleGuides.push( - { message: "Airbnb: https://github.com/airbnb/javascript", name: "airbnb" }, - { message: "Standard: https://github.com/standard/standard", name: "standard" }, - { message: "XO: https://github.com/xojs/eslint-config-xo", name: "xo" } - ); - } - return val; - } - }, - { - type: "multiselect", - name: "env", - message: "Where does your code run?", - hint: "(Press to select, to toggle all, to invert selection)", - initial: 0, - choices: [ - { message: "Browser", name: "browser" }, - { message: "Node", name: "node" } - ] - }, - { - type: "select", - name: "source", - message: "How would you like to define a style for your project?", - choices: [ - { message: "Use a popular style guide", name: "guide" }, - { message: "Answer questions about your style", name: "prompt" } - ], - skip() { - return this.state.answers.purpose !== "style"; - }, - result(input) { - return this.skipped ? null : input; - } - }, - { - type: "select", - name: "styleguide", - message: "Which style guide do you want to follow?", - choices: styleGuides, - skip() { - return this.state.answers.source !== "guide"; - }, - result(input) { - return this.skipped ? null : input; - } - }, - { - type: "select", - name: "format", - message: "What format do you want your config file to be in?", - initial: 0, - choices: ["JavaScript", "YAML", "JSON"] - }, - { - type: "toggle", - name: "installESLint", - message() { - const { answers } = this.state; - const verb = semver.ltr(answers.localESLintVersion, answers.requiredESLintVersionRange) - ? "upgrade" - : "downgrade"; - - return `The style guide "${answers.styleguide}" requires eslint@${answers.requiredESLintVersionRange}. You are currently using eslint@${answers.localESLintVersion}.\n Do you want to ${verb}?`; - }, - enabled: "Yes", - disabled: "No", - initial: 1, - skip() { - return !(this.state.answers.source === "guide" && hasESLintVersionConflict(this.state.answers)); - }, - result(input) { - return this.skipped ? null : input; - } - } - ]).then(earlyAnswers => { - - // early exit if no style guide is necessary - if (earlyAnswers.purpose !== "style") { - const config = processAnswers(earlyAnswers); - const modules = getModulesList(config); - - return askInstallModules(modules) - .then(() => writeFile(config, earlyAnswers.format)); - } - - // early exit if you are using a style guide - if (earlyAnswers.source === "guide") { - if (earlyAnswers.installESLint === false && !semver.satisfies(earlyAnswers.localESLintVersion, earlyAnswers.requiredESLintVersionRange)) { - info(`Note: it might not work since ESLint's version is mismatched with the ${earlyAnswers.styleguide} config.`); - } - - const config = processAnswers(earlyAnswers); - const modules = getModulesList(config); - - return askInstallModules(modules) - .then(() => writeFile(config, earlyAnswers.format)); - - } - - // continue with the style questions otherwise... - return enquirer.prompt([ - { - type: "select", - name: "indent", - message: "What style of indentation do you use?", - initial: 0, - choices: [{ message: "Tabs", name: "tab" }, { message: "Spaces", name: 4 }] - }, - { - type: "select", - name: "quotes", - message: "What quotes do you use for strings?", - initial: 0, - choices: [{ message: "Double", name: "double" }, { message: "Single", name: "single" }] - }, - { - type: "select", - name: "linebreak", - message: "What line endings do you use?", - initial: 0, - choices: [{ message: "Unix", name: "unix" }, { message: "Windows", name: "windows" }] - }, - { - type: "toggle", - name: "semi", - message: "Do you require semicolons?", - enabled: "Yes", - disabled: "No", - initial: 1 - } - ]).then(answers => { - const totalAnswers = Object.assign({}, earlyAnswers, answers); - - const config = processAnswers(totalAnswers); - const modules = getModulesList(config); - - return askInstallModules(modules).then(() => writeFile(config, earlyAnswers.format)); - }); - }); -} - -/* istanbul ignore next */ -/** - * an wrapper for promptUser - * @returns {void} - */ -function initializeConfig() { - const argv = mri(process.argv.slice(2)); - - if (argv.config) { - const config = { - extends: typeof argv.config === "string" ? argv.config.split(",") : argv.config - }; - const modules = getModulesList(config); - - return askInstallModules(modules).then(() => writeFile(config, "JavaScript")); - } - - return promptUser(); -} - -//------------------------------------------------------------------------------ -// Public Interface -//------------------------------------------------------------------------------ - -export { - getModulesList, - hasESLintVersionConflict, - installModules, - processAnswers, - writeFile, - initializeConfig -}; diff --git a/lib/shared/logging.js b/lib/utils/logging.js similarity index 100% rename from lib/shared/logging.js rename to lib/utils/logging.js diff --git a/lib/init/npm-utils.js b/lib/utils/npm-utils.js similarity index 87% rename from lib/init/npm-utils.js rename to lib/utils/npm-utils.js index cfce2172..d3806e9c 100644 --- a/lib/init/npm-utils.js +++ b/lib/utils/npm-utils.js @@ -12,7 +12,7 @@ import fs from "fs"; import spawn from "cross-spawn"; import path from "path"; -import * as log from "../shared/logging.js"; +import * as log from "./logging.js"; //------------------------------------------------------------------------------ // Helpers @@ -77,13 +77,20 @@ function fetchPeerDependencies(packageName) { const error = npmProcess.error; if (error && error.code === "ENOENT") { + + // TODO: should throw an error instead of returning null return null; } const fetchedText = npmProcess.stdout.trim(); - return JSON.parse(fetchedText || "{}"); + const peers = JSON.parse(fetchedText || "{}"); + const ret = []; + Object.keys(peers).forEach(pkgName => { + ret.push(`${pkgName}@${peers[pkgName]}`); + }); + return ret; } /** @@ -155,6 +162,26 @@ function checkPackageJson(startDir) { return !!findPackageJson(startDir); } +/** + * check if the package.type === "module" + * @param {string} [cwd] The current working directory + * @returns {boolean} return true if the package.type === "module" + */ +function isPackageTypeModule(cwd) { + const pkgJSONPath = findPackageJson(cwd); + + if (pkgJSONPath) { + const pkgJSONContents = JSON.parse(fs.readFileSync(pkgJSONPath, "utf8")); + + if (pkgJSONContents.type === "module") { + return true; + } + } + + return false; +} + + //------------------------------------------------------------------------------ // Public Interface //------------------------------------------------------------------------------ @@ -165,5 +192,6 @@ export { findPackageJson, checkDeps, checkDevDeps, - checkPackageJson + checkPackageJson, + isPackageTypeModule }; diff --git a/package.json b/package.json index 33b58b29..b74fb6a0 100644 --- a/package.json +++ b/package.json @@ -35,27 +35,20 @@ "release:generate:beta": "eslint-generate-prerelease beta", "release:generate:rc": "eslint-generate-prerelease rc", "release:publish": "eslint-publish-release", - "test": "c8 mocha \"tests/init/**/*.js\"" - }, - "mocha": { - "loader": "esmock", - "ui": "bdd", - "timeout": 10000 + "test": "cross-env NODE_OPTIONS=--loader=esmock c8 vitest run \"./tests\"", + "test:snapshots": "vitest run snapshots", + "test:snapshots:update": "vitest -u run snapshots" }, "dependencies": { - "@eslint/eslintrc": "^1.0.3", "cross-spawn": "^7.0.2", "debug": "^4.0.1", - "enquirer": "^2.3.5", - "js-yaml": "^4.1.0", - "json-stable-stringify-without-jsonify": "^1.0.1", - "mri": "^1.2.0", - "semver": "^7.2.1" + "enquirer": "^2.3.5" }, "devDependencies": { "c8": "^7.10.0", "chai": "^4.3.4", - "eslint": "^8.48.0", + "cross-env": "^7.0.3", + "eslint": "^8.56.0", "eslint-config-eslint": "^9.0.0", "eslint-release": "^3.2.0", "esmock": "^2.5.8", @@ -66,6 +59,7 @@ "mocha": "^9.1.3", "shelljs": "^0.8.4", "sinon": "^12.0.1", + "vitest": "^1.1.1", "yorkie": "^2.0.0" }, "engines": { diff --git a/tests/__snapshots__/problem-commonjs-none-javascript b/tests/__snapshots__/problem-commonjs-none-javascript new file mode 100644 index 00000000..f544f93e --- /dev/null +++ b/tests/__snapshots__/problem-commonjs-none-javascript @@ -0,0 +1,16 @@ +{ + "configContent": "import pluginJs from "@eslint/js"; +import globals from "globals"; + + +export default [].concat( + { languageOptions: {sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, + pluginJs.configs.recommended, +);", + "configFilename": "eslint.config.js", + "devDependencies": [ + "eslint", + "@eslint/js", + "globals", + ], +} \ No newline at end of file diff --git a/tests/__snapshots__/problem-commonjs-none-typescript b/tests/__snapshots__/problem-commonjs-none-typescript new file mode 100644 index 00000000..a8d18870 --- /dev/null +++ b/tests/__snapshots__/problem-commonjs-none-typescript @@ -0,0 +1,19 @@ +{ + "configContent": "import pluginJs from "@eslint/js"; +import globals from "globals"; +import tseslint from "typescript-eslint"; + + +export default [].concat( + { languageOptions: {sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, + pluginJs.configs.recommended, + tseslint.configs.recommended, +);", + "configFilename": "eslint.config.js", + "devDependencies": [ + "eslint", + "@eslint/js", + "globals", + "typescript-eslint", + ], +} \ No newline at end of file diff --git a/tests/__snapshots__/problem-commonjs-react-javascript b/tests/__snapshots__/problem-commonjs-react-javascript new file mode 100644 index 00000000..6b42fb14 --- /dev/null +++ b/tests/__snapshots__/problem-commonjs-react-javascript @@ -0,0 +1,19 @@ +{ + "configContent": "import pluginJs from "@eslint/js"; +import globals from "globals"; +import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; + + +export default [].concat( + { languageOptions: {sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, + pluginJs.configs.recommended, + pluginReactConfig, +);", + "configFilename": "eslint.config.js", + "devDependencies": [ + "eslint", + "@eslint/js", + "globals", + "eslint-plugin-react", + ], +} \ No newline at end of file diff --git a/tests/__snapshots__/problem-commonjs-react-typescript b/tests/__snapshots__/problem-commonjs-react-typescript new file mode 100644 index 00000000..0e874dc5 --- /dev/null +++ b/tests/__snapshots__/problem-commonjs-react-typescript @@ -0,0 +1,22 @@ +{ + "configContent": "import pluginJs from "@eslint/js"; +import globals from "globals"; +import tseslint from "typescript-eslint"; +import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; + + +export default [].concat( + { languageOptions: {sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, + pluginJs.configs.recommended, + tseslint.configs.recommended, + pluginReactConfig, +);", + "configFilename": "eslint.config.js", + "devDependencies": [ + "eslint", + "@eslint/js", + "globals", + "typescript-eslint", + "eslint-plugin-react", + ], +} \ No newline at end of file diff --git a/tests/__snapshots__/problem-commonjs-vue-javascript b/tests/__snapshots__/problem-commonjs-vue-javascript new file mode 100644 index 00000000..5a80ccef --- /dev/null +++ b/tests/__snapshots__/problem-commonjs-vue-javascript @@ -0,0 +1,22 @@ +{ + "configContent": "import pluginJs from "@eslint/js"; +import globals from "globals"; + +// mimic CommonJS variables -- not needed if using CommonJS +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); +const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); + +export default [].concat( + { languageOptions: {sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, + pluginJs.configs.recommended, + compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), +);", + "configFilename": "eslint.config.js", + "devDependencies": [ + "eslint", + "@eslint/js", + "globals", + "eslint-plugin-vue", + ], +} \ No newline at end of file diff --git a/tests/__snapshots__/problem-commonjs-vue-typescript b/tests/__snapshots__/problem-commonjs-vue-typescript new file mode 100644 index 00000000..a8c1c96b --- /dev/null +++ b/tests/__snapshots__/problem-commonjs-vue-typescript @@ -0,0 +1,25 @@ +{ + "configContent": "import pluginJs from "@eslint/js"; +import globals from "globals"; +import tseslint from "typescript-eslint"; + +// mimic CommonJS variables -- not needed if using CommonJS +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); +const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); + +export default [].concat( + { languageOptions: {sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, + pluginJs.configs.recommended, + tseslint.configs.recommended, + compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), +);", + "configFilename": "eslint.config.js", + "devDependencies": [ + "eslint", + "@eslint/js", + "globals", + "typescript-eslint", + "eslint-plugin-vue", + ], +} \ No newline at end of file diff --git a/tests/__snapshots__/problem-esm-none-javascript b/tests/__snapshots__/problem-esm-none-javascript new file mode 100644 index 00000000..db91a232 --- /dev/null +++ b/tests/__snapshots__/problem-esm-none-javascript @@ -0,0 +1,16 @@ +{ + "configContent": "import pluginJs from "@eslint/js"; +import globals from "globals"; + + +export default [].concat( + { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, + pluginJs.configs.recommended, +);", + "configFilename": "eslint.config.js", + "devDependencies": [ + "eslint", + "@eslint/js", + "globals", + ], +} \ No newline at end of file diff --git a/tests/__snapshots__/problem-esm-none-typescript b/tests/__snapshots__/problem-esm-none-typescript new file mode 100644 index 00000000..5526b413 --- /dev/null +++ b/tests/__snapshots__/problem-esm-none-typescript @@ -0,0 +1,19 @@ +{ + "configContent": "import pluginJs from "@eslint/js"; +import globals from "globals"; +import tseslint from "typescript-eslint"; + + +export default [].concat( + { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, + pluginJs.configs.recommended, + tseslint.configs.recommended, +);", + "configFilename": "eslint.config.js", + "devDependencies": [ + "eslint", + "@eslint/js", + "globals", + "typescript-eslint", + ], +} \ No newline at end of file diff --git a/tests/__snapshots__/problem-esm-react-javascript b/tests/__snapshots__/problem-esm-react-javascript new file mode 100644 index 00000000..05ce5090 --- /dev/null +++ b/tests/__snapshots__/problem-esm-react-javascript @@ -0,0 +1,19 @@ +{ + "configContent": "import pluginJs from "@eslint/js"; +import globals from "globals"; +import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; + + +export default [].concat( + { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, + pluginJs.configs.recommended, + pluginReactConfig, +);", + "configFilename": "eslint.config.js", + "devDependencies": [ + "eslint", + "@eslint/js", + "globals", + "eslint-plugin-react", + ], +} \ No newline at end of file diff --git a/tests/__snapshots__/problem-esm-react-typescript b/tests/__snapshots__/problem-esm-react-typescript new file mode 100644 index 00000000..568552bb --- /dev/null +++ b/tests/__snapshots__/problem-esm-react-typescript @@ -0,0 +1,22 @@ +{ + "configContent": "import pluginJs from "@eslint/js"; +import globals from "globals"; +import tseslint from "typescript-eslint"; +import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; + + +export default [].concat( + { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, + pluginJs.configs.recommended, + tseslint.configs.recommended, + pluginReactConfig, +);", + "configFilename": "eslint.config.js", + "devDependencies": [ + "eslint", + "@eslint/js", + "globals", + "typescript-eslint", + "eslint-plugin-react", + ], +} \ No newline at end of file diff --git a/tests/__snapshots__/problem-esm-vue-javascript b/tests/__snapshots__/problem-esm-vue-javascript new file mode 100644 index 00000000..0590b838 --- /dev/null +++ b/tests/__snapshots__/problem-esm-vue-javascript @@ -0,0 +1,22 @@ +{ + "configContent": "import pluginJs from "@eslint/js"; +import globals from "globals"; + +// mimic CommonJS variables -- not needed if using CommonJS +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); +const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); + +export default [].concat( + { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, + pluginJs.configs.recommended, + compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), +);", + "configFilename": "eslint.config.js", + "devDependencies": [ + "eslint", + "@eslint/js", + "globals", + "eslint-plugin-vue", + ], +} \ No newline at end of file diff --git a/tests/__snapshots__/problem-esm-vue-typescript b/tests/__snapshots__/problem-esm-vue-typescript new file mode 100644 index 00000000..f2eee593 --- /dev/null +++ b/tests/__snapshots__/problem-esm-vue-typescript @@ -0,0 +1,25 @@ +{ + "configContent": "import pluginJs from "@eslint/js"; +import globals from "globals"; +import tseslint from "typescript-eslint"; + +// mimic CommonJS variables -- not needed if using CommonJS +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); +const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); + +export default [].concat( + { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, + pluginJs.configs.recommended, + tseslint.configs.recommended, + compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), +);", + "configFilename": "eslint.config.js", + "devDependencies": [ + "eslint", + "@eslint/js", + "globals", + "typescript-eslint", + "eslint-plugin-vue", + ], +} \ No newline at end of file diff --git a/tests/__snapshots__/problem-script-none-javascript b/tests/__snapshots__/problem-script-none-javascript new file mode 100644 index 00000000..db91a232 --- /dev/null +++ b/tests/__snapshots__/problem-script-none-javascript @@ -0,0 +1,16 @@ +{ + "configContent": "import pluginJs from "@eslint/js"; +import globals from "globals"; + + +export default [].concat( + { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, + pluginJs.configs.recommended, +);", + "configFilename": "eslint.config.js", + "devDependencies": [ + "eslint", + "@eslint/js", + "globals", + ], +} \ No newline at end of file diff --git a/tests/__snapshots__/problem-script-none-typescript b/tests/__snapshots__/problem-script-none-typescript new file mode 100644 index 00000000..5526b413 --- /dev/null +++ b/tests/__snapshots__/problem-script-none-typescript @@ -0,0 +1,19 @@ +{ + "configContent": "import pluginJs from "@eslint/js"; +import globals from "globals"; +import tseslint from "typescript-eslint"; + + +export default [].concat( + { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, + pluginJs.configs.recommended, + tseslint.configs.recommended, +);", + "configFilename": "eslint.config.js", + "devDependencies": [ + "eslint", + "@eslint/js", + "globals", + "typescript-eslint", + ], +} \ No newline at end of file diff --git a/tests/__snapshots__/problem-script-react-javascript b/tests/__snapshots__/problem-script-react-javascript new file mode 100644 index 00000000..05ce5090 --- /dev/null +++ b/tests/__snapshots__/problem-script-react-javascript @@ -0,0 +1,19 @@ +{ + "configContent": "import pluginJs from "@eslint/js"; +import globals from "globals"; +import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; + + +export default [].concat( + { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, + pluginJs.configs.recommended, + pluginReactConfig, +);", + "configFilename": "eslint.config.js", + "devDependencies": [ + "eslint", + "@eslint/js", + "globals", + "eslint-plugin-react", + ], +} \ No newline at end of file diff --git a/tests/__snapshots__/problem-script-react-typescript b/tests/__snapshots__/problem-script-react-typescript new file mode 100644 index 00000000..568552bb --- /dev/null +++ b/tests/__snapshots__/problem-script-react-typescript @@ -0,0 +1,22 @@ +{ + "configContent": "import pluginJs from "@eslint/js"; +import globals from "globals"; +import tseslint from "typescript-eslint"; +import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; + + +export default [].concat( + { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, + pluginJs.configs.recommended, + tseslint.configs.recommended, + pluginReactConfig, +);", + "configFilename": "eslint.config.js", + "devDependencies": [ + "eslint", + "@eslint/js", + "globals", + "typescript-eslint", + "eslint-plugin-react", + ], +} \ No newline at end of file diff --git a/tests/__snapshots__/problem-script-vue-javascript b/tests/__snapshots__/problem-script-vue-javascript new file mode 100644 index 00000000..0590b838 --- /dev/null +++ b/tests/__snapshots__/problem-script-vue-javascript @@ -0,0 +1,22 @@ +{ + "configContent": "import pluginJs from "@eslint/js"; +import globals from "globals"; + +// mimic CommonJS variables -- not needed if using CommonJS +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); +const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); + +export default [].concat( + { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, + pluginJs.configs.recommended, + compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), +);", + "configFilename": "eslint.config.js", + "devDependencies": [ + "eslint", + "@eslint/js", + "globals", + "eslint-plugin-vue", + ], +} \ No newline at end of file diff --git a/tests/__snapshots__/problem-script-vue-typescript b/tests/__snapshots__/problem-script-vue-typescript new file mode 100644 index 00000000..f2eee593 --- /dev/null +++ b/tests/__snapshots__/problem-script-vue-typescript @@ -0,0 +1,25 @@ +{ + "configContent": "import pluginJs from "@eslint/js"; +import globals from "globals"; +import tseslint from "typescript-eslint"; + +// mimic CommonJS variables -- not needed if using CommonJS +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); +const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); + +export default [].concat( + { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, + pluginJs.configs.recommended, + tseslint.configs.recommended, + compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), +);", + "configFilename": "eslint.config.js", + "devDependencies": [ + "eslint", + "@eslint/js", + "globals", + "typescript-eslint", + "eslint-plugin-vue", + ], +} \ No newline at end of file diff --git a/tests/__snapshots__/style-esm-none-xo-javascript b/tests/__snapshots__/style-esm-none-xo-javascript new file mode 100644 index 00000000..f5d10008 --- /dev/null +++ b/tests/__snapshots__/style-esm-none-xo-javascript @@ -0,0 +1,17 @@ +{ + "configContent": "import styleGuide from "undefined"; +import globals from "globals"; + + +export default [].concat( + { languageOptions: {globals: globals.node, }}, + styleGuide, +);", + "configFilename": "eslint.config.mjs", + "devDependencies": [ + "eslint", + undefined, + "@eslint/js", + "globals", + ], +} \ No newline at end of file diff --git a/tests/__snapshots__/style-esm-none-xo-typescript b/tests/__snapshots__/style-esm-none-xo-typescript new file mode 100644 index 00000000..a795125a --- /dev/null +++ b/tests/__snapshots__/style-esm-none-xo-typescript @@ -0,0 +1,20 @@ +{ + "configContent": "import styleGuide from "undefined"; +import globals from "globals"; +import tseslint from "typescript-eslint"; + + +export default [].concat( + { languageOptions: {globals: globals.browser, }}, + styleGuide, + tseslint.configs.recommended, +);", + "configFilename": "eslint.config.mjs", + "devDependencies": [ + "eslint", + undefined, + "@eslint/js", + "globals", + "typescript-eslint", + ], +} \ No newline at end of file diff --git a/tests/__snapshots__/syntax-commonjs-none-javascript b/tests/__snapshots__/syntax-commonjs-none-javascript new file mode 100644 index 00000000..466b4e40 --- /dev/null +++ b/tests/__snapshots__/syntax-commonjs-none-javascript @@ -0,0 +1,13 @@ +{ + "configContent": "import globals from "globals"; + + +export default [].concat( + { languageOptions: {sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, +);", + "configFilename": "eslint.config.js", + "devDependencies": [ + "eslint", + "globals", + ], +} \ No newline at end of file diff --git a/tests/__snapshots__/syntax-commonjs-none-typescript b/tests/__snapshots__/syntax-commonjs-none-typescript new file mode 100644 index 00000000..3fcd5ea8 --- /dev/null +++ b/tests/__snapshots__/syntax-commonjs-none-typescript @@ -0,0 +1,16 @@ +{ + "configContent": "import globals from "globals"; +import tseslint from "typescript-eslint"; + + +export default [].concat( + { languageOptions: {sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, + tseslint.configs.recommended, +);", + "configFilename": "eslint.config.js", + "devDependencies": [ + "eslint", + "globals", + "typescript-eslint", + ], +} \ No newline at end of file diff --git a/tests/__snapshots__/syntax-commonjs-react-javascript b/tests/__snapshots__/syntax-commonjs-react-javascript new file mode 100644 index 00000000..f99c0be3 --- /dev/null +++ b/tests/__snapshots__/syntax-commonjs-react-javascript @@ -0,0 +1,16 @@ +{ + "configContent": "import globals from "globals"; +import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; + + +export default [].concat( + { languageOptions: {sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, + pluginReactConfig, +);", + "configFilename": "eslint.config.js", + "devDependencies": [ + "eslint", + "globals", + "eslint-plugin-react", + ], +} \ No newline at end of file diff --git a/tests/__snapshots__/syntax-commonjs-react-typescript b/tests/__snapshots__/syntax-commonjs-react-typescript new file mode 100644 index 00000000..41406434 --- /dev/null +++ b/tests/__snapshots__/syntax-commonjs-react-typescript @@ -0,0 +1,19 @@ +{ + "configContent": "import globals from "globals"; +import tseslint from "typescript-eslint"; +import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; + + +export default [].concat( + { languageOptions: {sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, + tseslint.configs.recommended, + pluginReactConfig, +);", + "configFilename": "eslint.config.js", + "devDependencies": [ + "eslint", + "globals", + "typescript-eslint", + "eslint-plugin-react", + ], +} \ No newline at end of file diff --git a/tests/__snapshots__/syntax-commonjs-vue-javascript b/tests/__snapshots__/syntax-commonjs-vue-javascript new file mode 100644 index 00000000..8d49271a --- /dev/null +++ b/tests/__snapshots__/syntax-commonjs-vue-javascript @@ -0,0 +1,19 @@ +{ + "configContent": "import globals from "globals"; + +// mimic CommonJS variables -- not needed if using CommonJS +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); +const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); + +export default [].concat( + { languageOptions: {sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, + compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), +);", + "configFilename": "eslint.config.js", + "devDependencies": [ + "eslint", + "globals", + "eslint-plugin-vue", + ], +} \ No newline at end of file diff --git a/tests/__snapshots__/syntax-commonjs-vue-typescript b/tests/__snapshots__/syntax-commonjs-vue-typescript new file mode 100644 index 00000000..a2d64e3f --- /dev/null +++ b/tests/__snapshots__/syntax-commonjs-vue-typescript @@ -0,0 +1,22 @@ +{ + "configContent": "import globals from "globals"; +import tseslint from "typescript-eslint"; + +// mimic CommonJS variables -- not needed if using CommonJS +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); +const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); + +export default [].concat( + { languageOptions: {sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, + tseslint.configs.recommended, + compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), +);", + "configFilename": "eslint.config.js", + "devDependencies": [ + "eslint", + "globals", + "typescript-eslint", + "eslint-plugin-vue", + ], +} \ No newline at end of file diff --git a/tests/__snapshots__/syntax-esm-none-javascript b/tests/__snapshots__/syntax-esm-none-javascript new file mode 100644 index 00000000..9f748093 --- /dev/null +++ b/tests/__snapshots__/syntax-esm-none-javascript @@ -0,0 +1,13 @@ +{ + "configContent": "import globals from "globals"; + + +export default [].concat( + { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, +);", + "configFilename": "eslint.config.js", + "devDependencies": [ + "eslint", + "globals", + ], +} \ No newline at end of file diff --git a/tests/__snapshots__/syntax-esm-none-typescript b/tests/__snapshots__/syntax-esm-none-typescript new file mode 100644 index 00000000..81c5da76 --- /dev/null +++ b/tests/__snapshots__/syntax-esm-none-typescript @@ -0,0 +1,16 @@ +{ + "configContent": "import globals from "globals"; +import tseslint from "typescript-eslint"; + + +export default [].concat( + { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, + tseslint.configs.recommended, +);", + "configFilename": "eslint.config.js", + "devDependencies": [ + "eslint", + "globals", + "typescript-eslint", + ], +} \ No newline at end of file diff --git a/tests/__snapshots__/syntax-esm-react-javascript b/tests/__snapshots__/syntax-esm-react-javascript new file mode 100644 index 00000000..5e52b440 --- /dev/null +++ b/tests/__snapshots__/syntax-esm-react-javascript @@ -0,0 +1,16 @@ +{ + "configContent": "import globals from "globals"; +import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; + + +export default [].concat( + { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, + pluginReactConfig, +);", + "configFilename": "eslint.config.js", + "devDependencies": [ + "eslint", + "globals", + "eslint-plugin-react", + ], +} \ No newline at end of file diff --git a/tests/__snapshots__/syntax-esm-react-typescript b/tests/__snapshots__/syntax-esm-react-typescript new file mode 100644 index 00000000..7a1615f0 --- /dev/null +++ b/tests/__snapshots__/syntax-esm-react-typescript @@ -0,0 +1,19 @@ +{ + "configContent": "import globals from "globals"; +import tseslint from "typescript-eslint"; +import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; + + +export default [].concat( + { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, + tseslint.configs.recommended, + pluginReactConfig, +);", + "configFilename": "eslint.config.js", + "devDependencies": [ + "eslint", + "globals", + "typescript-eslint", + "eslint-plugin-react", + ], +} \ No newline at end of file diff --git a/tests/__snapshots__/syntax-esm-vue-javascript b/tests/__snapshots__/syntax-esm-vue-javascript new file mode 100644 index 00000000..dd729a12 --- /dev/null +++ b/tests/__snapshots__/syntax-esm-vue-javascript @@ -0,0 +1,19 @@ +{ + "configContent": "import globals from "globals"; + +// mimic CommonJS variables -- not needed if using CommonJS +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); +const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); + +export default [].concat( + { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, + compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), +);", + "configFilename": "eslint.config.js", + "devDependencies": [ + "eslint", + "globals", + "eslint-plugin-vue", + ], +} \ No newline at end of file diff --git a/tests/__snapshots__/syntax-esm-vue-typescript b/tests/__snapshots__/syntax-esm-vue-typescript new file mode 100644 index 00000000..2ad55884 --- /dev/null +++ b/tests/__snapshots__/syntax-esm-vue-typescript @@ -0,0 +1,22 @@ +{ + "configContent": "import globals from "globals"; +import tseslint from "typescript-eslint"; + +// mimic CommonJS variables -- not needed if using CommonJS +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); +const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); + +export default [].concat( + { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, + tseslint.configs.recommended, + compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), +);", + "configFilename": "eslint.config.js", + "devDependencies": [ + "eslint", + "globals", + "typescript-eslint", + "eslint-plugin-vue", + ], +} \ No newline at end of file diff --git a/tests/__snapshots__/syntax-script-none-javascript b/tests/__snapshots__/syntax-script-none-javascript new file mode 100644 index 00000000..9f748093 --- /dev/null +++ b/tests/__snapshots__/syntax-script-none-javascript @@ -0,0 +1,13 @@ +{ + "configContent": "import globals from "globals"; + + +export default [].concat( + { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, +);", + "configFilename": "eslint.config.js", + "devDependencies": [ + "eslint", + "globals", + ], +} \ No newline at end of file diff --git a/tests/__snapshots__/syntax-script-none-typescript b/tests/__snapshots__/syntax-script-none-typescript new file mode 100644 index 00000000..81c5da76 --- /dev/null +++ b/tests/__snapshots__/syntax-script-none-typescript @@ -0,0 +1,16 @@ +{ + "configContent": "import globals from "globals"; +import tseslint from "typescript-eslint"; + + +export default [].concat( + { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, + tseslint.configs.recommended, +);", + "configFilename": "eslint.config.js", + "devDependencies": [ + "eslint", + "globals", + "typescript-eslint", + ], +} \ No newline at end of file diff --git a/tests/__snapshots__/syntax-script-react-javascript b/tests/__snapshots__/syntax-script-react-javascript new file mode 100644 index 00000000..5e52b440 --- /dev/null +++ b/tests/__snapshots__/syntax-script-react-javascript @@ -0,0 +1,16 @@ +{ + "configContent": "import globals from "globals"; +import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; + + +export default [].concat( + { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, + pluginReactConfig, +);", + "configFilename": "eslint.config.js", + "devDependencies": [ + "eslint", + "globals", + "eslint-plugin-react", + ], +} \ No newline at end of file diff --git a/tests/__snapshots__/syntax-script-react-typescript b/tests/__snapshots__/syntax-script-react-typescript new file mode 100644 index 00000000..7a1615f0 --- /dev/null +++ b/tests/__snapshots__/syntax-script-react-typescript @@ -0,0 +1,19 @@ +{ + "configContent": "import globals from "globals"; +import tseslint from "typescript-eslint"; +import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; + + +export default [].concat( + { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, + tseslint.configs.recommended, + pluginReactConfig, +);", + "configFilename": "eslint.config.js", + "devDependencies": [ + "eslint", + "globals", + "typescript-eslint", + "eslint-plugin-react", + ], +} \ No newline at end of file diff --git a/tests/__snapshots__/syntax-script-vue-javascript b/tests/__snapshots__/syntax-script-vue-javascript new file mode 100644 index 00000000..dd729a12 --- /dev/null +++ b/tests/__snapshots__/syntax-script-vue-javascript @@ -0,0 +1,19 @@ +{ + "configContent": "import globals from "globals"; + +// mimic CommonJS variables -- not needed if using CommonJS +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); +const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); + +export default [].concat( + { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, + compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), +);", + "configFilename": "eslint.config.js", + "devDependencies": [ + "eslint", + "globals", + "eslint-plugin-vue", + ], +} \ No newline at end of file diff --git a/tests/__snapshots__/syntax-script-vue-typescript b/tests/__snapshots__/syntax-script-vue-typescript new file mode 100644 index 00000000..2ad55884 --- /dev/null +++ b/tests/__snapshots__/syntax-script-vue-typescript @@ -0,0 +1,22 @@ +{ + "configContent": "import globals from "globals"; +import tseslint from "typescript-eslint"; + +// mimic CommonJS variables -- not needed if using CommonJS +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); +const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); + +export default [].concat( + { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, + tseslint.configs.recommended, + compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), +);", + "configFilename": "eslint.config.js", + "devDependencies": [ + "eslint", + "globals", + "typescript-eslint", + "eslint-plugin-vue", + ], +} \ No newline at end of file diff --git a/tests/config-snapshots.spec.js b/tests/config-snapshots.spec.js new file mode 100644 index 00000000..fb2d7800 --- /dev/null +++ b/tests/config-snapshots.spec.js @@ -0,0 +1,95 @@ +/** + * @fileoverview snapshot tests for config-generator.js + * run `npm run test:snapshots` to assert snapshots + * run `npm run test:snapshots:update` to update snapshots - you need + * to check the changes manually (see the diff) and make sure it's correct. + * + * @author 唯然 + */ +import { ConfigGenerator } from "../lib/config-generator.js"; +import { expect, describe, test } from "vitest"; +import { fileURLToPath } from "node:url"; +import { join } from "path"; + +const __filename = fileURLToPath(import.meta.url); // eslint-disable-line no-underscore-dangle -- commonjs convention + +describe("generate config for esm projects", () => { + const esmProjectDir = join(__filename, "../fixtures/esm-project"); + const choices = { + purpose: ["syntax", "problem"], + module: ["esm", "commonjs", "script"], + framework: ["react", "vue", "none"], + language: ["javascript", "typescript"], + env: ["browser", "node"] + }; + + const inputs = []; + + // generate all possible combinations + for (let i = 0; i < choices.purpose.length; i++) { + for (let j = 0; j < choices.module.length; j++) { + for (let k = 0; k < choices.framework.length; k++) { + for (let m = 0; m < choices.language.length; m++) { + inputs.push({ + name: `${choices.purpose[i]}-${choices.module[j]}-${choices.framework[k]}-${choices.language[m]}`, + answers: { + purpose: choices.purpose[i], + module: choices.module[j], + framework: choices.framework[k], + language: choices.language[m], + env: ["browser", "node"] + } + }); + } + } + } + } + + inputs.forEach(item => { + test(`${item.name}`, () => { + const generator = new ConfigGenerator({ cwd: esmProjectDir, answers: item.answers }); + + generator.calc(); + + expect(generator.result.configFilename).toBe("eslint.config.js"); + expect(generator.result).toMatchFileSnapshot(`./__snapshots__/${item.name}`); + }); + }); +}); + +describe("generate config for cjs projects", () => { + const cjsProjectDir = join(__filename, "../fixtures/cjs-project"); + const inputs = [{ + name: "style-esm-none-xo-javascript", + answers: { + purpose: "style", + module: "esm", + framework: "none", + language: "javascript", + env: ["node"], + styleguide: "eslint-config-xo" + } + }, + { + name: "style-esm-none-xo-typescript", + answers: { + purpose: "style", + module: "esm", + framework: "none", + language: "typescript", + env: ["browser"], + styleguide: "eslint-config-xo-typescript" + } + }]; + + inputs.forEach(item => { + test(`${item.name}`, () => { + const generator = new ConfigGenerator({ cwd: cjsProjectDir, answers: item.answers }); + + generator.calc(); + + expect(generator.result.configFilename).toBe("eslint.config.mjs"); + expect(generator.result).toMatchFileSnapshot(`./__snapshots__/${item.name}`); + }); + }); +}); diff --git a/tests/fixtures/cjs-project/package.json b/tests/fixtures/cjs-project/package.json new file mode 100644 index 00000000..24d28279 --- /dev/null +++ b/tests/fixtures/cjs-project/package.json @@ -0,0 +1,6 @@ +{ + "name": "esm", + "private": true, + "type": "commonjs", + "version": "1.0.0" +} diff --git a/tests/fixtures/esm-project/package.json b/tests/fixtures/esm-project/package.json new file mode 100644 index 00000000..1da57407 --- /dev/null +++ b/tests/fixtures/esm-project/package.json @@ -0,0 +1,6 @@ +{ + "name": "esm", + "private": true, + "type": "module", + "version": "1.0.0" +} diff --git a/tests/init/config-file.js b/tests/init/config-file.js deleted file mode 100644 index 64947291..00000000 --- a/tests/init/config-file.js +++ /dev/null @@ -1,145 +0,0 @@ -/** - * @fileoverview Tests for ConfigFile - * @author Nicholas C. Zakas - */ - - -//------------------------------------------------------------------------------ -// Requirements -//------------------------------------------------------------------------------ - -import sinon from "sinon"; -import path from "path"; -import yaml from "js-yaml"; -import * as espree from "espree"; -import * as ConfigFile from "../../lib/init/config-file.js"; -import nodeAssert from "assert"; -import esmock from "esmock"; - -//------------------------------------------------------------------------------ -// Helpers -//------------------------------------------------------------------------------ - -/** - * Helper function get easily get a path in the fixtures directory. - * @param {string} filepath The path to find in the fixtures directory. - * @returns {string} Full path in the fixtures directory. - * @private - */ -function getFixturePath(filepath) { - const dirname = path.dirname(new URL(import.meta.url).pathname); - - return path.resolve(dirname, "../../fixtures/config-file", filepath); -} - -//------------------------------------------------------------------------------ -// Tests -//------------------------------------------------------------------------------ - -describe("ConfigFile", () => { - describe("write()", () => { - let config; - - beforeEach(() => { - config = { - env: { - browser: true, - node: true - }, - rules: { - quotes: 2, - semi: 1 - } - }; - }); - - afterEach(() => { - sinon.verifyAndRestore(); - }); - - [ - ["JavaScript", "foo.js", espree.parse], - ["JSON", "bar.json", JSON.parse], - ["YAML", "foo.yaml", yaml.load], - ["YML", "foo.yml", yaml.load] - ].forEach(([fileType, filename, validate]) => { - - it(`should write a file through fs when a ${fileType} path is passed`, async () => { - const fakeFS = { - writeFileSync() {} - }; - - sinon.mock(fakeFS).expects("writeFileSync").withExactArgs( - filename, - sinon.match(value => !!validate(value)), - "utf8" - ); - - const StubbedConfigFile = await esmock("../../lib/init/config-file.js", { - fs: fakeFS - }); - - await StubbedConfigFile.write(config, filename); - }); - - it("should include a newline character at EOF", async () => { - const fakeFS = { - writeFileSync() {} - }; - - sinon.mock(fakeFS).expects("writeFileSync").withExactArgs( - filename, - sinon.match(value => value.endsWith("\n")), - "utf8" - ); - - const StubbedConfigFile = await esmock("../../lib/init/config-file.js", { - fs: fakeFS - }); - - await StubbedConfigFile.write(config, filename); - }); - }); - - it("should run 'eslint --fix' to make sure js config files match linting rules", async () => { - const fakeFS = { - writeFileSync() {} - }; - - const singleQuoteConfig = { - rules: { - quotes: [2, "single"] - } - }; - - sinon.mock(fakeFS).expects("writeFileSync").withExactArgs( - "test-config.js", - sinon.match.string, - "utf8" - ); - - const syncStub = sinon.fake(); - const StubbedConfigFile = await esmock("../../lib/init/config-file.js", { - fs: fakeFS, - "cross-spawn": { - default: { - sync: syncStub - } - } - }); - - StubbedConfigFile.write(singleQuoteConfig, "test-config.js"); - nodeAssert(syncStub.called); - nodeAssert(syncStub.calledWith( - sinon.match("eslint"), - sinon.match.array.contains(["--fix"]) - )); - }); - - it("should throw error if file extension is not valid", () => { - nodeAssert.rejects(async () => { - await ConfigFile.write({}, getFixturePath("yaml/.eslintrc.class")); - }, /write to unknown file type/u); - }); - }); -}); diff --git a/tests/init/config-initializer.js b/tests/init/config-initializer.js deleted file mode 100644 index 18261b2d..00000000 --- a/tests/init/config-initializer.js +++ /dev/null @@ -1,544 +0,0 @@ -/** - * @fileoverview Tests for configInitializer. - * @author Ilya Volodin - */ - - -//------------------------------------------------------------------------------ -// Requirements -//------------------------------------------------------------------------------ - -import chai from "chai"; -import fs from "fs"; -import path from "path"; -import sinon from "sinon"; -import sh from "shelljs"; -import esmock from "esmock"; -import { fileURLToPath } from "url"; -import * as npmUtils from "../../lib/init/npm-utils.js"; -import { defineInMemoryFs } from "../_utils/in-memory-fs.js"; - -const originalDir = process.cwd(); -const { assert } = chai; - -//------------------------------------------------------------------------------ -// Helpers -//------------------------------------------------------------------------------ - -let fixtureDir; -let localInstalledEslintDir; - -/** - * change local installed eslint version in fixtures - * @param {string|null} version installed eslint version, null => not installed - * @returns {void} - */ -function setLocalInstalledEslint(version) { - const eslintPkgPath = path.join(localInstalledEslintDir, "./package.json"); - let pkg = JSON.parse(fs.readFileSync(eslintPkgPath, "utf8")); - - if (version) { - pkg.version = version; - } else { - pkg = {}; - } - - fs.writeFileSync(eslintPkgPath, JSON.stringify(pkg, null, 2), "utf8"); -} - - -//------------------------------------------------------------------------------ -// Tests -//------------------------------------------------------------------------------ - -let answers = {}; -let pkgJSONContents = {}; -let pkgJSONPath = ""; - -describe("configInitializer", () => { - - let npmCheckStub; - let npmInstallStub; - let npmFetchPeerDependenciesStub; - let init; - let log; - - - // copy into clean area so as not to get "infected" by this project's .eslintrc files - before(() => { - const __filename = fileURLToPath(import.meta.url); // eslint-disable-line no-underscore-dangle -- Conventional - - fixtureDir = path.join(__filename, "../../../tmp/eslint/fixtures/config-initializer"); - localInstalledEslintDir = path.join(fixtureDir, "./node_modules/eslint"); - sh.mkdir("-p", localInstalledEslintDir); - sh.cp("-r", "./tests/fixtures/config-initializer/.", fixtureDir); - sh.cp("-r", "./tests/fixtures/eslint/.", localInstalledEslintDir); - fixtureDir = fs.realpathSync(fixtureDir); - }); - - beforeEach(async () => { - log = { - info: sinon.spy(), - error: sinon.spy() - }; - - npmInstallStub = sinon.stub(); - npmCheckStub = sinon.fake(packages => packages.reduce((status, pkg) => { - status[pkg] = false; - return status; - }, {})); - npmFetchPeerDependenciesStub = sinon.fake(() => ({ - eslint: "^3.19.0", - "eslint-plugin-jsx-a11y": "^5.0.1", - "eslint-plugin-import": "^2.2.0", - "eslint-plugin-react": "^7.0.1" - })); - - const requireStubs = { - "../../lib/shared/logging.js": log, - "../../lib/init/npm-utils.js": { - ...npmUtils, - installSyncSaveDev: npmInstallStub, - checkDevDeps: npmCheckStub, - fetchPeerDependencies: npmFetchPeerDependenciesStub - } - }; - - init = await esmock("../../lib/init/config-initializer.js", requireStubs, {}); - }); - - afterEach(() => { - log.info.resetHistory(); - log.error.resetHistory(); - npmInstallStub.resetHistory(); - npmCheckStub.resetHistory(); - npmFetchPeerDependenciesStub.resetHistory(); - }); - - after(() => { - sh.rm("-r", fixtureDir); - }); - - describe("processAnswers()", () => { - - describe("prompt", () => { - - beforeEach(() => { - answers = { - purpose: "style", - source: "prompt", - extendDefault: true, - indent: 2, - quotes: "single", - linebreak: "unix", - semi: true, - moduleType: "esm", - es6Globals: true, - env: ["browser"], - format: "JSON" - }; - }); - it("should throw error with message when no package.json", async () => { - const requireStubs = { - "../../lib/shared/logging.js": log, - "../../lib/init/npm-utils.js": { - ...await esmock("../../lib/init/npm-utils.js", { fs: defineInMemoryFs({}) }) - } - }; - - - init = await esmock("../../lib/init/config-initializer.js", requireStubs, { }); - - assert.throws(() => { - init.initializeConfig(); - }, "A package.json file is necessary to initialize ESLint. Run `npm init` to create a package.json file and try again."); - }); - - it("should create default config", () => { - const config = init.processAnswers(answers); - - assert.deepStrictEqual(config.rules.indent, ["error", 2]); - assert.deepStrictEqual(config.rules.quotes, ["error", "single"]); - assert.deepStrictEqual(config.rules["linebreak-style"], ["error", "unix"]); - assert.deepStrictEqual(config.rules.semi, ["error", "always"]); - assert.strictEqual(config.env.es2021, true); - assert.strictEqual(config.parserOptions.ecmaVersion, "latest"); - assert.strictEqual(config.parserOptions.sourceType, "module"); - assert.strictEqual(config.env.browser, true); - assert.strictEqual(config.extends, "eslint:recommended"); - }); - - it("should disable semi", () => { - answers.semi = false; - const config = init.processAnswers(answers); - - assert.deepStrictEqual(config.rules.semi, ["error", "never"]); - }); - - it("should enable react plugin", () => { - answers.framework = "react"; - const config = init.processAnswers(answers); - - assert.strictEqual(config.parserOptions.ecmaVersion, "latest"); - assert.deepStrictEqual(config.plugins, ["react"]); - assert.include(config.extends, "plugin:react/recommended"); - }); - - it("should enable vue plugin", () => { - answers.framework = "vue"; - const config = init.processAnswers(answers); - - assert.strictEqual(config.parserOptions.ecmaVersion, "latest"); - assert.deepStrictEqual(config.plugins, ["vue"]); - assert.deepStrictEqual(config.extends, ["eslint:recommended", "plugin:vue/vue3-essential"]); - }); - - it("should enable typescript parser and plugin", () => { - answers.typescript = true; - const config = init.processAnswers(answers); - - assert.strictEqual(config.parser, "@typescript-eslint/parser"); - assert.deepStrictEqual(config.plugins, ["@typescript-eslint"]); - assert.deepStrictEqual(config.extends, ["eslint:recommended", "plugin:@typescript-eslint/recommended"]); - }); - - it("should enable typescript parser and plugin with vue", () => { - answers.framework = "vue"; - answers.typescript = true; - const config = init.processAnswers(answers); - - assert.include(config.parserOptions, { parser: "@typescript-eslint/parser" }); - assert.deepStrictEqual(config.extends, ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:vue/vue3-essential"]); - assert.deepStrictEqual(config.plugins, ["@typescript-eslint", "vue"]); - }); - - it("should extend eslint:recommended", () => { - const config = init.processAnswers(answers); - - assert.strictEqual(config.extends, "eslint:recommended"); - }); - - it("should not use commonjs by default", () => { - const config = init.processAnswers(answers); - - assert.isUndefined(config.env.commonjs); - }); - - it("should use commonjs when set", () => { - answers.moduleType = "commonjs"; - const config = init.processAnswers(answers); - - assert.isTrue(config.env.commonjs); - }); - - it("should set commonjs config for `.eslintrc.cjs` in esm projects", () => { - answers.moduleType = "esm"; - answers.format = "JavaScript"; - const config = init.processAnswers(answers); - - assert.isArray(config.overrides, "should have overrides config"); - assert.strictEqual(config.overrides.length, 1); - assert.deepStrictEqual(config.overrides[0].parserOptions, { sourceType: "script" }); - assert.deepStrictEqual(config.overrides[0].env, { node: true }); - }); - - }); - - describe("guide", () => { - it("should support the google style guide", () => { - const config = { extends: "google" }; - const modules = init.getModulesList(config); - - assert.deepStrictEqual(config, { extends: "google", installedESLint: true }); - assert.include(modules, "eslint-config-google@latest"); - }); - - it("should support the airbnb style guide", () => { - const config = { extends: "airbnb" }; - const modules = init.getModulesList(config); - - assert.deepStrictEqual(config, { extends: "airbnb", installedESLint: true }); - assert.include(modules, "eslint-config-airbnb@latest"); - }); - - it("should support the airbnb base style guide", () => { - const config = { extends: "airbnb-base" }; - const modules = init.getModulesList(config); - - assert.deepStrictEqual(config, { extends: "airbnb-base", installedESLint: true }); - assert.include(modules, "eslint-config-airbnb-base@latest"); - }); - - it("should support the standard style guide", () => { - const config = { extends: "standard" }; - const modules = init.getModulesList(config); - - assert.deepStrictEqual(config, { extends: "standard", installedESLint: true }); - assert.include(modules, "eslint-config-standard@latest"); - }); - - it("should support the xo style guide", () => { - const config = { extends: "xo" }; - const modules = init.getModulesList(config); - - assert.deepStrictEqual(config, { extends: "xo", installedESLint: true }); - assert.include(modules, "eslint-config-xo@latest"); - }); - - it("should support the xo-typescript style guide", () => { - const config = { extends: "xo", overrides: [{ files: ["*.ts"], extends: ["xo-typescript"] }] }; - const modules = init.getModulesList(config); - - assert.deepStrictEqual(config.extends, "xo"); - assert.deepStrictEqual(config.overrides[0].extends[0], "xo-typescript"); - assert.strictEqual(config.installedESLint, true); - assert.include(modules, "eslint-config-xo@latest"); - assert.include(modules, "eslint-config-xo-typescript@latest"); - }); - - it("should install required sharable config", () => { - const config = { extends: "google" }; - - init.installModules(init.getModulesList(config)); - assert(npmInstallStub.calledOnce); - assert(npmInstallStub.firstCall.args[0].some(name => name.startsWith("eslint-config-google@"))); - }); - - it("should install ESLint if not installed locally", () => { - const config = { extends: "google" }; - - init.installModules(init.getModulesList(config)); - assert(npmInstallStub.calledOnce); - assert(npmInstallStub.firstCall.args[0].some(name => name.startsWith("eslint@"))); - }); - - it("should install peerDependencies of the sharable config", () => { - const config = { extends: "airbnb" }; - - init.installModules(init.getModulesList(config)); - - assert(npmFetchPeerDependenciesStub.calledOnce); - assert(npmFetchPeerDependenciesStub.firstCall.args[0] === "eslint-config-airbnb@latest"); - assert(npmInstallStub.calledOnce); - assert.deepStrictEqual( - npmInstallStub.firstCall.args[0], - [ - "eslint-config-airbnb@latest", - "eslint@^3.19.0", - "eslint-plugin-jsx-a11y@^5.0.1", - "eslint-plugin-import@^2.2.0", - "eslint-plugin-react@^7.0.1" - ] - ); - }); - - describe('hasESLintVersionConflict (Note: peerDependencies always `eslint: "^3.19.0"` by stubs)', () => { - - before(() => { - - // FIX: not sure why it was changed somewhere??? - process.chdir(fixtureDir); - }); - - describe("if local ESLint is not found,", () => { - before(() => { - setLocalInstalledEslint(null); - }); - - it("should return false.", () => { - const result = init.hasESLintVersionConflict({ styleguide: "airbnb" }); - - assert.strictEqual(result, false); - }); - }); - - describe("if local ESLint is 3.19.0,", () => { - before(() => { - setLocalInstalledEslint("3.19.0"); - }); - - it("should return false.", () => { - const result = init.hasESLintVersionConflict({ styleguide: "airbnb" }); - - assert.strictEqual(result, false); - }); - }); - - describe("if local ESLint is 4.0.0,", () => { - before(() => { - setLocalInstalledEslint("4.0.0"); - }); - - it("should return true.", () => { - const result = init.hasESLintVersionConflict({ styleguide: "airbnb" }); - - assert.strictEqual(result, true); - }); - }); - - describe("if local ESLint is 3.18.0,", () => { - before(() => { - setLocalInstalledEslint("3.18.0"); - }); - - it("should return true.", () => { - const result = init.hasESLintVersionConflict({ styleguide: "airbnb" }); - - assert.strictEqual(result, true); - }); - }); - }); - - it("should support the standard style guide with Vue.js", () => { - const config = { - plugins: ["vue"], - extends: ["plugin:vue/vue3-essential", "standard"] - }; - const modules = init.getModulesList(config); - - assert.include(modules, "eslint-plugin-vue@latest"); - assert.include(modules, "eslint-config-standard@latest"); - }); - - it("should support custom parser", () => { - const config = { - parser: "@typescript-eslint/parser" - }; - const modules = init.getModulesList(config); - - assert.include(modules, "@typescript-eslint/parser@latest"); - }); - - it("should support custom parser with Vue.js", () => { - const config = { - - // We should declare the parser at `parserOptions` when using with `eslint-plugin-vue`. - parserOptions: { - parser: "@typescript-eslint/parser" - } - }; - const modules = init.getModulesList(config); - - assert.include(modules, "@typescript-eslint/parser@latest"); - }); - }); - - }); - - describe("writeFile()", () => { - - beforeEach(() => { - answers = { - purpose: "style", - source: "prompt", - extendDefault: true, - indent: 2, - quotes: "single", - linebreak: "unix", - semi: true, - moduleType: "esm", - es6Globals: true, - env: ["browser"], - format: "JSON" - }; - - pkgJSONContents = { - name: "config-initializer", - version: "1.0.0" - }; - - process.chdir(fixtureDir); - - pkgJSONPath = path.resolve(fixtureDir, "package.json"); - }); - - afterEach(() => { - process.chdir(originalDir); - }); - - it("should create .eslintrc.json", () => { - const config = init.processAnswers(answers); - const filePath = path.resolve(fixtureDir, ".eslintrc.json"); - - fs.writeFileSync(pkgJSONPath, JSON.stringify(pkgJSONContents)); - - init.writeFile(config, answers.format); - - assert.isTrue(fs.existsSync(filePath)); - - fs.unlinkSync(filePath); - fs.unlinkSync(pkgJSONPath); - }); - - it("should create .eslintrc.js", async () => { - answers.format = "JavaScript"; - - const config = init.processAnswers(answers); - const filePath = path.resolve(fixtureDir, ".eslintrc.js"); - - fs.writeFileSync(pkgJSONPath, JSON.stringify(pkgJSONContents)); - - await init.writeFile(config, answers.format); - - assert.isTrue(fs.existsSync(filePath)); - - fs.unlinkSync(filePath); - fs.unlinkSync(pkgJSONPath); - }); - - it("should create .eslintrc.yml", async () => { - answers.format = "YAML"; - - const config = init.processAnswers(answers); - const filePath = path.resolve(fixtureDir, ".eslintrc.yml"); - - fs.writeFileSync(pkgJSONPath, JSON.stringify(pkgJSONContents)); - - await init.writeFile(config, answers.format); - - assert.isTrue(fs.existsSync(filePath)); - - fs.unlinkSync(filePath); - fs.unlinkSync(pkgJSONPath); - }); - - // For https://github.com/eslint/eslint/issues/14137 - it("should create .eslintrc.cjs", async () => { - answers.format = "JavaScript"; - - // create package.json with "type": "module" - pkgJSONContents.type = "module"; - - fs.writeFileSync(pkgJSONPath, JSON.stringify(pkgJSONContents)); - - const config = init.processAnswers(answers); - const filePath = path.resolve(fixtureDir, ".eslintrc.cjs"); - - await init.writeFile(config, answers.format); - - assert.isTrue(fs.existsSync(filePath)); - - fs.unlinkSync(filePath); - fs.unlinkSync(pkgJSONPath); - }); - - it("should create .eslintrc.json even with type: 'module'", async () => { - answers.format = "JSON"; - - // create package.json with "type": "module" - pkgJSONContents.type = "module"; - - fs.writeFileSync(pkgJSONPath, JSON.stringify(pkgJSONContents)); - - const config = init.processAnswers(answers); - const filePath = path.resolve(fixtureDir, ".eslintrc.json"); - - await init.writeFile(config, answers.format); - - assert.isTrue(fs.existsSync(filePath)); - - fs.unlinkSync(filePath); - fs.unlinkSync(pkgJSONPath); - }); - }); -}); diff --git a/tests/init/npm-utils.js b/tests/utils/npm-utils.spec.js similarity index 93% rename from tests/init/npm-utils.js rename to tests/utils/npm-utils.spec.js index d7b72ca1..2899fc98 100644 --- a/tests/init/npm-utils.js +++ b/tests/utils/npm-utils.spec.js @@ -1,14 +1,12 @@ /** - * @fileoverview Tests for rule fixer. - * @author Ian VanSchooten + * @fileoverview Tests for npm-utils. + * @author Ian VanSchooten, 唯然 */ - //------------------------------------------------------------------------------ // Requirements //------------------------------------------------------------------------------ -import chai from "chai"; import spawn from "cross-spawn"; import sinon from "sinon"; import { @@ -16,11 +14,10 @@ import { fetchPeerDependencies, checkDeps, checkDevDeps -} from "../../lib/init/npm-utils.js"; +} from "../../lib/utils/npm-utils.js"; import { defineInMemoryFs } from "../_utils/in-memory-fs.js"; import esmock from "esmock"; - -const { assert } = chai; +import { assert, describe, afterEach, it } from "vitest"; //------------------------------------------------------------------------------ // Helpers @@ -34,7 +31,7 @@ const { assert } = chai; async function requireNpmUtilsWithInMemoryFileSystem(files) { const fs = defineInMemoryFs({ files }); - return await esmock("../../lib/init/npm-utils.js", { fs }); + return await esmock("../../lib/utils/npm-utils.js", { fs }); } //------------------------------------------------------------------------------ @@ -47,11 +44,7 @@ describe("npmUtils", () => { }); describe("checkDevDeps()", () => { - let installStatus; - - before(() => { - installStatus = checkDevDeps(["debug", "mocha", "notarealpackage", "jshint"]); - }); + let installStatus = checkDevDeps(["debug", "mocha", "notarealpackage", "jshint"]); it("should not find a direct dependency of the project", () => { assert.isFalse(installStatus.debug); @@ -95,11 +88,7 @@ describe("npmUtils", () => { }); describe("checkDeps()", () => { - let installStatus; - - before(() => { - installStatus = checkDeps(["debug", "mocha", "notarealpackage", "jshint"]); - }); + let installStatus = checkDeps(["debug", "mocha", "notarealpackage", "jshint"]); it("should find a direct dependency of the project", () => { assert.isTrue(installStatus.debug); @@ -200,8 +189,8 @@ describe("npmUtils", () => { const logErrorStub = sinon.spy(); const npmUtilsStub = sinon.stub(spawn, "sync").returns({ error: { code: "ENOENT" } }); - const { installSyncSaveDev: stubinstallSyncSaveDev } = await esmock("../../lib/init/npm-utils.js", { - "../../lib/shared/logging.js": { + const { installSyncSaveDev: stubinstallSyncSaveDev } = await esmock("../../lib/utils/npm-utils.js", { + "../../lib/utils/logging.js": { error: logErrorStub } }); From fcde6c35e07c05c2caa318e67e67a17966591f45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Wed, 28 Feb 2024 16:19:46 +0800 Subject: [PATCH 02/41] fix: do not support multi configs it's still needed in some rare cases, but need a few more refactor --- lib/config-generator.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/config-generator.js b/lib/config-generator.js index 4e7b43e8..a8b4c3d6 100644 --- a/lib/config-generator.js +++ b/lib/config-generator.js @@ -114,7 +114,7 @@ export class ConfigGenerator { ]; const tsStyleGuides = [ { message: "Standard: https://github.com/standard/eslint-config-standard-with-typescript", name: "standard", value: { packageName: "eslint-config-standard-with-typescript", type: "eslintrc" } }, - { message: "XO: https://github.com/xojs/eslint-config-xo-typescript", name: "xo", value: { packageName: ["eslint-config-xo", "eslint-config-xo-typescript"], type: "eslintrc" } } + { message: "XO: https://github.com/xojs/eslint-config-xo-typescript", name: "xo", value: { packageName: "eslint-config-xo-typescript", type: "eslintrc" } } ]; const choices = this.answers.language === "javascript" ? jsStyleGuides : tsStyleGuides; const styleguideAnswer = await enquirer.prompt({ @@ -169,12 +169,9 @@ export class ConfigGenerator { importContent += "import path from \"path\";\nimport { fileURLToPath } from \"url\"\n;import { FlatCompat } from \"@eslint/eslintrc\";\n"; helperContent ||= "// mimic CommonJS variables -- not needed if using CommonJS\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\nconst compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended});\n"; - const extended = Array.isArray(this.answers.styleguide.packageName) - ? this.answers.styleguide.packageName - : [this.answers.styleguide.packageName]; - const extendedNames = extended.map(it => it.replace("eslint-config-", "")); + const extendedName = this.answers.styleguide.packageName.replace("eslint-config-", ""); - exportContent += ` compat.extends("${extendedNames.join(", ")}"),\n`; + exportContent += ` compat.extends("${extendedName}"),\n`; } } From 8ddf82a3d519e5f333d22e594bd2f1de6ada4172 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Wed, 28 Feb 2024 16:40:10 +0800 Subject: [PATCH 03/41] fix: helpercontent --- lib/config-generator.js | 19 +++++++++++++------ .../problem-commonjs-vue-javascript | 4 ++++ .../problem-commonjs-vue-typescript | 4 ++++ .../__snapshots__/problem-esm-vue-javascript | 4 ++++ .../__snapshots__/problem-esm-vue-typescript | 4 ++++ .../problem-script-vue-javascript | 4 ++++ .../problem-script-vue-typescript | 4 ++++ .../syntax-commonjs-vue-javascript | 4 ++++ .../syntax-commonjs-vue-typescript | 4 ++++ tests/__snapshots__/syntax-esm-vue-javascript | 4 ++++ tests/__snapshots__/syntax-esm-vue-typescript | 4 ++++ .../syntax-script-vue-javascript | 4 ++++ .../syntax-script-vue-typescript | 4 ++++ 13 files changed, 61 insertions(+), 6 deletions(-) diff --git a/lib/config-generator.js b/lib/config-generator.js index a8b4c3d6..a928f3fe 100644 --- a/lib/config-generator.js +++ b/lib/config-generator.js @@ -139,9 +139,18 @@ export class ConfigGenerator { this.result.configFilename = isModule ? "eslint.config.js" : "eslint.config.mjs"; let importContent = ""; - let helperContent = ""; + const helperContent = `import path from "path"; +import { fileURLToPath } from "url"; +import { FlatCompat } from "@eslint/eslintrc"; + +// mimic CommonJS variables -- not needed if using CommonJS +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); +const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); +`; let exportContent = ""; let languageOptionsContent = ""; + let needCompatHelper = false; if (this.answers.purpose === "syntax") { @@ -166,8 +175,7 @@ export class ConfigGenerator { } else if (this.answers.styleguide.type === "eslintrc") { importContent += "import pluginJs from \"@eslint/js\";\n"; - importContent += "import path from \"path\";\nimport { fileURLToPath } from \"url\"\n;import { FlatCompat } from \"@eslint/eslintrc\";\n"; - helperContent ||= "// mimic CommonJS variables -- not needed if using CommonJS\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\nconst compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended});\n"; + needCompatHelper = true; const extendedName = this.answers.styleguide.packageName.replace("eslint-config-", ""); @@ -205,8 +213,7 @@ export class ConfigGenerator { // // TODO: there is a wip for flat support - https://github.com/vuejs/eslint-plugin-vue/pull/2319 // exportContent += " pluginVue.configs[\"flat/essential\"],\n"; - - helperContent ||= "// mimic CommonJS variables -- not needed if using CommonJS\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\nconst compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended});\n"; + needCompatHelper = true; exportContent += " compat.extends(\"plugin:vue/vue3-essential\").map(config => ({files: [\"**/*.vue\"], ...config})),\n"; } @@ -216,7 +223,7 @@ export class ConfigGenerator { exportContent += " pluginReactConfig,\n"; } - this.result.configContent = `${importContent}\n${helperContent}\nexport default [].concat(\n { languageOptions: {${languageOptionsContent}}},\n${exportContent});`; + this.result.configContent = `${importContent}\n${needCompatHelper ? helperContent : ""}\nexport default [].concat(\n { languageOptions: {${languageOptionsContent}}},\n${exportContent});`; } /** diff --git a/tests/__snapshots__/problem-commonjs-vue-javascript b/tests/__snapshots__/problem-commonjs-vue-javascript index 5a80ccef..869ed16f 100644 --- a/tests/__snapshots__/problem-commonjs-vue-javascript +++ b/tests/__snapshots__/problem-commonjs-vue-javascript @@ -2,6 +2,10 @@ "configContent": "import pluginJs from "@eslint/js"; import globals from "globals"; +import path from "path"; +import { fileURLToPath } from "url"; +import { FlatCompat } from "@eslint/eslintrc"; + // mimic CommonJS variables -- not needed if using CommonJS const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); diff --git a/tests/__snapshots__/problem-commonjs-vue-typescript b/tests/__snapshots__/problem-commonjs-vue-typescript index a8c1c96b..9fc2fb4d 100644 --- a/tests/__snapshots__/problem-commonjs-vue-typescript +++ b/tests/__snapshots__/problem-commonjs-vue-typescript @@ -3,6 +3,10 @@ import globals from "globals"; import tseslint from "typescript-eslint"; +import path from "path"; +import { fileURLToPath } from "url"; +import { FlatCompat } from "@eslint/eslintrc"; + // mimic CommonJS variables -- not needed if using CommonJS const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); diff --git a/tests/__snapshots__/problem-esm-vue-javascript b/tests/__snapshots__/problem-esm-vue-javascript index 0590b838..5fd9f0bd 100644 --- a/tests/__snapshots__/problem-esm-vue-javascript +++ b/tests/__snapshots__/problem-esm-vue-javascript @@ -2,6 +2,10 @@ "configContent": "import pluginJs from "@eslint/js"; import globals from "globals"; +import path from "path"; +import { fileURLToPath } from "url"; +import { FlatCompat } from "@eslint/eslintrc"; + // mimic CommonJS variables -- not needed if using CommonJS const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); diff --git a/tests/__snapshots__/problem-esm-vue-typescript b/tests/__snapshots__/problem-esm-vue-typescript index f2eee593..00dce4a5 100644 --- a/tests/__snapshots__/problem-esm-vue-typescript +++ b/tests/__snapshots__/problem-esm-vue-typescript @@ -3,6 +3,10 @@ import globals from "globals"; import tseslint from "typescript-eslint"; +import path from "path"; +import { fileURLToPath } from "url"; +import { FlatCompat } from "@eslint/eslintrc"; + // mimic CommonJS variables -- not needed if using CommonJS const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); diff --git a/tests/__snapshots__/problem-script-vue-javascript b/tests/__snapshots__/problem-script-vue-javascript index 0590b838..5fd9f0bd 100644 --- a/tests/__snapshots__/problem-script-vue-javascript +++ b/tests/__snapshots__/problem-script-vue-javascript @@ -2,6 +2,10 @@ "configContent": "import pluginJs from "@eslint/js"; import globals from "globals"; +import path from "path"; +import { fileURLToPath } from "url"; +import { FlatCompat } from "@eslint/eslintrc"; + // mimic CommonJS variables -- not needed if using CommonJS const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); diff --git a/tests/__snapshots__/problem-script-vue-typescript b/tests/__snapshots__/problem-script-vue-typescript index f2eee593..00dce4a5 100644 --- a/tests/__snapshots__/problem-script-vue-typescript +++ b/tests/__snapshots__/problem-script-vue-typescript @@ -3,6 +3,10 @@ import globals from "globals"; import tseslint from "typescript-eslint"; +import path from "path"; +import { fileURLToPath } from "url"; +import { FlatCompat } from "@eslint/eslintrc"; + // mimic CommonJS variables -- not needed if using CommonJS const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); diff --git a/tests/__snapshots__/syntax-commonjs-vue-javascript b/tests/__snapshots__/syntax-commonjs-vue-javascript index 8d49271a..2beb9ca5 100644 --- a/tests/__snapshots__/syntax-commonjs-vue-javascript +++ b/tests/__snapshots__/syntax-commonjs-vue-javascript @@ -1,6 +1,10 @@ { "configContent": "import globals from "globals"; +import path from "path"; +import { fileURLToPath } from "url"; +import { FlatCompat } from "@eslint/eslintrc"; + // mimic CommonJS variables -- not needed if using CommonJS const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); diff --git a/tests/__snapshots__/syntax-commonjs-vue-typescript b/tests/__snapshots__/syntax-commonjs-vue-typescript index a2d64e3f..b38ea43e 100644 --- a/tests/__snapshots__/syntax-commonjs-vue-typescript +++ b/tests/__snapshots__/syntax-commonjs-vue-typescript @@ -2,6 +2,10 @@ "configContent": "import globals from "globals"; import tseslint from "typescript-eslint"; +import path from "path"; +import { fileURLToPath } from "url"; +import { FlatCompat } from "@eslint/eslintrc"; + // mimic CommonJS variables -- not needed if using CommonJS const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); diff --git a/tests/__snapshots__/syntax-esm-vue-javascript b/tests/__snapshots__/syntax-esm-vue-javascript index dd729a12..13eaa1ee 100644 --- a/tests/__snapshots__/syntax-esm-vue-javascript +++ b/tests/__snapshots__/syntax-esm-vue-javascript @@ -1,6 +1,10 @@ { "configContent": "import globals from "globals"; +import path from "path"; +import { fileURLToPath } from "url"; +import { FlatCompat } from "@eslint/eslintrc"; + // mimic CommonJS variables -- not needed if using CommonJS const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); diff --git a/tests/__snapshots__/syntax-esm-vue-typescript b/tests/__snapshots__/syntax-esm-vue-typescript index 2ad55884..f729af52 100644 --- a/tests/__snapshots__/syntax-esm-vue-typescript +++ b/tests/__snapshots__/syntax-esm-vue-typescript @@ -2,6 +2,10 @@ "configContent": "import globals from "globals"; import tseslint from "typescript-eslint"; +import path from "path"; +import { fileURLToPath } from "url"; +import { FlatCompat } from "@eslint/eslintrc"; + // mimic CommonJS variables -- not needed if using CommonJS const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); diff --git a/tests/__snapshots__/syntax-script-vue-javascript b/tests/__snapshots__/syntax-script-vue-javascript index dd729a12..13eaa1ee 100644 --- a/tests/__snapshots__/syntax-script-vue-javascript +++ b/tests/__snapshots__/syntax-script-vue-javascript @@ -1,6 +1,10 @@ { "configContent": "import globals from "globals"; +import path from "path"; +import { fileURLToPath } from "url"; +import { FlatCompat } from "@eslint/eslintrc"; + // mimic CommonJS variables -- not needed if using CommonJS const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); diff --git a/tests/__snapshots__/syntax-script-vue-typescript b/tests/__snapshots__/syntax-script-vue-typescript index 2ad55884..f729af52 100644 --- a/tests/__snapshots__/syntax-script-vue-typescript +++ b/tests/__snapshots__/syntax-script-vue-typescript @@ -2,6 +2,10 @@ "configContent": "import globals from "globals"; import tseslint from "typescript-eslint"; +import path from "path"; +import { fileURLToPath } from "url"; +import { FlatCompat } from "@eslint/eslintrc"; + // mimic CommonJS variables -- not needed if using CommonJS const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); From 1199d6e969a30e26865aa3bba240e54a6fd1db69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Wed, 28 Feb 2024 16:43:14 +0800 Subject: [PATCH 04/41] fix: review suggestions --- .editorconfig | 8 ----- lib/config-generator.js | 29 ++++++++++--------- lib/utils/npm-utils.js | 6 ++-- .../problem-commonjs-none-javascript | 2 +- .../problem-commonjs-none-typescript | 2 +- .../problem-commonjs-react-javascript | 2 +- .../problem-commonjs-react-typescript | 2 +- .../problem-commonjs-vue-javascript | 2 +- .../problem-commonjs-vue-typescript | 2 +- .../__snapshots__/problem-esm-none-javascript | 2 +- .../__snapshots__/problem-esm-none-typescript | 2 +- .../problem-esm-react-javascript | 2 +- .../problem-esm-react-typescript | 2 +- .../__snapshots__/problem-esm-vue-javascript | 2 +- .../__snapshots__/problem-esm-vue-typescript | 2 +- .../problem-script-none-javascript | 2 +- .../problem-script-none-typescript | 2 +- .../problem-script-react-javascript | 2 +- .../problem-script-react-typescript | 2 +- .../problem-script-vue-javascript | 2 +- .../problem-script-vue-typescript | 2 +- .../style-esm-none-xo-javascript | 2 +- .../style-esm-none-xo-typescript | 2 +- .../syntax-commonjs-none-javascript | 2 +- .../syntax-commonjs-none-typescript | 2 +- .../syntax-commonjs-react-javascript | 2 +- .../syntax-commonjs-react-typescript | 2 +- .../syntax-commonjs-vue-javascript | 2 +- .../syntax-commonjs-vue-typescript | 2 +- .../__snapshots__/syntax-esm-none-javascript | 2 +- .../__snapshots__/syntax-esm-none-typescript | 2 +- .../__snapshots__/syntax-esm-react-javascript | 2 +- .../__snapshots__/syntax-esm-react-typescript | 2 +- tests/__snapshots__/syntax-esm-vue-javascript | 2 +- tests/__snapshots__/syntax-esm-vue-typescript | 2 +- .../syntax-script-none-javascript | 2 +- .../syntax-script-none-typescript | 2 +- .../syntax-script-react-javascript | 2 +- .../syntax-script-react-typescript | 2 +- .../syntax-script-vue-javascript | 2 +- .../syntax-script-vue-typescript | 2 +- 41 files changed, 56 insertions(+), 63 deletions(-) delete mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 2e62126f..00000000 --- a/.editorconfig +++ /dev/null @@ -1,8 +0,0 @@ -root = true - -[*] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true -end_of_line = lf -insert_final_newline = true diff --git a/lib/config-generator.js b/lib/config-generator.js index a928f3fe..47c95532 100644 --- a/lib/config-generator.js +++ b/lib/config-generator.js @@ -10,6 +10,17 @@ import enquirer from "enquirer"; import { isPackageTypeModule, installSyncSaveDev, checkPackageJson, fetchPeerDependencies } from "./utils/npm-utils.js"; import * as log from "./utils/logging.js"; +// TODO: need to specify the package version - they may export flat configs in the future. +const jsStyleGuides = [ + { message: "Airbnb: https://github.com/airbnb/javascript", name: "airbnb", value: { packageName: "eslint-config-airbnb", type: "eslintrc" } }, + { message: "Standard: https://github.com/standard/standard", name: "standard", value: { packageName: "eslint-config-standard", type: "eslintrc" } }, + { message: "XO: https://github.com/xojs/eslint-config-xo", name: "xo", value: { packageName: "eslint-config-xo", type: "eslintrc" } } +]; +const tsStyleGuides = [ + { message: "Standard: https://github.com/standard/eslint-config-standard-with-typescript", name: "standard", value: { packageName: "eslint-config-standard-with-typescript", type: "eslintrc" } }, + { message: "XO: https://github.com/xojs/eslint-config-xo-typescript", name: "xo", value: { packageName: "eslint-config-xo-typescript", type: "eslintrc" } } +]; + /** * Class representing a ConfigGenerator. */ @@ -105,17 +116,6 @@ export class ConfigGenerator { Object.assign(this.answers, answers); if (answers.purpose === "style") { - - // TODO: need to specify the package version - they may export flat configs in the future. - const jsStyleGuides = [ - { message: "Airbnb: https://github.com/airbnb/javascript", name: "airbnb", value: { packageName: "eslint-config-airbnb", type: "eslintrc" } }, - { message: "Standard: https://github.com/standard/standard", name: "standard", value: { packageName: "eslint-config-standard", type: "eslintrc" } }, - { message: "XO: https://github.com/xojs/eslint-config-xo", name: "xo", value: { packageName: "eslint-config-xo", type: "eslintrc" } } - ]; - const tsStyleGuides = [ - { message: "Standard: https://github.com/standard/eslint-config-standard-with-typescript", name: "standard", value: { packageName: "eslint-config-standard-with-typescript", type: "eslintrc" } }, - { message: "XO: https://github.com/xojs/eslint-config-xo-typescript", name: "xo", value: { packageName: "eslint-config-xo-typescript", type: "eslintrc" } } - ]; const choices = this.answers.language === "javascript" ? jsStyleGuides : tsStyleGuides; const styleguideAnswer = await enquirer.prompt({ type: "select", @@ -134,9 +134,9 @@ export class ConfigGenerator { * @returns {void} */ calc() { - const isModule = isPackageTypeModule(this.cwd); + const isESMModule = isPackageTypeModule(this.cwd); - this.result.configFilename = isModule ? "eslint.config.js" : "eslint.config.mjs"; + this.result.configFilename = isESMModule ? "eslint.config.js" : "eslint.config.mjs"; let importContent = ""; const helperContent = `import path from "path"; @@ -223,7 +223,8 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug exportContent += " pluginReactConfig,\n"; } - this.result.configContent = `${importContent}\n${needCompatHelper ? helperContent : ""}\nexport default [].concat(\n { languageOptions: {${languageOptionsContent}}},\n${exportContent});`; + this.result.configContent = `${importContent}\n${needCompatHelper ? helperContent : ""} +export default [].concat(\n { languageOptions: {${languageOptionsContent}}},\n ${exportContent});`; } /** diff --git a/lib/utils/npm-utils.js b/lib/utils/npm-utils.js index d3806e9c..93256e1e 100644 --- a/lib/utils/npm-utils.js +++ b/lib/utils/npm-utils.js @@ -84,13 +84,13 @@ function fetchPeerDependencies(packageName) { const fetchedText = npmProcess.stdout.trim(); const peers = JSON.parse(fetchedText || "{}"); - const ret = []; + const dependencies = []; Object.keys(peers).forEach(pkgName => { - ret.push(`${pkgName}@${peers[pkgName]}`); + dependencies.push(`${pkgName}@${peers[pkgName]}`); }); - return ret; + return dependencies; } /** diff --git a/tests/__snapshots__/problem-commonjs-none-javascript b/tests/__snapshots__/problem-commonjs-none-javascript index f544f93e..afe65c07 100644 --- a/tests/__snapshots__/problem-commonjs-none-javascript +++ b/tests/__snapshots__/problem-commonjs-none-javascript @@ -5,7 +5,7 @@ import globals from "globals"; export default [].concat( { languageOptions: {sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, - pluginJs.configs.recommended, + pluginJs.configs.recommended, );", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/problem-commonjs-none-typescript b/tests/__snapshots__/problem-commonjs-none-typescript index a8d18870..d07fdc88 100644 --- a/tests/__snapshots__/problem-commonjs-none-typescript +++ b/tests/__snapshots__/problem-commonjs-none-typescript @@ -6,7 +6,7 @@ import tseslint from "typescript-eslint"; export default [].concat( { languageOptions: {sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, - pluginJs.configs.recommended, + pluginJs.configs.recommended, tseslint.configs.recommended, );", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/problem-commonjs-react-javascript b/tests/__snapshots__/problem-commonjs-react-javascript index 6b42fb14..7a1242fd 100644 --- a/tests/__snapshots__/problem-commonjs-react-javascript +++ b/tests/__snapshots__/problem-commonjs-react-javascript @@ -6,7 +6,7 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [].concat( { languageOptions: {sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, - pluginJs.configs.recommended, + pluginJs.configs.recommended, pluginReactConfig, );", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/problem-commonjs-react-typescript b/tests/__snapshots__/problem-commonjs-react-typescript index 0e874dc5..75f23a56 100644 --- a/tests/__snapshots__/problem-commonjs-react-typescript +++ b/tests/__snapshots__/problem-commonjs-react-typescript @@ -7,7 +7,7 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [].concat( { languageOptions: {sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, - pluginJs.configs.recommended, + pluginJs.configs.recommended, tseslint.configs.recommended, pluginReactConfig, );", diff --git a/tests/__snapshots__/problem-commonjs-vue-javascript b/tests/__snapshots__/problem-commonjs-vue-javascript index 869ed16f..e5456f03 100644 --- a/tests/__snapshots__/problem-commonjs-vue-javascript +++ b/tests/__snapshots__/problem-commonjs-vue-javascript @@ -13,7 +13,7 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug export default [].concat( { languageOptions: {sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, - pluginJs.configs.recommended, + pluginJs.configs.recommended, compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), );", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/problem-commonjs-vue-typescript b/tests/__snapshots__/problem-commonjs-vue-typescript index 9fc2fb4d..cc84d930 100644 --- a/tests/__snapshots__/problem-commonjs-vue-typescript +++ b/tests/__snapshots__/problem-commonjs-vue-typescript @@ -14,7 +14,7 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug export default [].concat( { languageOptions: {sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, - pluginJs.configs.recommended, + pluginJs.configs.recommended, tseslint.configs.recommended, compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), );", diff --git a/tests/__snapshots__/problem-esm-none-javascript b/tests/__snapshots__/problem-esm-none-javascript index db91a232..d825c38d 100644 --- a/tests/__snapshots__/problem-esm-none-javascript +++ b/tests/__snapshots__/problem-esm-none-javascript @@ -5,7 +5,7 @@ import globals from "globals"; export default [].concat( { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, - pluginJs.configs.recommended, + pluginJs.configs.recommended, );", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/problem-esm-none-typescript b/tests/__snapshots__/problem-esm-none-typescript index 5526b413..4379fcb6 100644 --- a/tests/__snapshots__/problem-esm-none-typescript +++ b/tests/__snapshots__/problem-esm-none-typescript @@ -6,7 +6,7 @@ import tseslint from "typescript-eslint"; export default [].concat( { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, - pluginJs.configs.recommended, + pluginJs.configs.recommended, tseslint.configs.recommended, );", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/problem-esm-react-javascript b/tests/__snapshots__/problem-esm-react-javascript index 05ce5090..83bc9861 100644 --- a/tests/__snapshots__/problem-esm-react-javascript +++ b/tests/__snapshots__/problem-esm-react-javascript @@ -6,7 +6,7 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [].concat( { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, - pluginJs.configs.recommended, + pluginJs.configs.recommended, pluginReactConfig, );", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/problem-esm-react-typescript b/tests/__snapshots__/problem-esm-react-typescript index 568552bb..73949396 100644 --- a/tests/__snapshots__/problem-esm-react-typescript +++ b/tests/__snapshots__/problem-esm-react-typescript @@ -7,7 +7,7 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [].concat( { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, - pluginJs.configs.recommended, + pluginJs.configs.recommended, tseslint.configs.recommended, pluginReactConfig, );", diff --git a/tests/__snapshots__/problem-esm-vue-javascript b/tests/__snapshots__/problem-esm-vue-javascript index 5fd9f0bd..42ceb82d 100644 --- a/tests/__snapshots__/problem-esm-vue-javascript +++ b/tests/__snapshots__/problem-esm-vue-javascript @@ -13,7 +13,7 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug export default [].concat( { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, - pluginJs.configs.recommended, + pluginJs.configs.recommended, compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), );", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/problem-esm-vue-typescript b/tests/__snapshots__/problem-esm-vue-typescript index 00dce4a5..4792c8b8 100644 --- a/tests/__snapshots__/problem-esm-vue-typescript +++ b/tests/__snapshots__/problem-esm-vue-typescript @@ -14,7 +14,7 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug export default [].concat( { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, - pluginJs.configs.recommended, + pluginJs.configs.recommended, tseslint.configs.recommended, compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), );", diff --git a/tests/__snapshots__/problem-script-none-javascript b/tests/__snapshots__/problem-script-none-javascript index db91a232..d825c38d 100644 --- a/tests/__snapshots__/problem-script-none-javascript +++ b/tests/__snapshots__/problem-script-none-javascript @@ -5,7 +5,7 @@ import globals from "globals"; export default [].concat( { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, - pluginJs.configs.recommended, + pluginJs.configs.recommended, );", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/problem-script-none-typescript b/tests/__snapshots__/problem-script-none-typescript index 5526b413..4379fcb6 100644 --- a/tests/__snapshots__/problem-script-none-typescript +++ b/tests/__snapshots__/problem-script-none-typescript @@ -6,7 +6,7 @@ import tseslint from "typescript-eslint"; export default [].concat( { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, - pluginJs.configs.recommended, + pluginJs.configs.recommended, tseslint.configs.recommended, );", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/problem-script-react-javascript b/tests/__snapshots__/problem-script-react-javascript index 05ce5090..83bc9861 100644 --- a/tests/__snapshots__/problem-script-react-javascript +++ b/tests/__snapshots__/problem-script-react-javascript @@ -6,7 +6,7 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [].concat( { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, - pluginJs.configs.recommended, + pluginJs.configs.recommended, pluginReactConfig, );", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/problem-script-react-typescript b/tests/__snapshots__/problem-script-react-typescript index 568552bb..73949396 100644 --- a/tests/__snapshots__/problem-script-react-typescript +++ b/tests/__snapshots__/problem-script-react-typescript @@ -7,7 +7,7 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [].concat( { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, - pluginJs.configs.recommended, + pluginJs.configs.recommended, tseslint.configs.recommended, pluginReactConfig, );", diff --git a/tests/__snapshots__/problem-script-vue-javascript b/tests/__snapshots__/problem-script-vue-javascript index 5fd9f0bd..42ceb82d 100644 --- a/tests/__snapshots__/problem-script-vue-javascript +++ b/tests/__snapshots__/problem-script-vue-javascript @@ -13,7 +13,7 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug export default [].concat( { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, - pluginJs.configs.recommended, + pluginJs.configs.recommended, compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), );", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/problem-script-vue-typescript b/tests/__snapshots__/problem-script-vue-typescript index 00dce4a5..4792c8b8 100644 --- a/tests/__snapshots__/problem-script-vue-typescript +++ b/tests/__snapshots__/problem-script-vue-typescript @@ -14,7 +14,7 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug export default [].concat( { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, - pluginJs.configs.recommended, + pluginJs.configs.recommended, tseslint.configs.recommended, compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), );", diff --git a/tests/__snapshots__/style-esm-none-xo-javascript b/tests/__snapshots__/style-esm-none-xo-javascript index f5d10008..7d3d86df 100644 --- a/tests/__snapshots__/style-esm-none-xo-javascript +++ b/tests/__snapshots__/style-esm-none-xo-javascript @@ -5,7 +5,7 @@ import globals from "globals"; export default [].concat( { languageOptions: {globals: globals.node, }}, - styleGuide, + styleGuide, );", "configFilename": "eslint.config.mjs", "devDependencies": [ diff --git a/tests/__snapshots__/style-esm-none-xo-typescript b/tests/__snapshots__/style-esm-none-xo-typescript index a795125a..ed805065 100644 --- a/tests/__snapshots__/style-esm-none-xo-typescript +++ b/tests/__snapshots__/style-esm-none-xo-typescript @@ -6,7 +6,7 @@ import tseslint from "typescript-eslint"; export default [].concat( { languageOptions: {globals: globals.browser, }}, - styleGuide, + styleGuide, tseslint.configs.recommended, );", "configFilename": "eslint.config.mjs", diff --git a/tests/__snapshots__/syntax-commonjs-none-javascript b/tests/__snapshots__/syntax-commonjs-none-javascript index 466b4e40..3822dca6 100644 --- a/tests/__snapshots__/syntax-commonjs-none-javascript +++ b/tests/__snapshots__/syntax-commonjs-none-javascript @@ -4,7 +4,7 @@ export default [].concat( { languageOptions: {sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, -);", + );", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", diff --git a/tests/__snapshots__/syntax-commonjs-none-typescript b/tests/__snapshots__/syntax-commonjs-none-typescript index 3fcd5ea8..20caea3f 100644 --- a/tests/__snapshots__/syntax-commonjs-none-typescript +++ b/tests/__snapshots__/syntax-commonjs-none-typescript @@ -5,7 +5,7 @@ import tseslint from "typescript-eslint"; export default [].concat( { languageOptions: {sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, - tseslint.configs.recommended, + tseslint.configs.recommended, );", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/syntax-commonjs-react-javascript b/tests/__snapshots__/syntax-commonjs-react-javascript index f99c0be3..3fae923b 100644 --- a/tests/__snapshots__/syntax-commonjs-react-javascript +++ b/tests/__snapshots__/syntax-commonjs-react-javascript @@ -5,7 +5,7 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [].concat( { languageOptions: {sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, - pluginReactConfig, + pluginReactConfig, );", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/syntax-commonjs-react-typescript b/tests/__snapshots__/syntax-commonjs-react-typescript index 41406434..a8e166fb 100644 --- a/tests/__snapshots__/syntax-commonjs-react-typescript +++ b/tests/__snapshots__/syntax-commonjs-react-typescript @@ -6,7 +6,7 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [].concat( { languageOptions: {sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, - tseslint.configs.recommended, + tseslint.configs.recommended, pluginReactConfig, );", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/syntax-commonjs-vue-javascript b/tests/__snapshots__/syntax-commonjs-vue-javascript index 2beb9ca5..9286ed76 100644 --- a/tests/__snapshots__/syntax-commonjs-vue-javascript +++ b/tests/__snapshots__/syntax-commonjs-vue-javascript @@ -12,7 +12,7 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug export default [].concat( { languageOptions: {sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, - compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), + compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), );", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/syntax-commonjs-vue-typescript b/tests/__snapshots__/syntax-commonjs-vue-typescript index b38ea43e..86b88cc1 100644 --- a/tests/__snapshots__/syntax-commonjs-vue-typescript +++ b/tests/__snapshots__/syntax-commonjs-vue-typescript @@ -13,7 +13,7 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug export default [].concat( { languageOptions: {sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, - tseslint.configs.recommended, + tseslint.configs.recommended, compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), );", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/syntax-esm-none-javascript b/tests/__snapshots__/syntax-esm-none-javascript index 9f748093..36dd7e25 100644 --- a/tests/__snapshots__/syntax-esm-none-javascript +++ b/tests/__snapshots__/syntax-esm-none-javascript @@ -4,7 +4,7 @@ export default [].concat( { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, -);", + );", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", diff --git a/tests/__snapshots__/syntax-esm-none-typescript b/tests/__snapshots__/syntax-esm-none-typescript index 81c5da76..775f8a5a 100644 --- a/tests/__snapshots__/syntax-esm-none-typescript +++ b/tests/__snapshots__/syntax-esm-none-typescript @@ -5,7 +5,7 @@ import tseslint from "typescript-eslint"; export default [].concat( { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, - tseslint.configs.recommended, + tseslint.configs.recommended, );", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/syntax-esm-react-javascript b/tests/__snapshots__/syntax-esm-react-javascript index 5e52b440..b057d27b 100644 --- a/tests/__snapshots__/syntax-esm-react-javascript +++ b/tests/__snapshots__/syntax-esm-react-javascript @@ -5,7 +5,7 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [].concat( { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, - pluginReactConfig, + pluginReactConfig, );", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/syntax-esm-react-typescript b/tests/__snapshots__/syntax-esm-react-typescript index 7a1615f0..4be43b5a 100644 --- a/tests/__snapshots__/syntax-esm-react-typescript +++ b/tests/__snapshots__/syntax-esm-react-typescript @@ -6,7 +6,7 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [].concat( { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, - tseslint.configs.recommended, + tseslint.configs.recommended, pluginReactConfig, );", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/syntax-esm-vue-javascript b/tests/__snapshots__/syntax-esm-vue-javascript index 13eaa1ee..82ff47fc 100644 --- a/tests/__snapshots__/syntax-esm-vue-javascript +++ b/tests/__snapshots__/syntax-esm-vue-javascript @@ -12,7 +12,7 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug export default [].concat( { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, - compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), + compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), );", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/syntax-esm-vue-typescript b/tests/__snapshots__/syntax-esm-vue-typescript index f729af52..6a07b594 100644 --- a/tests/__snapshots__/syntax-esm-vue-typescript +++ b/tests/__snapshots__/syntax-esm-vue-typescript @@ -13,7 +13,7 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug export default [].concat( { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, - tseslint.configs.recommended, + tseslint.configs.recommended, compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), );", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/syntax-script-none-javascript b/tests/__snapshots__/syntax-script-none-javascript index 9f748093..36dd7e25 100644 --- a/tests/__snapshots__/syntax-script-none-javascript +++ b/tests/__snapshots__/syntax-script-none-javascript @@ -4,7 +4,7 @@ export default [].concat( { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, -);", + );", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", diff --git a/tests/__snapshots__/syntax-script-none-typescript b/tests/__snapshots__/syntax-script-none-typescript index 81c5da76..775f8a5a 100644 --- a/tests/__snapshots__/syntax-script-none-typescript +++ b/tests/__snapshots__/syntax-script-none-typescript @@ -5,7 +5,7 @@ import tseslint from "typescript-eslint"; export default [].concat( { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, - tseslint.configs.recommended, + tseslint.configs.recommended, );", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/syntax-script-react-javascript b/tests/__snapshots__/syntax-script-react-javascript index 5e52b440..b057d27b 100644 --- a/tests/__snapshots__/syntax-script-react-javascript +++ b/tests/__snapshots__/syntax-script-react-javascript @@ -5,7 +5,7 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [].concat( { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, - pluginReactConfig, + pluginReactConfig, );", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/syntax-script-react-typescript b/tests/__snapshots__/syntax-script-react-typescript index 7a1615f0..4be43b5a 100644 --- a/tests/__snapshots__/syntax-script-react-typescript +++ b/tests/__snapshots__/syntax-script-react-typescript @@ -6,7 +6,7 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [].concat( { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, - tseslint.configs.recommended, + tseslint.configs.recommended, pluginReactConfig, );", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/syntax-script-vue-javascript b/tests/__snapshots__/syntax-script-vue-javascript index 13eaa1ee..82ff47fc 100644 --- a/tests/__snapshots__/syntax-script-vue-javascript +++ b/tests/__snapshots__/syntax-script-vue-javascript @@ -12,7 +12,7 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug export default [].concat( { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, - compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), + compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), );", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/syntax-script-vue-typescript b/tests/__snapshots__/syntax-script-vue-typescript index f729af52..6a07b594 100644 --- a/tests/__snapshots__/syntax-script-vue-typescript +++ b/tests/__snapshots__/syntax-script-vue-typescript @@ -13,7 +13,7 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug export default [].concat( { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, - tseslint.configs.recommended, + tseslint.configs.recommended, compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), );", "configFilename": "eslint.config.js", From 222e432494a0bacc16bdc1d411923e3152c387b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Wed, 28 Feb 2024 17:07:21 +0800 Subject: [PATCH 05/41] fix: rm unused dev deps --- package.json | 3 --- tests/utils/npm-utils.spec.js | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index b74fb6a0..f182b772 100644 --- a/package.json +++ b/package.json @@ -52,11 +52,8 @@ "eslint-config-eslint": "^9.0.0", "eslint-release": "^3.2.0", "esmock": "^2.5.8", - "espree": "^9.0.0", - "globals": "^13.21.0", "lint-staged": "^12.1.2", "memfs": "^3.4.0", - "mocha": "^9.1.3", "shelljs": "^0.8.4", "sinon": "^12.0.1", "vitest": "^1.1.1", diff --git a/tests/utils/npm-utils.spec.js b/tests/utils/npm-utils.spec.js index 2899fc98..5f67e79d 100644 --- a/tests/utils/npm-utils.spec.js +++ b/tests/utils/npm-utils.spec.js @@ -44,14 +44,14 @@ describe("npmUtils", () => { }); describe("checkDevDeps()", () => { - let installStatus = checkDevDeps(["debug", "mocha", "notarealpackage", "jshint"]); + let installStatus = checkDevDeps(["debug", "eslint", "notarealpackage", "jshint"]); it("should not find a direct dependency of the project", () => { assert.isFalse(installStatus.debug); }); it("should find a dev dependency of the project", () => { - assert.isTrue(installStatus.mocha); + assert.isTrue(installStatus.eslint); }); it("should not find non-dependencies", () => { From 46027138738a8296a39dfd21b0221e36d9d1f805 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Thu, 29 Feb 2024 13:54:57 +0800 Subject: [PATCH 06/41] fix: rm unused dev deps --- package.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/package.json b/package.json index f182b772..3dfebfdf 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,6 @@ }, "devDependencies": { "c8": "^7.10.0", - "chai": "^4.3.4", "cross-env": "^7.0.3", "eslint": "^8.56.0", "eslint-config-eslint": "^9.0.0", @@ -54,7 +53,6 @@ "esmock": "^2.5.8", "lint-staged": "^12.1.2", "memfs": "^3.4.0", - "shelljs": "^0.8.4", "sinon": "^12.0.1", "vitest": "^1.1.1", "yorkie": "^2.0.0" From a46bdf77634449f0fb3610ff6cf2de0930198df9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Thu, 29 Feb 2024 15:28:35 +0800 Subject: [PATCH 07/41] fix: add missing @eslint/eslintrc --- lib/config-generator.js | 5 ++++- tests/__snapshots__/problem-commonjs-vue-javascript | 3 +++ tests/__snapshots__/problem-commonjs-vue-typescript | 3 +++ tests/__snapshots__/problem-esm-vue-javascript | 3 +++ tests/__snapshots__/problem-esm-vue-typescript | 3 +++ tests/__snapshots__/problem-script-vue-javascript | 3 +++ tests/__snapshots__/problem-script-vue-typescript | 3 +++ tests/__snapshots__/syntax-commonjs-vue-javascript | 3 +++ tests/__snapshots__/syntax-commonjs-vue-typescript | 3 +++ tests/__snapshots__/syntax-esm-vue-javascript | 3 +++ tests/__snapshots__/syntax-esm-vue-typescript | 3 +++ tests/__snapshots__/syntax-script-vue-javascript | 3 +++ tests/__snapshots__/syntax-script-vue-typescript | 3 +++ 13 files changed, 40 insertions(+), 1 deletion(-) diff --git a/lib/config-generator.js b/lib/config-generator.js index 47c95532..4cdd797c 100644 --- a/lib/config-generator.js +++ b/lib/config-generator.js @@ -142,6 +142,7 @@ export class ConfigGenerator { const helperContent = `import path from "path"; import { fileURLToPath } from "url"; import { FlatCompat } from "@eslint/eslintrc"; +import pluginJs from "@eslint/js"; // mimic CommonJS variables -- not needed if using CommonJS const __filename = fileURLToPath(import.meta.url); @@ -173,7 +174,6 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug importContent += `import styleGuide from "${this.answers.styleguide.packageName}";\n`; exportContent += " styleGuide,\n"; } else if (this.answers.styleguide.type === "eslintrc") { - importContent += "import pluginJs from \"@eslint/js\";\n"; needCompatHelper = true; @@ -223,6 +223,9 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug exportContent += " pluginReactConfig,\n"; } + if (needCompatHelper) { + this.result.devDependencies.push("@eslint/eslintrc", "@eslint/js"); + } this.result.configContent = `${importContent}\n${needCompatHelper ? helperContent : ""} export default [].concat(\n { languageOptions: {${languageOptionsContent}}},\n ${exportContent});`; } diff --git a/tests/__snapshots__/problem-commonjs-vue-javascript b/tests/__snapshots__/problem-commonjs-vue-javascript index e5456f03..e6808c26 100644 --- a/tests/__snapshots__/problem-commonjs-vue-javascript +++ b/tests/__snapshots__/problem-commonjs-vue-javascript @@ -5,6 +5,7 @@ import globals from "globals"; import path from "path"; import { fileURLToPath } from "url"; import { FlatCompat } from "@eslint/eslintrc"; +import pluginJs from "@eslint/js"; // mimic CommonJS variables -- not needed if using CommonJS const __filename = fileURLToPath(import.meta.url); @@ -22,5 +23,7 @@ export default [].concat( "@eslint/js", "globals", "eslint-plugin-vue", + "@eslint/eslintrc", + "@eslint/js", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problem-commonjs-vue-typescript b/tests/__snapshots__/problem-commonjs-vue-typescript index cc84d930..af9f4a8a 100644 --- a/tests/__snapshots__/problem-commonjs-vue-typescript +++ b/tests/__snapshots__/problem-commonjs-vue-typescript @@ -6,6 +6,7 @@ import tseslint from "typescript-eslint"; import path from "path"; import { fileURLToPath } from "url"; import { FlatCompat } from "@eslint/eslintrc"; +import pluginJs from "@eslint/js"; // mimic CommonJS variables -- not needed if using CommonJS const __filename = fileURLToPath(import.meta.url); @@ -25,5 +26,7 @@ export default [].concat( "globals", "typescript-eslint", "eslint-plugin-vue", + "@eslint/eslintrc", + "@eslint/js", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problem-esm-vue-javascript b/tests/__snapshots__/problem-esm-vue-javascript index 42ceb82d..53700904 100644 --- a/tests/__snapshots__/problem-esm-vue-javascript +++ b/tests/__snapshots__/problem-esm-vue-javascript @@ -5,6 +5,7 @@ import globals from "globals"; import path from "path"; import { fileURLToPath } from "url"; import { FlatCompat } from "@eslint/eslintrc"; +import pluginJs from "@eslint/js"; // mimic CommonJS variables -- not needed if using CommonJS const __filename = fileURLToPath(import.meta.url); @@ -22,5 +23,7 @@ export default [].concat( "@eslint/js", "globals", "eslint-plugin-vue", + "@eslint/eslintrc", + "@eslint/js", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problem-esm-vue-typescript b/tests/__snapshots__/problem-esm-vue-typescript index 4792c8b8..c3ea84a4 100644 --- a/tests/__snapshots__/problem-esm-vue-typescript +++ b/tests/__snapshots__/problem-esm-vue-typescript @@ -6,6 +6,7 @@ import tseslint from "typescript-eslint"; import path from "path"; import { fileURLToPath } from "url"; import { FlatCompat } from "@eslint/eslintrc"; +import pluginJs from "@eslint/js"; // mimic CommonJS variables -- not needed if using CommonJS const __filename = fileURLToPath(import.meta.url); @@ -25,5 +26,7 @@ export default [].concat( "globals", "typescript-eslint", "eslint-plugin-vue", + "@eslint/eslintrc", + "@eslint/js", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problem-script-vue-javascript b/tests/__snapshots__/problem-script-vue-javascript index 42ceb82d..53700904 100644 --- a/tests/__snapshots__/problem-script-vue-javascript +++ b/tests/__snapshots__/problem-script-vue-javascript @@ -5,6 +5,7 @@ import globals from "globals"; import path from "path"; import { fileURLToPath } from "url"; import { FlatCompat } from "@eslint/eslintrc"; +import pluginJs from "@eslint/js"; // mimic CommonJS variables -- not needed if using CommonJS const __filename = fileURLToPath(import.meta.url); @@ -22,5 +23,7 @@ export default [].concat( "@eslint/js", "globals", "eslint-plugin-vue", + "@eslint/eslintrc", + "@eslint/js", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problem-script-vue-typescript b/tests/__snapshots__/problem-script-vue-typescript index 4792c8b8..c3ea84a4 100644 --- a/tests/__snapshots__/problem-script-vue-typescript +++ b/tests/__snapshots__/problem-script-vue-typescript @@ -6,6 +6,7 @@ import tseslint from "typescript-eslint"; import path from "path"; import { fileURLToPath } from "url"; import { FlatCompat } from "@eslint/eslintrc"; +import pluginJs from "@eslint/js"; // mimic CommonJS variables -- not needed if using CommonJS const __filename = fileURLToPath(import.meta.url); @@ -25,5 +26,7 @@ export default [].concat( "globals", "typescript-eslint", "eslint-plugin-vue", + "@eslint/eslintrc", + "@eslint/js", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-commonjs-vue-javascript b/tests/__snapshots__/syntax-commonjs-vue-javascript index 9286ed76..a73092eb 100644 --- a/tests/__snapshots__/syntax-commonjs-vue-javascript +++ b/tests/__snapshots__/syntax-commonjs-vue-javascript @@ -4,6 +4,7 @@ import path from "path"; import { fileURLToPath } from "url"; import { FlatCompat } from "@eslint/eslintrc"; +import pluginJs from "@eslint/js"; // mimic CommonJS variables -- not needed if using CommonJS const __filename = fileURLToPath(import.meta.url); @@ -19,5 +20,7 @@ export default [].concat( "eslint", "globals", "eslint-plugin-vue", + "@eslint/eslintrc", + "@eslint/js", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-commonjs-vue-typescript b/tests/__snapshots__/syntax-commonjs-vue-typescript index 86b88cc1..9520bc99 100644 --- a/tests/__snapshots__/syntax-commonjs-vue-typescript +++ b/tests/__snapshots__/syntax-commonjs-vue-typescript @@ -5,6 +5,7 @@ import tseslint from "typescript-eslint"; import path from "path"; import { fileURLToPath } from "url"; import { FlatCompat } from "@eslint/eslintrc"; +import pluginJs from "@eslint/js"; // mimic CommonJS variables -- not needed if using CommonJS const __filename = fileURLToPath(import.meta.url); @@ -22,5 +23,7 @@ export default [].concat( "globals", "typescript-eslint", "eslint-plugin-vue", + "@eslint/eslintrc", + "@eslint/js", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-esm-vue-javascript b/tests/__snapshots__/syntax-esm-vue-javascript index 82ff47fc..c8bbcc98 100644 --- a/tests/__snapshots__/syntax-esm-vue-javascript +++ b/tests/__snapshots__/syntax-esm-vue-javascript @@ -4,6 +4,7 @@ import path from "path"; import { fileURLToPath } from "url"; import { FlatCompat } from "@eslint/eslintrc"; +import pluginJs from "@eslint/js"; // mimic CommonJS variables -- not needed if using CommonJS const __filename = fileURLToPath(import.meta.url); @@ -19,5 +20,7 @@ export default [].concat( "eslint", "globals", "eslint-plugin-vue", + "@eslint/eslintrc", + "@eslint/js", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-esm-vue-typescript b/tests/__snapshots__/syntax-esm-vue-typescript index 6a07b594..a57d5d47 100644 --- a/tests/__snapshots__/syntax-esm-vue-typescript +++ b/tests/__snapshots__/syntax-esm-vue-typescript @@ -5,6 +5,7 @@ import tseslint from "typescript-eslint"; import path from "path"; import { fileURLToPath } from "url"; import { FlatCompat } from "@eslint/eslintrc"; +import pluginJs from "@eslint/js"; // mimic CommonJS variables -- not needed if using CommonJS const __filename = fileURLToPath(import.meta.url); @@ -22,5 +23,7 @@ export default [].concat( "globals", "typescript-eslint", "eslint-plugin-vue", + "@eslint/eslintrc", + "@eslint/js", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-script-vue-javascript b/tests/__snapshots__/syntax-script-vue-javascript index 82ff47fc..c8bbcc98 100644 --- a/tests/__snapshots__/syntax-script-vue-javascript +++ b/tests/__snapshots__/syntax-script-vue-javascript @@ -4,6 +4,7 @@ import path from "path"; import { fileURLToPath } from "url"; import { FlatCompat } from "@eslint/eslintrc"; +import pluginJs from "@eslint/js"; // mimic CommonJS variables -- not needed if using CommonJS const __filename = fileURLToPath(import.meta.url); @@ -19,5 +20,7 @@ export default [].concat( "eslint", "globals", "eslint-plugin-vue", + "@eslint/eslintrc", + "@eslint/js", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-script-vue-typescript b/tests/__snapshots__/syntax-script-vue-typescript index 6a07b594..a57d5d47 100644 --- a/tests/__snapshots__/syntax-script-vue-typescript +++ b/tests/__snapshots__/syntax-script-vue-typescript @@ -5,6 +5,7 @@ import tseslint from "typescript-eslint"; import path from "path"; import { fileURLToPath } from "url"; import { FlatCompat } from "@eslint/eslintrc"; +import pluginJs from "@eslint/js"; // mimic CommonJS variables -- not needed if using CommonJS const __filename = fileURLToPath(import.meta.url); @@ -22,5 +23,7 @@ export default [].concat( "globals", "typescript-eslint", "eslint-plugin-vue", + "@eslint/eslintrc", + "@eslint/js", ], } \ No newline at end of file From 893522ddb67183a67a4b77fb1c1b8a6667581b37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Thu, 29 Feb 2024 15:45:58 +0800 Subject: [PATCH 08/41] chore: clean fixtures --- tests/fixtures/cjs-project/package.json | 2 +- .../config-initializer/lib/doubleQuotes.js | 1 - .../config-initializer/lib/no-semi.js | 1 - .../new-es-features/new-es-features.js | 3 - .../parse-error/parse-error.js | 1 - .../config-initializer/singleQuotes.js | 1 - .../config-initializer/tests/console-log.js | 1 - .../config-initializer/tests/doubleQuotes.js | 1 - tests/fixtures/config-rule/schemas.js | 118 ------------------ tests/fixtures/eslint/lib/api.js | 12 -- tests/fixtures/eslint/package.json | 5 - tests/fixtures/esm-project/package.json | 2 +- 12 files changed, 2 insertions(+), 146 deletions(-) delete mode 100644 tests/fixtures/config-initializer/lib/doubleQuotes.js delete mode 100644 tests/fixtures/config-initializer/lib/no-semi.js delete mode 100644 tests/fixtures/config-initializer/new-es-features/new-es-features.js delete mode 100644 tests/fixtures/config-initializer/parse-error/parse-error.js delete mode 100644 tests/fixtures/config-initializer/singleQuotes.js delete mode 100644 tests/fixtures/config-initializer/tests/console-log.js delete mode 100644 tests/fixtures/config-initializer/tests/doubleQuotes.js delete mode 100644 tests/fixtures/config-rule/schemas.js delete mode 100644 tests/fixtures/eslint/lib/api.js delete mode 100644 tests/fixtures/eslint/package.json diff --git a/tests/fixtures/cjs-project/package.json b/tests/fixtures/cjs-project/package.json index 24d28279..a483e4c8 100644 --- a/tests/fixtures/cjs-project/package.json +++ b/tests/fixtures/cjs-project/package.json @@ -1,5 +1,5 @@ { - "name": "esm", + "name": "cjs-project", "private": true, "type": "commonjs", "version": "1.0.0" diff --git a/tests/fixtures/config-initializer/lib/doubleQuotes.js b/tests/fixtures/config-initializer/lib/doubleQuotes.js deleted file mode 100644 index 3c1ce5e4..00000000 --- a/tests/fixtures/config-initializer/lib/doubleQuotes.js +++ /dev/null @@ -1 +0,0 @@ -var foo = 'doubleQuotes'; diff --git a/tests/fixtures/config-initializer/lib/no-semi.js b/tests/fixtures/config-initializer/lib/no-semi.js deleted file mode 100644 index 050ea54a..00000000 --- a/tests/fixtures/config-initializer/lib/no-semi.js +++ /dev/null @@ -1 +0,0 @@ -var name = 'ESLint'; diff --git a/tests/fixtures/config-initializer/new-es-features/new-es-features.js b/tests/fixtures/config-initializer/new-es-features/new-es-features.js deleted file mode 100644 index de6686df..00000000 --- a/tests/fixtures/config-initializer/new-es-features/new-es-features.js +++ /dev/null @@ -1,3 +0,0 @@ -async function fn() { - await Promise.resolve(); -} diff --git a/tests/fixtures/config-initializer/parse-error/parse-error.js b/tests/fixtures/config-initializer/parse-error/parse-error.js deleted file mode 100644 index 90bd920c..00000000 --- a/tests/fixtures/config-initializer/parse-error/parse-error.js +++ /dev/null @@ -1 +0,0 @@ -+; diff --git a/tests/fixtures/config-initializer/singleQuotes.js b/tests/fixtures/config-initializer/singleQuotes.js deleted file mode 100644 index db1e01fe..00000000 --- a/tests/fixtures/config-initializer/singleQuotes.js +++ /dev/null @@ -1 +0,0 @@ -var foo = 'singleQuotes'; diff --git a/tests/fixtures/config-initializer/tests/console-log.js b/tests/fixtures/config-initializer/tests/console-log.js deleted file mode 100644 index 53b32b51..00000000 --- a/tests/fixtures/config-initializer/tests/console-log.js +++ /dev/null @@ -1 +0,0 @@ -console.log('I\'m a log'); diff --git a/tests/fixtures/config-initializer/tests/doubleQuotes.js b/tests/fixtures/config-initializer/tests/doubleQuotes.js deleted file mode 100644 index 3c1ce5e4..00000000 --- a/tests/fixtures/config-initializer/tests/doubleQuotes.js +++ /dev/null @@ -1 +0,0 @@ -var foo = 'doubleQuotes'; diff --git a/tests/fixtures/config-rule/schemas.js b/tests/fixtures/config-rule/schemas.js deleted file mode 100644 index 9984fe72..00000000 --- a/tests/fixtures/config-rule/schemas.js +++ /dev/null @@ -1,118 +0,0 @@ -export const schemas = { - enum: [{ enum: ['always', 'never'] }], - - objectWithEnum: [{ - type: 'object', - properties: { - enumProperty: { - enum: ['always', 'never'] - } - }, - additionalProperties: false - }], - - objectWithMultipleEnums: [{ - type: 'object', - properties: { - firstEnum: { - enum: ['always', 'never'] - }, - anotherEnum: { - enum: ['var', 'let', 'const'] - } - }, - additionalProperties: false - }], - - objectWithBool: [{ - type: 'object', - properties: { - boolProperty: { - type: 'boolean' - } - }, - additionalProperties: false - }], - - objectWithMultipleBools: [{ - type: 'object', - properties: { - firstBool: { - type: 'boolean' - }, - anotherBool: { - type: 'boolean' - } - }, - additionalProperties: false - }], - - mixedEnumObject: [{ - enum: ['always', 'never'] - }, - { - type: 'object', - properties: { - singleValue: { - type: 'boolean' - } - }, - additionalProperties: false - }], - - mixedEnumObjectWithNothing: [{ - enum: ['always', 'never'] - }, - { - type: 'object', - properties: {}, - additionalProperties: false - }], - - mixedObjectWithNothingEnum: [{ - type: 'object', - properties: {}, - additionalProperties: false - }, - { - enum: ['always', 'never'] - }], - - mixedStringEnum: [{ - type: 'string' - }, - { - enum: ['always', 'never'] - }], - - oneOf: [{ - oneOf: [ - { - enum: ['before', 'after', 'both', 'neither'] - }, - { - type: 'object', - properties: { - before: { type: 'boolean' }, - after: { type: 'boolean' } - }, - additionalProperties: false - } - ] - }], - - nestedObjects: [{ - type: 'object', - properties: { - prefer: { - type: 'object', - properties: { - nestedProperty: { - type: 'boolean' - } - } - } - } - }] - -}; diff --git a/tests/fixtures/eslint/lib/api.js b/tests/fixtures/eslint/lib/api.js deleted file mode 100644 index edc25f33..00000000 --- a/tests/fixtures/eslint/lib/api.js +++ /dev/null @@ -1,12 +0,0 @@ -/** - * @fileoverview the file is to mock local-installed eslint for testing - */ -"use strict"; -const _module = require("module"); -const path = require("path"); - -const { createRequire } = _module; -const root = path.resolve(__dirname, "../../../../../../"); - -const realEslintPath = createRequire(root).resolve("eslint"); -module.exports = require(realEslintPath); diff --git a/tests/fixtures/eslint/package.json b/tests/fixtures/eslint/package.json deleted file mode 100644 index ffa290cc..00000000 --- a/tests/fixtures/eslint/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "eslint", - "version": "3.18.0", - "main": "./lib/api.js" -} \ No newline at end of file diff --git a/tests/fixtures/esm-project/package.json b/tests/fixtures/esm-project/package.json index 1da57407..af755b3b 100644 --- a/tests/fixtures/esm-project/package.json +++ b/tests/fixtures/esm-project/package.json @@ -1,5 +1,5 @@ { - "name": "esm", + "name": "esm-project", "private": true, "type": "module", "version": "1.0.0" From 595b5b7a975bb4ff632a2487d28109edb64622ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Thu, 29 Feb 2024 16:05:39 +0800 Subject: [PATCH 09/41] fix: styleguide tests --- package.json | 2 +- .../style-esm-none-xo-javascript | 18 +++++++++++++--- .../style-esm-none-xo-typescript | 21 ++++++++++++++++--- tests/config-snapshots.spec.js | 4 ++-- 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 3dfebfdf..99f937c0 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "access": "public" }, "scripts": { - "lint": "eslint . --report-unused-disable-directives", + "lint": "eslint .", "release:generate:latest": "eslint-generate-release", "release:generate:alpha": "eslint-generate-prerelease alpha", "release:generate:beta": "eslint-generate-prerelease beta", diff --git a/tests/__snapshots__/style-esm-none-xo-javascript b/tests/__snapshots__/style-esm-none-xo-javascript index 7d3d86df..774ad3e1 100644 --- a/tests/__snapshots__/style-esm-none-xo-javascript +++ b/tests/__snapshots__/style-esm-none-xo-javascript @@ -1,17 +1,29 @@ { - "configContent": "import styleGuide from "undefined"; + "configContent": "import pluginJs from "@eslint/js"; import globals from "globals"; +import path from "path"; +import { fileURLToPath } from "url"; +import { FlatCompat } from "@eslint/eslintrc"; +import pluginJs from "@eslint/js"; + +// mimic CommonJS variables -- not needed if using CommonJS +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); +const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [].concat( { languageOptions: {globals: globals.node, }}, - styleGuide, + compat.extends("xo"), );", "configFilename": "eslint.config.mjs", "devDependencies": [ "eslint", - undefined, + "eslint-config-xo", "@eslint/js", + "eslint@>=8.56.0", "globals", + "@eslint/eslintrc", + "@eslint/js", ], } \ No newline at end of file diff --git a/tests/__snapshots__/style-esm-none-xo-typescript b/tests/__snapshots__/style-esm-none-xo-typescript index ed805065..62b51a55 100644 --- a/tests/__snapshots__/style-esm-none-xo-typescript +++ b/tests/__snapshots__/style-esm-none-xo-typescript @@ -1,20 +1,35 @@ { - "configContent": "import styleGuide from "undefined"; + "configContent": "import pluginJs from "@eslint/js"; import globals from "globals"; import tseslint from "typescript-eslint"; +import path from "path"; +import { fileURLToPath } from "url"; +import { FlatCompat } from "@eslint/eslintrc"; +import pluginJs from "@eslint/js"; + +// mimic CommonJS variables -- not needed if using CommonJS +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); +const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [].concat( { languageOptions: {globals: globals.browser, }}, - styleGuide, + compat.extends("xo-typescript"), tseslint.configs.recommended, );", "configFilename": "eslint.config.mjs", "devDependencies": [ "eslint", - undefined, + "eslint-config-xo-typescript", "@eslint/js", + "@typescript-eslint/eslint-plugin@>=7.0.2", + "@typescript-eslint/parser@>=7.0.2", + "eslint@>=8.56.0", + "typescript@>=5.0.0", "globals", "typescript-eslint", + "@eslint/eslintrc", + "@eslint/js", ], } \ No newline at end of file diff --git a/tests/config-snapshots.spec.js b/tests/config-snapshots.spec.js index fb2d7800..7d6c943b 100644 --- a/tests/config-snapshots.spec.js +++ b/tests/config-snapshots.spec.js @@ -67,7 +67,7 @@ describe("generate config for cjs projects", () => { framework: "none", language: "javascript", env: ["node"], - styleguide: "eslint-config-xo" + styleguide: { packageName: "eslint-config-xo", type: "eslintrc" } } }, { @@ -78,7 +78,7 @@ describe("generate config for cjs projects", () => { framework: "none", language: "typescript", env: ["browser"], - styleguide: "eslint-config-xo-typescript" + styleguide: { packageName: "eslint-config-xo-typescript", type: "eslintrc" } } }]; From 9fd59b0b3f5bd55114af3413cc3e169d063cce7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Thu, 29 Feb 2024 16:12:36 +0800 Subject: [PATCH 10/41] feat: allow styleguide to be string (type = flat) --- lib/config-generator.js | 17 ++++++++++------- .../__snapshots__/style-esm-none-xo-javascript | 4 +--- .../__snapshots__/style-esm-none-xo-typescript | 4 +--- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/lib/config-generator.js b/lib/config-generator.js index 4cdd797c..a83e53e3 100644 --- a/lib/config-generator.js +++ b/lib/config-generator.js @@ -161,23 +161,26 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug importContent += "import pluginJs from \"@eslint/js\";\n"; exportContent += " pluginJs.configs.recommended,\n"; } else if (this.answers.purpose === "style") { - this.result.devDependencies.push(this.answers.styleguide.packageName, "@eslint/js"); + const styleguide = typeof this.answers.styleguide === "string" + ? { packageName: this.answers.styleguide, type: "flat" } + : this.answers.styleguide; + + this.result.devDependencies.push(styleguide.packageName); // install peer dependencies - it's needed for most eslintrc-style shared configs. - const peers = fetchPeerDependencies(this.answers.styleguide.packageName); + const peers = fetchPeerDependencies(styleguide.packageName); if (peers !== null) { this.result.devDependencies.push(...peers); } - if (this.answers.styleguide.type === "flat" || this.answers.styleguide.type === void 0) { - importContent += `import styleGuide from "${this.answers.styleguide.packageName}";\n`; + if (styleguide.type === "flat" || styleguide.type === void 0) { + importContent += `import styleGuide from "${styleguide.packageName}";\n`; exportContent += " styleGuide,\n"; - } else if (this.answers.styleguide.type === "eslintrc") { - importContent += "import pluginJs from \"@eslint/js\";\n"; + } else if (styleguide.type === "eslintrc") { needCompatHelper = true; - const extendedName = this.answers.styleguide.packageName.replace("eslint-config-", ""); + const extendedName = styleguide.packageName.replace("eslint-config-", ""); exportContent += ` compat.extends("${extendedName}"),\n`; } diff --git a/tests/__snapshots__/style-esm-none-xo-javascript b/tests/__snapshots__/style-esm-none-xo-javascript index 774ad3e1..11f02aed 100644 --- a/tests/__snapshots__/style-esm-none-xo-javascript +++ b/tests/__snapshots__/style-esm-none-xo-javascript @@ -1,6 +1,5 @@ { - "configContent": "import pluginJs from "@eslint/js"; -import globals from "globals"; + "configContent": "import globals from "globals"; import path from "path"; import { fileURLToPath } from "url"; @@ -20,7 +19,6 @@ export default [].concat( "devDependencies": [ "eslint", "eslint-config-xo", - "@eslint/js", "eslint@>=8.56.0", "globals", "@eslint/eslintrc", diff --git a/tests/__snapshots__/style-esm-none-xo-typescript b/tests/__snapshots__/style-esm-none-xo-typescript index 62b51a55..77d2f302 100644 --- a/tests/__snapshots__/style-esm-none-xo-typescript +++ b/tests/__snapshots__/style-esm-none-xo-typescript @@ -1,6 +1,5 @@ { - "configContent": "import pluginJs from "@eslint/js"; -import globals from "globals"; + "configContent": "import globals from "globals"; import tseslint from "typescript-eslint"; import path from "path"; @@ -22,7 +21,6 @@ export default [].concat( "devDependencies": [ "eslint", "eslint-config-xo-typescript", - "@eslint/js", "@typescript-eslint/eslint-plugin@>=7.0.2", "@typescript-eslint/parser@>=7.0.2", "eslint@>=8.56.0", From f9941312fc67d0c928c1cd39e7a932da2d27a386 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Thu, 29 Feb 2024 16:25:16 +0800 Subject: [PATCH 11/41] fix: sourceType: script --- lib/config-generator.js | 7 ++++--- tests/__snapshots__/problem-script-none-javascript | 2 +- tests/__snapshots__/problem-script-none-typescript | 2 +- tests/__snapshots__/problem-script-react-javascript | 2 +- tests/__snapshots__/problem-script-react-typescript | 2 +- tests/__snapshots__/problem-script-vue-javascript | 2 +- tests/__snapshots__/problem-script-vue-typescript | 2 +- tests/__snapshots__/syntax-script-none-javascript | 2 +- tests/__snapshots__/syntax-script-none-typescript | 2 +- tests/__snapshots__/syntax-script-react-javascript | 2 +- tests/__snapshots__/syntax-script-react-typescript | 2 +- tests/__snapshots__/syntax-script-vue-javascript | 2 +- tests/__snapshots__/syntax-script-vue-typescript | 2 +- 13 files changed, 16 insertions(+), 15 deletions(-) diff --git a/lib/config-generator.js b/lib/config-generator.js index a83e53e3..13418bfc 100644 --- a/lib/config-generator.js +++ b/lib/config-generator.js @@ -74,7 +74,7 @@ export class ConfigGenerator { choices: [ { message: "JavaScript modules (import/export)", name: "esm" }, { message: "CommonJS (require/exports)", name: "commonjs" }, - { message: "None of these", name: "none" } + { message: "None of these", name: "script" } ] }, { @@ -186,9 +186,10 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug } } - if (this.answers.module === "commonjs") { - languageOptionsContent += "sourceType: \"commonjs\", "; + if (this.answers.module === "commonjs" || this.answers.module === "script") { + languageOptionsContent += `sourceType: "${this.answers.module}", `; } + if (this.answers.env?.length > 0) { this.result.devDependencies.push("globals"); importContent += "import globals from \"globals\";\n"; diff --git a/tests/__snapshots__/problem-script-none-javascript b/tests/__snapshots__/problem-script-none-javascript index d825c38d..62d54cc7 100644 --- a/tests/__snapshots__/problem-script-none-javascript +++ b/tests/__snapshots__/problem-script-none-javascript @@ -4,7 +4,7 @@ import globals from "globals"; export default [].concat( - { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, + { languageOptions: {sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, pluginJs.configs.recommended, );", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/problem-script-none-typescript b/tests/__snapshots__/problem-script-none-typescript index 4379fcb6..78729a52 100644 --- a/tests/__snapshots__/problem-script-none-typescript +++ b/tests/__snapshots__/problem-script-none-typescript @@ -5,7 +5,7 @@ import tseslint from "typescript-eslint"; export default [].concat( - { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, + { languageOptions: {sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, pluginJs.configs.recommended, tseslint.configs.recommended, );", diff --git a/tests/__snapshots__/problem-script-react-javascript b/tests/__snapshots__/problem-script-react-javascript index 83bc9861..ecdf374f 100644 --- a/tests/__snapshots__/problem-script-react-javascript +++ b/tests/__snapshots__/problem-script-react-javascript @@ -5,7 +5,7 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [].concat( - { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, + { languageOptions: {sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, pluginJs.configs.recommended, pluginReactConfig, );", diff --git a/tests/__snapshots__/problem-script-react-typescript b/tests/__snapshots__/problem-script-react-typescript index 73949396..8d455a72 100644 --- a/tests/__snapshots__/problem-script-react-typescript +++ b/tests/__snapshots__/problem-script-react-typescript @@ -6,7 +6,7 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [].concat( - { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, + { languageOptions: {sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, pluginJs.configs.recommended, tseslint.configs.recommended, pluginReactConfig, diff --git a/tests/__snapshots__/problem-script-vue-javascript b/tests/__snapshots__/problem-script-vue-javascript index 53700904..f918d6c8 100644 --- a/tests/__snapshots__/problem-script-vue-javascript +++ b/tests/__snapshots__/problem-script-vue-javascript @@ -13,7 +13,7 @@ const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [].concat( - { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, + { languageOptions: {sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, pluginJs.configs.recommended, compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), );", diff --git a/tests/__snapshots__/problem-script-vue-typescript b/tests/__snapshots__/problem-script-vue-typescript index c3ea84a4..930e5287 100644 --- a/tests/__snapshots__/problem-script-vue-typescript +++ b/tests/__snapshots__/problem-script-vue-typescript @@ -14,7 +14,7 @@ const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [].concat( - { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, + { languageOptions: {sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, pluginJs.configs.recommended, tseslint.configs.recommended, compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), diff --git a/tests/__snapshots__/syntax-script-none-javascript b/tests/__snapshots__/syntax-script-none-javascript index 36dd7e25..5583d5aa 100644 --- a/tests/__snapshots__/syntax-script-none-javascript +++ b/tests/__snapshots__/syntax-script-none-javascript @@ -3,7 +3,7 @@ export default [].concat( - { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, + { languageOptions: {sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, );", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/syntax-script-none-typescript b/tests/__snapshots__/syntax-script-none-typescript index 775f8a5a..bf866962 100644 --- a/tests/__snapshots__/syntax-script-none-typescript +++ b/tests/__snapshots__/syntax-script-none-typescript @@ -4,7 +4,7 @@ import tseslint from "typescript-eslint"; export default [].concat( - { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, + { languageOptions: {sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, tseslint.configs.recommended, );", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/syntax-script-react-javascript b/tests/__snapshots__/syntax-script-react-javascript index b057d27b..259694d3 100644 --- a/tests/__snapshots__/syntax-script-react-javascript +++ b/tests/__snapshots__/syntax-script-react-javascript @@ -4,7 +4,7 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [].concat( - { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, + { languageOptions: {sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, pluginReactConfig, );", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/syntax-script-react-typescript b/tests/__snapshots__/syntax-script-react-typescript index 4be43b5a..e99476af 100644 --- a/tests/__snapshots__/syntax-script-react-typescript +++ b/tests/__snapshots__/syntax-script-react-typescript @@ -5,7 +5,7 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [].concat( - { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, + { languageOptions: {sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, tseslint.configs.recommended, pluginReactConfig, );", diff --git a/tests/__snapshots__/syntax-script-vue-javascript b/tests/__snapshots__/syntax-script-vue-javascript index c8bbcc98..12629c20 100644 --- a/tests/__snapshots__/syntax-script-vue-javascript +++ b/tests/__snapshots__/syntax-script-vue-javascript @@ -12,7 +12,7 @@ const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [].concat( - { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, + { languageOptions: {sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), );", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/syntax-script-vue-typescript b/tests/__snapshots__/syntax-script-vue-typescript index a57d5d47..c4cbd10d 100644 --- a/tests/__snapshots__/syntax-script-vue-typescript +++ b/tests/__snapshots__/syntax-script-vue-typescript @@ -13,7 +13,7 @@ const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [].concat( - { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, + { languageOptions: {sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, tseslint.configs.recommended, compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), );", From ed29ad7b27554ba87becbbb1feb8eea841ab8085 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Thu, 29 Feb 2024 19:13:57 +0800 Subject: [PATCH 12/41] fix: indent --- lib/config-generator.js | 2 +- tests/__snapshots__/problem-commonjs-none-javascript | 4 ++-- tests/__snapshots__/problem-commonjs-none-typescript | 4 ++-- tests/__snapshots__/problem-commonjs-react-javascript | 4 ++-- tests/__snapshots__/problem-commonjs-react-typescript | 4 ++-- tests/__snapshots__/problem-commonjs-vue-javascript | 4 ++-- tests/__snapshots__/problem-commonjs-vue-typescript | 4 ++-- tests/__snapshots__/problem-esm-none-javascript | 4 ++-- tests/__snapshots__/problem-esm-none-typescript | 4 ++-- tests/__snapshots__/problem-esm-react-javascript | 4 ++-- tests/__snapshots__/problem-esm-react-typescript | 4 ++-- tests/__snapshots__/problem-esm-vue-javascript | 4 ++-- tests/__snapshots__/problem-esm-vue-typescript | 4 ++-- tests/__snapshots__/problem-script-none-javascript | 4 ++-- tests/__snapshots__/problem-script-none-typescript | 4 ++-- tests/__snapshots__/problem-script-react-javascript | 4 ++-- tests/__snapshots__/problem-script-react-typescript | 4 ++-- tests/__snapshots__/problem-script-vue-javascript | 4 ++-- tests/__snapshots__/problem-script-vue-typescript | 4 ++-- tests/__snapshots__/style-esm-none-xo-javascript | 4 ++-- tests/__snapshots__/style-esm-none-xo-typescript | 4 ++-- tests/__snapshots__/syntax-commonjs-none-javascript | 4 ++-- tests/__snapshots__/syntax-commonjs-none-typescript | 4 ++-- tests/__snapshots__/syntax-commonjs-react-javascript | 4 ++-- tests/__snapshots__/syntax-commonjs-react-typescript | 4 ++-- tests/__snapshots__/syntax-commonjs-vue-javascript | 4 ++-- tests/__snapshots__/syntax-commonjs-vue-typescript | 4 ++-- tests/__snapshots__/syntax-esm-none-javascript | 4 ++-- tests/__snapshots__/syntax-esm-none-typescript | 4 ++-- tests/__snapshots__/syntax-esm-react-javascript | 4 ++-- tests/__snapshots__/syntax-esm-react-typescript | 4 ++-- tests/__snapshots__/syntax-esm-vue-javascript | 4 ++-- tests/__snapshots__/syntax-esm-vue-typescript | 4 ++-- tests/__snapshots__/syntax-script-none-javascript | 4 ++-- tests/__snapshots__/syntax-script-none-typescript | 4 ++-- tests/__snapshots__/syntax-script-react-javascript | 4 ++-- tests/__snapshots__/syntax-script-react-typescript | 4 ++-- tests/__snapshots__/syntax-script-vue-javascript | 4 ++-- tests/__snapshots__/syntax-script-vue-typescript | 4 ++-- 39 files changed, 77 insertions(+), 77 deletions(-) diff --git a/lib/config-generator.js b/lib/config-generator.js index 13418bfc..1afc61ed 100644 --- a/lib/config-generator.js +++ b/lib/config-generator.js @@ -231,7 +231,7 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug this.result.devDependencies.push("@eslint/eslintrc", "@eslint/js"); } this.result.configContent = `${importContent}\n${needCompatHelper ? helperContent : ""} -export default [].concat(\n { languageOptions: {${languageOptionsContent}}},\n ${exportContent});`; +export default [].concat(\n {languageOptions:{${languageOptionsContent}}},\n${exportContent});`; } /** diff --git a/tests/__snapshots__/problem-commonjs-none-javascript b/tests/__snapshots__/problem-commonjs-none-javascript index afe65c07..ab455bbe 100644 --- a/tests/__snapshots__/problem-commonjs-none-javascript +++ b/tests/__snapshots__/problem-commonjs-none-javascript @@ -4,8 +4,8 @@ import globals from "globals"; export default [].concat( - { languageOptions: {sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, - pluginJs.configs.recommended, + {languageOptions:{sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, + pluginJs.configs.recommended, );", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/problem-commonjs-none-typescript b/tests/__snapshots__/problem-commonjs-none-typescript index d07fdc88..7e1e547c 100644 --- a/tests/__snapshots__/problem-commonjs-none-typescript +++ b/tests/__snapshots__/problem-commonjs-none-typescript @@ -5,8 +5,8 @@ import tseslint from "typescript-eslint"; export default [].concat( - { languageOptions: {sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, - pluginJs.configs.recommended, + {languageOptions:{sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, + pluginJs.configs.recommended, tseslint.configs.recommended, );", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/problem-commonjs-react-javascript b/tests/__snapshots__/problem-commonjs-react-javascript index 7a1242fd..305ca9f9 100644 --- a/tests/__snapshots__/problem-commonjs-react-javascript +++ b/tests/__snapshots__/problem-commonjs-react-javascript @@ -5,8 +5,8 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [].concat( - { languageOptions: {sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, - pluginJs.configs.recommended, + {languageOptions:{sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, + pluginJs.configs.recommended, pluginReactConfig, );", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/problem-commonjs-react-typescript b/tests/__snapshots__/problem-commonjs-react-typescript index 75f23a56..bd1f6705 100644 --- a/tests/__snapshots__/problem-commonjs-react-typescript +++ b/tests/__snapshots__/problem-commonjs-react-typescript @@ -6,8 +6,8 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [].concat( - { languageOptions: {sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, - pluginJs.configs.recommended, + {languageOptions:{sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, + pluginJs.configs.recommended, tseslint.configs.recommended, pluginReactConfig, );", diff --git a/tests/__snapshots__/problem-commonjs-vue-javascript b/tests/__snapshots__/problem-commonjs-vue-javascript index e6808c26..6d4ceb89 100644 --- a/tests/__snapshots__/problem-commonjs-vue-javascript +++ b/tests/__snapshots__/problem-commonjs-vue-javascript @@ -13,8 +13,8 @@ const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [].concat( - { languageOptions: {sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, - pluginJs.configs.recommended, + {languageOptions:{sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, + pluginJs.configs.recommended, compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), );", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/problem-commonjs-vue-typescript b/tests/__snapshots__/problem-commonjs-vue-typescript index af9f4a8a..2572b634 100644 --- a/tests/__snapshots__/problem-commonjs-vue-typescript +++ b/tests/__snapshots__/problem-commonjs-vue-typescript @@ -14,8 +14,8 @@ const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [].concat( - { languageOptions: {sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, - pluginJs.configs.recommended, + {languageOptions:{sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, + pluginJs.configs.recommended, tseslint.configs.recommended, compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), );", diff --git a/tests/__snapshots__/problem-esm-none-javascript b/tests/__snapshots__/problem-esm-none-javascript index d825c38d..a0aaece1 100644 --- a/tests/__snapshots__/problem-esm-none-javascript +++ b/tests/__snapshots__/problem-esm-none-javascript @@ -4,8 +4,8 @@ import globals from "globals"; export default [].concat( - { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, - pluginJs.configs.recommended, + {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, + pluginJs.configs.recommended, );", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/problem-esm-none-typescript b/tests/__snapshots__/problem-esm-none-typescript index 4379fcb6..ce959e27 100644 --- a/tests/__snapshots__/problem-esm-none-typescript +++ b/tests/__snapshots__/problem-esm-none-typescript @@ -5,8 +5,8 @@ import tseslint from "typescript-eslint"; export default [].concat( - { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, - pluginJs.configs.recommended, + {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, + pluginJs.configs.recommended, tseslint.configs.recommended, );", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/problem-esm-react-javascript b/tests/__snapshots__/problem-esm-react-javascript index 83bc9861..0ab6444c 100644 --- a/tests/__snapshots__/problem-esm-react-javascript +++ b/tests/__snapshots__/problem-esm-react-javascript @@ -5,8 +5,8 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [].concat( - { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, - pluginJs.configs.recommended, + {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, + pluginJs.configs.recommended, pluginReactConfig, );", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/problem-esm-react-typescript b/tests/__snapshots__/problem-esm-react-typescript index 73949396..9ff170dc 100644 --- a/tests/__snapshots__/problem-esm-react-typescript +++ b/tests/__snapshots__/problem-esm-react-typescript @@ -6,8 +6,8 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [].concat( - { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, - pluginJs.configs.recommended, + {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, + pluginJs.configs.recommended, tseslint.configs.recommended, pluginReactConfig, );", diff --git a/tests/__snapshots__/problem-esm-vue-javascript b/tests/__snapshots__/problem-esm-vue-javascript index 53700904..c8984288 100644 --- a/tests/__snapshots__/problem-esm-vue-javascript +++ b/tests/__snapshots__/problem-esm-vue-javascript @@ -13,8 +13,8 @@ const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [].concat( - { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, - pluginJs.configs.recommended, + {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, + pluginJs.configs.recommended, compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), );", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/problem-esm-vue-typescript b/tests/__snapshots__/problem-esm-vue-typescript index c3ea84a4..50d7190f 100644 --- a/tests/__snapshots__/problem-esm-vue-typescript +++ b/tests/__snapshots__/problem-esm-vue-typescript @@ -14,8 +14,8 @@ const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [].concat( - { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, - pluginJs.configs.recommended, + {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, + pluginJs.configs.recommended, tseslint.configs.recommended, compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), );", diff --git a/tests/__snapshots__/problem-script-none-javascript b/tests/__snapshots__/problem-script-none-javascript index 62d54cc7..191ad485 100644 --- a/tests/__snapshots__/problem-script-none-javascript +++ b/tests/__snapshots__/problem-script-none-javascript @@ -4,8 +4,8 @@ import globals from "globals"; export default [].concat( - { languageOptions: {sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, - pluginJs.configs.recommended, + {languageOptions:{sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, + pluginJs.configs.recommended, );", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/problem-script-none-typescript b/tests/__snapshots__/problem-script-none-typescript index 78729a52..792c3d6d 100644 --- a/tests/__snapshots__/problem-script-none-typescript +++ b/tests/__snapshots__/problem-script-none-typescript @@ -5,8 +5,8 @@ import tseslint from "typescript-eslint"; export default [].concat( - { languageOptions: {sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, - pluginJs.configs.recommended, + {languageOptions:{sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, + pluginJs.configs.recommended, tseslint.configs.recommended, );", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/problem-script-react-javascript b/tests/__snapshots__/problem-script-react-javascript index ecdf374f..5d1435e9 100644 --- a/tests/__snapshots__/problem-script-react-javascript +++ b/tests/__snapshots__/problem-script-react-javascript @@ -5,8 +5,8 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [].concat( - { languageOptions: {sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, - pluginJs.configs.recommended, + {languageOptions:{sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, + pluginJs.configs.recommended, pluginReactConfig, );", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/problem-script-react-typescript b/tests/__snapshots__/problem-script-react-typescript index 8d455a72..4dee281d 100644 --- a/tests/__snapshots__/problem-script-react-typescript +++ b/tests/__snapshots__/problem-script-react-typescript @@ -6,8 +6,8 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [].concat( - { languageOptions: {sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, - pluginJs.configs.recommended, + {languageOptions:{sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, + pluginJs.configs.recommended, tseslint.configs.recommended, pluginReactConfig, );", diff --git a/tests/__snapshots__/problem-script-vue-javascript b/tests/__snapshots__/problem-script-vue-javascript index f918d6c8..e768779c 100644 --- a/tests/__snapshots__/problem-script-vue-javascript +++ b/tests/__snapshots__/problem-script-vue-javascript @@ -13,8 +13,8 @@ const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [].concat( - { languageOptions: {sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, - pluginJs.configs.recommended, + {languageOptions:{sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, + pluginJs.configs.recommended, compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), );", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/problem-script-vue-typescript b/tests/__snapshots__/problem-script-vue-typescript index 930e5287..d0954e7e 100644 --- a/tests/__snapshots__/problem-script-vue-typescript +++ b/tests/__snapshots__/problem-script-vue-typescript @@ -14,8 +14,8 @@ const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [].concat( - { languageOptions: {sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, - pluginJs.configs.recommended, + {languageOptions:{sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, + pluginJs.configs.recommended, tseslint.configs.recommended, compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), );", diff --git a/tests/__snapshots__/style-esm-none-xo-javascript b/tests/__snapshots__/style-esm-none-xo-javascript index 11f02aed..20318d30 100644 --- a/tests/__snapshots__/style-esm-none-xo-javascript +++ b/tests/__snapshots__/style-esm-none-xo-javascript @@ -12,8 +12,8 @@ const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [].concat( - { languageOptions: {globals: globals.node, }}, - compat.extends("xo"), + {languageOptions:{globals: globals.node, }}, + compat.extends("xo"), );", "configFilename": "eslint.config.mjs", "devDependencies": [ diff --git a/tests/__snapshots__/style-esm-none-xo-typescript b/tests/__snapshots__/style-esm-none-xo-typescript index 77d2f302..0b04c96a 100644 --- a/tests/__snapshots__/style-esm-none-xo-typescript +++ b/tests/__snapshots__/style-esm-none-xo-typescript @@ -13,8 +13,8 @@ const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [].concat( - { languageOptions: {globals: globals.browser, }}, - compat.extends("xo-typescript"), + {languageOptions:{globals: globals.browser, }}, + compat.extends("xo-typescript"), tseslint.configs.recommended, );", "configFilename": "eslint.config.mjs", diff --git a/tests/__snapshots__/syntax-commonjs-none-javascript b/tests/__snapshots__/syntax-commonjs-none-javascript index 3822dca6..7b25856c 100644 --- a/tests/__snapshots__/syntax-commonjs-none-javascript +++ b/tests/__snapshots__/syntax-commonjs-none-javascript @@ -3,8 +3,8 @@ export default [].concat( - { languageOptions: {sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, - );", + {languageOptions:{sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, +);", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", diff --git a/tests/__snapshots__/syntax-commonjs-none-typescript b/tests/__snapshots__/syntax-commonjs-none-typescript index 20caea3f..5f50661f 100644 --- a/tests/__snapshots__/syntax-commonjs-none-typescript +++ b/tests/__snapshots__/syntax-commonjs-none-typescript @@ -4,8 +4,8 @@ import tseslint from "typescript-eslint"; export default [].concat( - { languageOptions: {sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, - tseslint.configs.recommended, + {languageOptions:{sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, + tseslint.configs.recommended, );", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/syntax-commonjs-react-javascript b/tests/__snapshots__/syntax-commonjs-react-javascript index 3fae923b..342bab15 100644 --- a/tests/__snapshots__/syntax-commonjs-react-javascript +++ b/tests/__snapshots__/syntax-commonjs-react-javascript @@ -4,8 +4,8 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [].concat( - { languageOptions: {sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, - pluginReactConfig, + {languageOptions:{sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, + pluginReactConfig, );", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/syntax-commonjs-react-typescript b/tests/__snapshots__/syntax-commonjs-react-typescript index a8e166fb..5ca75b2c 100644 --- a/tests/__snapshots__/syntax-commonjs-react-typescript +++ b/tests/__snapshots__/syntax-commonjs-react-typescript @@ -5,8 +5,8 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [].concat( - { languageOptions: {sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, - tseslint.configs.recommended, + {languageOptions:{sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, + tseslint.configs.recommended, pluginReactConfig, );", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/syntax-commonjs-vue-javascript b/tests/__snapshots__/syntax-commonjs-vue-javascript index a73092eb..95429683 100644 --- a/tests/__snapshots__/syntax-commonjs-vue-javascript +++ b/tests/__snapshots__/syntax-commonjs-vue-javascript @@ -12,8 +12,8 @@ const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [].concat( - { languageOptions: {sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, - compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), + {languageOptions:{sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, + compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), );", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/syntax-commonjs-vue-typescript b/tests/__snapshots__/syntax-commonjs-vue-typescript index 9520bc99..0e5afa8a 100644 --- a/tests/__snapshots__/syntax-commonjs-vue-typescript +++ b/tests/__snapshots__/syntax-commonjs-vue-typescript @@ -13,8 +13,8 @@ const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [].concat( - { languageOptions: {sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, - tseslint.configs.recommended, + {languageOptions:{sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, + tseslint.configs.recommended, compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), );", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/syntax-esm-none-javascript b/tests/__snapshots__/syntax-esm-none-javascript index 36dd7e25..a0b9bb4c 100644 --- a/tests/__snapshots__/syntax-esm-none-javascript +++ b/tests/__snapshots__/syntax-esm-none-javascript @@ -3,8 +3,8 @@ export default [].concat( - { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, - );", + {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, +);", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", diff --git a/tests/__snapshots__/syntax-esm-none-typescript b/tests/__snapshots__/syntax-esm-none-typescript index 775f8a5a..a2af9d49 100644 --- a/tests/__snapshots__/syntax-esm-none-typescript +++ b/tests/__snapshots__/syntax-esm-none-typescript @@ -4,8 +4,8 @@ import tseslint from "typescript-eslint"; export default [].concat( - { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, - tseslint.configs.recommended, + {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, + tseslint.configs.recommended, );", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/syntax-esm-react-javascript b/tests/__snapshots__/syntax-esm-react-javascript index b057d27b..b28929aa 100644 --- a/tests/__snapshots__/syntax-esm-react-javascript +++ b/tests/__snapshots__/syntax-esm-react-javascript @@ -4,8 +4,8 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [].concat( - { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, - pluginReactConfig, + {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, + pluginReactConfig, );", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/syntax-esm-react-typescript b/tests/__snapshots__/syntax-esm-react-typescript index 4be43b5a..a091e3c5 100644 --- a/tests/__snapshots__/syntax-esm-react-typescript +++ b/tests/__snapshots__/syntax-esm-react-typescript @@ -5,8 +5,8 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [].concat( - { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, - tseslint.configs.recommended, + {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, + tseslint.configs.recommended, pluginReactConfig, );", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/syntax-esm-vue-javascript b/tests/__snapshots__/syntax-esm-vue-javascript index c8bbcc98..92e57091 100644 --- a/tests/__snapshots__/syntax-esm-vue-javascript +++ b/tests/__snapshots__/syntax-esm-vue-javascript @@ -12,8 +12,8 @@ const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [].concat( - { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, - compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), + {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, + compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), );", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/syntax-esm-vue-typescript b/tests/__snapshots__/syntax-esm-vue-typescript index a57d5d47..7d2efce7 100644 --- a/tests/__snapshots__/syntax-esm-vue-typescript +++ b/tests/__snapshots__/syntax-esm-vue-typescript @@ -13,8 +13,8 @@ const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [].concat( - { languageOptions: {globals: {...globals.browser, ...globals.node}, }}, - tseslint.configs.recommended, + {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, + tseslint.configs.recommended, compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), );", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/syntax-script-none-javascript b/tests/__snapshots__/syntax-script-none-javascript index 5583d5aa..1b007ba3 100644 --- a/tests/__snapshots__/syntax-script-none-javascript +++ b/tests/__snapshots__/syntax-script-none-javascript @@ -3,8 +3,8 @@ export default [].concat( - { languageOptions: {sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, - );", + {languageOptions:{sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, +);", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", diff --git a/tests/__snapshots__/syntax-script-none-typescript b/tests/__snapshots__/syntax-script-none-typescript index bf866962..6b02a7d2 100644 --- a/tests/__snapshots__/syntax-script-none-typescript +++ b/tests/__snapshots__/syntax-script-none-typescript @@ -4,8 +4,8 @@ import tseslint from "typescript-eslint"; export default [].concat( - { languageOptions: {sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, - tseslint.configs.recommended, + {languageOptions:{sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, + tseslint.configs.recommended, );", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/syntax-script-react-javascript b/tests/__snapshots__/syntax-script-react-javascript index 259694d3..12b3373e 100644 --- a/tests/__snapshots__/syntax-script-react-javascript +++ b/tests/__snapshots__/syntax-script-react-javascript @@ -4,8 +4,8 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [].concat( - { languageOptions: {sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, - pluginReactConfig, + {languageOptions:{sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, + pluginReactConfig, );", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/syntax-script-react-typescript b/tests/__snapshots__/syntax-script-react-typescript index e99476af..861cafff 100644 --- a/tests/__snapshots__/syntax-script-react-typescript +++ b/tests/__snapshots__/syntax-script-react-typescript @@ -5,8 +5,8 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [].concat( - { languageOptions: {sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, - tseslint.configs.recommended, + {languageOptions:{sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, + tseslint.configs.recommended, pluginReactConfig, );", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/syntax-script-vue-javascript b/tests/__snapshots__/syntax-script-vue-javascript index 12629c20..16748cc2 100644 --- a/tests/__snapshots__/syntax-script-vue-javascript +++ b/tests/__snapshots__/syntax-script-vue-javascript @@ -12,8 +12,8 @@ const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [].concat( - { languageOptions: {sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, - compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), + {languageOptions:{sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, + compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), );", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/syntax-script-vue-typescript b/tests/__snapshots__/syntax-script-vue-typescript index c4cbd10d..3ec5caef 100644 --- a/tests/__snapshots__/syntax-script-vue-typescript +++ b/tests/__snapshots__/syntax-script-vue-typescript @@ -13,8 +13,8 @@ const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [].concat( - { languageOptions: {sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, - tseslint.configs.recommended, + {languageOptions:{sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, + tseslint.configs.recommended, compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), );", "configFilename": "eslint.config.js", From 0cc0c416d186e9e13909b4c8b10ea0576406df6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Fri, 1 Mar 2024 10:22:52 +0800 Subject: [PATCH 13/41] fix: use `[].concat()` only for shared configs --- lib/config-generator.js | 10 +++++----- tests/__snapshots__/problem-commonjs-none-javascript | 4 ++-- tests/__snapshots__/problem-commonjs-none-typescript | 6 +++--- tests/__snapshots__/problem-commonjs-react-javascript | 4 ++-- tests/__snapshots__/problem-commonjs-react-typescript | 6 +++--- tests/__snapshots__/problem-commonjs-vue-javascript | 6 +++--- tests/__snapshots__/problem-commonjs-vue-typescript | 8 ++++---- tests/__snapshots__/problem-esm-none-javascript | 4 ++-- tests/__snapshots__/problem-esm-none-typescript | 6 +++--- tests/__snapshots__/problem-esm-react-javascript | 4 ++-- tests/__snapshots__/problem-esm-react-typescript | 6 +++--- tests/__snapshots__/problem-esm-vue-javascript | 6 +++--- tests/__snapshots__/problem-esm-vue-typescript | 8 ++++---- tests/__snapshots__/problem-script-none-javascript | 4 ++-- tests/__snapshots__/problem-script-none-typescript | 6 +++--- tests/__snapshots__/problem-script-react-javascript | 4 ++-- tests/__snapshots__/problem-script-react-typescript | 6 +++--- tests/__snapshots__/problem-script-vue-javascript | 6 +++--- tests/__snapshots__/problem-script-vue-typescript | 8 ++++---- tests/__snapshots__/style-esm-none-xo-javascript | 6 +++--- tests/__snapshots__/style-esm-none-xo-typescript | 8 ++++---- tests/__snapshots__/syntax-commonjs-none-javascript | 4 ++-- tests/__snapshots__/syntax-commonjs-none-typescript | 6 +++--- tests/__snapshots__/syntax-commonjs-react-javascript | 4 ++-- tests/__snapshots__/syntax-commonjs-react-typescript | 6 +++--- tests/__snapshots__/syntax-commonjs-vue-javascript | 6 +++--- tests/__snapshots__/syntax-commonjs-vue-typescript | 8 ++++---- tests/__snapshots__/syntax-esm-none-javascript | 4 ++-- tests/__snapshots__/syntax-esm-none-typescript | 6 +++--- tests/__snapshots__/syntax-esm-react-javascript | 4 ++-- tests/__snapshots__/syntax-esm-react-typescript | 6 +++--- tests/__snapshots__/syntax-esm-vue-javascript | 6 +++--- tests/__snapshots__/syntax-esm-vue-typescript | 8 ++++---- tests/__snapshots__/syntax-script-none-javascript | 4 ++-- tests/__snapshots__/syntax-script-none-typescript | 6 +++--- tests/__snapshots__/syntax-script-react-javascript | 4 ++-- tests/__snapshots__/syntax-script-react-typescript | 6 +++--- tests/__snapshots__/syntax-script-vue-javascript | 6 +++--- tests/__snapshots__/syntax-script-vue-typescript | 8 ++++---- 39 files changed, 114 insertions(+), 114 deletions(-) diff --git a/lib/config-generator.js b/lib/config-generator.js index 1afc61ed..3b926ec0 100644 --- a/lib/config-generator.js +++ b/lib/config-generator.js @@ -176,13 +176,13 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug if (styleguide.type === "flat" || styleguide.type === void 0) { importContent += `import styleGuide from "${styleguide.packageName}";\n`; - exportContent += " styleGuide,\n"; + exportContent += " ...[].concat(styleGuide),\n"; } else if (styleguide.type === "eslintrc") { needCompatHelper = true; const extendedName = styleguide.packageName.replace("eslint-config-", ""); - exportContent += ` compat.extends("${extendedName}"),\n`; + exportContent += ` ...compat.extends("${extendedName}"),\n`; } } @@ -206,7 +206,7 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug if (this.answers.language === "typescript") { this.result.devDependencies.push("typescript-eslint"); importContent += "import tseslint from \"typescript-eslint\";\n"; - exportContent += " tseslint.configs.recommended,\n"; + exportContent += " ...tseslint.configs.recommended,\n"; } if (this.answers.framework === "vue") { @@ -218,7 +218,7 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug // // TODO: there is a wip for flat support - https://github.com/vuejs/eslint-plugin-vue/pull/2319 // exportContent += " pluginVue.configs[\"flat/essential\"],\n"; needCompatHelper = true; - exportContent += " compat.extends(\"plugin:vue/vue3-essential\").map(config => ({files: [\"**/*.vue\"], ...config})),\n"; + exportContent += " ...compat.extends(\"plugin:vue/vue3-essential\").map(config => ({files: [\"**/*.vue\"], ...config})),\n"; } if (this.answers.framework === "react") { @@ -231,7 +231,7 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug this.result.devDependencies.push("@eslint/eslintrc", "@eslint/js"); } this.result.configContent = `${importContent}\n${needCompatHelper ? helperContent : ""} -export default [].concat(\n {languageOptions:{${languageOptionsContent}}},\n${exportContent});`; +export default [\n {languageOptions:{${languageOptionsContent}}},\n${exportContent}];`; } /** diff --git a/tests/__snapshots__/problem-commonjs-none-javascript b/tests/__snapshots__/problem-commonjs-none-javascript index ab455bbe..fab39c7c 100644 --- a/tests/__snapshots__/problem-commonjs-none-javascript +++ b/tests/__snapshots__/problem-commonjs-none-javascript @@ -3,10 +3,10 @@ import globals from "globals"; -export default [].concat( +export default [ {languageOptions:{sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, pluginJs.configs.recommended, -);", +];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", diff --git a/tests/__snapshots__/problem-commonjs-none-typescript b/tests/__snapshots__/problem-commonjs-none-typescript index 7e1e547c..20b51eb4 100644 --- a/tests/__snapshots__/problem-commonjs-none-typescript +++ b/tests/__snapshots__/problem-commonjs-none-typescript @@ -4,11 +4,11 @@ import globals from "globals"; import tseslint from "typescript-eslint"; -export default [].concat( +export default [ {languageOptions:{sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, pluginJs.configs.recommended, - tseslint.configs.recommended, -);", + ...tseslint.configs.recommended, +];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", diff --git a/tests/__snapshots__/problem-commonjs-react-javascript b/tests/__snapshots__/problem-commonjs-react-javascript index 305ca9f9..996982c9 100644 --- a/tests/__snapshots__/problem-commonjs-react-javascript +++ b/tests/__snapshots__/problem-commonjs-react-javascript @@ -4,11 +4,11 @@ import globals from "globals"; import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; -export default [].concat( +export default [ {languageOptions:{sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, pluginJs.configs.recommended, pluginReactConfig, -);", +];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", diff --git a/tests/__snapshots__/problem-commonjs-react-typescript b/tests/__snapshots__/problem-commonjs-react-typescript index bd1f6705..d4db10b9 100644 --- a/tests/__snapshots__/problem-commonjs-react-typescript +++ b/tests/__snapshots__/problem-commonjs-react-typescript @@ -5,12 +5,12 @@ import tseslint from "typescript-eslint"; import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; -export default [].concat( +export default [ {languageOptions:{sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, pluginJs.configs.recommended, - tseslint.configs.recommended, + ...tseslint.configs.recommended, pluginReactConfig, -);", +];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", diff --git a/tests/__snapshots__/problem-commonjs-vue-javascript b/tests/__snapshots__/problem-commonjs-vue-javascript index 6d4ceb89..d2084a1a 100644 --- a/tests/__snapshots__/problem-commonjs-vue-javascript +++ b/tests/__snapshots__/problem-commonjs-vue-javascript @@ -12,11 +12,11 @@ const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); -export default [].concat( +export default [ {languageOptions:{sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, pluginJs.configs.recommended, - compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), -);", + ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), +];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", diff --git a/tests/__snapshots__/problem-commonjs-vue-typescript b/tests/__snapshots__/problem-commonjs-vue-typescript index 2572b634..f52c1f0b 100644 --- a/tests/__snapshots__/problem-commonjs-vue-typescript +++ b/tests/__snapshots__/problem-commonjs-vue-typescript @@ -13,12 +13,12 @@ const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); -export default [].concat( +export default [ {languageOptions:{sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, pluginJs.configs.recommended, - tseslint.configs.recommended, - compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), -);", + ...tseslint.configs.recommended, + ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), +];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", diff --git a/tests/__snapshots__/problem-esm-none-javascript b/tests/__snapshots__/problem-esm-none-javascript index a0aaece1..844f4133 100644 --- a/tests/__snapshots__/problem-esm-none-javascript +++ b/tests/__snapshots__/problem-esm-none-javascript @@ -3,10 +3,10 @@ import globals from "globals"; -export default [].concat( +export default [ {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, pluginJs.configs.recommended, -);", +];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", diff --git a/tests/__snapshots__/problem-esm-none-typescript b/tests/__snapshots__/problem-esm-none-typescript index ce959e27..49a967e4 100644 --- a/tests/__snapshots__/problem-esm-none-typescript +++ b/tests/__snapshots__/problem-esm-none-typescript @@ -4,11 +4,11 @@ import globals from "globals"; import tseslint from "typescript-eslint"; -export default [].concat( +export default [ {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, pluginJs.configs.recommended, - tseslint.configs.recommended, -);", + ...tseslint.configs.recommended, +];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", diff --git a/tests/__snapshots__/problem-esm-react-javascript b/tests/__snapshots__/problem-esm-react-javascript index 0ab6444c..73dc0102 100644 --- a/tests/__snapshots__/problem-esm-react-javascript +++ b/tests/__snapshots__/problem-esm-react-javascript @@ -4,11 +4,11 @@ import globals from "globals"; import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; -export default [].concat( +export default [ {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, pluginJs.configs.recommended, pluginReactConfig, -);", +];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", diff --git a/tests/__snapshots__/problem-esm-react-typescript b/tests/__snapshots__/problem-esm-react-typescript index 9ff170dc..255a31ca 100644 --- a/tests/__snapshots__/problem-esm-react-typescript +++ b/tests/__snapshots__/problem-esm-react-typescript @@ -5,12 +5,12 @@ import tseslint from "typescript-eslint"; import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; -export default [].concat( +export default [ {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, pluginJs.configs.recommended, - tseslint.configs.recommended, + ...tseslint.configs.recommended, pluginReactConfig, -);", +];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", diff --git a/tests/__snapshots__/problem-esm-vue-javascript b/tests/__snapshots__/problem-esm-vue-javascript index c8984288..3185cbcc 100644 --- a/tests/__snapshots__/problem-esm-vue-javascript +++ b/tests/__snapshots__/problem-esm-vue-javascript @@ -12,11 +12,11 @@ const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); -export default [].concat( +export default [ {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, pluginJs.configs.recommended, - compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), -);", + ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), +];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", diff --git a/tests/__snapshots__/problem-esm-vue-typescript b/tests/__snapshots__/problem-esm-vue-typescript index 50d7190f..0fb362d8 100644 --- a/tests/__snapshots__/problem-esm-vue-typescript +++ b/tests/__snapshots__/problem-esm-vue-typescript @@ -13,12 +13,12 @@ const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); -export default [].concat( +export default [ {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, pluginJs.configs.recommended, - tseslint.configs.recommended, - compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), -);", + ...tseslint.configs.recommended, + ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), +];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", diff --git a/tests/__snapshots__/problem-script-none-javascript b/tests/__snapshots__/problem-script-none-javascript index 191ad485..d50ea6a3 100644 --- a/tests/__snapshots__/problem-script-none-javascript +++ b/tests/__snapshots__/problem-script-none-javascript @@ -3,10 +3,10 @@ import globals from "globals"; -export default [].concat( +export default [ {languageOptions:{sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, pluginJs.configs.recommended, -);", +];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", diff --git a/tests/__snapshots__/problem-script-none-typescript b/tests/__snapshots__/problem-script-none-typescript index 792c3d6d..299aca68 100644 --- a/tests/__snapshots__/problem-script-none-typescript +++ b/tests/__snapshots__/problem-script-none-typescript @@ -4,11 +4,11 @@ import globals from "globals"; import tseslint from "typescript-eslint"; -export default [].concat( +export default [ {languageOptions:{sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, pluginJs.configs.recommended, - tseslint.configs.recommended, -);", + ...tseslint.configs.recommended, +];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", diff --git a/tests/__snapshots__/problem-script-react-javascript b/tests/__snapshots__/problem-script-react-javascript index 5d1435e9..162b3acd 100644 --- a/tests/__snapshots__/problem-script-react-javascript +++ b/tests/__snapshots__/problem-script-react-javascript @@ -4,11 +4,11 @@ import globals from "globals"; import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; -export default [].concat( +export default [ {languageOptions:{sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, pluginJs.configs.recommended, pluginReactConfig, -);", +];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", diff --git a/tests/__snapshots__/problem-script-react-typescript b/tests/__snapshots__/problem-script-react-typescript index 4dee281d..4a9f5a9b 100644 --- a/tests/__snapshots__/problem-script-react-typescript +++ b/tests/__snapshots__/problem-script-react-typescript @@ -5,12 +5,12 @@ import tseslint from "typescript-eslint"; import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; -export default [].concat( +export default [ {languageOptions:{sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, pluginJs.configs.recommended, - tseslint.configs.recommended, + ...tseslint.configs.recommended, pluginReactConfig, -);", +];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", diff --git a/tests/__snapshots__/problem-script-vue-javascript b/tests/__snapshots__/problem-script-vue-javascript index e768779c..a72573c2 100644 --- a/tests/__snapshots__/problem-script-vue-javascript +++ b/tests/__snapshots__/problem-script-vue-javascript @@ -12,11 +12,11 @@ const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); -export default [].concat( +export default [ {languageOptions:{sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, pluginJs.configs.recommended, - compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), -);", + ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), +];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", diff --git a/tests/__snapshots__/problem-script-vue-typescript b/tests/__snapshots__/problem-script-vue-typescript index d0954e7e..b2cd2ac8 100644 --- a/tests/__snapshots__/problem-script-vue-typescript +++ b/tests/__snapshots__/problem-script-vue-typescript @@ -13,12 +13,12 @@ const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); -export default [].concat( +export default [ {languageOptions:{sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, pluginJs.configs.recommended, - tseslint.configs.recommended, - compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), -);", + ...tseslint.configs.recommended, + ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), +];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", diff --git a/tests/__snapshots__/style-esm-none-xo-javascript b/tests/__snapshots__/style-esm-none-xo-javascript index 20318d30..1250475f 100644 --- a/tests/__snapshots__/style-esm-none-xo-javascript +++ b/tests/__snapshots__/style-esm-none-xo-javascript @@ -11,10 +11,10 @@ const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); -export default [].concat( +export default [ {languageOptions:{globals: globals.node, }}, - compat.extends("xo"), -);", + ...compat.extends("xo"), +];", "configFilename": "eslint.config.mjs", "devDependencies": [ "eslint", diff --git a/tests/__snapshots__/style-esm-none-xo-typescript b/tests/__snapshots__/style-esm-none-xo-typescript index 0b04c96a..eeb3a1f1 100644 --- a/tests/__snapshots__/style-esm-none-xo-typescript +++ b/tests/__snapshots__/style-esm-none-xo-typescript @@ -12,11 +12,11 @@ const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); -export default [].concat( +export default [ {languageOptions:{globals: globals.browser, }}, - compat.extends("xo-typescript"), - tseslint.configs.recommended, -);", + ...compat.extends("xo-typescript"), + ...tseslint.configs.recommended, +];", "configFilename": "eslint.config.mjs", "devDependencies": [ "eslint", diff --git a/tests/__snapshots__/syntax-commonjs-none-javascript b/tests/__snapshots__/syntax-commonjs-none-javascript index 7b25856c..61922ccb 100644 --- a/tests/__snapshots__/syntax-commonjs-none-javascript +++ b/tests/__snapshots__/syntax-commonjs-none-javascript @@ -2,9 +2,9 @@ "configContent": "import globals from "globals"; -export default [].concat( +export default [ {languageOptions:{sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, -);", +];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", diff --git a/tests/__snapshots__/syntax-commonjs-none-typescript b/tests/__snapshots__/syntax-commonjs-none-typescript index 5f50661f..dc46e427 100644 --- a/tests/__snapshots__/syntax-commonjs-none-typescript +++ b/tests/__snapshots__/syntax-commonjs-none-typescript @@ -3,10 +3,10 @@ import tseslint from "typescript-eslint"; -export default [].concat( +export default [ {languageOptions:{sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, - tseslint.configs.recommended, -);", + ...tseslint.configs.recommended, +];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", diff --git a/tests/__snapshots__/syntax-commonjs-react-javascript b/tests/__snapshots__/syntax-commonjs-react-javascript index 342bab15..67ddf34f 100644 --- a/tests/__snapshots__/syntax-commonjs-react-javascript +++ b/tests/__snapshots__/syntax-commonjs-react-javascript @@ -3,10 +3,10 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; -export default [].concat( +export default [ {languageOptions:{sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, pluginReactConfig, -);", +];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", diff --git a/tests/__snapshots__/syntax-commonjs-react-typescript b/tests/__snapshots__/syntax-commonjs-react-typescript index 5ca75b2c..14f67ac8 100644 --- a/tests/__snapshots__/syntax-commonjs-react-typescript +++ b/tests/__snapshots__/syntax-commonjs-react-typescript @@ -4,11 +4,11 @@ import tseslint from "typescript-eslint"; import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; -export default [].concat( +export default [ {languageOptions:{sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, - tseslint.configs.recommended, + ...tseslint.configs.recommended, pluginReactConfig, -);", +];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", diff --git a/tests/__snapshots__/syntax-commonjs-vue-javascript b/tests/__snapshots__/syntax-commonjs-vue-javascript index 95429683..2f68c2ba 100644 --- a/tests/__snapshots__/syntax-commonjs-vue-javascript +++ b/tests/__snapshots__/syntax-commonjs-vue-javascript @@ -11,10 +11,10 @@ const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); -export default [].concat( +export default [ {languageOptions:{sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, - compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), -);", + ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), +];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", diff --git a/tests/__snapshots__/syntax-commonjs-vue-typescript b/tests/__snapshots__/syntax-commonjs-vue-typescript index 0e5afa8a..9c0e5f01 100644 --- a/tests/__snapshots__/syntax-commonjs-vue-typescript +++ b/tests/__snapshots__/syntax-commonjs-vue-typescript @@ -12,11 +12,11 @@ const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); -export default [].concat( +export default [ {languageOptions:{sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, - tseslint.configs.recommended, - compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), -);", + ...tseslint.configs.recommended, + ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), +];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", diff --git a/tests/__snapshots__/syntax-esm-none-javascript b/tests/__snapshots__/syntax-esm-none-javascript index a0b9bb4c..474c1e5b 100644 --- a/tests/__snapshots__/syntax-esm-none-javascript +++ b/tests/__snapshots__/syntax-esm-none-javascript @@ -2,9 +2,9 @@ "configContent": "import globals from "globals"; -export default [].concat( +export default [ {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, -);", +];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", diff --git a/tests/__snapshots__/syntax-esm-none-typescript b/tests/__snapshots__/syntax-esm-none-typescript index a2af9d49..ec99468f 100644 --- a/tests/__snapshots__/syntax-esm-none-typescript +++ b/tests/__snapshots__/syntax-esm-none-typescript @@ -3,10 +3,10 @@ import tseslint from "typescript-eslint"; -export default [].concat( +export default [ {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, - tseslint.configs.recommended, -);", + ...tseslint.configs.recommended, +];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", diff --git a/tests/__snapshots__/syntax-esm-react-javascript b/tests/__snapshots__/syntax-esm-react-javascript index b28929aa..5d3663f7 100644 --- a/tests/__snapshots__/syntax-esm-react-javascript +++ b/tests/__snapshots__/syntax-esm-react-javascript @@ -3,10 +3,10 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; -export default [].concat( +export default [ {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, pluginReactConfig, -);", +];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", diff --git a/tests/__snapshots__/syntax-esm-react-typescript b/tests/__snapshots__/syntax-esm-react-typescript index a091e3c5..ce4fd002 100644 --- a/tests/__snapshots__/syntax-esm-react-typescript +++ b/tests/__snapshots__/syntax-esm-react-typescript @@ -4,11 +4,11 @@ import tseslint from "typescript-eslint"; import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; -export default [].concat( +export default [ {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, - tseslint.configs.recommended, + ...tseslint.configs.recommended, pluginReactConfig, -);", +];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", diff --git a/tests/__snapshots__/syntax-esm-vue-javascript b/tests/__snapshots__/syntax-esm-vue-javascript index 92e57091..af6abbb1 100644 --- a/tests/__snapshots__/syntax-esm-vue-javascript +++ b/tests/__snapshots__/syntax-esm-vue-javascript @@ -11,10 +11,10 @@ const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); -export default [].concat( +export default [ {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, - compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), -);", + ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), +];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", diff --git a/tests/__snapshots__/syntax-esm-vue-typescript b/tests/__snapshots__/syntax-esm-vue-typescript index 7d2efce7..40c0e31d 100644 --- a/tests/__snapshots__/syntax-esm-vue-typescript +++ b/tests/__snapshots__/syntax-esm-vue-typescript @@ -12,11 +12,11 @@ const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); -export default [].concat( +export default [ {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, - tseslint.configs.recommended, - compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), -);", + ...tseslint.configs.recommended, + ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), +];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", diff --git a/tests/__snapshots__/syntax-script-none-javascript b/tests/__snapshots__/syntax-script-none-javascript index 1b007ba3..14ceec85 100644 --- a/tests/__snapshots__/syntax-script-none-javascript +++ b/tests/__snapshots__/syntax-script-none-javascript @@ -2,9 +2,9 @@ "configContent": "import globals from "globals"; -export default [].concat( +export default [ {languageOptions:{sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, -);", +];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", diff --git a/tests/__snapshots__/syntax-script-none-typescript b/tests/__snapshots__/syntax-script-none-typescript index 6b02a7d2..65669beb 100644 --- a/tests/__snapshots__/syntax-script-none-typescript +++ b/tests/__snapshots__/syntax-script-none-typescript @@ -3,10 +3,10 @@ import tseslint from "typescript-eslint"; -export default [].concat( +export default [ {languageOptions:{sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, - tseslint.configs.recommended, -);", + ...tseslint.configs.recommended, +];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", diff --git a/tests/__snapshots__/syntax-script-react-javascript b/tests/__snapshots__/syntax-script-react-javascript index 12b3373e..515edb5f 100644 --- a/tests/__snapshots__/syntax-script-react-javascript +++ b/tests/__snapshots__/syntax-script-react-javascript @@ -3,10 +3,10 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; -export default [].concat( +export default [ {languageOptions:{sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, pluginReactConfig, -);", +];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", diff --git a/tests/__snapshots__/syntax-script-react-typescript b/tests/__snapshots__/syntax-script-react-typescript index 861cafff..ec5fd472 100644 --- a/tests/__snapshots__/syntax-script-react-typescript +++ b/tests/__snapshots__/syntax-script-react-typescript @@ -4,11 +4,11 @@ import tseslint from "typescript-eslint"; import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; -export default [].concat( +export default [ {languageOptions:{sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, - tseslint.configs.recommended, + ...tseslint.configs.recommended, pluginReactConfig, -);", +];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", diff --git a/tests/__snapshots__/syntax-script-vue-javascript b/tests/__snapshots__/syntax-script-vue-javascript index 16748cc2..43cf5847 100644 --- a/tests/__snapshots__/syntax-script-vue-javascript +++ b/tests/__snapshots__/syntax-script-vue-javascript @@ -11,10 +11,10 @@ const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); -export default [].concat( +export default [ {languageOptions:{sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, - compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), -);", + ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), +];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", diff --git a/tests/__snapshots__/syntax-script-vue-typescript b/tests/__snapshots__/syntax-script-vue-typescript index 3ec5caef..50d81c15 100644 --- a/tests/__snapshots__/syntax-script-vue-typescript +++ b/tests/__snapshots__/syntax-script-vue-typescript @@ -12,11 +12,11 @@ const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); -export default [].concat( +export default [ {languageOptions:{sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, - tseslint.configs.recommended, - compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), -);", + ...tseslint.configs.recommended, + ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), +];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", From d8d81d581184204a1df91741a04709a8f6544d96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Fri, 1 Mar 2024 16:19:39 +0800 Subject: [PATCH 14/41] chore: c8 -> v8 --- package.json | 4 ++-- vitest.config.js | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 vitest.config.js diff --git a/package.json b/package.json index 99f937c0..1c942ddd 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "release:generate:beta": "eslint-generate-prerelease beta", "release:generate:rc": "eslint-generate-prerelease rc", "release:publish": "eslint-publish-release", - "test": "cross-env NODE_OPTIONS=--loader=esmock c8 vitest run \"./tests\"", + "test": "cross-env NODE_OPTIONS=--loader=esmock vitest run --coverage", "test:snapshots": "vitest run snapshots", "test:snapshots:update": "vitest -u run snapshots" }, @@ -45,7 +45,7 @@ "enquirer": "^2.3.5" }, "devDependencies": { - "c8": "^7.10.0", + "@vitest/coverage-v8": "^1.3.1", "cross-env": "^7.0.3", "eslint": "^8.56.0", "eslint-config-eslint": "^9.0.0", diff --git a/vitest.config.js b/vitest.config.js new file mode 100644 index 00000000..149d1eb6 --- /dev/null +++ b/vitest.config.js @@ -0,0 +1,10 @@ +import { defineConfig } from "vitest/config"; + +export default defineConfig({ + test: { + coverage: { + include: ["lib/**/*"], + reporter: ["text", "html"] + } + } +}); From 74e83ab7462bac6aba0624894ce6b89871b5712d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Tue, 5 Mar 2024 14:58:17 +0800 Subject: [PATCH 15/41] refactor: do not throw in constructor --- bin/create-config.js | 14 +++++++++++--- lib/config-generator.js | 8 +------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/bin/create-config.js b/bin/create-config.js index 0e646316..ccc32947 100755 --- a/bin/create-config.js +++ b/bin/create-config.js @@ -6,13 +6,21 @@ */ import { ConfigGenerator } from "../lib/config-generator.js"; +import { checkPackageJson } from "../lib/utils/npm-utils.js"; import process from "process"; -const argv = process.argv; +const cwd = process.cwd(); +const packageJsonExists = checkPackageJson(cwd); + +if (!packageJsonExists) { + throw new Error("A package.json file is necessary to initialize ESLint. Run `npm init` to create a package.json file and try again."); +} + +const argv = process.argv; const sharedConfigIndex = process.argv.indexOf("--config"); if (sharedConfigIndex === -1) { - const generator = new ConfigGenerator(); + const generator = new ConfigGenerator({ cwd }); await generator.prompt(); generator.calc(); @@ -23,7 +31,7 @@ if (sharedConfigIndex === -1) { const packageName = argv[sharedConfigIndex + 1]; const type = argv.includes("--eslintrc") ? "eslintrc" : "flat"; const answers = { purpose: "style", moduleType: "module", styleguide: { packageName, type } }; - const generator = new ConfigGenerator({ answers }); + const generator = new ConfigGenerator({ cwd, answers }); generator.calc(); await generator.output(); diff --git a/lib/config-generator.js b/lib/config-generator.js index 3b926ec0..4262d751 100644 --- a/lib/config-generator.js +++ b/lib/config-generator.js @@ -7,7 +7,7 @@ import path from "path"; import { spawnSync } from "child_process"; import { writeFile } from "fs/promises"; import enquirer from "enquirer"; -import { isPackageTypeModule, installSyncSaveDev, checkPackageJson, fetchPeerDependencies } from "./utils/npm-utils.js"; +import { isPackageTypeModule, installSyncSaveDev, fetchPeerDependencies } from "./utils/npm-utils.js"; import * as log from "./utils/logging.js"; // TODO: need to specify the package version - they may export flat configs in the future. @@ -41,12 +41,6 @@ export class ConfigGenerator { configFilename: "eslint.config.js", configContent: "" }; - - const packageJsonExists = checkPackageJson(this.cwd); - - if (!packageJsonExists) { - throw new Error("A package.json file is necessary to initialize ESLint. Run `npm init` to create a package.json file and try again."); - } } /** From ec2642f9cd6e588e3faa94c72cb786f380539583 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Thu, 7 Mar 2024 17:13:03 +0800 Subject: [PATCH 16/41] fix: rm deps debug --- package.json | 1 - tests/utils/npm-utils.spec.js | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 1c942ddd..79f7ac67 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,6 @@ }, "dependencies": { "cross-spawn": "^7.0.2", - "debug": "^4.0.1", "enquirer": "^2.3.5" }, "devDependencies": { diff --git a/tests/utils/npm-utils.spec.js b/tests/utils/npm-utils.spec.js index 5f67e79d..1cb89837 100644 --- a/tests/utils/npm-utils.spec.js +++ b/tests/utils/npm-utils.spec.js @@ -88,10 +88,10 @@ describe("npmUtils", () => { }); describe("checkDeps()", () => { - let installStatus = checkDeps(["debug", "mocha", "notarealpackage", "jshint"]); + let installStatus = checkDeps(["enquirer", "mocha", "notarealpackage", "jshint"]); it("should find a direct dependency of the project", () => { - assert.isTrue(installStatus.debug); + assert.isTrue(installStatus.enquirer); }); it("should not find a dev dependency of the project", () => { From 640d0d54f5784a1effac625fee15c377cf0ed882 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Thu, 7 Mar 2024 18:24:05 +0800 Subject: [PATCH 17/41] fix: shortname for scoped packages --- lib/config-generator.js | 3 +- lib/utils/naming.js | 98 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 lib/utils/naming.js diff --git a/lib/config-generator.js b/lib/config-generator.js index 4262d751..c01b5742 100644 --- a/lib/config-generator.js +++ b/lib/config-generator.js @@ -8,6 +8,7 @@ import { spawnSync } from "child_process"; import { writeFile } from "fs/promises"; import enquirer from "enquirer"; import { isPackageTypeModule, installSyncSaveDev, fetchPeerDependencies } from "./utils/npm-utils.js"; +import { getShorthandName } from "./utils/naming.js"; import * as log from "./utils/logging.js"; // TODO: need to specify the package version - they may export flat configs in the future. @@ -174,7 +175,7 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug } else if (styleguide.type === "eslintrc") { needCompatHelper = true; - const extendedName = styleguide.packageName.replace("eslint-config-", ""); + const extendedName = getShorthandName(styleguide.packageName, "eslint-config"); exportContent += ` ...compat.extends("${extendedName}"),\n`; } diff --git a/lib/utils/naming.js b/lib/utils/naming.js new file mode 100644 index 00000000..da66b21b --- /dev/null +++ b/lib/utils/naming.js @@ -0,0 +1,98 @@ +/** + * Do not change! + * the file was copied from @eslint/eslintrc, to avoid the dependency on it. + * @fileoverview Common helpers for naming of plugins, formatters and configs + */ + +const NAMESPACE_REGEX = /^@.*\//iu; + +/** + * Brings package name to correct format based on prefix + * @param {string} name The name of the package. + * @param {string} prefix Can be either "eslint-plugin", "eslint-config" or "eslint-formatter" + * @returns {string} Normalized name of the package + * @private + */ +function normalizePackageName(name, prefix) { + let normalizedName = name; + + /** + * On Windows, name can come in with Windows slashes instead of Unix slashes. + * Normalize to Unix first to avoid errors later on. + * https://github.com/eslint/eslint/issues/5644 + */ + if (normalizedName.includes("\\")) { + normalizedName = normalizedName.replace(/\\/gu, "/"); + } + + if (normalizedName.charAt(0) === "@") { + + /** + * it's a scoped package + * package name is the prefix, or just a username + */ + const scopedPackageShortcutRegex = new RegExp(`^(@[^/]+)(?:/(?:${prefix})?)?$`, "u"), + scopedPackageNameRegex = new RegExp(`^${prefix}(-|$)`, "u"); + + if (scopedPackageShortcutRegex.test(normalizedName)) { + normalizedName = normalizedName.replace(scopedPackageShortcutRegex, `$1/${prefix}`); + } else if (!scopedPackageNameRegex.test(normalizedName.split("/")[1])) { + + /** + * for scoped packages, insert the prefix after the first / unless + * the path is already @scope/eslint or @scope/eslint-xxx-yyy + */ + normalizedName = normalizedName.replace(/^@([^/]+)\/(.*)$/u, `@$1/${prefix}-$2`); + } + } else if (!normalizedName.startsWith(`${prefix}-`)) { + normalizedName = `${prefix}-${normalizedName}`; + } + + return normalizedName; +} + +/** + * Removes the prefix from a fullname. + * @param {string} fullname The term which may have the prefix. + * @param {string} prefix The prefix to remove. + * @returns {string} The term without prefix. + */ +function getShorthandName(fullname, prefix) { + if (fullname[0] === "@") { + let matchResult = new RegExp(`^(@[^/]+)/${prefix}$`, "u").exec(fullname); + + if (matchResult) { + return matchResult[1]; + } + + matchResult = new RegExp(`^(@[^/]+)/${prefix}-(.+)$`, "u").exec(fullname); + if (matchResult) { + return `${matchResult[1]}/${matchResult[2]}`; + } + } else if (fullname.startsWith(`${prefix}-`)) { + return fullname.slice(prefix.length + 1); + } + + return fullname; +} + +/** + * Gets the scope (namespace) of a term. + * @param {string} term The term which may have the namespace. + * @returns {string} The namespace of the term if it has one. + */ +function getNamespaceFromTerm(term) { + const match = term.match(NAMESPACE_REGEX); + + return match ? match[0] : ""; +} + +//------------------------------------------------------------------------------ +// Public Interface +//------------------------------------------------------------------------------ + +export { + normalizePackageName, + getShorthandName, + getNamespaceFromTerm +}; From 9a8affb2b77684b7aafabcca4313919f1c87fe6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Tue, 12 Mar 2024 14:00:50 +0800 Subject: [PATCH 18/41] chore: put env in .npmrc --- .npmrc | 3 ++- package.json | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.npmrc b/.npmrc index 9cf94950..30866b50 100644 --- a/.npmrc +++ b/.npmrc @@ -1 +1,2 @@ -package-lock=false \ No newline at end of file +package-lock=false +node-options=--loader=esmock diff --git a/package.json b/package.json index 79f7ac67..ed23e694 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "release:generate:beta": "eslint-generate-prerelease beta", "release:generate:rc": "eslint-generate-prerelease rc", "release:publish": "eslint-publish-release", - "test": "cross-env NODE_OPTIONS=--loader=esmock vitest run --coverage", + "test": "vitest run --coverage", "test:snapshots": "vitest run snapshots", "test:snapshots:update": "vitest -u run snapshots" }, @@ -45,7 +45,6 @@ }, "devDependencies": { "@vitest/coverage-v8": "^1.3.1", - "cross-env": "^7.0.3", "eslint": "^8.56.0", "eslint-config-eslint": "^9.0.0", "eslint-release": "^3.2.0", From 399a0f7c39faf5907efc27dae2ea5edc4b11c613 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Tue, 12 Mar 2024 14:07:37 +0800 Subject: [PATCH 19/41] fix: change cwd to the `package.json` located dir --- bin/create-config.js | 10 ++++++---- lib/utils/npm-utils.js | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/bin/create-config.js b/bin/create-config.js index ccc32947..39b57097 100755 --- a/bin/create-config.js +++ b/bin/create-config.js @@ -6,16 +6,18 @@ */ import { ConfigGenerator } from "../lib/config-generator.js"; -import { checkPackageJson } from "../lib/utils/npm-utils.js"; +import { findPackageJson } from "../lib/utils/npm-utils.js"; import process from "process"; +import path from "path"; -const cwd = process.cwd(); -const packageJsonExists = checkPackageJson(cwd); +const packageJsonPath = findPackageJson(); -if (!packageJsonExists) { +if (packageJsonPath === null) { throw new Error("A package.json file is necessary to initialize ESLint. Run `npm init` to create a package.json file and try again."); } +const cwd = path.join(packageJsonPath, ".."); + const argv = process.argv; const sharedConfigIndex = process.argv.indexOf("--config"); diff --git a/lib/utils/npm-utils.js b/lib/utils/npm-utils.js index 93256e1e..ba9455a7 100644 --- a/lib/utils/npm-utils.js +++ b/lib/utils/npm-utils.js @@ -168,7 +168,7 @@ function checkPackageJson(startDir) { * @returns {boolean} return true if the package.type === "module" */ function isPackageTypeModule(cwd) { - const pkgJSONPath = findPackageJson(cwd); + const pkgJSONPath = path.join(cwd, "./package.json"); if (pkgJSONPath) { const pkgJSONContents = JSON.parse(fs.readFileSync(pkgJSONPath, "utf8")); From 85a6fb23f882b3922874ba3d318b9ef6b5bf0a1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Wed, 13 Mar 2024 14:16:06 +0800 Subject: [PATCH 20/41] fix: review suggestions --- bin/create-config.js | 11 +++++------ lib/config-generator.js | 5 +++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/bin/create-config.js b/bin/create-config.js index 39b57097..f385b205 100755 --- a/bin/create-config.js +++ b/bin/create-config.js @@ -8,21 +8,20 @@ import { ConfigGenerator } from "../lib/config-generator.js"; import { findPackageJson } from "../lib/utils/npm-utils.js"; import process from "process"; -import path from "path"; -const packageJsonPath = findPackageJson(); + +const cwd = process.cwd(); +const packageJsonPath = findPackageJson(cwd); if (packageJsonPath === null) { throw new Error("A package.json file is necessary to initialize ESLint. Run `npm init` to create a package.json file and try again."); } -const cwd = path.join(packageJsonPath, ".."); - const argv = process.argv; const sharedConfigIndex = process.argv.indexOf("--config"); if (sharedConfigIndex === -1) { - const generator = new ConfigGenerator({ cwd }); + const generator = new ConfigGenerator({ cwd, packageJsonPath }); await generator.prompt(); generator.calc(); @@ -33,7 +32,7 @@ if (sharedConfigIndex === -1) { const packageName = argv[sharedConfigIndex + 1]; const type = argv.includes("--eslintrc") ? "eslintrc" : "flat"; const answers = { purpose: "style", moduleType: "module", styleguide: { packageName, type } }; - const generator = new ConfigGenerator({ cwd, answers }); + const generator = new ConfigGenerator({ cwd, packageJsonPath, answers }); generator.calc(); await generator.output(); diff --git a/lib/config-generator.js b/lib/config-generator.js index c01b5742..fe18d9c9 100644 --- a/lib/config-generator.js +++ b/lib/config-generator.js @@ -7,7 +7,7 @@ import path from "path"; import { spawnSync } from "child_process"; import { writeFile } from "fs/promises"; import enquirer from "enquirer"; -import { isPackageTypeModule, installSyncSaveDev, fetchPeerDependencies } from "./utils/npm-utils.js"; +import { isPackageTypeModule, installSyncSaveDev, fetchPeerDependencies, findPackageJson } from "./utils/npm-utils.js"; import { getShorthandName } from "./utils/naming.js"; import * as log from "./utils/logging.js"; @@ -36,6 +36,7 @@ export class ConfigGenerator { */ constructor(options = {}) { this.cwd = options.cwd || process.cwd(); + this.packageJsonPath = options.packageJsonPath || findPackageJson(this.cwd); this.answers = options.answers || {}; this.result = { devDependencies: ["eslint"], @@ -250,7 +251,7 @@ export default [\n {languageOptions:{${languageOptionsContent}}},\n${exportCont // import("eslint") won't work in some cases. // refs: https://github.com/eslint/create-config/issues/8, https://github.com/eslint/create-config/issues/12 - const eslintBin = path.join(this.cwd, "./node_modules/.bin/eslint"); + const eslintBin = path.join(this.packageJsonPath, "../node_modules/.bin/eslint"); const result = spawnSync(eslintBin, ["--fix", "--quiet", configPath], { encoding: "utf8" }); if (result.error || result.status !== 0) { From 07479e14eb257636e6fe159194c0bcf5faaa95e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Thu, 14 Mar 2024 15:58:27 +0800 Subject: [PATCH 21/41] fix: generage config for sub-dir --- lib/config-generator.js | 2 +- lib/utils/npm-utils.js | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/config-generator.js b/lib/config-generator.js index fe18d9c9..4ef72255 100644 --- a/lib/config-generator.js +++ b/lib/config-generator.js @@ -130,7 +130,7 @@ export class ConfigGenerator { * @returns {void} */ calc() { - const isESMModule = isPackageTypeModule(this.cwd); + const isESMModule = isPackageTypeModule(this.packageJsonPath); this.result.configFilename = isESMModule ? "eslint.config.js" : "eslint.config.mjs"; diff --git a/lib/utils/npm-utils.js b/lib/utils/npm-utils.js index ba9455a7..f8a4dd2c 100644 --- a/lib/utils/npm-utils.js +++ b/lib/utils/npm-utils.js @@ -164,11 +164,10 @@ function checkPackageJson(startDir) { /** * check if the package.type === "module" - * @param {string} [cwd] The current working directory + * @param {string} pkgJSONPath path to package.json * @returns {boolean} return true if the package.type === "module" */ -function isPackageTypeModule(cwd) { - const pkgJSONPath = path.join(cwd, "./package.json"); +function isPackageTypeModule(pkgJSONPath) { if (pkgJSONPath) { const pkgJSONContents = JSON.parse(fs.readFileSync(pkgJSONPath, "utf8")); From d08ec843f7fa1215e510d75e833cb70216cdebec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Thu, 14 Mar 2024 16:08:00 +0800 Subject: [PATCH 22/41] Update lib/config-generator.js Co-authored-by: Francesco Trotta --- lib/config-generator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/config-generator.js b/lib/config-generator.js index 4ef72255..77af48e4 100644 --- a/lib/config-generator.js +++ b/lib/config-generator.js @@ -252,7 +252,7 @@ export default [\n {languageOptions:{${languageOptionsContent}}},\n${exportCont // import("eslint") won't work in some cases. // refs: https://github.com/eslint/create-config/issues/8, https://github.com/eslint/create-config/issues/12 const eslintBin = path.join(this.packageJsonPath, "../node_modules/.bin/eslint"); - const result = spawnSync(eslintBin, ["--fix", "--quiet", configPath], { encoding: "utf8" }); + const result = spawnSync(process.execPath, [eslintBin, "--fix", "--quiet", configPath], { encoding: "utf8" }); if (result.error || result.status !== 0) { log.error("A config file was generated, but the config file itself may not follow your linting rules."); From 6fe2d6a5ede46e9e58b99ad3a7aecd27312dbe87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Fri, 15 Mar 2024 14:07:31 +0800 Subject: [PATCH 23/41] chore: add tests for sub dir --- tests/config-snapshots.spec.js | 10 ++++++++++ tests/fixtures/esm-project/sub/foo.js | 0 2 files changed, 10 insertions(+) create mode 100644 tests/fixtures/esm-project/sub/foo.js diff --git a/tests/config-snapshots.spec.js b/tests/config-snapshots.spec.js index 7d6c943b..0bb8d234 100644 --- a/tests/config-snapshots.spec.js +++ b/tests/config-snapshots.spec.js @@ -55,6 +55,16 @@ describe("generate config for esm projects", () => { expect(generator.result).toMatchFileSnapshot(`./__snapshots__/${item.name}`); }); }); + + test("sub dir", () => { + const sub = join(__filename, "../fixtures/esm-project/sub"); + const generator = new ConfigGenerator({ cwd: sub, answers: { purpose: "problem", module: "esm", framework: "none", language: "javascript", env: ["node"] } }); + + generator.calc(); + + expect(generator.result.configFilename).toBe("eslint.config.js"); + }); + }); describe("generate config for cjs projects", () => { diff --git a/tests/fixtures/esm-project/sub/foo.js b/tests/fixtures/esm-project/sub/foo.js new file mode 100644 index 00000000..e69de29b From bd4232b8984337f6ee73ccfd677fdba0af9602c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Tue, 19 Mar 2024 04:09:14 +0800 Subject: [PATCH 24/41] Update lib/config-generator.js Co-authored-by: Francesco Trotta --- lib/config-generator.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/config-generator.js b/lib/config-generator.js index 77af48e4..cbf3c4f6 100644 --- a/lib/config-generator.js +++ b/lib/config-generator.js @@ -176,9 +176,9 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug } else if (styleguide.type === "eslintrc") { needCompatHelper = true; - const extendedName = getShorthandName(styleguide.packageName, "eslint-config"); + const shorthandName = getShorthandName(styleguide.packageName, "eslint-config"); - exportContent += ` ...compat.extends("${extendedName}"),\n`; + exportContent += ` ...compat.extends("${shorthandName}"),\n`; } } From 082044d07dfb72868a50658b78caa248656eb211 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Tue, 19 Mar 2024 04:09:32 +0800 Subject: [PATCH 25/41] Update lib/config-generator.js Co-authored-by: Francesco Trotta --- lib/config-generator.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/config-generator.js b/lib/config-generator.js index cbf3c4f6..0e8e23ef 100644 --- a/lib/config-generator.js +++ b/lib/config-generator.js @@ -34,8 +34,8 @@ export class ConfigGenerator { * @param {Object} options.answers The answers provided by the user. * @returns {ConfigGenerator} The ConfigGenerator instance. */ - constructor(options = {}) { - this.cwd = options.cwd || process.cwd(); + constructor(options) { + this.cwd = options.cwd; this.packageJsonPath = options.packageJsonPath || findPackageJson(this.cwd); this.answers = options.answers || {}; this.result = { From bb8e042ed2f36f0a5637314f90411604e5551425 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Tue, 19 Mar 2024 09:59:51 +0800 Subject: [PATCH 26/41] fix: module => moduleType --- lib/config-generator.js | 4 ++-- tests/config-snapshots.spec.js | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/config-generator.js b/lib/config-generator.js index 0e8e23ef..326722fd 100644 --- a/lib/config-generator.js +++ b/lib/config-generator.js @@ -182,8 +182,8 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug } } - if (this.answers.module === "commonjs" || this.answers.module === "script") { - languageOptionsContent += `sourceType: "${this.answers.module}", `; + if (this.answers.moduleType === "commonjs" || this.answers.moduleType === "script") { + languageOptionsContent += `sourceType: "${this.answers.moduleType}", `; } if (this.answers.env?.length > 0) { diff --git a/tests/config-snapshots.spec.js b/tests/config-snapshots.spec.js index 0bb8d234..e5bdf38c 100644 --- a/tests/config-snapshots.spec.js +++ b/tests/config-snapshots.spec.js @@ -17,7 +17,7 @@ describe("generate config for esm projects", () => { const esmProjectDir = join(__filename, "../fixtures/esm-project"); const choices = { purpose: ["syntax", "problem"], - module: ["esm", "commonjs", "script"], + moduleType: ["esm", "commonjs", "script"], framework: ["react", "vue", "none"], language: ["javascript", "typescript"], env: ["browser", "node"] @@ -27,14 +27,14 @@ describe("generate config for esm projects", () => { // generate all possible combinations for (let i = 0; i < choices.purpose.length; i++) { - for (let j = 0; j < choices.module.length; j++) { + for (let j = 0; j < choices.moduleType.length; j++) { for (let k = 0; k < choices.framework.length; k++) { for (let m = 0; m < choices.language.length; m++) { inputs.push({ - name: `${choices.purpose[i]}-${choices.module[j]}-${choices.framework[k]}-${choices.language[m]}`, + name: `${choices.purpose[i]}-${choices.moduleType[j]}-${choices.framework[k]}-${choices.language[m]}`, answers: { purpose: choices.purpose[i], - module: choices.module[j], + moduleType: choices.moduleType[j], framework: choices.framework[k], language: choices.language[m], env: ["browser", "node"] @@ -58,7 +58,7 @@ describe("generate config for esm projects", () => { test("sub dir", () => { const sub = join(__filename, "../fixtures/esm-project/sub"); - const generator = new ConfigGenerator({ cwd: sub, answers: { purpose: "problem", module: "esm", framework: "none", language: "javascript", env: ["node"] } }); + const generator = new ConfigGenerator({ cwd: sub, answers: { purpose: "problem", moduleType: "esm", framework: "none", language: "javascript", env: ["node"] } }); generator.calc(); @@ -73,7 +73,7 @@ describe("generate config for cjs projects", () => { name: "style-esm-none-xo-javascript", answers: { purpose: "style", - module: "esm", + moduleType: "esm", framework: "none", language: "javascript", env: ["node"], @@ -84,7 +84,7 @@ describe("generate config for cjs projects", () => { name: "style-esm-none-xo-typescript", answers: { purpose: "style", - module: "esm", + moduleType: "esm", framework: "none", language: "typescript", env: ["browser"], From 8354c9ff3e523b283b7d1ee1c7440c4c1d0acdbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Tue, 19 Mar 2024 16:25:04 +0800 Subject: [PATCH 27/41] fix: only apply sourceType to js files --- lib/config-generator.js | 8 ++++---- tests/__snapshots__/problem-commonjs-none-javascript | 3 ++- tests/__snapshots__/problem-commonjs-none-typescript | 3 ++- tests/__snapshots__/problem-commonjs-react-javascript | 3 ++- tests/__snapshots__/problem-commonjs-react-typescript | 3 ++- tests/__snapshots__/problem-commonjs-vue-javascript | 3 ++- tests/__snapshots__/problem-commonjs-vue-typescript | 3 ++- tests/__snapshots__/problem-script-none-javascript | 3 ++- tests/__snapshots__/problem-script-none-typescript | 3 ++- tests/__snapshots__/problem-script-react-javascript | 3 ++- tests/__snapshots__/problem-script-react-typescript | 3 ++- tests/__snapshots__/problem-script-vue-javascript | 3 ++- tests/__snapshots__/problem-script-vue-typescript | 3 ++- tests/__snapshots__/syntax-commonjs-none-javascript | 3 ++- tests/__snapshots__/syntax-commonjs-none-typescript | 3 ++- tests/__snapshots__/syntax-commonjs-react-javascript | 3 ++- tests/__snapshots__/syntax-commonjs-react-typescript | 3 ++- tests/__snapshots__/syntax-commonjs-vue-javascript | 3 ++- tests/__snapshots__/syntax-commonjs-vue-typescript | 3 ++- tests/__snapshots__/syntax-script-none-javascript | 3 ++- tests/__snapshots__/syntax-script-none-typescript | 3 ++- tests/__snapshots__/syntax-script-react-javascript | 3 ++- tests/__snapshots__/syntax-script-react-typescript | 3 ++- tests/__snapshots__/syntax-script-vue-javascript | 3 ++- tests/__snapshots__/syntax-script-vue-typescript | 3 ++- 25 files changed, 52 insertions(+), 28 deletions(-) diff --git a/lib/config-generator.js b/lib/config-generator.js index 326722fd..5ac04b73 100644 --- a/lib/config-generator.js +++ b/lib/config-generator.js @@ -149,6 +149,10 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug let languageOptionsContent = ""; let needCompatHelper = false; + if (this.answers.moduleType === "commonjs" || this.answers.moduleType === "script") { + exportContent += ` {files: ["**/*.js"], languageOptions: {sourceType: "${this.answers.moduleType}"}},\n`; + } + if (this.answers.purpose === "syntax") { // no need to install any plugin @@ -182,10 +186,6 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug } } - if (this.answers.moduleType === "commonjs" || this.answers.moduleType === "script") { - languageOptionsContent += `sourceType: "${this.answers.moduleType}", `; - } - if (this.answers.env?.length > 0) { this.result.devDependencies.push("globals"); importContent += "import globals from \"globals\";\n"; diff --git a/tests/__snapshots__/problem-commonjs-none-javascript b/tests/__snapshots__/problem-commonjs-none-javascript index fab39c7c..0f0e9919 100644 --- a/tests/__snapshots__/problem-commonjs-none-javascript +++ b/tests/__snapshots__/problem-commonjs-none-javascript @@ -4,7 +4,8 @@ import globals from "globals"; export default [ - {languageOptions:{sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, + {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, + {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, pluginJs.configs.recommended, ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/problem-commonjs-none-typescript b/tests/__snapshots__/problem-commonjs-none-typescript index 20b51eb4..4314e95b 100644 --- a/tests/__snapshots__/problem-commonjs-none-typescript +++ b/tests/__snapshots__/problem-commonjs-none-typescript @@ -5,7 +5,8 @@ import tseslint from "typescript-eslint"; export default [ - {languageOptions:{sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, + {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, + {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, pluginJs.configs.recommended, ...tseslint.configs.recommended, ];", diff --git a/tests/__snapshots__/problem-commonjs-react-javascript b/tests/__snapshots__/problem-commonjs-react-javascript index 996982c9..0ab127e8 100644 --- a/tests/__snapshots__/problem-commonjs-react-javascript +++ b/tests/__snapshots__/problem-commonjs-react-javascript @@ -5,7 +5,8 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [ - {languageOptions:{sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, + {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, + {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, pluginJs.configs.recommended, pluginReactConfig, ];", diff --git a/tests/__snapshots__/problem-commonjs-react-typescript b/tests/__snapshots__/problem-commonjs-react-typescript index d4db10b9..a48bc13a 100644 --- a/tests/__snapshots__/problem-commonjs-react-typescript +++ b/tests/__snapshots__/problem-commonjs-react-typescript @@ -6,7 +6,8 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [ - {languageOptions:{sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, + {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, + {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, pluginJs.configs.recommended, ...tseslint.configs.recommended, pluginReactConfig, diff --git a/tests/__snapshots__/problem-commonjs-vue-javascript b/tests/__snapshots__/problem-commonjs-vue-javascript index d2084a1a..3159d1ae 100644 --- a/tests/__snapshots__/problem-commonjs-vue-javascript +++ b/tests/__snapshots__/problem-commonjs-vue-javascript @@ -13,7 +13,8 @@ const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [ - {languageOptions:{sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, + {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, + {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, pluginJs.configs.recommended, ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), ];", diff --git a/tests/__snapshots__/problem-commonjs-vue-typescript b/tests/__snapshots__/problem-commonjs-vue-typescript index f52c1f0b..70743042 100644 --- a/tests/__snapshots__/problem-commonjs-vue-typescript +++ b/tests/__snapshots__/problem-commonjs-vue-typescript @@ -14,7 +14,8 @@ const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [ - {languageOptions:{sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, + {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, + {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, pluginJs.configs.recommended, ...tseslint.configs.recommended, ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), diff --git a/tests/__snapshots__/problem-script-none-javascript b/tests/__snapshots__/problem-script-none-javascript index d50ea6a3..1a106614 100644 --- a/tests/__snapshots__/problem-script-none-javascript +++ b/tests/__snapshots__/problem-script-none-javascript @@ -4,7 +4,8 @@ import globals from "globals"; export default [ - {languageOptions:{sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, + {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, + {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, pluginJs.configs.recommended, ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/problem-script-none-typescript b/tests/__snapshots__/problem-script-none-typescript index 299aca68..2d16486e 100644 --- a/tests/__snapshots__/problem-script-none-typescript +++ b/tests/__snapshots__/problem-script-none-typescript @@ -5,7 +5,8 @@ import tseslint from "typescript-eslint"; export default [ - {languageOptions:{sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, + {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, + {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, pluginJs.configs.recommended, ...tseslint.configs.recommended, ];", diff --git a/tests/__snapshots__/problem-script-react-javascript b/tests/__snapshots__/problem-script-react-javascript index 162b3acd..072e665d 100644 --- a/tests/__snapshots__/problem-script-react-javascript +++ b/tests/__snapshots__/problem-script-react-javascript @@ -5,7 +5,8 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [ - {languageOptions:{sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, + {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, + {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, pluginJs.configs.recommended, pluginReactConfig, ];", diff --git a/tests/__snapshots__/problem-script-react-typescript b/tests/__snapshots__/problem-script-react-typescript index 4a9f5a9b..8df158cb 100644 --- a/tests/__snapshots__/problem-script-react-typescript +++ b/tests/__snapshots__/problem-script-react-typescript @@ -6,7 +6,8 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [ - {languageOptions:{sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, + {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, + {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, pluginJs.configs.recommended, ...tseslint.configs.recommended, pluginReactConfig, diff --git a/tests/__snapshots__/problem-script-vue-javascript b/tests/__snapshots__/problem-script-vue-javascript index a72573c2..31594c4a 100644 --- a/tests/__snapshots__/problem-script-vue-javascript +++ b/tests/__snapshots__/problem-script-vue-javascript @@ -13,7 +13,8 @@ const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [ - {languageOptions:{sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, + {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, + {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, pluginJs.configs.recommended, ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), ];", diff --git a/tests/__snapshots__/problem-script-vue-typescript b/tests/__snapshots__/problem-script-vue-typescript index b2cd2ac8..708e11f4 100644 --- a/tests/__snapshots__/problem-script-vue-typescript +++ b/tests/__snapshots__/problem-script-vue-typescript @@ -14,7 +14,8 @@ const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [ - {languageOptions:{sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, + {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, + {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, pluginJs.configs.recommended, ...tseslint.configs.recommended, ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), diff --git a/tests/__snapshots__/syntax-commonjs-none-javascript b/tests/__snapshots__/syntax-commonjs-none-javascript index 61922ccb..5d8564be 100644 --- a/tests/__snapshots__/syntax-commonjs-none-javascript +++ b/tests/__snapshots__/syntax-commonjs-none-javascript @@ -3,7 +3,8 @@ export default [ - {languageOptions:{sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, + {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, + {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, ];", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/syntax-commonjs-none-typescript b/tests/__snapshots__/syntax-commonjs-none-typescript index dc46e427..dd179121 100644 --- a/tests/__snapshots__/syntax-commonjs-none-typescript +++ b/tests/__snapshots__/syntax-commonjs-none-typescript @@ -4,7 +4,8 @@ import tseslint from "typescript-eslint"; export default [ - {languageOptions:{sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, + {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, + {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, ...tseslint.configs.recommended, ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/syntax-commonjs-react-javascript b/tests/__snapshots__/syntax-commonjs-react-javascript index 67ddf34f..9b864e5a 100644 --- a/tests/__snapshots__/syntax-commonjs-react-javascript +++ b/tests/__snapshots__/syntax-commonjs-react-javascript @@ -4,7 +4,8 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [ - {languageOptions:{sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, + {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, + {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, pluginReactConfig, ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/syntax-commonjs-react-typescript b/tests/__snapshots__/syntax-commonjs-react-typescript index 14f67ac8..d93bc107 100644 --- a/tests/__snapshots__/syntax-commonjs-react-typescript +++ b/tests/__snapshots__/syntax-commonjs-react-typescript @@ -5,7 +5,8 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [ - {languageOptions:{sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, + {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, + {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, ...tseslint.configs.recommended, pluginReactConfig, ];", diff --git a/tests/__snapshots__/syntax-commonjs-vue-javascript b/tests/__snapshots__/syntax-commonjs-vue-javascript index 2f68c2ba..ad4e6f1e 100644 --- a/tests/__snapshots__/syntax-commonjs-vue-javascript +++ b/tests/__snapshots__/syntax-commonjs-vue-javascript @@ -12,7 +12,8 @@ const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [ - {languageOptions:{sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, + {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, + {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/syntax-commonjs-vue-typescript b/tests/__snapshots__/syntax-commonjs-vue-typescript index 9c0e5f01..649e3fa4 100644 --- a/tests/__snapshots__/syntax-commonjs-vue-typescript +++ b/tests/__snapshots__/syntax-commonjs-vue-typescript @@ -13,7 +13,8 @@ const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [ - {languageOptions:{sourceType: "commonjs", globals: {...globals.browser, ...globals.node}, }}, + {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, + {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, ...tseslint.configs.recommended, ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), ];", diff --git a/tests/__snapshots__/syntax-script-none-javascript b/tests/__snapshots__/syntax-script-none-javascript index 14ceec85..addf1929 100644 --- a/tests/__snapshots__/syntax-script-none-javascript +++ b/tests/__snapshots__/syntax-script-none-javascript @@ -3,7 +3,8 @@ export default [ - {languageOptions:{sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, + {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, + {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, ];", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/syntax-script-none-typescript b/tests/__snapshots__/syntax-script-none-typescript index 65669beb..b7fe6836 100644 --- a/tests/__snapshots__/syntax-script-none-typescript +++ b/tests/__snapshots__/syntax-script-none-typescript @@ -4,7 +4,8 @@ import tseslint from "typescript-eslint"; export default [ - {languageOptions:{sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, + {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, + {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, ...tseslint.configs.recommended, ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/syntax-script-react-javascript b/tests/__snapshots__/syntax-script-react-javascript index 515edb5f..be14fd94 100644 --- a/tests/__snapshots__/syntax-script-react-javascript +++ b/tests/__snapshots__/syntax-script-react-javascript @@ -4,7 +4,8 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [ - {languageOptions:{sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, + {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, + {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, pluginReactConfig, ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/syntax-script-react-typescript b/tests/__snapshots__/syntax-script-react-typescript index ec5fd472..bcf36a50 100644 --- a/tests/__snapshots__/syntax-script-react-typescript +++ b/tests/__snapshots__/syntax-script-react-typescript @@ -5,7 +5,8 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [ - {languageOptions:{sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, + {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, + {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, ...tseslint.configs.recommended, pluginReactConfig, ];", diff --git a/tests/__snapshots__/syntax-script-vue-javascript b/tests/__snapshots__/syntax-script-vue-javascript index 43cf5847..6b649d3c 100644 --- a/tests/__snapshots__/syntax-script-vue-javascript +++ b/tests/__snapshots__/syntax-script-vue-javascript @@ -12,7 +12,8 @@ const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [ - {languageOptions:{sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, + {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, + {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/syntax-script-vue-typescript b/tests/__snapshots__/syntax-script-vue-typescript index 50d81c15..8002e348 100644 --- a/tests/__snapshots__/syntax-script-vue-typescript +++ b/tests/__snapshots__/syntax-script-vue-typescript @@ -13,7 +13,8 @@ const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [ - {languageOptions:{sourceType: "script", globals: {...globals.browser, ...globals.node}, }}, + {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, + {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, ...tseslint.configs.recommended, ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), ];", From ca7521653422f349138b24664d56575c72f460a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Wed, 20 Mar 2024 10:07:37 +0800 Subject: [PATCH 28/41] fix: problem => problems --- lib/config-generator.js | 2 +- tests/config-snapshots.spec.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/config-generator.js b/lib/config-generator.js index 5ac04b73..727360a6 100644 --- a/lib/config-generator.js +++ b/lib/config-generator.js @@ -156,7 +156,7 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug if (this.answers.purpose === "syntax") { // no need to install any plugin - } else if (this.answers.purpose === "problem") { + } else if (this.answers.purpose === "problems") { this.result.devDependencies.push("@eslint/js"); importContent += "import pluginJs from \"@eslint/js\";\n"; exportContent += " pluginJs.configs.recommended,\n"; diff --git a/tests/config-snapshots.spec.js b/tests/config-snapshots.spec.js index e5bdf38c..2af74573 100644 --- a/tests/config-snapshots.spec.js +++ b/tests/config-snapshots.spec.js @@ -16,7 +16,7 @@ const __filename = fileURLToPath(import.meta.url); // eslint-disable-line no-und describe("generate config for esm projects", () => { const esmProjectDir = join(__filename, "../fixtures/esm-project"); const choices = { - purpose: ["syntax", "problem"], + purpose: ["syntax", "problems"], moduleType: ["esm", "commonjs", "script"], framework: ["react", "vue", "none"], language: ["javascript", "typescript"], @@ -58,7 +58,7 @@ describe("generate config for esm projects", () => { test("sub dir", () => { const sub = join(__filename, "../fixtures/esm-project/sub"); - const generator = new ConfigGenerator({ cwd: sub, answers: { purpose: "problem", moduleType: "esm", framework: "none", language: "javascript", env: ["node"] } }); + const generator = new ConfigGenerator({ cwd: sub, answers: { purpose: "problems", moduleType: "esm", framework: "none", language: "javascript", env: ["node"] } }); generator.calc(); From 71d57676ddb7922c7cfc594f8f7c2a423ad7063f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Wed, 20 Mar 2024 10:08:45 +0800 Subject: [PATCH 29/41] fix: eslint bin --- lib/config-generator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/config-generator.js b/lib/config-generator.js index 727360a6..e202f3b3 100644 --- a/lib/config-generator.js +++ b/lib/config-generator.js @@ -251,7 +251,7 @@ export default [\n {languageOptions:{${languageOptionsContent}}},\n${exportCont // import("eslint") won't work in some cases. // refs: https://github.com/eslint/create-config/issues/8, https://github.com/eslint/create-config/issues/12 - const eslintBin = path.join(this.packageJsonPath, "../node_modules/.bin/eslint"); + const eslintBin = path.join(this.packageJsonPath, "../node_modules/eslint/bin/eslint.js"); const result = spawnSync(process.execPath, [eslintBin, "--fix", "--quiet", configPath], { encoding: "utf8" }); if (result.error || result.status !== 0) { From 2f61590e3f34fc868227b7f3c2a40f91a401c65b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Wed, 20 Mar 2024 10:09:18 +0800 Subject: [PATCH 30/41] fix: update snapshots --- ...commonjs-none-javascript => problems-commonjs-none-javascript} | 0 ...commonjs-none-typescript => problems-commonjs-none-typescript} | 0 ...mmonjs-react-javascript => problems-commonjs-react-javascript} | 0 ...mmonjs-react-typescript => problems-commonjs-react-typescript} | 0 ...m-commonjs-vue-javascript => problems-commonjs-vue-javascript} | 0 ...m-commonjs-vue-typescript => problems-commonjs-vue-typescript} | 0 .../{problem-esm-none-javascript => problems-esm-none-javascript} | 0 .../{problem-esm-none-typescript => problems-esm-none-typescript} | 0 ...problem-esm-react-javascript => problems-esm-react-javascript} | 0 ...problem-esm-react-typescript => problems-esm-react-typescript} | 0 .../{problem-esm-vue-javascript => problems-esm-vue-javascript} | 0 .../{problem-esm-vue-typescript => problems-esm-vue-typescript} | 0 ...lem-script-none-javascript => problems-script-none-javascript} | 0 ...lem-script-none-typescript => problems-script-none-typescript} | 0 ...m-script-react-javascript => problems-script-react-javascript} | 0 ...m-script-react-typescript => problems-script-react-typescript} | 0 ...oblem-script-vue-javascript => problems-script-vue-javascript} | 0 ...oblem-script-vue-typescript => problems-script-vue-typescript} | 0 18 files changed, 0 insertions(+), 0 deletions(-) rename tests/__snapshots__/{problem-commonjs-none-javascript => problems-commonjs-none-javascript} (100%) rename tests/__snapshots__/{problem-commonjs-none-typescript => problems-commonjs-none-typescript} (100%) rename tests/__snapshots__/{problem-commonjs-react-javascript => problems-commonjs-react-javascript} (100%) rename tests/__snapshots__/{problem-commonjs-react-typescript => problems-commonjs-react-typescript} (100%) rename tests/__snapshots__/{problem-commonjs-vue-javascript => problems-commonjs-vue-javascript} (100%) rename tests/__snapshots__/{problem-commonjs-vue-typescript => problems-commonjs-vue-typescript} (100%) rename tests/__snapshots__/{problem-esm-none-javascript => problems-esm-none-javascript} (100%) rename tests/__snapshots__/{problem-esm-none-typescript => problems-esm-none-typescript} (100%) rename tests/__snapshots__/{problem-esm-react-javascript => problems-esm-react-javascript} (100%) rename tests/__snapshots__/{problem-esm-react-typescript => problems-esm-react-typescript} (100%) rename tests/__snapshots__/{problem-esm-vue-javascript => problems-esm-vue-javascript} (100%) rename tests/__snapshots__/{problem-esm-vue-typescript => problems-esm-vue-typescript} (100%) rename tests/__snapshots__/{problem-script-none-javascript => problems-script-none-javascript} (100%) rename tests/__snapshots__/{problem-script-none-typescript => problems-script-none-typescript} (100%) rename tests/__snapshots__/{problem-script-react-javascript => problems-script-react-javascript} (100%) rename tests/__snapshots__/{problem-script-react-typescript => problems-script-react-typescript} (100%) rename tests/__snapshots__/{problem-script-vue-javascript => problems-script-vue-javascript} (100%) rename tests/__snapshots__/{problem-script-vue-typescript => problems-script-vue-typescript} (100%) diff --git a/tests/__snapshots__/problem-commonjs-none-javascript b/tests/__snapshots__/problems-commonjs-none-javascript similarity index 100% rename from tests/__snapshots__/problem-commonjs-none-javascript rename to tests/__snapshots__/problems-commonjs-none-javascript diff --git a/tests/__snapshots__/problem-commonjs-none-typescript b/tests/__snapshots__/problems-commonjs-none-typescript similarity index 100% rename from tests/__snapshots__/problem-commonjs-none-typescript rename to tests/__snapshots__/problems-commonjs-none-typescript diff --git a/tests/__snapshots__/problem-commonjs-react-javascript b/tests/__snapshots__/problems-commonjs-react-javascript similarity index 100% rename from tests/__snapshots__/problem-commonjs-react-javascript rename to tests/__snapshots__/problems-commonjs-react-javascript diff --git a/tests/__snapshots__/problem-commonjs-react-typescript b/tests/__snapshots__/problems-commonjs-react-typescript similarity index 100% rename from tests/__snapshots__/problem-commonjs-react-typescript rename to tests/__snapshots__/problems-commonjs-react-typescript diff --git a/tests/__snapshots__/problem-commonjs-vue-javascript b/tests/__snapshots__/problems-commonjs-vue-javascript similarity index 100% rename from tests/__snapshots__/problem-commonjs-vue-javascript rename to tests/__snapshots__/problems-commonjs-vue-javascript diff --git a/tests/__snapshots__/problem-commonjs-vue-typescript b/tests/__snapshots__/problems-commonjs-vue-typescript similarity index 100% rename from tests/__snapshots__/problem-commonjs-vue-typescript rename to tests/__snapshots__/problems-commonjs-vue-typescript diff --git a/tests/__snapshots__/problem-esm-none-javascript b/tests/__snapshots__/problems-esm-none-javascript similarity index 100% rename from tests/__snapshots__/problem-esm-none-javascript rename to tests/__snapshots__/problems-esm-none-javascript diff --git a/tests/__snapshots__/problem-esm-none-typescript b/tests/__snapshots__/problems-esm-none-typescript similarity index 100% rename from tests/__snapshots__/problem-esm-none-typescript rename to tests/__snapshots__/problems-esm-none-typescript diff --git a/tests/__snapshots__/problem-esm-react-javascript b/tests/__snapshots__/problems-esm-react-javascript similarity index 100% rename from tests/__snapshots__/problem-esm-react-javascript rename to tests/__snapshots__/problems-esm-react-javascript diff --git a/tests/__snapshots__/problem-esm-react-typescript b/tests/__snapshots__/problems-esm-react-typescript similarity index 100% rename from tests/__snapshots__/problem-esm-react-typescript rename to tests/__snapshots__/problems-esm-react-typescript diff --git a/tests/__snapshots__/problem-esm-vue-javascript b/tests/__snapshots__/problems-esm-vue-javascript similarity index 100% rename from tests/__snapshots__/problem-esm-vue-javascript rename to tests/__snapshots__/problems-esm-vue-javascript diff --git a/tests/__snapshots__/problem-esm-vue-typescript b/tests/__snapshots__/problems-esm-vue-typescript similarity index 100% rename from tests/__snapshots__/problem-esm-vue-typescript rename to tests/__snapshots__/problems-esm-vue-typescript diff --git a/tests/__snapshots__/problem-script-none-javascript b/tests/__snapshots__/problems-script-none-javascript similarity index 100% rename from tests/__snapshots__/problem-script-none-javascript rename to tests/__snapshots__/problems-script-none-javascript diff --git a/tests/__snapshots__/problem-script-none-typescript b/tests/__snapshots__/problems-script-none-typescript similarity index 100% rename from tests/__snapshots__/problem-script-none-typescript rename to tests/__snapshots__/problems-script-none-typescript diff --git a/tests/__snapshots__/problem-script-react-javascript b/tests/__snapshots__/problems-script-react-javascript similarity index 100% rename from tests/__snapshots__/problem-script-react-javascript rename to tests/__snapshots__/problems-script-react-javascript diff --git a/tests/__snapshots__/problem-script-react-typescript b/tests/__snapshots__/problems-script-react-typescript similarity index 100% rename from tests/__snapshots__/problem-script-react-typescript rename to tests/__snapshots__/problems-script-react-typescript diff --git a/tests/__snapshots__/problem-script-vue-javascript b/tests/__snapshots__/problems-script-vue-javascript similarity index 100% rename from tests/__snapshots__/problem-script-vue-javascript rename to tests/__snapshots__/problems-script-vue-javascript diff --git a/tests/__snapshots__/problem-script-vue-typescript b/tests/__snapshots__/problems-script-vue-typescript similarity index 100% rename from tests/__snapshots__/problem-script-vue-typescript rename to tests/__snapshots__/problems-script-vue-typescript From 1a6fe9d2a8280e0a40b35ed858ba0ca049652098 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Thu, 21 Mar 2024 14:14:23 +0800 Subject: [PATCH 31/41] chore: refactor export content MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 唯然 --- lib/config-generator.js | 8 ++++---- tests/__snapshots__/problems-commonjs-none-javascript | 2 +- tests/__snapshots__/problems-commonjs-none-typescript | 2 +- tests/__snapshots__/problems-commonjs-react-javascript | 2 +- tests/__snapshots__/problems-commonjs-react-typescript | 2 +- tests/__snapshots__/problems-commonjs-vue-javascript | 2 +- tests/__snapshots__/problems-commonjs-vue-typescript | 2 +- tests/__snapshots__/problems-esm-none-javascript | 2 +- tests/__snapshots__/problems-esm-none-typescript | 2 +- tests/__snapshots__/problems-esm-react-javascript | 2 +- tests/__snapshots__/problems-esm-react-typescript | 2 +- tests/__snapshots__/problems-esm-vue-javascript | 2 +- tests/__snapshots__/problems-esm-vue-typescript | 2 +- tests/__snapshots__/problems-script-none-javascript | 2 +- tests/__snapshots__/problems-script-none-typescript | 2 +- tests/__snapshots__/problems-script-react-javascript | 2 +- tests/__snapshots__/problems-script-react-typescript | 2 +- tests/__snapshots__/problems-script-vue-javascript | 2 +- tests/__snapshots__/problems-script-vue-typescript | 2 +- tests/__snapshots__/style-esm-none-xo-javascript | 2 +- tests/__snapshots__/style-esm-none-xo-typescript | 2 +- tests/__snapshots__/syntax-commonjs-none-javascript | 2 +- tests/__snapshots__/syntax-commonjs-none-typescript | 2 +- tests/__snapshots__/syntax-commonjs-react-javascript | 2 +- tests/__snapshots__/syntax-commonjs-react-typescript | 2 +- tests/__snapshots__/syntax-commonjs-vue-javascript | 2 +- tests/__snapshots__/syntax-commonjs-vue-typescript | 2 +- tests/__snapshots__/syntax-esm-none-javascript | 2 +- tests/__snapshots__/syntax-esm-none-typescript | 2 +- tests/__snapshots__/syntax-esm-react-javascript | 2 +- tests/__snapshots__/syntax-esm-react-typescript | 2 +- tests/__snapshots__/syntax-esm-vue-javascript | 2 +- tests/__snapshots__/syntax-esm-vue-typescript | 2 +- tests/__snapshots__/syntax-script-none-javascript | 2 +- tests/__snapshots__/syntax-script-none-typescript | 2 +- tests/__snapshots__/syntax-script-react-javascript | 2 +- tests/__snapshots__/syntax-script-react-typescript | 2 +- tests/__snapshots__/syntax-script-vue-javascript | 2 +- tests/__snapshots__/syntax-script-vue-typescript | 2 +- 39 files changed, 42 insertions(+), 42 deletions(-) diff --git a/lib/config-generator.js b/lib/config-generator.js index e202f3b3..9272bcd8 100644 --- a/lib/config-generator.js +++ b/lib/config-generator.js @@ -146,7 +146,6 @@ const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); `; let exportContent = ""; - let languageOptionsContent = ""; let needCompatHelper = false; if (this.answers.moduleType === "commonjs" || this.answers.moduleType === "script") { @@ -195,7 +194,7 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug "browser,node": "globals: {...globals.browser, ...globals.node}" }; - languageOptionsContent += `${envContent[this.answers.env.join(",")]}, `; + exportContent += ` {languageOptions: ${envContent[this.answers.env.join(",")]}},\n`; } @@ -226,8 +225,9 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug if (needCompatHelper) { this.result.devDependencies.push("@eslint/eslintrc", "@eslint/js"); } - this.result.configContent = `${importContent}\n${needCompatHelper ? helperContent : ""} -export default [\n {languageOptions:{${languageOptionsContent}}},\n${exportContent}];`; + this.result.configContent = `${importContent} +${needCompatHelper ? helperContent : ""} +export default [\n${exportContent}];`; } /** diff --git a/tests/__snapshots__/problems-commonjs-none-javascript b/tests/__snapshots__/problems-commonjs-none-javascript index 0f0e9919..19b7421f 100644 --- a/tests/__snapshots__/problems-commonjs-none-javascript +++ b/tests/__snapshots__/problems-commonjs-none-javascript @@ -4,9 +4,9 @@ import globals from "globals"; export default [ - {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, pluginJs.configs.recommended, + {languageOptions: globals: {...globals.browser, ...globals.node}}, ];", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/problems-commonjs-none-typescript b/tests/__snapshots__/problems-commonjs-none-typescript index 4314e95b..31be1b19 100644 --- a/tests/__snapshots__/problems-commonjs-none-typescript +++ b/tests/__snapshots__/problems-commonjs-none-typescript @@ -5,9 +5,9 @@ import tseslint from "typescript-eslint"; export default [ - {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, pluginJs.configs.recommended, + {languageOptions: globals: {...globals.browser, ...globals.node}}, ...tseslint.configs.recommended, ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/problems-commonjs-react-javascript b/tests/__snapshots__/problems-commonjs-react-javascript index 0ab127e8..ffde0142 100644 --- a/tests/__snapshots__/problems-commonjs-react-javascript +++ b/tests/__snapshots__/problems-commonjs-react-javascript @@ -5,9 +5,9 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [ - {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, pluginJs.configs.recommended, + {languageOptions: globals: {...globals.browser, ...globals.node}}, pluginReactConfig, ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/problems-commonjs-react-typescript b/tests/__snapshots__/problems-commonjs-react-typescript index a48bc13a..fa2b7266 100644 --- a/tests/__snapshots__/problems-commonjs-react-typescript +++ b/tests/__snapshots__/problems-commonjs-react-typescript @@ -6,9 +6,9 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [ - {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, pluginJs.configs.recommended, + {languageOptions: globals: {...globals.browser, ...globals.node}}, ...tseslint.configs.recommended, pluginReactConfig, ];", diff --git a/tests/__snapshots__/problems-commonjs-vue-javascript b/tests/__snapshots__/problems-commonjs-vue-javascript index 3159d1ae..660ca24c 100644 --- a/tests/__snapshots__/problems-commonjs-vue-javascript +++ b/tests/__snapshots__/problems-commonjs-vue-javascript @@ -13,9 +13,9 @@ const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [ - {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, pluginJs.configs.recommended, + {languageOptions: globals: {...globals.browser, ...globals.node}}, ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/problems-commonjs-vue-typescript b/tests/__snapshots__/problems-commonjs-vue-typescript index 70743042..4c34e847 100644 --- a/tests/__snapshots__/problems-commonjs-vue-typescript +++ b/tests/__snapshots__/problems-commonjs-vue-typescript @@ -14,9 +14,9 @@ const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [ - {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, pluginJs.configs.recommended, + {languageOptions: globals: {...globals.browser, ...globals.node}}, ...tseslint.configs.recommended, ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), ];", diff --git a/tests/__snapshots__/problems-esm-none-javascript b/tests/__snapshots__/problems-esm-none-javascript index 844f4133..22ae4ca0 100644 --- a/tests/__snapshots__/problems-esm-none-javascript +++ b/tests/__snapshots__/problems-esm-none-javascript @@ -4,8 +4,8 @@ import globals from "globals"; export default [ - {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, pluginJs.configs.recommended, + {languageOptions: globals: {...globals.browser, ...globals.node}}, ];", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/problems-esm-none-typescript b/tests/__snapshots__/problems-esm-none-typescript index 49a967e4..286e855d 100644 --- a/tests/__snapshots__/problems-esm-none-typescript +++ b/tests/__snapshots__/problems-esm-none-typescript @@ -5,8 +5,8 @@ import tseslint from "typescript-eslint"; export default [ - {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, pluginJs.configs.recommended, + {languageOptions: globals: {...globals.browser, ...globals.node}}, ...tseslint.configs.recommended, ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/problems-esm-react-javascript b/tests/__snapshots__/problems-esm-react-javascript index 73dc0102..a82202de 100644 --- a/tests/__snapshots__/problems-esm-react-javascript +++ b/tests/__snapshots__/problems-esm-react-javascript @@ -5,8 +5,8 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [ - {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, pluginJs.configs.recommended, + {languageOptions: globals: {...globals.browser, ...globals.node}}, pluginReactConfig, ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/problems-esm-react-typescript b/tests/__snapshots__/problems-esm-react-typescript index 255a31ca..d1ce6b45 100644 --- a/tests/__snapshots__/problems-esm-react-typescript +++ b/tests/__snapshots__/problems-esm-react-typescript @@ -6,8 +6,8 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [ - {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, pluginJs.configs.recommended, + {languageOptions: globals: {...globals.browser, ...globals.node}}, ...tseslint.configs.recommended, pluginReactConfig, ];", diff --git a/tests/__snapshots__/problems-esm-vue-javascript b/tests/__snapshots__/problems-esm-vue-javascript index 3185cbcc..b27b85ba 100644 --- a/tests/__snapshots__/problems-esm-vue-javascript +++ b/tests/__snapshots__/problems-esm-vue-javascript @@ -13,8 +13,8 @@ const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [ - {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, pluginJs.configs.recommended, + {languageOptions: globals: {...globals.browser, ...globals.node}}, ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/problems-esm-vue-typescript b/tests/__snapshots__/problems-esm-vue-typescript index 0fb362d8..09b84c77 100644 --- a/tests/__snapshots__/problems-esm-vue-typescript +++ b/tests/__snapshots__/problems-esm-vue-typescript @@ -14,8 +14,8 @@ const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [ - {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, pluginJs.configs.recommended, + {languageOptions: globals: {...globals.browser, ...globals.node}}, ...tseslint.configs.recommended, ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), ];", diff --git a/tests/__snapshots__/problems-script-none-javascript b/tests/__snapshots__/problems-script-none-javascript index 1a106614..f864019e 100644 --- a/tests/__snapshots__/problems-script-none-javascript +++ b/tests/__snapshots__/problems-script-none-javascript @@ -4,9 +4,9 @@ import globals from "globals"; export default [ - {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, pluginJs.configs.recommended, + {languageOptions: globals: {...globals.browser, ...globals.node}}, ];", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/problems-script-none-typescript b/tests/__snapshots__/problems-script-none-typescript index 2d16486e..84064353 100644 --- a/tests/__snapshots__/problems-script-none-typescript +++ b/tests/__snapshots__/problems-script-none-typescript @@ -5,9 +5,9 @@ import tseslint from "typescript-eslint"; export default [ - {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, pluginJs.configs.recommended, + {languageOptions: globals: {...globals.browser, ...globals.node}}, ...tseslint.configs.recommended, ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/problems-script-react-javascript b/tests/__snapshots__/problems-script-react-javascript index 072e665d..3f85ab8c 100644 --- a/tests/__snapshots__/problems-script-react-javascript +++ b/tests/__snapshots__/problems-script-react-javascript @@ -5,9 +5,9 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [ - {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, pluginJs.configs.recommended, + {languageOptions: globals: {...globals.browser, ...globals.node}}, pluginReactConfig, ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/problems-script-react-typescript b/tests/__snapshots__/problems-script-react-typescript index 8df158cb..6fba6ae6 100644 --- a/tests/__snapshots__/problems-script-react-typescript +++ b/tests/__snapshots__/problems-script-react-typescript @@ -6,9 +6,9 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [ - {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, pluginJs.configs.recommended, + {languageOptions: globals: {...globals.browser, ...globals.node}}, ...tseslint.configs.recommended, pluginReactConfig, ];", diff --git a/tests/__snapshots__/problems-script-vue-javascript b/tests/__snapshots__/problems-script-vue-javascript index 31594c4a..3a475ae3 100644 --- a/tests/__snapshots__/problems-script-vue-javascript +++ b/tests/__snapshots__/problems-script-vue-javascript @@ -13,9 +13,9 @@ const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [ - {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, pluginJs.configs.recommended, + {languageOptions: globals: {...globals.browser, ...globals.node}}, ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/problems-script-vue-typescript b/tests/__snapshots__/problems-script-vue-typescript index 708e11f4..2b71cb94 100644 --- a/tests/__snapshots__/problems-script-vue-typescript +++ b/tests/__snapshots__/problems-script-vue-typescript @@ -14,9 +14,9 @@ const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [ - {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, pluginJs.configs.recommended, + {languageOptions: globals: {...globals.browser, ...globals.node}}, ...tseslint.configs.recommended, ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), ];", diff --git a/tests/__snapshots__/style-esm-none-xo-javascript b/tests/__snapshots__/style-esm-none-xo-javascript index 1250475f..507d5f0b 100644 --- a/tests/__snapshots__/style-esm-none-xo-javascript +++ b/tests/__snapshots__/style-esm-none-xo-javascript @@ -12,8 +12,8 @@ const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [ - {languageOptions:{globals: globals.node, }}, ...compat.extends("xo"), + {languageOptions: globals: globals.node}, ];", "configFilename": "eslint.config.mjs", "devDependencies": [ diff --git a/tests/__snapshots__/style-esm-none-xo-typescript b/tests/__snapshots__/style-esm-none-xo-typescript index eeb3a1f1..2986d98d 100644 --- a/tests/__snapshots__/style-esm-none-xo-typescript +++ b/tests/__snapshots__/style-esm-none-xo-typescript @@ -13,8 +13,8 @@ const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [ - {languageOptions:{globals: globals.browser, }}, ...compat.extends("xo-typescript"), + {languageOptions: globals: globals.browser}, ...tseslint.configs.recommended, ];", "configFilename": "eslint.config.mjs", diff --git a/tests/__snapshots__/syntax-commonjs-none-javascript b/tests/__snapshots__/syntax-commonjs-none-javascript index 5d8564be..455963e8 100644 --- a/tests/__snapshots__/syntax-commonjs-none-javascript +++ b/tests/__snapshots__/syntax-commonjs-none-javascript @@ -3,8 +3,8 @@ export default [ - {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, + {languageOptions: globals: {...globals.browser, ...globals.node}}, ];", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/syntax-commonjs-none-typescript b/tests/__snapshots__/syntax-commonjs-none-typescript index dd179121..bd9713ed 100644 --- a/tests/__snapshots__/syntax-commonjs-none-typescript +++ b/tests/__snapshots__/syntax-commonjs-none-typescript @@ -4,8 +4,8 @@ import tseslint from "typescript-eslint"; export default [ - {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, + {languageOptions: globals: {...globals.browser, ...globals.node}}, ...tseslint.configs.recommended, ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/syntax-commonjs-react-javascript b/tests/__snapshots__/syntax-commonjs-react-javascript index 9b864e5a..62995fa6 100644 --- a/tests/__snapshots__/syntax-commonjs-react-javascript +++ b/tests/__snapshots__/syntax-commonjs-react-javascript @@ -4,8 +4,8 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [ - {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, + {languageOptions: globals: {...globals.browser, ...globals.node}}, pluginReactConfig, ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/syntax-commonjs-react-typescript b/tests/__snapshots__/syntax-commonjs-react-typescript index d93bc107..e9db659b 100644 --- a/tests/__snapshots__/syntax-commonjs-react-typescript +++ b/tests/__snapshots__/syntax-commonjs-react-typescript @@ -5,8 +5,8 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [ - {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, + {languageOptions: globals: {...globals.browser, ...globals.node}}, ...tseslint.configs.recommended, pluginReactConfig, ];", diff --git a/tests/__snapshots__/syntax-commonjs-vue-javascript b/tests/__snapshots__/syntax-commonjs-vue-javascript index ad4e6f1e..81e3b05c 100644 --- a/tests/__snapshots__/syntax-commonjs-vue-javascript +++ b/tests/__snapshots__/syntax-commonjs-vue-javascript @@ -12,8 +12,8 @@ const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [ - {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, + {languageOptions: globals: {...globals.browser, ...globals.node}}, ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/syntax-commonjs-vue-typescript b/tests/__snapshots__/syntax-commonjs-vue-typescript index 649e3fa4..175cfd7e 100644 --- a/tests/__snapshots__/syntax-commonjs-vue-typescript +++ b/tests/__snapshots__/syntax-commonjs-vue-typescript @@ -13,8 +13,8 @@ const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [ - {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, + {languageOptions: globals: {...globals.browser, ...globals.node}}, ...tseslint.configs.recommended, ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), ];", diff --git a/tests/__snapshots__/syntax-esm-none-javascript b/tests/__snapshots__/syntax-esm-none-javascript index 474c1e5b..97f4913e 100644 --- a/tests/__snapshots__/syntax-esm-none-javascript +++ b/tests/__snapshots__/syntax-esm-none-javascript @@ -3,7 +3,7 @@ export default [ - {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, + {languageOptions: globals: {...globals.browser, ...globals.node}}, ];", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/syntax-esm-none-typescript b/tests/__snapshots__/syntax-esm-none-typescript index ec99468f..650741cb 100644 --- a/tests/__snapshots__/syntax-esm-none-typescript +++ b/tests/__snapshots__/syntax-esm-none-typescript @@ -4,7 +4,7 @@ import tseslint from "typescript-eslint"; export default [ - {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, + {languageOptions: globals: {...globals.browser, ...globals.node}}, ...tseslint.configs.recommended, ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/syntax-esm-react-javascript b/tests/__snapshots__/syntax-esm-react-javascript index 5d3663f7..71ebb1ac 100644 --- a/tests/__snapshots__/syntax-esm-react-javascript +++ b/tests/__snapshots__/syntax-esm-react-javascript @@ -4,7 +4,7 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [ - {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, + {languageOptions: globals: {...globals.browser, ...globals.node}}, pluginReactConfig, ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/syntax-esm-react-typescript b/tests/__snapshots__/syntax-esm-react-typescript index ce4fd002..8e1a4f30 100644 --- a/tests/__snapshots__/syntax-esm-react-typescript +++ b/tests/__snapshots__/syntax-esm-react-typescript @@ -5,7 +5,7 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [ - {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, + {languageOptions: globals: {...globals.browser, ...globals.node}}, ...tseslint.configs.recommended, pluginReactConfig, ];", diff --git a/tests/__snapshots__/syntax-esm-vue-javascript b/tests/__snapshots__/syntax-esm-vue-javascript index af6abbb1..265cb64e 100644 --- a/tests/__snapshots__/syntax-esm-vue-javascript +++ b/tests/__snapshots__/syntax-esm-vue-javascript @@ -12,7 +12,7 @@ const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [ - {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, + {languageOptions: globals: {...globals.browser, ...globals.node}}, ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/syntax-esm-vue-typescript b/tests/__snapshots__/syntax-esm-vue-typescript index 40c0e31d..85735902 100644 --- a/tests/__snapshots__/syntax-esm-vue-typescript +++ b/tests/__snapshots__/syntax-esm-vue-typescript @@ -13,7 +13,7 @@ const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [ - {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, + {languageOptions: globals: {...globals.browser, ...globals.node}}, ...tseslint.configs.recommended, ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), ];", diff --git a/tests/__snapshots__/syntax-script-none-javascript b/tests/__snapshots__/syntax-script-none-javascript index addf1929..f53b9e1c 100644 --- a/tests/__snapshots__/syntax-script-none-javascript +++ b/tests/__snapshots__/syntax-script-none-javascript @@ -3,8 +3,8 @@ export default [ - {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, + {languageOptions: globals: {...globals.browser, ...globals.node}}, ];", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/syntax-script-none-typescript b/tests/__snapshots__/syntax-script-none-typescript index b7fe6836..39f9b44f 100644 --- a/tests/__snapshots__/syntax-script-none-typescript +++ b/tests/__snapshots__/syntax-script-none-typescript @@ -4,8 +4,8 @@ import tseslint from "typescript-eslint"; export default [ - {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, + {languageOptions: globals: {...globals.browser, ...globals.node}}, ...tseslint.configs.recommended, ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/syntax-script-react-javascript b/tests/__snapshots__/syntax-script-react-javascript index be14fd94..8cbc3a47 100644 --- a/tests/__snapshots__/syntax-script-react-javascript +++ b/tests/__snapshots__/syntax-script-react-javascript @@ -4,8 +4,8 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [ - {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, + {languageOptions: globals: {...globals.browser, ...globals.node}}, pluginReactConfig, ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/syntax-script-react-typescript b/tests/__snapshots__/syntax-script-react-typescript index bcf36a50..3284753b 100644 --- a/tests/__snapshots__/syntax-script-react-typescript +++ b/tests/__snapshots__/syntax-script-react-typescript @@ -5,8 +5,8 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [ - {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, + {languageOptions: globals: {...globals.browser, ...globals.node}}, ...tseslint.configs.recommended, pluginReactConfig, ];", diff --git a/tests/__snapshots__/syntax-script-vue-javascript b/tests/__snapshots__/syntax-script-vue-javascript index 6b649d3c..01cc91df 100644 --- a/tests/__snapshots__/syntax-script-vue-javascript +++ b/tests/__snapshots__/syntax-script-vue-javascript @@ -12,8 +12,8 @@ const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [ - {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, + {languageOptions: globals: {...globals.browser, ...globals.node}}, ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/syntax-script-vue-typescript b/tests/__snapshots__/syntax-script-vue-typescript index 8002e348..0ba7463f 100644 --- a/tests/__snapshots__/syntax-script-vue-typescript +++ b/tests/__snapshots__/syntax-script-vue-typescript @@ -13,8 +13,8 @@ const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [ - {languageOptions:{globals: {...globals.browser, ...globals.node}, }}, {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, + {languageOptions: globals: {...globals.browser, ...globals.node}}, ...tseslint.configs.recommended, ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), ];", From 5b83cf02bf28c93d0ecf265c8d90d328c4f1293d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Fri, 22 Mar 2024 10:10:57 +0800 Subject: [PATCH 32/41] fix: review suggestions --- README.md | 5 ----- tests/config-snapshots.spec.js | 3 +++ 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 7da4059b..e0a0db4a 100644 --- a/README.md +++ b/README.md @@ -22,12 +22,7 @@ If you want to use a specific shareable config that is hosted on npm, you can us ```bash # use `eslint-config-standard` shared config - -# npm 7+ npm init @eslint/config -- --config eslint-config-standard - -# ⚠️ npm 6.x no extra double-dash: -npm init @eslint/config --config eslint-config-standard ``` To use an eslintrc-style shared config: diff --git a/tests/config-snapshots.spec.js b/tests/config-snapshots.spec.js index 2af74573..f5f74bd5 100644 --- a/tests/config-snapshots.spec.js +++ b/tests/config-snapshots.spec.js @@ -52,6 +52,7 @@ describe("generate config for esm projects", () => { generator.calc(); expect(generator.result.configFilename).toBe("eslint.config.js"); + expect(generator.packageJsonPath).toBe(join(esmProjectDir, "./package.json")); expect(generator.result).toMatchFileSnapshot(`./__snapshots__/${item.name}`); }); }); @@ -63,6 +64,7 @@ describe("generate config for esm projects", () => { generator.calc(); expect(generator.result.configFilename).toBe("eslint.config.js"); + expect(generator.packageJsonPath).toBe(join(esmProjectDir, "./package.json")); }); }); @@ -99,6 +101,7 @@ describe("generate config for cjs projects", () => { generator.calc(); expect(generator.result.configFilename).toBe("eslint.config.mjs"); + expect(generator.packageJsonPath).toBe(join(cjsProjectDir, "./package.json")); expect(generator.result).toMatchFileSnapshot(`./__snapshots__/${item.name}`); }); }); From 36ad1eca9b0803afec720997038b7d8529969cfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Fri, 22 Mar 2024 11:36:17 +0800 Subject: [PATCH 33/41] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e0a0db4a..a687911d 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ If you want to use a specific shareable config that is hosted on npm, you can us npm init @eslint/config -- --config eslint-config-standard ``` -To use an eslintrc-style shared config: +To use an eslintrc-style(deprecated) shared config: ```bash npm init @eslint/config -- --eslintrc --config eslint-config-standard From c8011cec13deb97e46318a75a2c0a791b5f43659 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Mon, 25 Mar 2024 00:04:56 +0800 Subject: [PATCH 34/41] Update lib/config-generator.js Co-authored-by: Francesco Trotta --- lib/config-generator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/config-generator.js b/lib/config-generator.js index 9272bcd8..b9d14d8c 100644 --- a/lib/config-generator.js +++ b/lib/config-generator.js @@ -194,7 +194,7 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug "browser,node": "globals: {...globals.browser, ...globals.node}" }; - exportContent += ` {languageOptions: ${envContent[this.answers.env.join(",")]}},\n`; + exportContent += ` {languageOptions: { ${envContent[this.answers.env.join(",")]} }},\n`; } From a1eae823b755f353cd78fdb4d348cb52f4b9ce8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Mon, 25 Mar 2024 09:51:28 +0800 Subject: [PATCH 35/41] Update README.md Co-authored-by: Francesco Trotta --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a687911d..bce04e27 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ If you want to use a specific shareable config that is hosted on npm, you can us npm init @eslint/config -- --config eslint-config-standard ``` -To use an eslintrc-style(deprecated) shared config: +To use an eslintrc-style (legacy) shared config: ```bash npm init @eslint/config -- --eslintrc --config eslint-config-standard From 0c19e326a51dc4e142e36a64ddf2f90b5b3e586b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Mon, 25 Mar 2024 09:51:58 +0800 Subject: [PATCH 36/41] chore: update snapshots --- tests/__snapshots__/problems-commonjs-none-javascript | 2 +- tests/__snapshots__/problems-commonjs-none-typescript | 2 +- tests/__snapshots__/problems-commonjs-react-javascript | 2 +- tests/__snapshots__/problems-commonjs-react-typescript | 2 +- tests/__snapshots__/problems-commonjs-vue-javascript | 2 +- tests/__snapshots__/problems-commonjs-vue-typescript | 2 +- tests/__snapshots__/problems-esm-none-javascript | 2 +- tests/__snapshots__/problems-esm-none-typescript | 2 +- tests/__snapshots__/problems-esm-react-javascript | 2 +- tests/__snapshots__/problems-esm-react-typescript | 2 +- tests/__snapshots__/problems-esm-vue-javascript | 2 +- tests/__snapshots__/problems-esm-vue-typescript | 2 +- tests/__snapshots__/problems-script-none-javascript | 2 +- tests/__snapshots__/problems-script-none-typescript | 2 +- tests/__snapshots__/problems-script-react-javascript | 2 +- tests/__snapshots__/problems-script-react-typescript | 2 +- tests/__snapshots__/problems-script-vue-javascript | 2 +- tests/__snapshots__/problems-script-vue-typescript | 2 +- tests/__snapshots__/style-esm-none-xo-javascript | 2 +- tests/__snapshots__/style-esm-none-xo-typescript | 2 +- tests/__snapshots__/syntax-commonjs-none-javascript | 2 +- tests/__snapshots__/syntax-commonjs-none-typescript | 2 +- tests/__snapshots__/syntax-commonjs-react-javascript | 2 +- tests/__snapshots__/syntax-commonjs-react-typescript | 2 +- tests/__snapshots__/syntax-commonjs-vue-javascript | 2 +- tests/__snapshots__/syntax-commonjs-vue-typescript | 2 +- tests/__snapshots__/syntax-esm-none-javascript | 2 +- tests/__snapshots__/syntax-esm-none-typescript | 2 +- tests/__snapshots__/syntax-esm-react-javascript | 2 +- tests/__snapshots__/syntax-esm-react-typescript | 2 +- tests/__snapshots__/syntax-esm-vue-javascript | 2 +- tests/__snapshots__/syntax-esm-vue-typescript | 2 +- tests/__snapshots__/syntax-script-none-javascript | 2 +- tests/__snapshots__/syntax-script-none-typescript | 2 +- tests/__snapshots__/syntax-script-react-javascript | 2 +- tests/__snapshots__/syntax-script-react-typescript | 2 +- tests/__snapshots__/syntax-script-vue-javascript | 2 +- tests/__snapshots__/syntax-script-vue-typescript | 2 +- 38 files changed, 38 insertions(+), 38 deletions(-) diff --git a/tests/__snapshots__/problems-commonjs-none-javascript b/tests/__snapshots__/problems-commonjs-none-javascript index 19b7421f..54e87bd6 100644 --- a/tests/__snapshots__/problems-commonjs-none-javascript +++ b/tests/__snapshots__/problems-commonjs-none-javascript @@ -6,7 +6,7 @@ import globals from "globals"; export default [ {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, pluginJs.configs.recommended, - {languageOptions: globals: {...globals.browser, ...globals.node}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ];", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/problems-commonjs-none-typescript b/tests/__snapshots__/problems-commonjs-none-typescript index 31be1b19..b0cff62b 100644 --- a/tests/__snapshots__/problems-commonjs-none-typescript +++ b/tests/__snapshots__/problems-commonjs-none-typescript @@ -7,7 +7,7 @@ import tseslint from "typescript-eslint"; export default [ {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, pluginJs.configs.recommended, - {languageOptions: globals: {...globals.browser, ...globals.node}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ...tseslint.configs.recommended, ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/problems-commonjs-react-javascript b/tests/__snapshots__/problems-commonjs-react-javascript index ffde0142..86d51e7e 100644 --- a/tests/__snapshots__/problems-commonjs-react-javascript +++ b/tests/__snapshots__/problems-commonjs-react-javascript @@ -7,7 +7,7 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [ {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, pluginJs.configs.recommended, - {languageOptions: globals: {...globals.browser, ...globals.node}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, pluginReactConfig, ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/problems-commonjs-react-typescript b/tests/__snapshots__/problems-commonjs-react-typescript index fa2b7266..14c08324 100644 --- a/tests/__snapshots__/problems-commonjs-react-typescript +++ b/tests/__snapshots__/problems-commonjs-react-typescript @@ -8,7 +8,7 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [ {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, pluginJs.configs.recommended, - {languageOptions: globals: {...globals.browser, ...globals.node}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ...tseslint.configs.recommended, pluginReactConfig, ];", diff --git a/tests/__snapshots__/problems-commonjs-vue-javascript b/tests/__snapshots__/problems-commonjs-vue-javascript index 660ca24c..db8bfa8a 100644 --- a/tests/__snapshots__/problems-commonjs-vue-javascript +++ b/tests/__snapshots__/problems-commonjs-vue-javascript @@ -15,7 +15,7 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug export default [ {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, pluginJs.configs.recommended, - {languageOptions: globals: {...globals.browser, ...globals.node}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/problems-commonjs-vue-typescript b/tests/__snapshots__/problems-commonjs-vue-typescript index 4c34e847..b9af7256 100644 --- a/tests/__snapshots__/problems-commonjs-vue-typescript +++ b/tests/__snapshots__/problems-commonjs-vue-typescript @@ -16,7 +16,7 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug export default [ {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, pluginJs.configs.recommended, - {languageOptions: globals: {...globals.browser, ...globals.node}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ...tseslint.configs.recommended, ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), ];", diff --git a/tests/__snapshots__/problems-esm-none-javascript b/tests/__snapshots__/problems-esm-none-javascript index 22ae4ca0..ac252ae9 100644 --- a/tests/__snapshots__/problems-esm-none-javascript +++ b/tests/__snapshots__/problems-esm-none-javascript @@ -5,7 +5,7 @@ import globals from "globals"; export default [ pluginJs.configs.recommended, - {languageOptions: globals: {...globals.browser, ...globals.node}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ];", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/problems-esm-none-typescript b/tests/__snapshots__/problems-esm-none-typescript index 286e855d..fae52e3f 100644 --- a/tests/__snapshots__/problems-esm-none-typescript +++ b/tests/__snapshots__/problems-esm-none-typescript @@ -6,7 +6,7 @@ import tseslint from "typescript-eslint"; export default [ pluginJs.configs.recommended, - {languageOptions: globals: {...globals.browser, ...globals.node}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ...tseslint.configs.recommended, ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/problems-esm-react-javascript b/tests/__snapshots__/problems-esm-react-javascript index a82202de..b9f2b766 100644 --- a/tests/__snapshots__/problems-esm-react-javascript +++ b/tests/__snapshots__/problems-esm-react-javascript @@ -6,7 +6,7 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [ pluginJs.configs.recommended, - {languageOptions: globals: {...globals.browser, ...globals.node}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, pluginReactConfig, ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/problems-esm-react-typescript b/tests/__snapshots__/problems-esm-react-typescript index d1ce6b45..ec3e3ecb 100644 --- a/tests/__snapshots__/problems-esm-react-typescript +++ b/tests/__snapshots__/problems-esm-react-typescript @@ -7,7 +7,7 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [ pluginJs.configs.recommended, - {languageOptions: globals: {...globals.browser, ...globals.node}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ...tseslint.configs.recommended, pluginReactConfig, ];", diff --git a/tests/__snapshots__/problems-esm-vue-javascript b/tests/__snapshots__/problems-esm-vue-javascript index b27b85ba..abb68e69 100644 --- a/tests/__snapshots__/problems-esm-vue-javascript +++ b/tests/__snapshots__/problems-esm-vue-javascript @@ -14,7 +14,7 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug export default [ pluginJs.configs.recommended, - {languageOptions: globals: {...globals.browser, ...globals.node}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/problems-esm-vue-typescript b/tests/__snapshots__/problems-esm-vue-typescript index 09b84c77..88e1658e 100644 --- a/tests/__snapshots__/problems-esm-vue-typescript +++ b/tests/__snapshots__/problems-esm-vue-typescript @@ -15,7 +15,7 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug export default [ pluginJs.configs.recommended, - {languageOptions: globals: {...globals.browser, ...globals.node}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ...tseslint.configs.recommended, ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), ];", diff --git a/tests/__snapshots__/problems-script-none-javascript b/tests/__snapshots__/problems-script-none-javascript index f864019e..d27e85ef 100644 --- a/tests/__snapshots__/problems-script-none-javascript +++ b/tests/__snapshots__/problems-script-none-javascript @@ -6,7 +6,7 @@ import globals from "globals"; export default [ {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, pluginJs.configs.recommended, - {languageOptions: globals: {...globals.browser, ...globals.node}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ];", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/problems-script-none-typescript b/tests/__snapshots__/problems-script-none-typescript index 84064353..aa52d345 100644 --- a/tests/__snapshots__/problems-script-none-typescript +++ b/tests/__snapshots__/problems-script-none-typescript @@ -7,7 +7,7 @@ import tseslint from "typescript-eslint"; export default [ {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, pluginJs.configs.recommended, - {languageOptions: globals: {...globals.browser, ...globals.node}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ...tseslint.configs.recommended, ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/problems-script-react-javascript b/tests/__snapshots__/problems-script-react-javascript index 3f85ab8c..d87d5b74 100644 --- a/tests/__snapshots__/problems-script-react-javascript +++ b/tests/__snapshots__/problems-script-react-javascript @@ -7,7 +7,7 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [ {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, pluginJs.configs.recommended, - {languageOptions: globals: {...globals.browser, ...globals.node}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, pluginReactConfig, ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/problems-script-react-typescript b/tests/__snapshots__/problems-script-react-typescript index 6fba6ae6..34863cd3 100644 --- a/tests/__snapshots__/problems-script-react-typescript +++ b/tests/__snapshots__/problems-script-react-typescript @@ -8,7 +8,7 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [ {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, pluginJs.configs.recommended, - {languageOptions: globals: {...globals.browser, ...globals.node}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ...tseslint.configs.recommended, pluginReactConfig, ];", diff --git a/tests/__snapshots__/problems-script-vue-javascript b/tests/__snapshots__/problems-script-vue-javascript index 3a475ae3..2c5d7fcd 100644 --- a/tests/__snapshots__/problems-script-vue-javascript +++ b/tests/__snapshots__/problems-script-vue-javascript @@ -15,7 +15,7 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug export default [ {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, pluginJs.configs.recommended, - {languageOptions: globals: {...globals.browser, ...globals.node}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/problems-script-vue-typescript b/tests/__snapshots__/problems-script-vue-typescript index 2b71cb94..3e69cc5e 100644 --- a/tests/__snapshots__/problems-script-vue-typescript +++ b/tests/__snapshots__/problems-script-vue-typescript @@ -16,7 +16,7 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug export default [ {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, pluginJs.configs.recommended, - {languageOptions: globals: {...globals.browser, ...globals.node}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ...tseslint.configs.recommended, ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), ];", diff --git a/tests/__snapshots__/style-esm-none-xo-javascript b/tests/__snapshots__/style-esm-none-xo-javascript index 507d5f0b..7ceffe4e 100644 --- a/tests/__snapshots__/style-esm-none-xo-javascript +++ b/tests/__snapshots__/style-esm-none-xo-javascript @@ -13,7 +13,7 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug export default [ ...compat.extends("xo"), - {languageOptions: globals: globals.node}, + {languageOptions: { globals: globals.node }}, ];", "configFilename": "eslint.config.mjs", "devDependencies": [ diff --git a/tests/__snapshots__/style-esm-none-xo-typescript b/tests/__snapshots__/style-esm-none-xo-typescript index 2986d98d..80d86f3a 100644 --- a/tests/__snapshots__/style-esm-none-xo-typescript +++ b/tests/__snapshots__/style-esm-none-xo-typescript @@ -14,7 +14,7 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug export default [ ...compat.extends("xo-typescript"), - {languageOptions: globals: globals.browser}, + {languageOptions: { globals: globals.browser }}, ...tseslint.configs.recommended, ];", "configFilename": "eslint.config.mjs", diff --git a/tests/__snapshots__/syntax-commonjs-none-javascript b/tests/__snapshots__/syntax-commonjs-none-javascript index 455963e8..c92284f0 100644 --- a/tests/__snapshots__/syntax-commonjs-none-javascript +++ b/tests/__snapshots__/syntax-commonjs-none-javascript @@ -4,7 +4,7 @@ export default [ {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, - {languageOptions: globals: {...globals.browser, ...globals.node}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ];", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/syntax-commonjs-none-typescript b/tests/__snapshots__/syntax-commonjs-none-typescript index bd9713ed..7f3d2be4 100644 --- a/tests/__snapshots__/syntax-commonjs-none-typescript +++ b/tests/__snapshots__/syntax-commonjs-none-typescript @@ -5,7 +5,7 @@ import tseslint from "typescript-eslint"; export default [ {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, - {languageOptions: globals: {...globals.browser, ...globals.node}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ...tseslint.configs.recommended, ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/syntax-commonjs-react-javascript b/tests/__snapshots__/syntax-commonjs-react-javascript index 62995fa6..c99a6ffa 100644 --- a/tests/__snapshots__/syntax-commonjs-react-javascript +++ b/tests/__snapshots__/syntax-commonjs-react-javascript @@ -5,7 +5,7 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [ {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, - {languageOptions: globals: {...globals.browser, ...globals.node}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, pluginReactConfig, ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/syntax-commonjs-react-typescript b/tests/__snapshots__/syntax-commonjs-react-typescript index e9db659b..80e932ed 100644 --- a/tests/__snapshots__/syntax-commonjs-react-typescript +++ b/tests/__snapshots__/syntax-commonjs-react-typescript @@ -6,7 +6,7 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [ {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, - {languageOptions: globals: {...globals.browser, ...globals.node}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ...tseslint.configs.recommended, pluginReactConfig, ];", diff --git a/tests/__snapshots__/syntax-commonjs-vue-javascript b/tests/__snapshots__/syntax-commonjs-vue-javascript index 81e3b05c..2ee55f5c 100644 --- a/tests/__snapshots__/syntax-commonjs-vue-javascript +++ b/tests/__snapshots__/syntax-commonjs-vue-javascript @@ -13,7 +13,7 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug export default [ {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, - {languageOptions: globals: {...globals.browser, ...globals.node}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/syntax-commonjs-vue-typescript b/tests/__snapshots__/syntax-commonjs-vue-typescript index 175cfd7e..9dff4244 100644 --- a/tests/__snapshots__/syntax-commonjs-vue-typescript +++ b/tests/__snapshots__/syntax-commonjs-vue-typescript @@ -14,7 +14,7 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug export default [ {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, - {languageOptions: globals: {...globals.browser, ...globals.node}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ...tseslint.configs.recommended, ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), ];", diff --git a/tests/__snapshots__/syntax-esm-none-javascript b/tests/__snapshots__/syntax-esm-none-javascript index 97f4913e..2da23401 100644 --- a/tests/__snapshots__/syntax-esm-none-javascript +++ b/tests/__snapshots__/syntax-esm-none-javascript @@ -3,7 +3,7 @@ export default [ - {languageOptions: globals: {...globals.browser, ...globals.node}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ];", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/syntax-esm-none-typescript b/tests/__snapshots__/syntax-esm-none-typescript index 650741cb..e9f51f11 100644 --- a/tests/__snapshots__/syntax-esm-none-typescript +++ b/tests/__snapshots__/syntax-esm-none-typescript @@ -4,7 +4,7 @@ import tseslint from "typescript-eslint"; export default [ - {languageOptions: globals: {...globals.browser, ...globals.node}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ...tseslint.configs.recommended, ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/syntax-esm-react-javascript b/tests/__snapshots__/syntax-esm-react-javascript index 71ebb1ac..9a6bdf16 100644 --- a/tests/__snapshots__/syntax-esm-react-javascript +++ b/tests/__snapshots__/syntax-esm-react-javascript @@ -4,7 +4,7 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [ - {languageOptions: globals: {...globals.browser, ...globals.node}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, pluginReactConfig, ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/syntax-esm-react-typescript b/tests/__snapshots__/syntax-esm-react-typescript index 8e1a4f30..42213310 100644 --- a/tests/__snapshots__/syntax-esm-react-typescript +++ b/tests/__snapshots__/syntax-esm-react-typescript @@ -5,7 +5,7 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [ - {languageOptions: globals: {...globals.browser, ...globals.node}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ...tseslint.configs.recommended, pluginReactConfig, ];", diff --git a/tests/__snapshots__/syntax-esm-vue-javascript b/tests/__snapshots__/syntax-esm-vue-javascript index 265cb64e..3f5544c1 100644 --- a/tests/__snapshots__/syntax-esm-vue-javascript +++ b/tests/__snapshots__/syntax-esm-vue-javascript @@ -12,7 +12,7 @@ const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [ - {languageOptions: globals: {...globals.browser, ...globals.node}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/syntax-esm-vue-typescript b/tests/__snapshots__/syntax-esm-vue-typescript index 85735902..bf83e7c7 100644 --- a/tests/__snapshots__/syntax-esm-vue-typescript +++ b/tests/__snapshots__/syntax-esm-vue-typescript @@ -13,7 +13,7 @@ const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [ - {languageOptions: globals: {...globals.browser, ...globals.node}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ...tseslint.configs.recommended, ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), ];", diff --git a/tests/__snapshots__/syntax-script-none-javascript b/tests/__snapshots__/syntax-script-none-javascript index f53b9e1c..0e7bc5de 100644 --- a/tests/__snapshots__/syntax-script-none-javascript +++ b/tests/__snapshots__/syntax-script-none-javascript @@ -4,7 +4,7 @@ export default [ {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, - {languageOptions: globals: {...globals.browser, ...globals.node}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ];", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/syntax-script-none-typescript b/tests/__snapshots__/syntax-script-none-typescript index 39f9b44f..917262d4 100644 --- a/tests/__snapshots__/syntax-script-none-typescript +++ b/tests/__snapshots__/syntax-script-none-typescript @@ -5,7 +5,7 @@ import tseslint from "typescript-eslint"; export default [ {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, - {languageOptions: globals: {...globals.browser, ...globals.node}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ...tseslint.configs.recommended, ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/syntax-script-react-javascript b/tests/__snapshots__/syntax-script-react-javascript index 8cbc3a47..733b3b8d 100644 --- a/tests/__snapshots__/syntax-script-react-javascript +++ b/tests/__snapshots__/syntax-script-react-javascript @@ -5,7 +5,7 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [ {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, - {languageOptions: globals: {...globals.browser, ...globals.node}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, pluginReactConfig, ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/syntax-script-react-typescript b/tests/__snapshots__/syntax-script-react-typescript index 3284753b..475ab3f9 100644 --- a/tests/__snapshots__/syntax-script-react-typescript +++ b/tests/__snapshots__/syntax-script-react-typescript @@ -6,7 +6,7 @@ import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [ {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, - {languageOptions: globals: {...globals.browser, ...globals.node}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ...tseslint.configs.recommended, pluginReactConfig, ];", diff --git a/tests/__snapshots__/syntax-script-vue-javascript b/tests/__snapshots__/syntax-script-vue-javascript index 01cc91df..ed7626bb 100644 --- a/tests/__snapshots__/syntax-script-vue-javascript +++ b/tests/__snapshots__/syntax-script-vue-javascript @@ -13,7 +13,7 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug export default [ {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, - {languageOptions: globals: {...globals.browser, ...globals.node}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/syntax-script-vue-typescript b/tests/__snapshots__/syntax-script-vue-typescript index 0ba7463f..bff345cc 100644 --- a/tests/__snapshots__/syntax-script-vue-typescript +++ b/tests/__snapshots__/syntax-script-vue-typescript @@ -14,7 +14,7 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug export default [ {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, - {languageOptions: globals: {...globals.browser, ...globals.node}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ...tseslint.configs.recommended, ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), ];", From cdc443003ff4382741176b76384aeb3496dd849a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Thu, 28 Mar 2024 16:42:02 +0800 Subject: [PATCH 37/41] feat: offical vue supports --- lib/config-generator.js | 41 ++++++++----------- .../problems-commonjs-none-javascript | 2 +- .../problems-commonjs-none-typescript | 8 ++-- .../problems-commonjs-react-javascript | 8 ++-- .../problems-commonjs-react-typescript | 8 ++-- .../problems-commonjs-vue-javascript | 18 ++------ .../problems-commonjs-vue-typescript | 22 +++------- .../problems-esm-none-typescript | 6 +-- .../problems-esm-react-javascript | 6 +-- .../problems-esm-react-typescript | 6 +-- .../__snapshots__/problems-esm-vue-javascript | 16 ++------ .../__snapshots__/problems-esm-vue-typescript | 20 +++------ .../problems-script-none-javascript | 2 +- .../problems-script-none-typescript | 8 ++-- .../problems-script-react-javascript | 8 ++-- .../problems-script-react-typescript | 8 ++-- .../problems-script-vue-javascript | 18 ++------ .../problems-script-vue-typescript | 22 +++------- .../style-esm-none-xo-typescript | 8 ++-- .../syntax-commonjs-none-typescript | 8 ++-- .../syntax-commonjs-react-javascript | 8 ++-- .../syntax-commonjs-react-typescript | 10 ++--- .../syntax-commonjs-vue-javascript | 18 ++------ .../syntax-commonjs-vue-typescript | 22 +++------- .../__snapshots__/syntax-esm-none-typescript | 8 ++-- .../__snapshots__/syntax-esm-react-javascript | 8 ++-- .../__snapshots__/syntax-esm-react-typescript | 8 ++-- tests/__snapshots__/syntax-esm-vue-javascript | 18 ++------ tests/__snapshots__/syntax-esm-vue-typescript | 22 +++------- .../syntax-script-none-typescript | 8 ++-- .../syntax-script-react-javascript | 8 ++-- .../syntax-script-react-typescript | 10 ++--- .../syntax-script-vue-javascript | 18 ++------ .../syntax-script-vue-typescript | 22 +++------- 34 files changed, 153 insertions(+), 278 deletions(-) diff --git a/lib/config-generator.js b/lib/config-generator.js index b9d14d8c..04978a46 100644 --- a/lib/config-generator.js +++ b/lib/config-generator.js @@ -148,10 +148,6 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug let exportContent = ""; let needCompatHelper = false; - if (this.answers.moduleType === "commonjs" || this.answers.moduleType === "script") { - exportContent += ` {files: ["**/*.js"], languageOptions: {sourceType: "${this.answers.moduleType}"}},\n`; - } - if (this.answers.purpose === "syntax") { // no need to install any plugin @@ -185,19 +181,6 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug } } - if (this.answers.env?.length > 0) { - this.result.devDependencies.push("globals"); - importContent += "import globals from \"globals\";\n"; - const envContent = { - browser: "globals: globals.browser", - node: "globals: globals.node", - "browser,node": "globals: {...globals.browser, ...globals.node}" - }; - - exportContent += ` {languageOptions: { ${envContent[this.answers.env.join(",")]} }},\n`; - } - - if (this.answers.language === "typescript") { this.result.devDependencies.push("typescript-eslint"); importContent += "import tseslint from \"typescript-eslint\";\n"; @@ -208,12 +191,8 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug this.result.devDependencies.push("eslint-plugin-vue"); - // importContent += "import pluginVue from \"eslint-plugin-vue\";\n"; - - // // TODO: there is a wip for flat support - https://github.com/vuejs/eslint-plugin-vue/pull/2319 - // exportContent += " pluginVue.configs[\"flat/essential\"],\n"; - needCompatHelper = true; - exportContent += " ...compat.extends(\"plugin:vue/vue3-essential\").map(config => ({files: [\"**/*.vue\"], ...config})),\n"; + importContent += "import pluginVue from \"eslint-plugin-vue\";\n"; + exportContent += " pluginVue.configs[\"flat/essential\"],\n"; } if (this.answers.framework === "react") { @@ -222,6 +201,22 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug exportContent += " pluginReactConfig,\n"; } + if (this.answers.moduleType === "commonjs" || this.answers.moduleType === "script") { + exportContent += ` {files: ["**/*.js"], languageOptions: {sourceType: "${this.answers.moduleType}"}},\n`; + } + + if (this.answers.env?.length > 0) { + this.result.devDependencies.push("globals"); + importContent += "import globals from \"globals\";\n"; + const envContent = { + browser: "globals: globals.browser", + node: "globals: globals.node", + "browser,node": "globals: {...globals.browser, ...globals.node}" + }; + + exportContent += ` {languageOptions: { ${envContent[this.answers.env.join(",")]} }},\n`; + } + if (needCompatHelper) { this.result.devDependencies.push("@eslint/eslintrc", "@eslint/js"); } diff --git a/tests/__snapshots__/problems-commonjs-none-javascript b/tests/__snapshots__/problems-commonjs-none-javascript index 54e87bd6..546a51bc 100644 --- a/tests/__snapshots__/problems-commonjs-none-javascript +++ b/tests/__snapshots__/problems-commonjs-none-javascript @@ -4,8 +4,8 @@ import globals from "globals"; export default [ - {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, pluginJs.configs.recommended, + {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/problems-commonjs-none-typescript b/tests/__snapshots__/problems-commonjs-none-typescript index b0cff62b..ab9ae4c1 100644 --- a/tests/__snapshots__/problems-commonjs-none-typescript +++ b/tests/__snapshots__/problems-commonjs-none-typescript @@ -1,20 +1,20 @@ { "configContent": "import pluginJs from "@eslint/js"; -import globals from "globals"; import tseslint from "typescript-eslint"; +import globals from "globals"; export default [ - {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, pluginJs.configs.recommended, - {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ...tseslint.configs.recommended, + {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", "@eslint/js", - "globals", "typescript-eslint", + "globals", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problems-commonjs-react-javascript b/tests/__snapshots__/problems-commonjs-react-javascript index 86d51e7e..988d8303 100644 --- a/tests/__snapshots__/problems-commonjs-react-javascript +++ b/tests/__snapshots__/problems-commonjs-react-javascript @@ -1,20 +1,20 @@ { "configContent": "import pluginJs from "@eslint/js"; -import globals from "globals"; import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; +import globals from "globals"; export default [ - {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, pluginJs.configs.recommended, - {languageOptions: { globals: {...globals.browser, ...globals.node} }}, pluginReactConfig, + {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", "@eslint/js", - "globals", "eslint-plugin-react", + "globals", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problems-commonjs-react-typescript b/tests/__snapshots__/problems-commonjs-react-typescript index 14c08324..147c8fce 100644 --- a/tests/__snapshots__/problems-commonjs-react-typescript +++ b/tests/__snapshots__/problems-commonjs-react-typescript @@ -1,23 +1,23 @@ { "configContent": "import pluginJs from "@eslint/js"; -import globals from "globals"; import tseslint from "typescript-eslint"; import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; +import globals from "globals"; export default [ - {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, pluginJs.configs.recommended, - {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ...tseslint.configs.recommended, pluginReactConfig, + {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", "@eslint/js", - "globals", "typescript-eslint", "eslint-plugin-react", + "globals", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problems-commonjs-vue-javascript b/tests/__snapshots__/problems-commonjs-vue-javascript index db8bfa8a..c6c1d229 100644 --- a/tests/__snapshots__/problems-commonjs-vue-javascript +++ b/tests/__snapshots__/problems-commonjs-vue-javascript @@ -1,30 +1,20 @@ { "configContent": "import pluginJs from "@eslint/js"; +import pluginVue from "eslint-plugin-vue"; import globals from "globals"; -import path from "path"; -import { fileURLToPath } from "url"; -import { FlatCompat } from "@eslint/eslintrc"; -import pluginJs from "@eslint/js"; - -// mimic CommonJS variables -- not needed if using CommonJS -const __filename = fileURLToPath(import.meta.url); -const __dirname = path.dirname(__filename); -const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [ - {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, pluginJs.configs.recommended, + pluginVue.configs["flat/essential"], + {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, {languageOptions: { globals: {...globals.browser, ...globals.node} }}, - ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", "@eslint/js", - "globals", "eslint-plugin-vue", - "@eslint/eslintrc", - "@eslint/js", + "globals", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problems-commonjs-vue-typescript b/tests/__snapshots__/problems-commonjs-vue-typescript index b9af7256..7fb07112 100644 --- a/tests/__snapshots__/problems-commonjs-vue-typescript +++ b/tests/__snapshots__/problems-commonjs-vue-typescript @@ -1,33 +1,23 @@ { "configContent": "import pluginJs from "@eslint/js"; -import globals from "globals"; import tseslint from "typescript-eslint"; +import pluginVue from "eslint-plugin-vue"; +import globals from "globals"; -import path from "path"; -import { fileURLToPath } from "url"; -import { FlatCompat } from "@eslint/eslintrc"; -import pluginJs from "@eslint/js"; - -// mimic CommonJS variables -- not needed if using CommonJS -const __filename = fileURLToPath(import.meta.url); -const __dirname = path.dirname(__filename); -const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [ - {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, pluginJs.configs.recommended, - {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ...tseslint.configs.recommended, - ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), + pluginVue.configs["flat/essential"], + {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", "@eslint/js", - "globals", "typescript-eslint", "eslint-plugin-vue", - "@eslint/eslintrc", - "@eslint/js", + "globals", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problems-esm-none-typescript b/tests/__snapshots__/problems-esm-none-typescript index fae52e3f..a4872d79 100644 --- a/tests/__snapshots__/problems-esm-none-typescript +++ b/tests/__snapshots__/problems-esm-none-typescript @@ -1,19 +1,19 @@ { "configContent": "import pluginJs from "@eslint/js"; -import globals from "globals"; import tseslint from "typescript-eslint"; +import globals from "globals"; export default [ pluginJs.configs.recommended, - {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ...tseslint.configs.recommended, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", "@eslint/js", - "globals", "typescript-eslint", + "globals", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problems-esm-react-javascript b/tests/__snapshots__/problems-esm-react-javascript index b9f2b766..b08e42f7 100644 --- a/tests/__snapshots__/problems-esm-react-javascript +++ b/tests/__snapshots__/problems-esm-react-javascript @@ -1,19 +1,19 @@ { "configContent": "import pluginJs from "@eslint/js"; -import globals from "globals"; import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; +import globals from "globals"; export default [ pluginJs.configs.recommended, - {languageOptions: { globals: {...globals.browser, ...globals.node} }}, pluginReactConfig, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", "@eslint/js", - "globals", "eslint-plugin-react", + "globals", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problems-esm-react-typescript b/tests/__snapshots__/problems-esm-react-typescript index ec3e3ecb..3888eec6 100644 --- a/tests/__snapshots__/problems-esm-react-typescript +++ b/tests/__snapshots__/problems-esm-react-typescript @@ -1,22 +1,22 @@ { "configContent": "import pluginJs from "@eslint/js"; -import globals from "globals"; import tseslint from "typescript-eslint"; import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; +import globals from "globals"; export default [ pluginJs.configs.recommended, - {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ...tseslint.configs.recommended, pluginReactConfig, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", "@eslint/js", - "globals", "typescript-eslint", "eslint-plugin-react", + "globals", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problems-esm-vue-javascript b/tests/__snapshots__/problems-esm-vue-javascript index abb68e69..4c6fe303 100644 --- a/tests/__snapshots__/problems-esm-vue-javascript +++ b/tests/__snapshots__/problems-esm-vue-javascript @@ -1,29 +1,19 @@ { "configContent": "import pluginJs from "@eslint/js"; +import pluginVue from "eslint-plugin-vue"; import globals from "globals"; -import path from "path"; -import { fileURLToPath } from "url"; -import { FlatCompat } from "@eslint/eslintrc"; -import pluginJs from "@eslint/js"; - -// mimic CommonJS variables -- not needed if using CommonJS -const __filename = fileURLToPath(import.meta.url); -const __dirname = path.dirname(__filename); -const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [ pluginJs.configs.recommended, + pluginVue.configs["flat/essential"], {languageOptions: { globals: {...globals.browser, ...globals.node} }}, - ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", "@eslint/js", - "globals", "eslint-plugin-vue", - "@eslint/eslintrc", - "@eslint/js", + "globals", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problems-esm-vue-typescript b/tests/__snapshots__/problems-esm-vue-typescript index 88e1658e..9cf6e900 100644 --- a/tests/__snapshots__/problems-esm-vue-typescript +++ b/tests/__snapshots__/problems-esm-vue-typescript @@ -1,32 +1,22 @@ { "configContent": "import pluginJs from "@eslint/js"; -import globals from "globals"; import tseslint from "typescript-eslint"; +import pluginVue from "eslint-plugin-vue"; +import globals from "globals"; -import path from "path"; -import { fileURLToPath } from "url"; -import { FlatCompat } from "@eslint/eslintrc"; -import pluginJs from "@eslint/js"; - -// mimic CommonJS variables -- not needed if using CommonJS -const __filename = fileURLToPath(import.meta.url); -const __dirname = path.dirname(__filename); -const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [ pluginJs.configs.recommended, - {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ...tseslint.configs.recommended, - ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), + pluginVue.configs["flat/essential"], + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", "@eslint/js", - "globals", "typescript-eslint", "eslint-plugin-vue", - "@eslint/eslintrc", - "@eslint/js", + "globals", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problems-script-none-javascript b/tests/__snapshots__/problems-script-none-javascript index d27e85ef..392d2b0c 100644 --- a/tests/__snapshots__/problems-script-none-javascript +++ b/tests/__snapshots__/problems-script-none-javascript @@ -4,8 +4,8 @@ import globals from "globals"; export default [ - {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, pluginJs.configs.recommended, + {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ];", "configFilename": "eslint.config.js", diff --git a/tests/__snapshots__/problems-script-none-typescript b/tests/__snapshots__/problems-script-none-typescript index aa52d345..54a59d5f 100644 --- a/tests/__snapshots__/problems-script-none-typescript +++ b/tests/__snapshots__/problems-script-none-typescript @@ -1,20 +1,20 @@ { "configContent": "import pluginJs from "@eslint/js"; -import globals from "globals"; import tseslint from "typescript-eslint"; +import globals from "globals"; export default [ - {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, pluginJs.configs.recommended, - {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ...tseslint.configs.recommended, + {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", "@eslint/js", - "globals", "typescript-eslint", + "globals", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problems-script-react-javascript b/tests/__snapshots__/problems-script-react-javascript index d87d5b74..72b779aa 100644 --- a/tests/__snapshots__/problems-script-react-javascript +++ b/tests/__snapshots__/problems-script-react-javascript @@ -1,20 +1,20 @@ { "configContent": "import pluginJs from "@eslint/js"; -import globals from "globals"; import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; +import globals from "globals"; export default [ - {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, pluginJs.configs.recommended, - {languageOptions: { globals: {...globals.browser, ...globals.node} }}, pluginReactConfig, + {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", "@eslint/js", - "globals", "eslint-plugin-react", + "globals", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problems-script-react-typescript b/tests/__snapshots__/problems-script-react-typescript index 34863cd3..cded05b4 100644 --- a/tests/__snapshots__/problems-script-react-typescript +++ b/tests/__snapshots__/problems-script-react-typescript @@ -1,23 +1,23 @@ { "configContent": "import pluginJs from "@eslint/js"; -import globals from "globals"; import tseslint from "typescript-eslint"; import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; +import globals from "globals"; export default [ - {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, pluginJs.configs.recommended, - {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ...tseslint.configs.recommended, pluginReactConfig, + {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", "@eslint/js", - "globals", "typescript-eslint", "eslint-plugin-react", + "globals", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problems-script-vue-javascript b/tests/__snapshots__/problems-script-vue-javascript index 2c5d7fcd..d242eb13 100644 --- a/tests/__snapshots__/problems-script-vue-javascript +++ b/tests/__snapshots__/problems-script-vue-javascript @@ -1,30 +1,20 @@ { "configContent": "import pluginJs from "@eslint/js"; +import pluginVue from "eslint-plugin-vue"; import globals from "globals"; -import path from "path"; -import { fileURLToPath } from "url"; -import { FlatCompat } from "@eslint/eslintrc"; -import pluginJs from "@eslint/js"; - -// mimic CommonJS variables -- not needed if using CommonJS -const __filename = fileURLToPath(import.meta.url); -const __dirname = path.dirname(__filename); -const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [ - {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, pluginJs.configs.recommended, + pluginVue.configs["flat/essential"], + {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, {languageOptions: { globals: {...globals.browser, ...globals.node} }}, - ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", "@eslint/js", - "globals", "eslint-plugin-vue", - "@eslint/eslintrc", - "@eslint/js", + "globals", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problems-script-vue-typescript b/tests/__snapshots__/problems-script-vue-typescript index 3e69cc5e..fcc53d3e 100644 --- a/tests/__snapshots__/problems-script-vue-typescript +++ b/tests/__snapshots__/problems-script-vue-typescript @@ -1,33 +1,23 @@ { "configContent": "import pluginJs from "@eslint/js"; -import globals from "globals"; import tseslint from "typescript-eslint"; +import pluginVue from "eslint-plugin-vue"; +import globals from "globals"; -import path from "path"; -import { fileURLToPath } from "url"; -import { FlatCompat } from "@eslint/eslintrc"; -import pluginJs from "@eslint/js"; - -// mimic CommonJS variables -- not needed if using CommonJS -const __filename = fileURLToPath(import.meta.url); -const __dirname = path.dirname(__filename); -const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [ - {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, pluginJs.configs.recommended, - {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ...tseslint.configs.recommended, - ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), + pluginVue.configs["flat/essential"], + {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", "@eslint/js", - "globals", "typescript-eslint", "eslint-plugin-vue", - "@eslint/eslintrc", - "@eslint/js", + "globals", ], } \ No newline at end of file diff --git a/tests/__snapshots__/style-esm-none-xo-typescript b/tests/__snapshots__/style-esm-none-xo-typescript index 80d86f3a..4ddc1ab5 100644 --- a/tests/__snapshots__/style-esm-none-xo-typescript +++ b/tests/__snapshots__/style-esm-none-xo-typescript @@ -1,6 +1,6 @@ { - "configContent": "import globals from "globals"; -import tseslint from "typescript-eslint"; + "configContent": "import tseslint from "typescript-eslint"; +import globals from "globals"; import path from "path"; import { fileURLToPath } from "url"; @@ -14,8 +14,8 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug export default [ ...compat.extends("xo-typescript"), - {languageOptions: { globals: globals.browser }}, ...tseslint.configs.recommended, + {languageOptions: { globals: globals.browser }}, ];", "configFilename": "eslint.config.mjs", "devDependencies": [ @@ -25,8 +25,8 @@ export default [ "@typescript-eslint/parser@>=7.0.2", "eslint@>=8.56.0", "typescript@>=5.0.0", - "globals", "typescript-eslint", + "globals", "@eslint/eslintrc", "@eslint/js", ], diff --git a/tests/__snapshots__/syntax-commonjs-none-typescript b/tests/__snapshots__/syntax-commonjs-none-typescript index 7f3d2be4..431b2d1d 100644 --- a/tests/__snapshots__/syntax-commonjs-none-typescript +++ b/tests/__snapshots__/syntax-commonjs-none-typescript @@ -1,17 +1,17 @@ { - "configContent": "import globals from "globals"; -import tseslint from "typescript-eslint"; + "configContent": "import tseslint from "typescript-eslint"; +import globals from "globals"; export default [ + ...tseslint.configs.recommended, {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, {languageOptions: { globals: {...globals.browser, ...globals.node} }}, - ...tseslint.configs.recommended, ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", - "globals", "typescript-eslint", + "globals", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-commonjs-react-javascript b/tests/__snapshots__/syntax-commonjs-react-javascript index c99a6ffa..961e8881 100644 --- a/tests/__snapshots__/syntax-commonjs-react-javascript +++ b/tests/__snapshots__/syntax-commonjs-react-javascript @@ -1,17 +1,17 @@ { - "configContent": "import globals from "globals"; -import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; + "configContent": "import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; +import globals from "globals"; export default [ + pluginReactConfig, {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, {languageOptions: { globals: {...globals.browser, ...globals.node} }}, - pluginReactConfig, ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", - "globals", "eslint-plugin-react", + "globals", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-commonjs-react-typescript b/tests/__snapshots__/syntax-commonjs-react-typescript index 80e932ed..1c6b599d 100644 --- a/tests/__snapshots__/syntax-commonjs-react-typescript +++ b/tests/__snapshots__/syntax-commonjs-react-typescript @@ -1,20 +1,20 @@ { - "configContent": "import globals from "globals"; -import tseslint from "typescript-eslint"; + "configContent": "import tseslint from "typescript-eslint"; import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; +import globals from "globals"; export default [ - {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, - {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ...tseslint.configs.recommended, pluginReactConfig, + {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", - "globals", "typescript-eslint", "eslint-plugin-react", + "globals", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-commonjs-vue-javascript b/tests/__snapshots__/syntax-commonjs-vue-javascript index 2ee55f5c..9a18386c 100644 --- a/tests/__snapshots__/syntax-commonjs-vue-javascript +++ b/tests/__snapshots__/syntax-commonjs-vue-javascript @@ -1,27 +1,17 @@ { - "configContent": "import globals from "globals"; + "configContent": "import pluginVue from "eslint-plugin-vue"; +import globals from "globals"; -import path from "path"; -import { fileURLToPath } from "url"; -import { FlatCompat } from "@eslint/eslintrc"; -import pluginJs from "@eslint/js"; - -// mimic CommonJS variables -- not needed if using CommonJS -const __filename = fileURLToPath(import.meta.url); -const __dirname = path.dirname(__filename); -const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [ + pluginVue.configs["flat/essential"], {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, {languageOptions: { globals: {...globals.browser, ...globals.node} }}, - ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", - "globals", "eslint-plugin-vue", - "@eslint/eslintrc", - "@eslint/js", + "globals", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-commonjs-vue-typescript b/tests/__snapshots__/syntax-commonjs-vue-typescript index 9dff4244..bdf8584c 100644 --- a/tests/__snapshots__/syntax-commonjs-vue-typescript +++ b/tests/__snapshots__/syntax-commonjs-vue-typescript @@ -1,30 +1,20 @@ { - "configContent": "import globals from "globals"; -import tseslint from "typescript-eslint"; + "configContent": "import tseslint from "typescript-eslint"; +import pluginVue from "eslint-plugin-vue"; +import globals from "globals"; -import path from "path"; -import { fileURLToPath } from "url"; -import { FlatCompat } from "@eslint/eslintrc"; -import pluginJs from "@eslint/js"; - -// mimic CommonJS variables -- not needed if using CommonJS -const __filename = fileURLToPath(import.meta.url); -const __dirname = path.dirname(__filename); -const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [ + ...tseslint.configs.recommended, + pluginVue.configs["flat/essential"], {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, {languageOptions: { globals: {...globals.browser, ...globals.node} }}, - ...tseslint.configs.recommended, - ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", - "globals", "typescript-eslint", "eslint-plugin-vue", - "@eslint/eslintrc", - "@eslint/js", + "globals", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-esm-none-typescript b/tests/__snapshots__/syntax-esm-none-typescript index e9f51f11..21f073e6 100644 --- a/tests/__snapshots__/syntax-esm-none-typescript +++ b/tests/__snapshots__/syntax-esm-none-typescript @@ -1,16 +1,16 @@ { - "configContent": "import globals from "globals"; -import tseslint from "typescript-eslint"; + "configContent": "import tseslint from "typescript-eslint"; +import globals from "globals"; export default [ - {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ...tseslint.configs.recommended, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", - "globals", "typescript-eslint", + "globals", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-esm-react-javascript b/tests/__snapshots__/syntax-esm-react-javascript index 9a6bdf16..d23cb6d9 100644 --- a/tests/__snapshots__/syntax-esm-react-javascript +++ b/tests/__snapshots__/syntax-esm-react-javascript @@ -1,16 +1,16 @@ { - "configContent": "import globals from "globals"; -import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; + "configContent": "import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; +import globals from "globals"; export default [ - {languageOptions: { globals: {...globals.browser, ...globals.node} }}, pluginReactConfig, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", - "globals", "eslint-plugin-react", + "globals", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-esm-react-typescript b/tests/__snapshots__/syntax-esm-react-typescript index 42213310..bf927e04 100644 --- a/tests/__snapshots__/syntax-esm-react-typescript +++ b/tests/__snapshots__/syntax-esm-react-typescript @@ -1,19 +1,19 @@ { - "configContent": "import globals from "globals"; -import tseslint from "typescript-eslint"; + "configContent": "import tseslint from "typescript-eslint"; import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; +import globals from "globals"; export default [ - {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ...tseslint.configs.recommended, pluginReactConfig, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", - "globals", "typescript-eslint", "eslint-plugin-react", + "globals", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-esm-vue-javascript b/tests/__snapshots__/syntax-esm-vue-javascript index 3f5544c1..b9169537 100644 --- a/tests/__snapshots__/syntax-esm-vue-javascript +++ b/tests/__snapshots__/syntax-esm-vue-javascript @@ -1,26 +1,16 @@ { - "configContent": "import globals from "globals"; + "configContent": "import pluginVue from "eslint-plugin-vue"; +import globals from "globals"; -import path from "path"; -import { fileURLToPath } from "url"; -import { FlatCompat } from "@eslint/eslintrc"; -import pluginJs from "@eslint/js"; - -// mimic CommonJS variables -- not needed if using CommonJS -const __filename = fileURLToPath(import.meta.url); -const __dirname = path.dirname(__filename); -const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [ + pluginVue.configs["flat/essential"], {languageOptions: { globals: {...globals.browser, ...globals.node} }}, - ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", - "globals", "eslint-plugin-vue", - "@eslint/eslintrc", - "@eslint/js", + "globals", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-esm-vue-typescript b/tests/__snapshots__/syntax-esm-vue-typescript index bf83e7c7..4fcc0ca1 100644 --- a/tests/__snapshots__/syntax-esm-vue-typescript +++ b/tests/__snapshots__/syntax-esm-vue-typescript @@ -1,29 +1,19 @@ { - "configContent": "import globals from "globals"; -import tseslint from "typescript-eslint"; + "configContent": "import tseslint from "typescript-eslint"; +import pluginVue from "eslint-plugin-vue"; +import globals from "globals"; -import path from "path"; -import { fileURLToPath } from "url"; -import { FlatCompat } from "@eslint/eslintrc"; -import pluginJs from "@eslint/js"; - -// mimic CommonJS variables -- not needed if using CommonJS -const __filename = fileURLToPath(import.meta.url); -const __dirname = path.dirname(__filename); -const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [ - {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ...tseslint.configs.recommended, - ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), + pluginVue.configs["flat/essential"], + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", - "globals", "typescript-eslint", "eslint-plugin-vue", - "@eslint/eslintrc", - "@eslint/js", + "globals", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-script-none-typescript b/tests/__snapshots__/syntax-script-none-typescript index 917262d4..2e3de116 100644 --- a/tests/__snapshots__/syntax-script-none-typescript +++ b/tests/__snapshots__/syntax-script-none-typescript @@ -1,17 +1,17 @@ { - "configContent": "import globals from "globals"; -import tseslint from "typescript-eslint"; + "configContent": "import tseslint from "typescript-eslint"; +import globals from "globals"; export default [ + ...tseslint.configs.recommended, {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, {languageOptions: { globals: {...globals.browser, ...globals.node} }}, - ...tseslint.configs.recommended, ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", - "globals", "typescript-eslint", + "globals", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-script-react-javascript b/tests/__snapshots__/syntax-script-react-javascript index 733b3b8d..da9a882e 100644 --- a/tests/__snapshots__/syntax-script-react-javascript +++ b/tests/__snapshots__/syntax-script-react-javascript @@ -1,17 +1,17 @@ { - "configContent": "import globals from "globals"; -import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; + "configContent": "import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; +import globals from "globals"; export default [ + pluginReactConfig, {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, {languageOptions: { globals: {...globals.browser, ...globals.node} }}, - pluginReactConfig, ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", - "globals", "eslint-plugin-react", + "globals", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-script-react-typescript b/tests/__snapshots__/syntax-script-react-typescript index 475ab3f9..409de801 100644 --- a/tests/__snapshots__/syntax-script-react-typescript +++ b/tests/__snapshots__/syntax-script-react-typescript @@ -1,20 +1,20 @@ { - "configContent": "import globals from "globals"; -import tseslint from "typescript-eslint"; + "configContent": "import tseslint from "typescript-eslint"; import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; +import globals from "globals"; export default [ - {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, - {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ...tseslint.configs.recommended, pluginReactConfig, + {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", - "globals", "typescript-eslint", "eslint-plugin-react", + "globals", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-script-vue-javascript b/tests/__snapshots__/syntax-script-vue-javascript index ed7626bb..adfc3ee2 100644 --- a/tests/__snapshots__/syntax-script-vue-javascript +++ b/tests/__snapshots__/syntax-script-vue-javascript @@ -1,27 +1,17 @@ { - "configContent": "import globals from "globals"; + "configContent": "import pluginVue from "eslint-plugin-vue"; +import globals from "globals"; -import path from "path"; -import { fileURLToPath } from "url"; -import { FlatCompat } from "@eslint/eslintrc"; -import pluginJs from "@eslint/js"; - -// mimic CommonJS variables -- not needed if using CommonJS -const __filename = fileURLToPath(import.meta.url); -const __dirname = path.dirname(__filename); -const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [ + pluginVue.configs["flat/essential"], {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, {languageOptions: { globals: {...globals.browser, ...globals.node} }}, - ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", - "globals", "eslint-plugin-vue", - "@eslint/eslintrc", - "@eslint/js", + "globals", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-script-vue-typescript b/tests/__snapshots__/syntax-script-vue-typescript index bff345cc..437ea3a6 100644 --- a/tests/__snapshots__/syntax-script-vue-typescript +++ b/tests/__snapshots__/syntax-script-vue-typescript @@ -1,30 +1,20 @@ { - "configContent": "import globals from "globals"; -import tseslint from "typescript-eslint"; + "configContent": "import tseslint from "typescript-eslint"; +import pluginVue from "eslint-plugin-vue"; +import globals from "globals"; -import path from "path"; -import { fileURLToPath } from "url"; -import { FlatCompat } from "@eslint/eslintrc"; -import pluginJs from "@eslint/js"; - -// mimic CommonJS variables -- not needed if using CommonJS -const __filename = fileURLToPath(import.meta.url); -const __dirname = path.dirname(__filename); -const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [ + ...tseslint.configs.recommended, + pluginVue.configs["flat/essential"], {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, {languageOptions: { globals: {...globals.browser, ...globals.node} }}, - ...tseslint.configs.recommended, - ...compat.extends("plugin:vue/vue3-essential").map(config => ({files: ["**/*.vue"], ...config})), ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", - "globals", "typescript-eslint", "eslint-plugin-vue", - "@eslint/eslintrc", - "@eslint/js", + "globals", ], } \ No newline at end of file From 0551e8655418534e82e65a6da7dc31fb7472bf97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Fri, 29 Mar 2024 14:28:07 +0800 Subject: [PATCH 38/41] fix: revert re-ordering --- lib/config-generator.js | 32 +++++++++---------- .../problems-commonjs-none-javascript | 8 ++--- .../problems-commonjs-none-typescript | 10 +++--- .../problems-commonjs-react-javascript | 10 +++--- .../problems-commonjs-react-typescript | 10 +++--- .../problems-commonjs-vue-javascript | 10 +++--- .../problems-commonjs-vue-typescript | 10 +++--- .../problems-esm-none-javascript | 8 ++--- .../problems-esm-none-typescript | 8 ++--- .../problems-esm-react-javascript | 8 ++--- .../problems-esm-react-typescript | 8 ++--- .../__snapshots__/problems-esm-vue-javascript | 8 ++--- .../__snapshots__/problems-esm-vue-typescript | 8 ++--- .../problems-script-none-javascript | 8 ++--- .../problems-script-none-typescript | 10 +++--- .../problems-script-react-javascript | 10 +++--- .../problems-script-react-typescript | 10 +++--- .../problems-script-vue-javascript | 10 +++--- .../problems-script-vue-typescript | 10 +++--- .../style-esm-none-xo-javascript | 4 +-- .../style-esm-none-xo-typescript | 8 ++--- .../syntax-commonjs-none-typescript | 8 ++--- .../syntax-commonjs-react-javascript | 8 ++--- .../syntax-commonjs-react-typescript | 10 +++--- .../syntax-commonjs-vue-javascript | 8 ++--- .../syntax-commonjs-vue-typescript | 10 +++--- .../__snapshots__/syntax-esm-none-typescript | 8 ++--- .../__snapshots__/syntax-esm-react-javascript | 8 ++--- .../__snapshots__/syntax-esm-react-typescript | 8 ++--- tests/__snapshots__/syntax-esm-vue-javascript | 8 ++--- tests/__snapshots__/syntax-esm-vue-typescript | 8 ++--- .../syntax-script-none-typescript | 8 ++--- .../syntax-script-react-javascript | 8 ++--- .../syntax-script-react-typescript | 10 +++--- .../syntax-script-vue-javascript | 8 ++--- .../syntax-script-vue-typescript | 10 +++--- 36 files changed, 168 insertions(+), 168 deletions(-) diff --git a/lib/config-generator.js b/lib/config-generator.js index 04978a46..a1160f06 100644 --- a/lib/config-generator.js +++ b/lib/config-generator.js @@ -148,6 +148,22 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug let exportContent = ""; let needCompatHelper = false; + if (this.answers.moduleType === "commonjs" || this.answers.moduleType === "script") { + exportContent += ` {files: ["**/*.js"], languageOptions: {sourceType: "${this.answers.moduleType}"}},\n`; + } + + if (this.answers.env?.length > 0) { + this.result.devDependencies.push("globals"); + importContent += "import globals from \"globals\";\n"; + const envContent = { + browser: "globals: globals.browser", + node: "globals: globals.node", + "browser,node": "globals: {...globals.browser, ...globals.node}" + }; + + exportContent += ` {languageOptions: { ${envContent[this.answers.env.join(",")]} }},\n`; + } + if (this.answers.purpose === "syntax") { // no need to install any plugin @@ -201,22 +217,6 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug exportContent += " pluginReactConfig,\n"; } - if (this.answers.moduleType === "commonjs" || this.answers.moduleType === "script") { - exportContent += ` {files: ["**/*.js"], languageOptions: {sourceType: "${this.answers.moduleType}"}},\n`; - } - - if (this.answers.env?.length > 0) { - this.result.devDependencies.push("globals"); - importContent += "import globals from \"globals\";\n"; - const envContent = { - browser: "globals: globals.browser", - node: "globals: globals.node", - "browser,node": "globals: {...globals.browser, ...globals.node}" - }; - - exportContent += ` {languageOptions: { ${envContent[this.answers.env.join(",")]} }},\n`; - } - if (needCompatHelper) { this.result.devDependencies.push("@eslint/eslintrc", "@eslint/js"); } diff --git a/tests/__snapshots__/problems-commonjs-none-javascript b/tests/__snapshots__/problems-commonjs-none-javascript index 546a51bc..be19a4ba 100644 --- a/tests/__snapshots__/problems-commonjs-none-javascript +++ b/tests/__snapshots__/problems-commonjs-none-javascript @@ -1,17 +1,17 @@ { - "configContent": "import pluginJs from "@eslint/js"; -import globals from "globals"; + "configContent": "import globals from "globals"; +import pluginJs from "@eslint/js"; export default [ - pluginJs.configs.recommended, {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, {languageOptions: { globals: {...globals.browser, ...globals.node} }}, + pluginJs.configs.recommended, ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", - "@eslint/js", "globals", + "@eslint/js", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problems-commonjs-none-typescript b/tests/__snapshots__/problems-commonjs-none-typescript index ab9ae4c1..00a021df 100644 --- a/tests/__snapshots__/problems-commonjs-none-typescript +++ b/tests/__snapshots__/problems-commonjs-none-typescript @@ -1,20 +1,20 @@ { - "configContent": "import pluginJs from "@eslint/js"; + "configContent": "import globals from "globals"; +import pluginJs from "@eslint/js"; import tseslint from "typescript-eslint"; -import globals from "globals"; export default [ - pluginJs.configs.recommended, - ...tseslint.configs.recommended, {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, {languageOptions: { globals: {...globals.browser, ...globals.node} }}, + pluginJs.configs.recommended, + ...tseslint.configs.recommended, ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", + "globals", "@eslint/js", "typescript-eslint", - "globals", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problems-commonjs-react-javascript b/tests/__snapshots__/problems-commonjs-react-javascript index 988d8303..bf035eaf 100644 --- a/tests/__snapshots__/problems-commonjs-react-javascript +++ b/tests/__snapshots__/problems-commonjs-react-javascript @@ -1,20 +1,20 @@ { - "configContent": "import pluginJs from "@eslint/js"; + "configContent": "import globals from "globals"; +import pluginJs from "@eslint/js"; import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; -import globals from "globals"; export default [ - pluginJs.configs.recommended, - pluginReactConfig, {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, {languageOptions: { globals: {...globals.browser, ...globals.node} }}, + pluginJs.configs.recommended, + pluginReactConfig, ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", + "globals", "@eslint/js", "eslint-plugin-react", - "globals", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problems-commonjs-react-typescript b/tests/__snapshots__/problems-commonjs-react-typescript index 147c8fce..efb4c318 100644 --- a/tests/__snapshots__/problems-commonjs-react-typescript +++ b/tests/__snapshots__/problems-commonjs-react-typescript @@ -1,23 +1,23 @@ { - "configContent": "import pluginJs from "@eslint/js"; + "configContent": "import globals from "globals"; +import pluginJs from "@eslint/js"; import tseslint from "typescript-eslint"; import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; -import globals from "globals"; export default [ + {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, pluginJs.configs.recommended, ...tseslint.configs.recommended, pluginReactConfig, - {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, - {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", + "globals", "@eslint/js", "typescript-eslint", "eslint-plugin-react", - "globals", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problems-commonjs-vue-javascript b/tests/__snapshots__/problems-commonjs-vue-javascript index c6c1d229..45cc1594 100644 --- a/tests/__snapshots__/problems-commonjs-vue-javascript +++ b/tests/__snapshots__/problems-commonjs-vue-javascript @@ -1,20 +1,20 @@ { - "configContent": "import pluginJs from "@eslint/js"; + "configContent": "import globals from "globals"; +import pluginJs from "@eslint/js"; import pluginVue from "eslint-plugin-vue"; -import globals from "globals"; export default [ - pluginJs.configs.recommended, - pluginVue.configs["flat/essential"], {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, {languageOptions: { globals: {...globals.browser, ...globals.node} }}, + pluginJs.configs.recommended, + pluginVue.configs["flat/essential"], ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", + "globals", "@eslint/js", "eslint-plugin-vue", - "globals", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problems-commonjs-vue-typescript b/tests/__snapshots__/problems-commonjs-vue-typescript index 7fb07112..34ea5fbc 100644 --- a/tests/__snapshots__/problems-commonjs-vue-typescript +++ b/tests/__snapshots__/problems-commonjs-vue-typescript @@ -1,23 +1,23 @@ { - "configContent": "import pluginJs from "@eslint/js"; + "configContent": "import globals from "globals"; +import pluginJs from "@eslint/js"; import tseslint from "typescript-eslint"; import pluginVue from "eslint-plugin-vue"; -import globals from "globals"; export default [ + {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, pluginJs.configs.recommended, ...tseslint.configs.recommended, pluginVue.configs["flat/essential"], - {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, - {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", + "globals", "@eslint/js", "typescript-eslint", "eslint-plugin-vue", - "globals", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problems-esm-none-javascript b/tests/__snapshots__/problems-esm-none-javascript index ac252ae9..feeaec46 100644 --- a/tests/__snapshots__/problems-esm-none-javascript +++ b/tests/__snapshots__/problems-esm-none-javascript @@ -1,16 +1,16 @@ { - "configContent": "import pluginJs from "@eslint/js"; -import globals from "globals"; + "configContent": "import globals from "globals"; +import pluginJs from "@eslint/js"; export default [ - pluginJs.configs.recommended, {languageOptions: { globals: {...globals.browser, ...globals.node} }}, + pluginJs.configs.recommended, ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", - "@eslint/js", "globals", + "@eslint/js", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problems-esm-none-typescript b/tests/__snapshots__/problems-esm-none-typescript index a4872d79..0ff96769 100644 --- a/tests/__snapshots__/problems-esm-none-typescript +++ b/tests/__snapshots__/problems-esm-none-typescript @@ -1,19 +1,19 @@ { - "configContent": "import pluginJs from "@eslint/js"; + "configContent": "import globals from "globals"; +import pluginJs from "@eslint/js"; import tseslint from "typescript-eslint"; -import globals from "globals"; export default [ + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, pluginJs.configs.recommended, ...tseslint.configs.recommended, - {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", + "globals", "@eslint/js", "typescript-eslint", - "globals", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problems-esm-react-javascript b/tests/__snapshots__/problems-esm-react-javascript index b08e42f7..a529a49e 100644 --- a/tests/__snapshots__/problems-esm-react-javascript +++ b/tests/__snapshots__/problems-esm-react-javascript @@ -1,19 +1,19 @@ { - "configContent": "import pluginJs from "@eslint/js"; + "configContent": "import globals from "globals"; +import pluginJs from "@eslint/js"; import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; -import globals from "globals"; export default [ + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, pluginJs.configs.recommended, pluginReactConfig, - {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", + "globals", "@eslint/js", "eslint-plugin-react", - "globals", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problems-esm-react-typescript b/tests/__snapshots__/problems-esm-react-typescript index 3888eec6..295b1efd 100644 --- a/tests/__snapshots__/problems-esm-react-typescript +++ b/tests/__snapshots__/problems-esm-react-typescript @@ -1,22 +1,22 @@ { - "configContent": "import pluginJs from "@eslint/js"; + "configContent": "import globals from "globals"; +import pluginJs from "@eslint/js"; import tseslint from "typescript-eslint"; import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; -import globals from "globals"; export default [ + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, pluginJs.configs.recommended, ...tseslint.configs.recommended, pluginReactConfig, - {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", + "globals", "@eslint/js", "typescript-eslint", "eslint-plugin-react", - "globals", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problems-esm-vue-javascript b/tests/__snapshots__/problems-esm-vue-javascript index 4c6fe303..126724c3 100644 --- a/tests/__snapshots__/problems-esm-vue-javascript +++ b/tests/__snapshots__/problems-esm-vue-javascript @@ -1,19 +1,19 @@ { - "configContent": "import pluginJs from "@eslint/js"; + "configContent": "import globals from "globals"; +import pluginJs from "@eslint/js"; import pluginVue from "eslint-plugin-vue"; -import globals from "globals"; export default [ + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, pluginJs.configs.recommended, pluginVue.configs["flat/essential"], - {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", + "globals", "@eslint/js", "eslint-plugin-vue", - "globals", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problems-esm-vue-typescript b/tests/__snapshots__/problems-esm-vue-typescript index 9cf6e900..9f1ce353 100644 --- a/tests/__snapshots__/problems-esm-vue-typescript +++ b/tests/__snapshots__/problems-esm-vue-typescript @@ -1,22 +1,22 @@ { - "configContent": "import pluginJs from "@eslint/js"; + "configContent": "import globals from "globals"; +import pluginJs from "@eslint/js"; import tseslint from "typescript-eslint"; import pluginVue from "eslint-plugin-vue"; -import globals from "globals"; export default [ + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, pluginJs.configs.recommended, ...tseslint.configs.recommended, pluginVue.configs["flat/essential"], - {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", + "globals", "@eslint/js", "typescript-eslint", "eslint-plugin-vue", - "globals", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problems-script-none-javascript b/tests/__snapshots__/problems-script-none-javascript index 392d2b0c..96840e00 100644 --- a/tests/__snapshots__/problems-script-none-javascript +++ b/tests/__snapshots__/problems-script-none-javascript @@ -1,17 +1,17 @@ { - "configContent": "import pluginJs from "@eslint/js"; -import globals from "globals"; + "configContent": "import globals from "globals"; +import pluginJs from "@eslint/js"; export default [ - pluginJs.configs.recommended, {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, {languageOptions: { globals: {...globals.browser, ...globals.node} }}, + pluginJs.configs.recommended, ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", - "@eslint/js", "globals", + "@eslint/js", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problems-script-none-typescript b/tests/__snapshots__/problems-script-none-typescript index 54a59d5f..d17bee0f 100644 --- a/tests/__snapshots__/problems-script-none-typescript +++ b/tests/__snapshots__/problems-script-none-typescript @@ -1,20 +1,20 @@ { - "configContent": "import pluginJs from "@eslint/js"; + "configContent": "import globals from "globals"; +import pluginJs from "@eslint/js"; import tseslint from "typescript-eslint"; -import globals from "globals"; export default [ - pluginJs.configs.recommended, - ...tseslint.configs.recommended, {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, {languageOptions: { globals: {...globals.browser, ...globals.node} }}, + pluginJs.configs.recommended, + ...tseslint.configs.recommended, ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", + "globals", "@eslint/js", "typescript-eslint", - "globals", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problems-script-react-javascript b/tests/__snapshots__/problems-script-react-javascript index 72b779aa..ed1e9bca 100644 --- a/tests/__snapshots__/problems-script-react-javascript +++ b/tests/__snapshots__/problems-script-react-javascript @@ -1,20 +1,20 @@ { - "configContent": "import pluginJs from "@eslint/js"; + "configContent": "import globals from "globals"; +import pluginJs from "@eslint/js"; import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; -import globals from "globals"; export default [ - pluginJs.configs.recommended, - pluginReactConfig, {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, {languageOptions: { globals: {...globals.browser, ...globals.node} }}, + pluginJs.configs.recommended, + pluginReactConfig, ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", + "globals", "@eslint/js", "eslint-plugin-react", - "globals", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problems-script-react-typescript b/tests/__snapshots__/problems-script-react-typescript index cded05b4..b35aafeb 100644 --- a/tests/__snapshots__/problems-script-react-typescript +++ b/tests/__snapshots__/problems-script-react-typescript @@ -1,23 +1,23 @@ { - "configContent": "import pluginJs from "@eslint/js"; + "configContent": "import globals from "globals"; +import pluginJs from "@eslint/js"; import tseslint from "typescript-eslint"; import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; -import globals from "globals"; export default [ + {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, pluginJs.configs.recommended, ...tseslint.configs.recommended, pluginReactConfig, - {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, - {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", + "globals", "@eslint/js", "typescript-eslint", "eslint-plugin-react", - "globals", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problems-script-vue-javascript b/tests/__snapshots__/problems-script-vue-javascript index d242eb13..2fe7b3c1 100644 --- a/tests/__snapshots__/problems-script-vue-javascript +++ b/tests/__snapshots__/problems-script-vue-javascript @@ -1,20 +1,20 @@ { - "configContent": "import pluginJs from "@eslint/js"; + "configContent": "import globals from "globals"; +import pluginJs from "@eslint/js"; import pluginVue from "eslint-plugin-vue"; -import globals from "globals"; export default [ - pluginJs.configs.recommended, - pluginVue.configs["flat/essential"], {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, {languageOptions: { globals: {...globals.browser, ...globals.node} }}, + pluginJs.configs.recommended, + pluginVue.configs["flat/essential"], ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", + "globals", "@eslint/js", "eslint-plugin-vue", - "globals", ], } \ No newline at end of file diff --git a/tests/__snapshots__/problems-script-vue-typescript b/tests/__snapshots__/problems-script-vue-typescript index fcc53d3e..e2df83a5 100644 --- a/tests/__snapshots__/problems-script-vue-typescript +++ b/tests/__snapshots__/problems-script-vue-typescript @@ -1,23 +1,23 @@ { - "configContent": "import pluginJs from "@eslint/js"; + "configContent": "import globals from "globals"; +import pluginJs from "@eslint/js"; import tseslint from "typescript-eslint"; import pluginVue from "eslint-plugin-vue"; -import globals from "globals"; export default [ + {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, pluginJs.configs.recommended, ...tseslint.configs.recommended, pluginVue.configs["flat/essential"], - {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, - {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", + "globals", "@eslint/js", "typescript-eslint", "eslint-plugin-vue", - "globals", ], } \ No newline at end of file diff --git a/tests/__snapshots__/style-esm-none-xo-javascript b/tests/__snapshots__/style-esm-none-xo-javascript index 7ceffe4e..f0a0acf5 100644 --- a/tests/__snapshots__/style-esm-none-xo-javascript +++ b/tests/__snapshots__/style-esm-none-xo-javascript @@ -12,15 +12,15 @@ const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [ - ...compat.extends("xo"), {languageOptions: { globals: globals.node }}, + ...compat.extends("xo"), ];", "configFilename": "eslint.config.mjs", "devDependencies": [ "eslint", + "globals", "eslint-config-xo", "eslint@>=8.56.0", - "globals", "@eslint/eslintrc", "@eslint/js", ], diff --git a/tests/__snapshots__/style-esm-none-xo-typescript b/tests/__snapshots__/style-esm-none-xo-typescript index 4ddc1ab5..7040761a 100644 --- a/tests/__snapshots__/style-esm-none-xo-typescript +++ b/tests/__snapshots__/style-esm-none-xo-typescript @@ -1,6 +1,6 @@ { - "configContent": "import tseslint from "typescript-eslint"; -import globals from "globals"; + "configContent": "import globals from "globals"; +import tseslint from "typescript-eslint"; import path from "path"; import { fileURLToPath } from "url"; @@ -13,20 +13,20 @@ const __dirname = path.dirname(__filename); const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: pluginJs.configs.recommended}); export default [ + {languageOptions: { globals: globals.browser }}, ...compat.extends("xo-typescript"), ...tseslint.configs.recommended, - {languageOptions: { globals: globals.browser }}, ];", "configFilename": "eslint.config.mjs", "devDependencies": [ "eslint", + "globals", "eslint-config-xo-typescript", "@typescript-eslint/eslint-plugin@>=7.0.2", "@typescript-eslint/parser@>=7.0.2", "eslint@>=8.56.0", "typescript@>=5.0.0", "typescript-eslint", - "globals", "@eslint/eslintrc", "@eslint/js", ], diff --git a/tests/__snapshots__/syntax-commonjs-none-typescript b/tests/__snapshots__/syntax-commonjs-none-typescript index 431b2d1d..7f3d2be4 100644 --- a/tests/__snapshots__/syntax-commonjs-none-typescript +++ b/tests/__snapshots__/syntax-commonjs-none-typescript @@ -1,17 +1,17 @@ { - "configContent": "import tseslint from "typescript-eslint"; -import globals from "globals"; + "configContent": "import globals from "globals"; +import tseslint from "typescript-eslint"; export default [ - ...tseslint.configs.recommended, {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, {languageOptions: { globals: {...globals.browser, ...globals.node} }}, + ...tseslint.configs.recommended, ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", - "typescript-eslint", "globals", + "typescript-eslint", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-commonjs-react-javascript b/tests/__snapshots__/syntax-commonjs-react-javascript index 961e8881..c99a6ffa 100644 --- a/tests/__snapshots__/syntax-commonjs-react-javascript +++ b/tests/__snapshots__/syntax-commonjs-react-javascript @@ -1,17 +1,17 @@ { - "configContent": "import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; -import globals from "globals"; + "configContent": "import globals from "globals"; +import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [ - pluginReactConfig, {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, {languageOptions: { globals: {...globals.browser, ...globals.node} }}, + pluginReactConfig, ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", - "eslint-plugin-react", "globals", + "eslint-plugin-react", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-commonjs-react-typescript b/tests/__snapshots__/syntax-commonjs-react-typescript index 1c6b599d..80e932ed 100644 --- a/tests/__snapshots__/syntax-commonjs-react-typescript +++ b/tests/__snapshots__/syntax-commonjs-react-typescript @@ -1,20 +1,20 @@ { - "configContent": "import tseslint from "typescript-eslint"; + "configContent": "import globals from "globals"; +import tseslint from "typescript-eslint"; import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; -import globals from "globals"; export default [ - ...tseslint.configs.recommended, - pluginReactConfig, {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, {languageOptions: { globals: {...globals.browser, ...globals.node} }}, + ...tseslint.configs.recommended, + pluginReactConfig, ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", + "globals", "typescript-eslint", "eslint-plugin-react", - "globals", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-commonjs-vue-javascript b/tests/__snapshots__/syntax-commonjs-vue-javascript index 9a18386c..d555eb0a 100644 --- a/tests/__snapshots__/syntax-commonjs-vue-javascript +++ b/tests/__snapshots__/syntax-commonjs-vue-javascript @@ -1,17 +1,17 @@ { - "configContent": "import pluginVue from "eslint-plugin-vue"; -import globals from "globals"; + "configContent": "import globals from "globals"; +import pluginVue from "eslint-plugin-vue"; export default [ - pluginVue.configs["flat/essential"], {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, {languageOptions: { globals: {...globals.browser, ...globals.node} }}, + pluginVue.configs["flat/essential"], ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", - "eslint-plugin-vue", "globals", + "eslint-plugin-vue", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-commonjs-vue-typescript b/tests/__snapshots__/syntax-commonjs-vue-typescript index bdf8584c..bfbe5776 100644 --- a/tests/__snapshots__/syntax-commonjs-vue-typescript +++ b/tests/__snapshots__/syntax-commonjs-vue-typescript @@ -1,20 +1,20 @@ { - "configContent": "import tseslint from "typescript-eslint"; + "configContent": "import globals from "globals"; +import tseslint from "typescript-eslint"; import pluginVue from "eslint-plugin-vue"; -import globals from "globals"; export default [ - ...tseslint.configs.recommended, - pluginVue.configs["flat/essential"], {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, {languageOptions: { globals: {...globals.browser, ...globals.node} }}, + ...tseslint.configs.recommended, + pluginVue.configs["flat/essential"], ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", + "globals", "typescript-eslint", "eslint-plugin-vue", - "globals", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-esm-none-typescript b/tests/__snapshots__/syntax-esm-none-typescript index 21f073e6..e9f51f11 100644 --- a/tests/__snapshots__/syntax-esm-none-typescript +++ b/tests/__snapshots__/syntax-esm-none-typescript @@ -1,16 +1,16 @@ { - "configContent": "import tseslint from "typescript-eslint"; -import globals from "globals"; + "configContent": "import globals from "globals"; +import tseslint from "typescript-eslint"; export default [ - ...tseslint.configs.recommended, {languageOptions: { globals: {...globals.browser, ...globals.node} }}, + ...tseslint.configs.recommended, ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", - "typescript-eslint", "globals", + "typescript-eslint", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-esm-react-javascript b/tests/__snapshots__/syntax-esm-react-javascript index d23cb6d9..9a6bdf16 100644 --- a/tests/__snapshots__/syntax-esm-react-javascript +++ b/tests/__snapshots__/syntax-esm-react-javascript @@ -1,16 +1,16 @@ { - "configContent": "import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; -import globals from "globals"; + "configContent": "import globals from "globals"; +import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [ - pluginReactConfig, {languageOptions: { globals: {...globals.browser, ...globals.node} }}, + pluginReactConfig, ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", - "eslint-plugin-react", "globals", + "eslint-plugin-react", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-esm-react-typescript b/tests/__snapshots__/syntax-esm-react-typescript index bf927e04..42213310 100644 --- a/tests/__snapshots__/syntax-esm-react-typescript +++ b/tests/__snapshots__/syntax-esm-react-typescript @@ -1,19 +1,19 @@ { - "configContent": "import tseslint from "typescript-eslint"; + "configContent": "import globals from "globals"; +import tseslint from "typescript-eslint"; import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; -import globals from "globals"; export default [ + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ...tseslint.configs.recommended, pluginReactConfig, - {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", + "globals", "typescript-eslint", "eslint-plugin-react", - "globals", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-esm-vue-javascript b/tests/__snapshots__/syntax-esm-vue-javascript index b9169537..b356c669 100644 --- a/tests/__snapshots__/syntax-esm-vue-javascript +++ b/tests/__snapshots__/syntax-esm-vue-javascript @@ -1,16 +1,16 @@ { - "configContent": "import pluginVue from "eslint-plugin-vue"; -import globals from "globals"; + "configContent": "import globals from "globals"; +import pluginVue from "eslint-plugin-vue"; export default [ - pluginVue.configs["flat/essential"], {languageOptions: { globals: {...globals.browser, ...globals.node} }}, + pluginVue.configs["flat/essential"], ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", - "eslint-plugin-vue", "globals", + "eslint-plugin-vue", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-esm-vue-typescript b/tests/__snapshots__/syntax-esm-vue-typescript index 4fcc0ca1..82241686 100644 --- a/tests/__snapshots__/syntax-esm-vue-typescript +++ b/tests/__snapshots__/syntax-esm-vue-typescript @@ -1,19 +1,19 @@ { - "configContent": "import tseslint from "typescript-eslint"; + "configContent": "import globals from "globals"; +import tseslint from "typescript-eslint"; import pluginVue from "eslint-plugin-vue"; -import globals from "globals"; export default [ + {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ...tseslint.configs.recommended, pluginVue.configs["flat/essential"], - {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", + "globals", "typescript-eslint", "eslint-plugin-vue", - "globals", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-script-none-typescript b/tests/__snapshots__/syntax-script-none-typescript index 2e3de116..917262d4 100644 --- a/tests/__snapshots__/syntax-script-none-typescript +++ b/tests/__snapshots__/syntax-script-none-typescript @@ -1,17 +1,17 @@ { - "configContent": "import tseslint from "typescript-eslint"; -import globals from "globals"; + "configContent": "import globals from "globals"; +import tseslint from "typescript-eslint"; export default [ - ...tseslint.configs.recommended, {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, {languageOptions: { globals: {...globals.browser, ...globals.node} }}, + ...tseslint.configs.recommended, ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", - "typescript-eslint", "globals", + "typescript-eslint", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-script-react-javascript b/tests/__snapshots__/syntax-script-react-javascript index da9a882e..733b3b8d 100644 --- a/tests/__snapshots__/syntax-script-react-javascript +++ b/tests/__snapshots__/syntax-script-react-javascript @@ -1,17 +1,17 @@ { - "configContent": "import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; -import globals from "globals"; + "configContent": "import globals from "globals"; +import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; export default [ - pluginReactConfig, {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, {languageOptions: { globals: {...globals.browser, ...globals.node} }}, + pluginReactConfig, ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", - "eslint-plugin-react", "globals", + "eslint-plugin-react", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-script-react-typescript b/tests/__snapshots__/syntax-script-react-typescript index 409de801..475ab3f9 100644 --- a/tests/__snapshots__/syntax-script-react-typescript +++ b/tests/__snapshots__/syntax-script-react-typescript @@ -1,20 +1,20 @@ { - "configContent": "import tseslint from "typescript-eslint"; + "configContent": "import globals from "globals"; +import tseslint from "typescript-eslint"; import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; -import globals from "globals"; export default [ - ...tseslint.configs.recommended, - pluginReactConfig, {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, {languageOptions: { globals: {...globals.browser, ...globals.node} }}, + ...tseslint.configs.recommended, + pluginReactConfig, ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", + "globals", "typescript-eslint", "eslint-plugin-react", - "globals", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-script-vue-javascript b/tests/__snapshots__/syntax-script-vue-javascript index adfc3ee2..4d6b3941 100644 --- a/tests/__snapshots__/syntax-script-vue-javascript +++ b/tests/__snapshots__/syntax-script-vue-javascript @@ -1,17 +1,17 @@ { - "configContent": "import pluginVue from "eslint-plugin-vue"; -import globals from "globals"; + "configContent": "import globals from "globals"; +import pluginVue from "eslint-plugin-vue"; export default [ - pluginVue.configs["flat/essential"], {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, {languageOptions: { globals: {...globals.browser, ...globals.node} }}, + pluginVue.configs["flat/essential"], ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", - "eslint-plugin-vue", "globals", + "eslint-plugin-vue", ], } \ No newline at end of file diff --git a/tests/__snapshots__/syntax-script-vue-typescript b/tests/__snapshots__/syntax-script-vue-typescript index 437ea3a6..7dcba7f8 100644 --- a/tests/__snapshots__/syntax-script-vue-typescript +++ b/tests/__snapshots__/syntax-script-vue-typescript @@ -1,20 +1,20 @@ { - "configContent": "import tseslint from "typescript-eslint"; + "configContent": "import globals from "globals"; +import tseslint from "typescript-eslint"; import pluginVue from "eslint-plugin-vue"; -import globals from "globals"; export default [ - ...tseslint.configs.recommended, - pluginVue.configs["flat/essential"], {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, {languageOptions: { globals: {...globals.browser, ...globals.node} }}, + ...tseslint.configs.recommended, + pluginVue.configs["flat/essential"], ];", "configFilename": "eslint.config.js", "devDependencies": [ "eslint", + "globals", "typescript-eslint", "eslint-plugin-vue", - "globals", ], } \ No newline at end of file From 0a4c547fe73dcb77706fcd15e894f84a5fde7760 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Wed, 3 Apr 2024 10:53:14 +0800 Subject: [PATCH 39/41] fix: allow skipping installing deps --- lib/config-generator.js | 54 +++++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/lib/config-generator.js b/lib/config-generator.js index a1160f06..23ecfb07 100644 --- a/lib/config-generator.js +++ b/lib/config-generator.js @@ -230,27 +230,49 @@ export default [\n${exportContent}];`; * @returns {void} */ async output() { - const packageManager = (await enquirer.prompt({ - type: "select", - name: "packageManager", - message: "Which package manager do you want to use?", - initial: 0, - choices: ["npm", "yarn", "pnpm", "bun"] - })).packageManager; - installSyncSaveDev(this.result.devDependencies, packageManager); + log.info("The config that you've selected requires the following dependencies:\n"); + log.info(this.result.devDependencies.join(", ")); - const configPath = path.join(this.cwd, this.result.configFilename); + const installDevDeps = (await enquirer.prompt({ + type: "toggle", + name: "executeInstallation", + message: "Would you like to install them now?", + enabled: "Yes", + disabled: "No", + initial: 1 + })).executeInstallation; - await writeFile(configPath, this.result.configContent); + const configPath = path.join(this.cwd, this.result.configFilename); - // import("eslint") won't work in some cases. - // refs: https://github.com/eslint/create-config/issues/8, https://github.com/eslint/create-config/issues/12 - const eslintBin = path.join(this.packageJsonPath, "../node_modules/eslint/bin/eslint.js"); - const result = spawnSync(process.execPath, [eslintBin, "--fix", "--quiet", configPath], { encoding: "utf8" }); + if (installDevDeps === true) { + const packageManager = (await enquirer.prompt({ + type: "select", + name: "packageManager", + message: "Which package manager do you want to use?", + initial: 0, + choices: ["npm", "yarn", "pnpm", "bun"] + })).packageManager; + + log.info("☕️Installing..."); + installSyncSaveDev(this.result.devDependencies, packageManager); + await writeFile(configPath, this.result.configContent); + + // import("eslint") won't work in some cases. + // refs: https://github.com/eslint/create-config/issues/8, https://github.com/eslint/create-config/issues/12 + const eslintBin = path.join(this.packageJsonPath, "../node_modules/eslint/bin/eslint.js"); + const result = spawnSync(process.execPath, [eslintBin, "--fix", "--quiet", configPath], { encoding: "utf8" }); + + if (result.error || result.status !== 0) { + log.error("A config file was generated, but the config file itself may not follow your linting rules."); + } else { + log.info(`Successfully created ${configPath} file.`); + } + } else { + await writeFile(configPath, this.result.configContent); - if (result.error || result.status !== 0) { - log.error("A config file was generated, but the config file itself may not follow your linting rules."); + log.info(`Successfully created ${configPath} file.`); + log.warn("You will need to install the dependencies yourself."); } } } From e7da8c7edecb98f131e20063e620cb85e797422c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Thu, 4 Apr 2024 16:10:07 +0800 Subject: [PATCH 40/41] Update lib/config-generator.js Co-authored-by: Milos Djermanovic --- lib/config-generator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/config-generator.js b/lib/config-generator.js index 23ecfb07..bdbdc676 100644 --- a/lib/config-generator.js +++ b/lib/config-generator.js @@ -208,7 +208,7 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug this.result.devDependencies.push("eslint-plugin-vue"); importContent += "import pluginVue from \"eslint-plugin-vue\";\n"; - exportContent += " pluginVue.configs[\"flat/essential\"],\n"; + exportContent += " ...pluginVue.configs[\"flat/essential\"],\n"; } if (this.answers.framework === "react") { From fce14fd4ee3517789a2939a2ef8f10328f3a9c6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Thu, 4 Apr 2024 16:17:43 +0800 Subject: [PATCH 41/41] chore: update snapshots --- tests/__snapshots__/problems-commonjs-vue-javascript | 2 +- tests/__snapshots__/problems-commonjs-vue-typescript | 2 +- tests/__snapshots__/problems-esm-vue-javascript | 2 +- tests/__snapshots__/problems-esm-vue-typescript | 2 +- tests/__snapshots__/problems-script-vue-javascript | 2 +- tests/__snapshots__/problems-script-vue-typescript | 2 +- tests/__snapshots__/syntax-commonjs-vue-javascript | 2 +- tests/__snapshots__/syntax-commonjs-vue-typescript | 2 +- tests/__snapshots__/syntax-esm-vue-javascript | 2 +- tests/__snapshots__/syntax-esm-vue-typescript | 2 +- tests/__snapshots__/syntax-script-vue-javascript | 2 +- tests/__snapshots__/syntax-script-vue-typescript | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/__snapshots__/problems-commonjs-vue-javascript b/tests/__snapshots__/problems-commonjs-vue-javascript index 45cc1594..8b58d41b 100644 --- a/tests/__snapshots__/problems-commonjs-vue-javascript +++ b/tests/__snapshots__/problems-commonjs-vue-javascript @@ -8,7 +8,7 @@ export default [ {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, {languageOptions: { globals: {...globals.browser, ...globals.node} }}, pluginJs.configs.recommended, - pluginVue.configs["flat/essential"], + ...pluginVue.configs["flat/essential"], ];", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/problems-commonjs-vue-typescript b/tests/__snapshots__/problems-commonjs-vue-typescript index 34ea5fbc..fbf258bb 100644 --- a/tests/__snapshots__/problems-commonjs-vue-typescript +++ b/tests/__snapshots__/problems-commonjs-vue-typescript @@ -10,7 +10,7 @@ export default [ {languageOptions: { globals: {...globals.browser, ...globals.node} }}, pluginJs.configs.recommended, ...tseslint.configs.recommended, - pluginVue.configs["flat/essential"], + ...pluginVue.configs["flat/essential"], ];", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/problems-esm-vue-javascript b/tests/__snapshots__/problems-esm-vue-javascript index 126724c3..da40a1b1 100644 --- a/tests/__snapshots__/problems-esm-vue-javascript +++ b/tests/__snapshots__/problems-esm-vue-javascript @@ -7,7 +7,7 @@ import pluginVue from "eslint-plugin-vue"; export default [ {languageOptions: { globals: {...globals.browser, ...globals.node} }}, pluginJs.configs.recommended, - pluginVue.configs["flat/essential"], + ...pluginVue.configs["flat/essential"], ];", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/problems-esm-vue-typescript b/tests/__snapshots__/problems-esm-vue-typescript index 9f1ce353..3b82eaab 100644 --- a/tests/__snapshots__/problems-esm-vue-typescript +++ b/tests/__snapshots__/problems-esm-vue-typescript @@ -9,7 +9,7 @@ export default [ {languageOptions: { globals: {...globals.browser, ...globals.node} }}, pluginJs.configs.recommended, ...tseslint.configs.recommended, - pluginVue.configs["flat/essential"], + ...pluginVue.configs["flat/essential"], ];", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/problems-script-vue-javascript b/tests/__snapshots__/problems-script-vue-javascript index 2fe7b3c1..4c0fb51a 100644 --- a/tests/__snapshots__/problems-script-vue-javascript +++ b/tests/__snapshots__/problems-script-vue-javascript @@ -8,7 +8,7 @@ export default [ {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, {languageOptions: { globals: {...globals.browser, ...globals.node} }}, pluginJs.configs.recommended, - pluginVue.configs["flat/essential"], + ...pluginVue.configs["flat/essential"], ];", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/problems-script-vue-typescript b/tests/__snapshots__/problems-script-vue-typescript index e2df83a5..9244df2e 100644 --- a/tests/__snapshots__/problems-script-vue-typescript +++ b/tests/__snapshots__/problems-script-vue-typescript @@ -10,7 +10,7 @@ export default [ {languageOptions: { globals: {...globals.browser, ...globals.node} }}, pluginJs.configs.recommended, ...tseslint.configs.recommended, - pluginVue.configs["flat/essential"], + ...pluginVue.configs["flat/essential"], ];", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/syntax-commonjs-vue-javascript b/tests/__snapshots__/syntax-commonjs-vue-javascript index d555eb0a..478b344c 100644 --- a/tests/__snapshots__/syntax-commonjs-vue-javascript +++ b/tests/__snapshots__/syntax-commonjs-vue-javascript @@ -6,7 +6,7 @@ import pluginVue from "eslint-plugin-vue"; export default [ {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, {languageOptions: { globals: {...globals.browser, ...globals.node} }}, - pluginVue.configs["flat/essential"], + ...pluginVue.configs["flat/essential"], ];", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/syntax-commonjs-vue-typescript b/tests/__snapshots__/syntax-commonjs-vue-typescript index bfbe5776..34a56352 100644 --- a/tests/__snapshots__/syntax-commonjs-vue-typescript +++ b/tests/__snapshots__/syntax-commonjs-vue-typescript @@ -8,7 +8,7 @@ export default [ {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ...tseslint.configs.recommended, - pluginVue.configs["flat/essential"], + ...pluginVue.configs["flat/essential"], ];", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/syntax-esm-vue-javascript b/tests/__snapshots__/syntax-esm-vue-javascript index b356c669..60f0964e 100644 --- a/tests/__snapshots__/syntax-esm-vue-javascript +++ b/tests/__snapshots__/syntax-esm-vue-javascript @@ -5,7 +5,7 @@ import pluginVue from "eslint-plugin-vue"; export default [ {languageOptions: { globals: {...globals.browser, ...globals.node} }}, - pluginVue.configs["flat/essential"], + ...pluginVue.configs["flat/essential"], ];", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/syntax-esm-vue-typescript b/tests/__snapshots__/syntax-esm-vue-typescript index 82241686..e909753e 100644 --- a/tests/__snapshots__/syntax-esm-vue-typescript +++ b/tests/__snapshots__/syntax-esm-vue-typescript @@ -7,7 +7,7 @@ import pluginVue from "eslint-plugin-vue"; export default [ {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ...tseslint.configs.recommended, - pluginVue.configs["flat/essential"], + ...pluginVue.configs["flat/essential"], ];", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/syntax-script-vue-javascript b/tests/__snapshots__/syntax-script-vue-javascript index 4d6b3941..03928128 100644 --- a/tests/__snapshots__/syntax-script-vue-javascript +++ b/tests/__snapshots__/syntax-script-vue-javascript @@ -6,7 +6,7 @@ import pluginVue from "eslint-plugin-vue"; export default [ {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, {languageOptions: { globals: {...globals.browser, ...globals.node} }}, - pluginVue.configs["flat/essential"], + ...pluginVue.configs["flat/essential"], ];", "configFilename": "eslint.config.js", "devDependencies": [ diff --git a/tests/__snapshots__/syntax-script-vue-typescript b/tests/__snapshots__/syntax-script-vue-typescript index 7dcba7f8..c15aa12a 100644 --- a/tests/__snapshots__/syntax-script-vue-typescript +++ b/tests/__snapshots__/syntax-script-vue-typescript @@ -8,7 +8,7 @@ export default [ {files: ["**/*.js"], languageOptions: {sourceType: "script"}}, {languageOptions: { globals: {...globals.browser, ...globals.node} }}, ...tseslint.configs.recommended, - pluginVue.configs["flat/essential"], + ...pluginVue.configs["flat/essential"], ];", "configFilename": "eslint.config.js", "devDependencies": [