config-initializer.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. /**
  2. * @fileoverview Config initialization wizard.
  3. * @author Ilya Volodin
  4. */
  5. "use strict";
  6. //------------------------------------------------------------------------------
  7. // Requirements
  8. //------------------------------------------------------------------------------
  9. const util = require("util"),
  10. path = require("path"),
  11. fs = require("fs"),
  12. enquirer = require("enquirer"),
  13. ProgressBar = require("progress"),
  14. semver = require("semver"),
  15. espree = require("espree"),
  16. recConfig = require("../../conf/eslint-recommended"),
  17. ConfigOps = require("@eslint/eslintrc/lib/shared/config-ops"),
  18. log = require("../shared/logging"),
  19. naming = require("@eslint/eslintrc/lib/shared/naming"),
  20. ModuleResolver = require("../shared/relative-module-resolver"),
  21. autoconfig = require("./autoconfig.js"),
  22. ConfigFile = require("./config-file"),
  23. npmUtils = require("./npm-utils"),
  24. { getSourceCodeOfFiles } = require("./source-code-utils");
  25. const debug = require("debug")("eslint:config-initializer");
  26. //------------------------------------------------------------------------------
  27. // Private
  28. //------------------------------------------------------------------------------
  29. /* istanbul ignore next: hard to test fs function */
  30. /**
  31. * Create .eslintrc file in the current working directory
  32. * @param {Object} config object that contains user's answers
  33. * @param {string} format The file format to write to.
  34. * @returns {void}
  35. */
  36. function writeFile(config, format) {
  37. // default is .js
  38. let extname = ".js";
  39. if (format === "YAML") {
  40. extname = ".yml";
  41. } else if (format === "JSON") {
  42. extname = ".json";
  43. } else if (format === "JavaScript") {
  44. const pkgJSONPath = npmUtils.findPackageJson();
  45. if (pkgJSONPath) {
  46. const pkgJSONContents = JSON.parse(fs.readFileSync(pkgJSONPath, "utf8"));
  47. if (pkgJSONContents.type === "module") {
  48. extname = ".cjs";
  49. }
  50. }
  51. }
  52. const installedESLint = config.installedESLint;
  53. delete config.installedESLint;
  54. ConfigFile.write(config, `./.eslintrc${extname}`);
  55. log.info(`Successfully created .eslintrc${extname} file in ${process.cwd()}`);
  56. if (installedESLint) {
  57. log.info("ESLint was installed locally. We recommend using this local copy instead of your globally-installed copy.");
  58. }
  59. }
  60. /**
  61. * Get the peer dependencies of the given module.
  62. * This adds the gotten value to cache at the first time, then reuses it.
  63. * In a process, this function is called twice, but `npmUtils.fetchPeerDependencies` needs to access network which is relatively slow.
  64. * @param {string} moduleName The module name to get.
  65. * @returns {Object} The peer dependencies of the given module.
  66. * This object is the object of `peerDependencies` field of `package.json`.
  67. * Returns null if npm was not found.
  68. */
  69. function getPeerDependencies(moduleName) {
  70. let result = getPeerDependencies.cache.get(moduleName);
  71. if (!result) {
  72. log.info(`Checking peerDependencies of ${moduleName}`);
  73. result = npmUtils.fetchPeerDependencies(moduleName);
  74. getPeerDependencies.cache.set(moduleName, result);
  75. }
  76. return result;
  77. }
  78. getPeerDependencies.cache = new Map();
  79. /**
  80. * Return necessary plugins, configs, parsers, etc. based on the config
  81. * @param {Object} config config object
  82. * @param {boolean} [installESLint=true] If `false` is given, it does not install eslint.
  83. * @returns {string[]} An array of modules to be installed.
  84. */
  85. function getModulesList(config, installESLint) {
  86. const modules = {};
  87. // Create a list of modules which should be installed based on config
  88. if (config.plugins) {
  89. for (const plugin of config.plugins) {
  90. const moduleName = naming.normalizePackageName(plugin, "eslint-plugin");
  91. modules[moduleName] = "latest";
  92. }
  93. }
  94. if (config.extends) {
  95. const extendList = Array.isArray(config.extends) ? config.extends : [config.extends];
  96. for (const extend of extendList) {
  97. if (extend.startsWith("eslint:") || extend.startsWith("plugin:")) {
  98. continue;
  99. }
  100. const moduleName = naming.normalizePackageName(extend, "eslint-config");
  101. modules[moduleName] = "latest";
  102. Object.assign(
  103. modules,
  104. getPeerDependencies(`${moduleName}@latest`)
  105. );
  106. }
  107. }
  108. const parser = config.parser || (config.parserOptions && config.parserOptions.parser);
  109. if (parser) {
  110. modules[parser] = "latest";
  111. }
  112. if (installESLint === false) {
  113. delete modules.eslint;
  114. } else {
  115. const installStatus = npmUtils.checkDevDeps(["eslint"]);
  116. // Mark to show messages if it's new installation of eslint.
  117. if (installStatus.eslint === false) {
  118. log.info("Local ESLint installation not found.");
  119. modules.eslint = modules.eslint || "latest";
  120. config.installedESLint = true;
  121. }
  122. }
  123. return Object.keys(modules).map(name => `${name}@${modules[name]}`);
  124. }
  125. /**
  126. * Set the `rules` of a config by examining a user's source code
  127. *
  128. * Note: This clones the config object and returns a new config to avoid mutating
  129. * the original config parameter.
  130. * @param {Object} answers answers received from enquirer
  131. * @param {Object} config config object
  132. * @returns {Object} config object with configured rules
  133. */
  134. function configureRules(answers, config) {
  135. const BAR_TOTAL = 20,
  136. BAR_SOURCE_CODE_TOTAL = 4,
  137. newConfig = Object.assign({}, config),
  138. disabledConfigs = {};
  139. let sourceCodes,
  140. registry;
  141. // Set up a progress bar, as this process can take a long time
  142. const bar = new ProgressBar("Determining Config: :percent [:bar] :elapseds elapsed, eta :etas ", {
  143. width: 30,
  144. total: BAR_TOTAL
  145. });
  146. bar.tick(0); // Shows the progress bar
  147. // Get the SourceCode of all chosen files
  148. const patterns = answers.patterns.split(/[\s]+/u);
  149. try {
  150. sourceCodes = getSourceCodeOfFiles(patterns, { baseConfig: newConfig, useEslintrc: false }, total => {
  151. bar.tick((BAR_SOURCE_CODE_TOTAL / total));
  152. });
  153. } catch (e) {
  154. log.info("\n");
  155. throw e;
  156. }
  157. const fileQty = Object.keys(sourceCodes).length;
  158. if (fileQty === 0) {
  159. log.info("\n");
  160. throw new Error("Automatic Configuration failed. No files were able to be parsed.");
  161. }
  162. // Create a registry of rule configs
  163. registry = new autoconfig.Registry();
  164. registry.populateFromCoreRules();
  165. // Lint all files with each rule config in the registry
  166. registry = registry.lintSourceCode(sourceCodes, newConfig, total => {
  167. bar.tick((BAR_TOTAL - BAR_SOURCE_CODE_TOTAL) / total); // Subtract out ticks used at beginning
  168. });
  169. debug(`\nRegistry: ${util.inspect(registry.rules, { depth: null })}`);
  170. // Create a list of recommended rules, because we don't want to disable them
  171. const recRules = Object.keys(recConfig.rules).filter(ruleId => ConfigOps.isErrorSeverity(recConfig.rules[ruleId]));
  172. // Find and disable rules which had no error-free configuration
  173. const failingRegistry = registry.getFailingRulesRegistry();
  174. Object.keys(failingRegistry.rules).forEach(ruleId => {
  175. // If the rule is recommended, set it to error, otherwise disable it
  176. disabledConfigs[ruleId] = (recRules.indexOf(ruleId) !== -1) ? 2 : 0;
  177. });
  178. // Now that we know which rules to disable, strip out configs with errors
  179. registry = registry.stripFailingConfigs();
  180. /*
  181. * If there is only one config that results in no errors for a rule, we should use it.
  182. * createConfig will only add rules that have one configuration in the registry.
  183. */
  184. const singleConfigs = registry.createConfig().rules;
  185. /*
  186. * The "sweet spot" for number of options in a config seems to be two (severity plus one option).
  187. * Very often, a third option (usually an object) is available to address
  188. * edge cases, exceptions, or unique situations. We will prefer to use a config with
  189. * specificity of two.
  190. */
  191. const specTwoConfigs = registry.filterBySpecificity(2).createConfig().rules;
  192. // Maybe a specific combination using all three options works
  193. const specThreeConfigs = registry.filterBySpecificity(3).createConfig().rules;
  194. // If all else fails, try to use the default (severity only)
  195. const defaultConfigs = registry.filterBySpecificity(1).createConfig().rules;
  196. // Combine configs in reverse priority order (later take precedence)
  197. newConfig.rules = Object.assign({}, disabledConfigs, defaultConfigs, specThreeConfigs, specTwoConfigs, singleConfigs);
  198. // Make sure progress bar has finished (floating point rounding)
  199. bar.update(BAR_TOTAL);
  200. // Log out some stats to let the user know what happened
  201. const finalRuleIds = Object.keys(newConfig.rules);
  202. const totalRules = finalRuleIds.length;
  203. const enabledRules = finalRuleIds.filter(ruleId => (newConfig.rules[ruleId] !== 0)).length;
  204. const resultMessage = [
  205. `\nEnabled ${enabledRules} out of ${totalRules}`,
  206. `rules based on ${fileQty}`,
  207. `file${(fileQty === 1) ? "." : "s."}`
  208. ].join(" ");
  209. log.info(resultMessage);
  210. ConfigOps.normalizeToStrings(newConfig);
  211. return newConfig;
  212. }
  213. /**
  214. * process user's answers and create config object
  215. * @param {Object} answers answers received from enquirer
  216. * @returns {Object} config object
  217. */
  218. function processAnswers(answers) {
  219. let config = {
  220. rules: {},
  221. env: {},
  222. parserOptions: {},
  223. extends: []
  224. };
  225. config.parserOptions.ecmaVersion = espree.latestEcmaVersion;
  226. config.env.es2021 = true;
  227. // set the module type
  228. if (answers.moduleType === "esm") {
  229. config.parserOptions.sourceType = "module";
  230. } else if (answers.moduleType === "commonjs") {
  231. config.env.commonjs = true;
  232. }
  233. // add in browser and node environments if necessary
  234. answers.env.forEach(env => {
  235. config.env[env] = true;
  236. });
  237. // add in library information
  238. if (answers.framework === "react") {
  239. config.parserOptions.ecmaFeatures = {
  240. jsx: true
  241. };
  242. config.plugins = ["react"];
  243. config.extends.push("plugin:react/recommended");
  244. } else if (answers.framework === "vue") {
  245. config.plugins = ["vue"];
  246. config.extends.push("plugin:vue/essential");
  247. }
  248. if (answers.typescript) {
  249. if (answers.framework === "vue") {
  250. config.parserOptions.parser = "@typescript-eslint/parser";
  251. } else {
  252. config.parser = "@typescript-eslint/parser";
  253. }
  254. if (Array.isArray(config.plugins)) {
  255. config.plugins.push("@typescript-eslint");
  256. } else {
  257. config.plugins = ["@typescript-eslint"];
  258. }
  259. }
  260. // setup rules based on problems/style enforcement preferences
  261. if (answers.purpose === "problems") {
  262. config.extends.unshift("eslint:recommended");
  263. } else if (answers.purpose === "style") {
  264. if (answers.source === "prompt") {
  265. config.extends.unshift("eslint:recommended");
  266. config.rules.indent = ["error", answers.indent];
  267. config.rules.quotes = ["error", answers.quotes];
  268. config.rules["linebreak-style"] = ["error", answers.linebreak];
  269. config.rules.semi = ["error", answers.semi ? "always" : "never"];
  270. } else if (answers.source === "auto") {
  271. config = configureRules(answers, config);
  272. config = autoconfig.extendFromRecommended(config);
  273. }
  274. }
  275. if (answers.typescript && config.extends.includes("eslint:recommended")) {
  276. config.extends.push("plugin:@typescript-eslint/recommended");
  277. }
  278. // normalize extends
  279. if (config.extends.length === 0) {
  280. delete config.extends;
  281. } else if (config.extends.length === 1) {
  282. config.extends = config.extends[0];
  283. }
  284. ConfigOps.normalizeToStrings(config);
  285. return config;
  286. }
  287. /**
  288. * Get the version of the local ESLint.
  289. * @returns {string|null} The version. If the local ESLint was not found, returns null.
  290. */
  291. function getLocalESLintVersion() {
  292. try {
  293. const eslintPath = ModuleResolver.resolve("eslint", path.join(process.cwd(), "__placeholder__.js"));
  294. const eslint = require(eslintPath);
  295. return eslint.linter.version || null;
  296. } catch {
  297. return null;
  298. }
  299. }
  300. /**
  301. * Get the shareable config name of the chosen style guide.
  302. * @param {Object} answers The answers object.
  303. * @returns {string} The shareable config name.
  304. */
  305. function getStyleGuideName(answers) {
  306. if (answers.styleguide === "airbnb" && answers.framework !== "react") {
  307. return "airbnb-base";
  308. }
  309. return answers.styleguide;
  310. }
  311. /**
  312. * Check whether the local ESLint version conflicts with the required version of the chosen shareable config.
  313. * @param {Object} answers The answers object.
  314. * @returns {boolean} `true` if the local ESLint is found then it conflicts with the required version of the chosen shareable config.
  315. */
  316. function hasESLintVersionConflict(answers) {
  317. // Get the local ESLint version.
  318. const localESLintVersion = getLocalESLintVersion();
  319. if (!localESLintVersion) {
  320. return false;
  321. }
  322. // Get the required range of ESLint version.
  323. const configName = getStyleGuideName(answers);
  324. const moduleName = `eslint-config-${configName}@latest`;
  325. const peerDependencies = getPeerDependencies(moduleName) || {};
  326. const requiredESLintVersionRange = peerDependencies.eslint;
  327. if (!requiredESLintVersionRange) {
  328. return false;
  329. }
  330. answers.localESLintVersion = localESLintVersion;
  331. answers.requiredESLintVersionRange = requiredESLintVersionRange;
  332. // Check the version.
  333. if (semver.satisfies(localESLintVersion, requiredESLintVersionRange)) {
  334. answers.installESLint = false;
  335. return false;
  336. }
  337. return true;
  338. }
  339. /**
  340. * Install modules.
  341. * @param {string[]} modules Modules to be installed.
  342. * @returns {void}
  343. */
  344. function installModules(modules) {
  345. log.info(`Installing ${modules.join(", ")}`);
  346. npmUtils.installSyncSaveDev(modules);
  347. }
  348. /* istanbul ignore next: no need to test enquirer */
  349. /**
  350. * Ask user to install modules.
  351. * @param {string[]} modules Array of modules to be installed.
  352. * @param {boolean} packageJsonExists Indicates if package.json is existed.
  353. * @returns {Promise} Answer that indicates if user wants to install.
  354. */
  355. function askInstallModules(modules, packageJsonExists) {
  356. // If no modules, do nothing.
  357. if (modules.length === 0) {
  358. return Promise.resolve();
  359. }
  360. log.info("The config that you've selected requires the following dependencies:\n");
  361. log.info(modules.join(" "));
  362. return enquirer.prompt([
  363. {
  364. type: "toggle",
  365. name: "executeInstallation",
  366. message: "Would you like to install them now with npm?",
  367. enabled: "Yes",
  368. disabled: "No",
  369. initial: 1,
  370. skip() {
  371. return !(modules.length && packageJsonExists);
  372. },
  373. result(input) {
  374. return this.skipped ? null : input;
  375. }
  376. }
  377. ]).then(({ executeInstallation }) => {
  378. if (executeInstallation) {
  379. installModules(modules);
  380. }
  381. });
  382. }
  383. /* istanbul ignore next: no need to test enquirer */
  384. /**
  385. * Ask use a few questions on command prompt
  386. * @returns {Promise} The promise with the result of the prompt
  387. */
  388. function promptUser() {
  389. return enquirer.prompt([
  390. {
  391. type: "select",
  392. name: "purpose",
  393. message: "How would you like to use ESLint?",
  394. // The returned number matches the name value of nth in the choices array.
  395. initial: 1,
  396. choices: [
  397. { message: "To check syntax only", name: "syntax" },
  398. { message: "To check syntax and find problems", name: "problems" },
  399. { message: "To check syntax, find problems, and enforce code style", name: "style" }
  400. ]
  401. },
  402. {
  403. type: "select",
  404. name: "moduleType",
  405. message: "What type of modules does your project use?",
  406. initial: 0,
  407. choices: [
  408. { message: "JavaScript modules (import/export)", name: "esm" },
  409. { message: "CommonJS (require/exports)", name: "commonjs" },
  410. { message: "None of these", name: "none" }
  411. ]
  412. },
  413. {
  414. type: "select",
  415. name: "framework",
  416. message: "Which framework does your project use?",
  417. initial: 0,
  418. choices: [
  419. { message: "React", name: "react" },
  420. { message: "Vue.js", name: "vue" },
  421. { message: "None of these", name: "none" }
  422. ]
  423. },
  424. {
  425. type: "toggle",
  426. name: "typescript",
  427. message: "Does your project use TypeScript?",
  428. enabled: "Yes",
  429. disabled: "No",
  430. initial: 0
  431. },
  432. {
  433. type: "multiselect",
  434. name: "env",
  435. message: "Where does your code run?",
  436. hint: "(Press <space> to select, <a> to toggle all, <i> to invert selection)",
  437. initial: 0,
  438. choices: [
  439. { message: "Browser", name: "browser" },
  440. { message: "Node", name: "node" }
  441. ]
  442. },
  443. {
  444. type: "select",
  445. name: "source",
  446. message: "How would you like to define a style for your project?",
  447. choices: [
  448. { message: "Use a popular style guide", name: "guide" },
  449. { message: "Answer questions about your style", name: "prompt" },
  450. { message: "Inspect your JavaScript file(s)", name: "auto" }
  451. ],
  452. skip() {
  453. return this.state.answers.purpose !== "style";
  454. },
  455. result(input) {
  456. return this.skipped ? null : input;
  457. }
  458. },
  459. {
  460. type: "select",
  461. name: "styleguide",
  462. message: "Which style guide do you want to follow?",
  463. choices: [
  464. { message: "Airbnb: https://github.com/airbnb/javascript", name: "airbnb" },
  465. { message: "Standard: https://github.com/standard/standard", name: "standard" },
  466. { message: "Google: https://github.com/google/eslint-config-google", name: "google" },
  467. { message: "XO: https://github.com/xojs/eslint-config-xo", name: "xo" }
  468. ],
  469. skip() {
  470. this.state.answers.packageJsonExists = npmUtils.checkPackageJson();
  471. return !(this.state.answers.source === "guide" && this.state.answers.packageJsonExists);
  472. },
  473. result(input) {
  474. return this.skipped ? null : input;
  475. }
  476. },
  477. {
  478. type: "input",
  479. name: "patterns",
  480. message: "Which file(s), path(s), or glob(s) should be examined?",
  481. skip() {
  482. return this.state.answers.source !== "auto";
  483. },
  484. validate(input) {
  485. if (!this.skipped && input.trim().length === 0 && input.trim() !== ",") {
  486. return "You must tell us what code to examine. Try again.";
  487. }
  488. return true;
  489. }
  490. },
  491. {
  492. type: "select",
  493. name: "format",
  494. message: "What format do you want your config file to be in?",
  495. initial: 0,
  496. choices: ["JavaScript", "YAML", "JSON"]
  497. },
  498. {
  499. type: "toggle",
  500. name: "installESLint",
  501. message() {
  502. const { answers } = this.state;
  503. const verb = semver.ltr(answers.localESLintVersion, answers.requiredESLintVersionRange)
  504. ? "upgrade"
  505. : "downgrade";
  506. return `The style guide "${answers.styleguide}" requires eslint@${answers.requiredESLintVersionRange}. You are currently using eslint@${answers.localESLintVersion}.\n Do you want to ${verb}?`;
  507. },
  508. enabled: "Yes",
  509. disabled: "No",
  510. initial: 1,
  511. skip() {
  512. return !(this.state.answers.source === "guide" && this.state.answers.packageJsonExists && hasESLintVersionConflict(this.state.answers));
  513. },
  514. result(input) {
  515. return this.skipped ? null : input;
  516. }
  517. }
  518. ]).then(earlyAnswers => {
  519. // early exit if no style guide is necessary
  520. if (earlyAnswers.purpose !== "style") {
  521. const config = processAnswers(earlyAnswers);
  522. const modules = getModulesList(config);
  523. return askInstallModules(modules, earlyAnswers.packageJsonExists)
  524. .then(() => writeFile(config, earlyAnswers.format));
  525. }
  526. // early exit if you are using a style guide
  527. if (earlyAnswers.source === "guide") {
  528. if (!earlyAnswers.packageJsonExists) {
  529. log.info("A package.json is necessary to install plugins such as style guides. Run `npm init` to create a package.json file and try again.");
  530. return void 0;
  531. }
  532. if (earlyAnswers.installESLint === false && !semver.satisfies(earlyAnswers.localESLintVersion, earlyAnswers.requiredESLintVersionRange)) {
  533. log.info(`Note: it might not work since ESLint's version is mismatched with the ${earlyAnswers.styleguide} config.`);
  534. }
  535. if (earlyAnswers.styleguide === "airbnb" && earlyAnswers.framework !== "react") {
  536. earlyAnswers.styleguide = "airbnb-base";
  537. }
  538. const config = processAnswers(earlyAnswers);
  539. if (Array.isArray(config.extends)) {
  540. config.extends.push(earlyAnswers.styleguide);
  541. } else if (config.extends) {
  542. config.extends = [config.extends, earlyAnswers.styleguide];
  543. } else {
  544. config.extends = [earlyAnswers.styleguide];
  545. }
  546. const modules = getModulesList(config);
  547. return askInstallModules(modules, earlyAnswers.packageJsonExists)
  548. .then(() => writeFile(config, earlyAnswers.format));
  549. }
  550. if (earlyAnswers.source === "auto") {
  551. const combinedAnswers = Object.assign({}, earlyAnswers);
  552. const config = processAnswers(combinedAnswers);
  553. const modules = getModulesList(config);
  554. return askInstallModules(modules).then(() => writeFile(config, earlyAnswers.format));
  555. }
  556. // continue with the style questions otherwise...
  557. return enquirer.prompt([
  558. {
  559. type: "select",
  560. name: "indent",
  561. message: "What style of indentation do you use?",
  562. initial: 0,
  563. choices: [{ message: "Tabs", name: "tab" }, { message: "Spaces", name: 4 }]
  564. },
  565. {
  566. type: "select",
  567. name: "quotes",
  568. message: "What quotes do you use for strings?",
  569. initial: 0,
  570. choices: [{ message: "Double", name: "double" }, { message: "Single", name: "single" }]
  571. },
  572. {
  573. type: "select",
  574. name: "linebreak",
  575. message: "What line endings do you use?",
  576. initial: 0,
  577. choices: [{ message: "Unix", name: "unix" }, { message: "Windows", name: "windows" }]
  578. },
  579. {
  580. type: "toggle",
  581. name: "semi",
  582. message: "Do you require semicolons?",
  583. enabled: "Yes",
  584. disabled: "No",
  585. initial: 1
  586. }
  587. ]).then(answers => {
  588. const totalAnswers = Object.assign({}, earlyAnswers, answers);
  589. const config = processAnswers(totalAnswers);
  590. const modules = getModulesList(config);
  591. return askInstallModules(modules).then(() => writeFile(config, earlyAnswers.format));
  592. });
  593. });
  594. }
  595. //------------------------------------------------------------------------------
  596. // Public Interface
  597. //------------------------------------------------------------------------------
  598. const init = {
  599. getModulesList,
  600. hasESLintVersionConflict,
  601. installModules,
  602. processAnswers,
  603. writeFile,
  604. /* istanbul ignore next */initializeConfig() {
  605. return promptUser();
  606. }
  607. };
  608. module.exports = init;