refactor: remove unnecessary code

This commit is contained in:
ikatyang committed 2017-09-07 16:41:51 +08:00
1 parent 4163a4fa83
commit 3aef0bf1a0
2 files changed
+8 -18

No files matched your search

+7 -14
View File
@@ -36,12 +36,6 @@ function getOptions(argv) {
}
function getParserOption(argv) {
const value = argv.parser;
if (value === undefined) {
return value;
}
// For backward compatibility. Deprecated in 0.0.10
/* istanbul ignore if */
if (argv["flow-parser"]) {
@@ -49,17 +43,14 @@ function getParserOption(argv) {
return "flow";
}
return value;
return argv["parser"];
}
function getIntOption(argv, optionName) {
const value = argv[optionName];
if (value === undefined) {
return value;
}
validator.validateIntOption(value, constant.options[optionName], {
// cursorOffset defaults to -1 and rangeEnd defaults to Infinity, which is not considered an integer.
exceptions: [apiDefaultOptions[kebabToCamel(optionName)]]
});
@@ -76,10 +67,12 @@ function getTrailingComma(argv) {
'Specify "none", "es5", or "all".'
);
return "es5";
case undefined:
return value;
default:
validator.validateChoiceOption(value, constant.options["trailing-comma"]);
validator.validateChoiceOption(
value,
constant.options["trailing-comma"],
{ exceptions: [undefined] }
);
return value;
}
}
+1 -4
View File
@@ -24,7 +24,7 @@ function validateIntOption(value, option, opts) {
}
}
function validateChoiceOption(value, option, opts) {
function validateChoiceOption(value, option) {
if (option.choices.indexOf(value) === -1) {
throw new Error(
`Invalid option for --${option.name}.\nExpected ${getJoinedChoices()}, but received: "${value}"`
@@ -33,9 +33,6 @@ function validateChoiceOption(value, option, opts) {
function getJoinedChoices() {
const choices = option.choices.map(choice => `"${choice}"`);
if (choices.length === 1) {
return choices[0];
}
const head = choices.slice(0, -2);
const tail = choices.slice(-2);
return head.concat(tail.join(" or ")).join(", ");