diff --git a/lib/config/config-initializer.js b/lib/config/config-initializer.js index 70a50691c77..73255c83918 100644 --- a/lib/config/config-initializer.js +++ b/lib/config/config-initializer.js @@ -3,6 +3,7 @@ * @author Ilya Volodin */ + "use strict"; //------------------------------------------------------------------------------ @@ -264,8 +265,10 @@ function processAnswers(answers) { }); // add in library information - if (answers.framwork === "react") { - config.parserOptions.ecmaFeatures.jsx = true; + if (answers.framework === "react") { + config.parserOptions.ecmaFeatures = { + jsx: true + }; config.plugins = ["react"]; } else if (answers.framework === "vue") { config.plugins = ["vue"]; @@ -473,7 +476,7 @@ function promptUser() { type: "list", name: "source", message: "How would you like to define a style for your project?", - default: "prompt", + default: "guide", choices: [ { name: "Use a popular style guide", value: "guide" }, { name: "Answer questions about your style", value: "prompt" }, @@ -516,10 +519,7 @@ function promptUser() { name: "format", message: "What format do you want your config file to be in?", default: "JavaScript", - choices: ["JavaScript", "YAML", "JSON"], - when(answers) { - return ((answers.source === "guide" && answers.packageJsonExists) || answers.source === "auto"); - } + choices: ["JavaScript", "YAML", "JSON"] }, { type: "confirm", @@ -538,6 +538,15 @@ function promptUser() { } ]).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, earlyAnswers.packageJsonExists) + .then(() => writeFile(config, earlyAnswers.format)); + } + // early exit if you are using a style guide if (earlyAnswers.source === "guide") { if (!earlyAnswers.packageJsonExists) { @@ -551,14 +560,16 @@ function promptUser() { earlyAnswers.styleguide = "airbnb-base"; } - const config = getConfigForStyleGuide(earlyAnswers.styleguide); + const config = ConfigOps.merge(processAnswers(earlyAnswers), getConfigForStyleGuide(earlyAnswers.styleguide)); const modules = getModulesList(config); return askInstallModules(modules, earlyAnswers.packageJsonExists) .then(() => writeFile(config, earlyAnswers.format)); - - } else if (earlyAnswers.source === "auto") { - const combinedAnswers = Object.assign({}, earlyAnswers, secondAnswers); + + } + + if (earlyAnswers.source === "auto") { + const combinedAnswers = Object.assign({}, earlyAnswers); const config = processAnswers(combinedAnswers); const modules = getModulesList(config); @@ -602,7 +613,7 @@ function promptUser() { choices: ["JavaScript", "YAML", "JSON"] } ]).then(answers => { - const totalAnswers = Object.assign({}, earlyAnswers, secondAnswers, answers); + const totalAnswers = Object.assign({}, earlyAnswers, answers); const config = processAnswers(totalAnswers); const modules = getModulesList(config); diff --git a/package.json b/package.json index cd25a4013a8..5d2fa0e0467 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,11 @@ "ignore": "^4.0.6", "import-fresh": "^3.0.0", "imurmurhash": "^0.1.4", +<<<<<<< HEAD "inquirer": "^6.2.2", +======= + "inquirer": "^6.2.1", +>>>>>>> Update: Behavior of --init (fixes #11105) "js-yaml": "^3.12.0", "json-stable-stringify-without-jsonify": "^1.0.1", "levn": "^0.3.0", diff --git a/tests/lib/config/config-initializer.js b/tests/lib/config/config-initializer.js index 3767fe376f3..6d332239d1d 100644 --- a/tests/lib/config/config-initializer.js +++ b/tests/lib/config/config-initializer.js @@ -117,20 +117,17 @@ describe("configInitializer", () => { beforeEach(() => { answers = { + purpose: "style", source: "prompt", extendDefault: true, indent: 2, quotes: "single", linebreak: "unix", semi: true, - ecmaVersion: 2015, - modules: true, + moduleType: "esm", es6Globals: true, env: ["browser"], - jsx: false, - react: false, - format: "JSON", - commonjs: false + format: "JSON" }; }); @@ -142,7 +139,7 @@ describe("configInitializer", () => { assert.deepStrictEqual(config.rules["linebreak-style"], ["error", "unix"]); assert.deepStrictEqual(config.rules.semi, ["error", "always"]); assert.strictEqual(config.env.es6, true); - assert.strictEqual(config.parserOptions.ecmaVersion, 2015); + assert.strictEqual(config.parserOptions.ecmaVersion, 2018); assert.strictEqual(config.parserOptions.sourceType, "module"); assert.strictEqual(config.env.browser, true); assert.strictEqual(config.extends, "eslint:recommended"); @@ -155,16 +152,8 @@ describe("configInitializer", () => { assert.deepStrictEqual(config.rules.semi, ["error", "never"]); }); - it("should enable jsx flag", () => { - answers.jsx = true; - const config = init.processAnswers(answers); - - assert.strictEqual(config.parserOptions.ecmaFeatures.jsx, true); - }); - it("should enable react plugin", () => { - answers.jsx = true; - answers.react = true; + answers.framework = "react"; const config = init.processAnswers(answers); assert.strictEqual(config.parserOptions.ecmaFeatures.jsx, true); @@ -172,14 +161,6 @@ describe("configInitializer", () => { assert.deepStrictEqual(config.plugins, ["react"]); }); - it("should not enable es6", () => { - answers.ecmaVersion = 5; - const config = init.processAnswers(answers); - - assert.strictEqual(config.parserOptions.ecmaVersion, 5); - assert.isUndefined(config.env.es6); - }); - it("should extend eslint:recommended", () => { const config = init.processAnswers(answers); @@ -193,7 +174,7 @@ describe("configInitializer", () => { }); it("should use commonjs when set", () => { - answers.commonjs = true; + answers.moduleType = "commonjs"; const config = init.processAnswers(answers); assert.isTrue(config.env.commonjs); @@ -338,14 +319,11 @@ describe("configInitializer", () => { ].join(" "); answers = { + purpose: "style", source: "auto", patterns, - ecmaVersion: 5, env: ["browser"], - jsx: false, - react: false, - format: "JSON", - commonjs: false + format: "JSON" }; sandbox = sinon.sandbox.create();