MCPcopy
hub / github.com/prettier/prettier / createUsage

Function createUsage

src/cli/usage.js:113–150  ·  view source on GitHub ↗
(context)

Source from the content-addressed store, hash-verified

111}
112
113function createUsage(context) {
114 const sortedOptions = context.detailedOptions.sort((optionA, optionB) =>
115 optionA.name.localeCompare(optionB.name),
116 );
117
118 const options = getOptionsWithOpposites(sortedOptions).filter(
119 // remove unnecessary option (e.g. `semi`, `color`, etc.), which is only used for --help <flag>
120 (option) =>
121 !(
122 option.type === "boolean" &&
123 option.oppositeDescription &&
124 !option.name.startsWith("no-")
125 ),
126 );
127 const groupedOptions = groupBy(options, (option) => option.category);
128
129 const firstCategories = categoryOrder.slice(0, -1);
130 const lastCategories = categoryOrder.slice(-1);
131 const restCategories = Object.keys(groupedOptions).filter(
132 (category) => !categoryOrder.includes(category),
133 );
134 const allCategories = [
135 ...firstCategories,
136 ...restCategories,
137 ...lastCategories,
138 ];
139
140 const optionsUsage = allCategories.map((category) => {
141 const categoryOptions = groupedOptions[category]
142 .map((option) =>
143 createOptionUsage(context, option, OPTION_USAGE_THRESHOLD),
144 )
145 .join("\n");
146 return `${category} options:\n\n${indent(categoryOptions, 2)}`;
147 });
148
149 return [usageSummary, ...optionsUsage, ""].join("\n\n");
150}
151
152function createPluginDefaults(pluginDefaults) {
153 if (!pluginDefaults || Object.keys(pluginDefaults).length === 0) {

Callers 1

mainFunction · 0.90

Calls 5

groupByFunction · 0.90
getOptionsWithOppositesFunction · 0.85
createOptionUsageFunction · 0.85
indentFunction · 0.70
mapMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…