New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Chore: Replace the inquirer dependency with enquirer #13254
Merged
Merged
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9f623e7
Update: Replace dependency inquirer with enquirer (fixes #13208)
Siilwyn c95a7d9
Replace confirm prompts with toggle prompts to match inquirer behaviour
Siilwyn 7390661
Fix skip property typo
Siilwyn 58aeeb5
Add help description
Siilwyn bd396b7
Use hint instead of message for usage informatino
Siilwyn 0f0b186
Add comment about initial select prompt
Siilwyn 31278e3
Merge branch 'master' into replace-inquirer
Siilwyn fe79cbb
Update config-initializer.js
Siilwyn 67088f2
Update config-initializer.js
Siilwyn File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
|
||
const util = require("util"), | ||
path = require("path"), | ||
inquirer = require("inquirer"), | ||
enquirer = require("enquirer"), | ||
ProgressBar = require("progress"), | ||
semver = require("semver"), | ||
espree = require("espree"), | ||
|
@@ -146,7 +146,7 @@ function getModulesList(config, installESLint) { | |
* | ||
* Note: This clones the config object and returns a new config to avoid mutating | ||
* the original config parameter. | ||
* @param {Object} answers answers received from inquirer | ||
* @param {Object} answers answers received from enquirer | ||
* @param {Object} config config object | ||
* @returns {Object} config object with configured rules | ||
*/ | ||
|
@@ -253,7 +253,7 @@ function configureRules(answers, config) { | |
|
||
/** | ||
* process user's answers and create config object | ||
* @param {Object} answers answers received from inquirer | ||
* @param {Object} answers answers received from enquirer | ||
* @returns {Object} config object | ||
*/ | ||
function processAnswers(answers) { | ||
|
@@ -412,7 +412,7 @@ function installModules(modules) { | |
npmUtils.installSyncSaveDev(modules); | ||
} | ||
|
||
/* istanbul ignore next: no need to test inquirer */ | ||
/* istanbul ignore next: no need to test enquirer */ | ||
/** | ||
* Ask user to install modules. | ||
* @param {string[]} modules Array of modules to be installed. | ||
|
@@ -428,14 +428,19 @@ function askInstallModules(modules, packageJsonExists) { | |
|
||
log.info("The config that you've selected requires the following dependencies:\n"); | ||
log.info(modules.join(" ")); | ||
return inquirer.prompt([ | ||
return enquirer.prompt([ | ||
{ | ||
type: "confirm", | ||
type: "toggle", | ||
name: "executeInstallation", | ||
message: "Would you like to install them now with npm?", | ||
default: true, | ||
when() { | ||
return modules.length && packageJsonExists; | ||
enabled: "Yes", | ||
disabled: "No", | ||
initial: 1, | ||
skip() { | ||
return !(modules.length && packageJsonExists); | ||
}, | ||
result(input) { | ||
return this.skipped ? null : input; | ||
} | ||
} | ||
]).then(({ executeInstallation }) => { | ||
|
@@ -445,114 +450,121 @@ function askInstallModules(modules, packageJsonExists) { | |
}); | ||
} | ||
|
||
/* istanbul ignore next: no need to test inquirer */ | ||
/* 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 | ||
*/ | ||
function promptUser() { | ||
|
||
return inquirer.prompt([ | ||
return enquirer.prompt([ | ||
{ | ||
type: "list", | ||
type: "select", | ||
name: "purpose", | ||
message: "How would you like to use ESLint?", | ||
default: "problems", | ||
initial: 1, | ||
choices: [ | ||
{ name: "To check syntax only", value: "syntax" }, | ||
{ name: "To check syntax and find problems", value: "problems" }, | ||
{ name: "To check syntax, find problems, and enforce code style", value: "style" } | ||
{ 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: "list", | ||
type: "select", | ||
name: "moduleType", | ||
message: "What type of modules does your project use?", | ||
default: "esm", | ||
initial: 0, | ||
choices: [ | ||
{ name: "JavaScript modules (import/export)", value: "esm" }, | ||
{ name: "CommonJS (require/exports)", value: "commonjs" }, | ||
{ name: "None of these", value: "none" } | ||
{ message: "JavaScript modules (import/export)", name: "esm" }, | ||
{ message: "CommonJS (require/exports)", name: "commonjs" }, | ||
{ message: "None of these", name: "none" } | ||
] | ||
}, | ||
{ | ||
type: "list", | ||
type: "select", | ||
name: "framework", | ||
message: "Which framework does your project use?", | ||
default: "react", | ||
initial: 0, | ||
choices: [ | ||
{ name: "React", value: "react" }, | ||
{ name: "Vue.js", value: "vue" }, | ||
{ name: "None of these", value: "none" } | ||
{ message: "React", name: "react" }, | ||
{ message: "Vue.js", name: "vue" }, | ||
{ message: "None of these", name: "none" } | ||
] | ||
}, | ||
{ | ||
type: "confirm", | ||
type: "toggle", | ||
name: "typescript", | ||
message: "Does your project use TypeScript?", | ||
default: false | ||
enabled: "Yes", | ||
disabled: "No", | ||
initial: 0 | ||
}, | ||
{ | ||
type: "checkbox", | ||
type: "multiselect", | ||
nzakas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
name: "env", | ||
message: "Where does your code run?", | ||
default: ["browser"], | ||
message: "Where does your code run? (Press <space> to select, <a> to toggle all, <i> to invert selection)", | ||
Siilwyn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
initial: 0, | ||
choices: [ | ||
{ name: "Browser", value: "browser" }, | ||
{ name: "Node", value: "node" } | ||
{ message: "Browser", name: "browser" }, | ||
{ message: "Node", name: "node" } | ||
] | ||
}, | ||
{ | ||
type: "list", | ||
type: "select", | ||
name: "source", | ||
message: "How would you like to define a style for your project?", | ||
default: "guide", | ||
choices: [ | ||
{ name: "Use a popular style guide", value: "guide" }, | ||
{ name: "Answer questions about your style", value: "prompt" }, | ||
{ name: "Inspect your JavaScript file(s)", value: "auto" } | ||
{ message: "Use a popular style guide", name: "guide" }, | ||
{ message: "Answer questions about your style", name: "prompt" }, | ||
{ message: "Inspect your JavaScript file(s)", name: "auto" } | ||
], | ||
when(answers) { | ||
return answers.purpose === "style"; | ||
skip() { | ||
return this.state.answers.purpose !== "style"; | ||
}, | ||
Comment on lines
+521
to
+523
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
result(input) { | ||
return this.skipped ? null : input; | ||
} | ||
}, | ||
{ | ||
type: "list", | ||
type: "select", | ||
name: "styleguide", | ||
message: "Which style guide do you want to follow?", | ||
choices: [ | ||
{ name: "Airbnb: https://github.com/airbnb/javascript", value: "airbnb" }, | ||
{ name: "Standard: https://github.com/standard/standard", value: "standard" }, | ||
{ name: "Google: https://github.com/google/eslint-config-google", value: "google" } | ||
{ message: "Airbnb: https://github.com/airbnb/javascript", name: "airbnb" }, | ||
{ message: "Standard: https://github.com/standard/standard", name: "standard" }, | ||
{ message: "Google: https://github.com/google/eslint-config-google", name: "google" } | ||
], | ||
when(answers) { | ||
answers.packageJsonExists = npmUtils.checkPackageJson(); | ||
return answers.source === "guide" && answers.packageJsonExists; | ||
skip() { | ||
this.state.answers.packageJsonExists = npmUtils.checkPackageJson(); | ||
return !(this.state.answers.source === "guide" && this.state.answers.packageJsonExists); | ||
}, | ||
result(input) { | ||
return this.skipped ? null : input; | ||
} | ||
}, | ||
{ | ||
type: "input", | ||
name: "patterns", | ||
message: "Which file(s), path(s), or glob(s) should be examined?", | ||
when(answers) { | ||
return (answers.source === "auto"); | ||
skip() { | ||
return this.state.answers.source !== "auto"; | ||
}, | ||
validate(input) { | ||
if (input.trim().length === 0 && input.trim() !== ",") { | ||
if (!this.skipped && input.trim().length === 0 && input.trim() !== ",") { | ||
return "You must tell us what code to examine. Try again."; | ||
} | ||
return true; | ||
} | ||
}, | ||
{ | ||
type: "list", | ||
type: "select", | ||
name: "format", | ||
message: "What format do you want your config file to be in?", | ||
default: "JavaScript", | ||
initial: 0, | ||
choices: ["JavaScript", "YAML", "JSON"] | ||
}, | ||
{ | ||
type: "confirm", | ||
type: "toggle", | ||
name: "installESLint", | ||
message(answers) { | ||
const verb = semver.ltr(answers.localESLintVersion, answers.requiredESLintVersionRange) | ||
|
@@ -561,9 +573,14 @@ function promptUser() { | |
|
||
return `The style guide "${answers.styleguide}" requires eslint@${answers.requiredESLintVersionRange}. You are currently using eslint@${answers.localESLintVersion}.\n Do you want to ${verb}?`; | ||
}, | ||
default: true, | ||
when(answers) { | ||
return answers.source === "guide" && answers.packageJsonExists && hasESLintVersionConflict(answers); | ||
enabled: "Yes", | ||
disabled: "No", | ||
initial: 1, | ||
skip() { | ||
return !(this.state.answers.source === "guide" && this.state.answers.packageJsonExists && hasESLintVersionConflict(this.state.answers)); | ||
}, | ||
result(input) { | ||
return this.skipped ? null : input; | ||
} | ||
} | ||
]).then(earlyAnswers => { | ||
|
@@ -616,33 +633,35 @@ function promptUser() { | |
} | ||
|
||
// continue with the style questions otherwise... | ||
return inquirer.prompt([ | ||
return enquirer.prompt([ | ||
{ | ||
type: "list", | ||
type: "select", | ||
name: "indent", | ||
message: "What style of indentation do you use?", | ||
default: "tab", | ||
choices: [{ name: "Tabs", value: "tab" }, { name: "Spaces", value: 4 }] | ||
initial: 0, | ||
choices: [{ message: "Tabs", name: "tab" }, { message: "Spaces", name: 4 }] | ||
}, | ||
{ | ||
type: "list", | ||
type: "select", | ||
name: "quotes", | ||
message: "What quotes do you use for strings?", | ||
default: "double", | ||
choices: [{ name: "Double", value: "double" }, { name: "Single", value: "single" }] | ||
initial: 0, | ||
choices: [{ message: "Double", name: "double" }, { message: "Single", name: "single" }] | ||
}, | ||
{ | ||
type: "list", | ||
type: "select", | ||
name: "linebreak", | ||
message: "What line endings do you use?", | ||
default: "unix", | ||
choices: [{ name: "Unix", value: "unix" }, { name: "Windows", value: "windows" }] | ||
initial: 0, | ||
choices: [{ message: "Unix", name: "unix" }, { message: "Windows", name: "windows" }] | ||
}, | ||
{ | ||
type: "confirm", | ||
type: "toggle", | ||
name: "semi", | ||
message: "Do you require semicolons?", | ||
default: true | ||
enabled: "Yes", | ||
disabled: "No", | ||
initial: 1 | ||
} | ||
]).then(answers => { | ||
const totalAnswers = Object.assign({}, earlyAnswers, answers); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The returned number matches the
name
value of nth in thechoices
array.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add that as a comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Siilwyn can you add this as a comment in the file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes 👍
(Didn't get a notification for your first comment.)