Repository: eslint/eslint (JavaScript)

Issue:
eslint --init: config.extends.push
**Tell us about your environment**
Node version: v12.14.0
npm version: v6.13.4
Local ESLint version: v6.8.0 (Currently used)
Global ESLint version: Not found

**What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.**
I want to enable eslint for my exists TypeScript project.

<!-- Paste the command you used to run ESLint: -->
```bash
eslint --init
```
```text
? How would you like to use ESLint? To check syntax, find problems, and enforce code style
? What type of modules does your project use? JavaScript modules (import/export)
? Which framework does your project use? React
? Does your project use TypeScript? Yes
? Where does your code run? Browser, Node
? How would you like to define a style for your project? Inspect your JavaScript file(s)
? Which file(s), path(s), or glob(s) should be examined? ./src/**.{ts,tsx}
? What format do you want your config file to be in? JavaScript
```

**What actually happened? Please include the actual, raw output from ESLint.**
Several module not found：
* @typescript-eslint/parser
* eslint-plugin-react
* @typescript-eslint

After install them all, It show me an error:
```text
Determining Config: 0% [------------------------------] 0.0s elapsed, eta 0.0s Warning: React version not specified in eslint-plugin-react settings. See https://github.com/yannickcr/eslint-plugin-react#configuration .
Determining Config: 100% [==============================] 0.1s elapsed, eta 0.0s

Enabled 275 out of 275 rules based on 2 files.

config.extends.push is not a function
TypeError: config.extends.push is not a function
    at processAnswers (/MY_PROJ/node_modules/eslint/lib/init/config-initializer.js:331:24)
    at /MY_PROJ/node_modules/eslint/lib/init/config-initializer.js:615:28
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
```

**Are you willing to submit a pull request to fix this bug?**
No, I found the problem, but don't know how to fix it (in your way).

### selected "react":
> https://github.com/eslint/eslint/blob/master/lib/init/config-initializer.js#L294


### select "Inspect your JavaScript file(s)":    
> https://github.com/eslint/eslint/blob/master/lib/init/config-initializer.js#L326    
https://github.com/eslint/eslint/blob/master/lib/init/autoconfig.js#L336

`extendFromRecommended` will set `config.extends` to `RECOMMENDED_CONFIG_NAME`, there are two problems:
* RECOMMENDED_CONFIG_NAME is a string, after `extendFromRecommended` return, the parent scope expect `config.extends` is an array
* It drop my selection of "react" (or "vue")

### selected "typescript":
> https://github.com/eslint/eslint/blob/master/lib/init/config-initializer.js#L329



Discussion:
I've run into the same problem trying to build the Typescript Node Starter project from Microsoft. There's no eslint config file, so I went to init it, and got the same error as @GongT 
It looks like a bug. I reproduced it- https://github.com/yeonjuan/autoconfbug.

I get a totally different error when following the same steps. Seems like this is unfortunately quite broken at the moment.

```sh
Failed to load plugin 'react' declared in 'BaseConfig': Cannot find module 'eslint-plugin-react'
```

PRs to fix this are very welcome!
> I get a totally different error when following the same steps. Seems like this is unfortunately quite broken at the moment.

To fix that you should just add `eslint-plugin-react` to your dev dependencies;

    yarn add --dev eslint-plugin-react

Or

    npm i --save-dev eslint-plugin-react
@koenpunt Check out the issue above. This is referring to the `eslint --init` functionality which should install deps for you.
> which should install deps for you.

Ah, didn't know this.

