Skip to content

Commit

Permalink
Refactor lib/utils/checkInvalidCLIOptions.js (#6003)
Browse files Browse the repository at this point in the history
This small refactoring aims to make `buildAllowedOptions()` more readable.

The number of loops is doubled (`Object.keys()` and `Object.values()`),
but it will not degrade performance since `allowedOptions` is a small array.
  • Loading branch information
ybiquitous committed Apr 1, 2022
1 parent 788c3ba commit 6ffbc41
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions lib/utils/checkInvalidCLIOptions.js
Expand Up @@ -9,17 +9,14 @@ const { red, cyan } = require('picocolors');
* @return {string[]}
*/
const buildAllowedOptions = (allowedOptions) => {
let options = Object.keys(allowedOptions);

options = options.reduce((opts, opt) => {
const alias = allowedOptions[opt].alias;
const options = Object.keys(allowedOptions);

for (const { alias } of Object.values(allowedOptions)) {
if (alias) {
opts.push(alias);
options.push(alias);
}
}

return opts;
}, options);
options.sort();

return options;
Expand Down

0 comments on commit 6ffbc41

Please sign in to comment.