Refactor option category grouping
parent
c2847d90cd
commit
2b9e1f80c5
|
@ -342,12 +342,7 @@ function createUsage() {
|
|||
.apply([], optionsWithOpposites)
|
||||
.filter(Boolean);
|
||||
|
||||
const groupedOptions = flattenedOptions.reduce((current, option) => {
|
||||
const category = option.category;
|
||||
const group = (current[category] = current[category] || []);
|
||||
group.push(option);
|
||||
return current;
|
||||
}, {});
|
||||
const groupedOptions = groupBy(flattenedOptions, option => option.category);
|
||||
|
||||
const usageSummary = "Usage: prettier [opts] [filename ...]";
|
||||
|
||||
|
@ -413,6 +408,14 @@ function indent(str, spaces) {
|
|||
return str.replace(/^/gm, " ".repeat(spaces));
|
||||
}
|
||||
|
||||
function groupBy(array, getKey) {
|
||||
return array.reduce((obj, item) => {
|
||||
const key = getKey(item);
|
||||
const previousItems = key in obj ? obj[key] : [];
|
||||
return Object.assign({}, obj, { [key]: previousItems.concat(item) });
|
||||
}, Object.create(null));
|
||||
}
|
||||
|
||||
function normalizeArgv(rawArgv, options) {
|
||||
options = options || {};
|
||||
|
||||
|
|
Loading…
Reference in New Issue