Unfortunately, it looks like there wasn't enough interest from the team
or community to implement this change. While we wish we'd be able to
accommodate everyone's requests, we do need to prioritize. We've found
that accepted issues failing to be implemented after 90 days tend to
never be implemented, and as such, we [close those issues](https://eslint.org/docs/maintainer-guide/issues#when-to-close-an-issue).
This doesn't mean the idea isn't interesting or useful, just that it's
not something the team can commit to.

Thanks for contributing to ESLint and we appreciate your understanding.

[//]: # (auto-close)

Reopening since there is PR #12738 to fix this.



Patch:
diff --git a/lib/init/autoconfig.js b/lib/init/autoconfig.js
index 64be3d2a84f4..c47c242dbd5a 100644
--- a/lib/init/autoconfig.js
+++ b/lib/init/autoconfig.js
@@ -316,10 +316,10 @@ class Registry {
 /**
  * Extract rule configuration into eslint:recommended where possible.
  *
- * This will return a new config with `"extends": "eslint:recommended"` and
+ * This will return a new config with `["extends": [ ..., "eslint:recommended"]` and
  * only the rules which have configurations different from the recommended config.
  * @param   {Object} config config object
- * @returns {Object}        config object using `"extends": "eslint:recommended"`
+ * @returns {Object}        config object using `"extends": ["eslint:recommended"]`
  */
 function extendFromRecommended(config) {
     const newConfig = Object.assign({}, config);
@@ -333,7 +333,7 @@ function extendFromRecommended(config) {
             delete newConfig.rules[ruleId];
         }
     });
-    newConfig.extends = RECOMMENDED_CONFIG_NAME;
+    newConfig.extends.unshift(RECOMMENDED_CONFIG_NAME);
     return newConfig;
 }
 


Test patch:
diff --git a/tests/lib/init/autoconfig.js b/tests/lib/init/autoconfig.js
index 3ce766a12833..1fa2b0476dea 100644
--- a/tests/lib/init/autoconfig.js
+++ b/tests/lib/init/autoconfig.js
@@ -12,7 +12,8 @@
 const assert = require("chai").assert,
     autoconfig = require("../../../lib/init/autoconfig"),
     sourceCodeUtils = require("../../../lib/init/source-code-utils"),
-    baseDefaultOptions = require("../../../conf/default-cli-options");
+    baseDefaultOptions = require("../../../conf/default-cli-options"),
+    recommendedConfig = require("../../conf/eslint-recommended");
 
 const defaultOptions = Object.assign({}, baseDefaultOptions, { cwd: process.cwd() });
 
@@ -328,4 +329,43 @@ describe("autoconfig", () => {
             });
         });
     });
+
+    describe("extendFromRecommended()", () => {
+        it("should return a configuration which has `extends` key with Array type value", () => {
+            const oldConfig = { extends: [], rules: {} };
+            const newConfig = autoconfig.extendFromRecommended(oldConfig);
+
+            assert.exists(newConfig.extends);
+            assert.isArray(newConfig.extends);
+        });
+
+        it("should return a configuration which has array property `extends`", () => {
+            const oldConfig = { extends: [], rules: {} };
+            const newConfig = autoconfig.extendFromRecommended(oldConfig);
+
+            assert.include(newConfig.extends, "eslint:recommended");
+        });
+
+        it("should return a configuration which preserves the previous extending configurations", () => {
+            const oldConfig = { extends: ["previous:configuration1", "previous:configuration2"], rules: {} };
+            const newConfig = autoconfig.extendFromRecommended(oldConfig);
+
+            assert.includeMembers(newConfig.extends, oldConfig.extends);
+        });
+
+        it("should return a configuration which has `eslint:recommended` at the first of `extends`", () => {
+            const oldConfig = { extends: ["previous:configuration1", "previous:configuration2"], rules: {} };
+            const newConfig = autoconfig.extendFromRecommended(oldConfig);
+            const [firstExtendInNewConfig] = newConfig.extends;
+
+            assert.strictEqual(firstExtendInNewConfig, "eslint:recommended");
+        });
+
+        it("should return a configuration which not includes rules configured in `eslint:recommended`", () => {
+            const oldConfig = { extends: [], rules: { ...recommendedConfig.rules } };
+            const newConfig = autoconfig.extendFromRecommended(oldConfig);
+
+            assert.notInclude(newConfig.rules, oldConfig.rules);
+        });
+    });
 });