diff --git a/src/cli-constant.js b/src/cli-constant.js index 8d5d182e5..7b1c97d52 100644 --- a/src/cli-constant.js +++ b/src/cli-constant.js @@ -22,6 +22,9 @@ * * // description to be displayed in usage * description?: string; + * + * // description for its no-option (`no-${name}`) to be displayed in usage + * oppositeDescription?: string; * * // indicate if this option is also used for api * // true: use camelified name as api key @@ -47,6 +50,7 @@ const detailOptions = normalizeDetailOptions({ type: "boolean", category: "format", forwardToApi: true, + oppositeDescription: "Do not print spaces between brackets.", hidden: true }, color: { @@ -56,13 +60,15 @@ const detailOptions = normalizeDetailOptions({ // See https://github.com/chalk/supports-color/#info for more information. type: "boolean", default: true, - hidden: true + hidden: true, + oppositeDescription: "Do not colorize error messages." }, config: { type: "path", category: "config", description: - "Path to a prettier configuration file (.prettierrc, package.json, prettier.config.js)." + "Path to a prettier configuration file (.prettierrc, package.json, prettier.config.js).", + oppositeDescription: "Do not look for a configuration file." }, "config-precedence": { type: "choice", @@ -136,26 +142,6 @@ const detailOptions = normalizeDetailOptions({ description: "Print filenames of files that are different from Prettier formatting." }, - "no-bracket-spacing": { - type: "boolean", - category: "format", - description: "Do not print spaces between brackets." - }, - "no-color": { - type: "boolean", - description: "Do not colorize error messages." - }, - "no-config": { - type: "boolean", - category: "config", - description: "Do not look for a configuration file." - }, - "no-semi": { - type: "boolean", - category: "format", - description: - "Do not print semicolons, except at the beginning of lines which may need them." - }, parser: { type: "choice", category: "format", @@ -199,7 +185,9 @@ const detailOptions = normalizeDetailOptions({ type: "boolean", category: "format", forwardToApi: true, - hidden: true + hidden: true, + oppositeDescription: + "Do not print semicolons, except at the beginning of lines which may need them." }, "single-quote": { type: "boolean", @@ -262,14 +250,10 @@ const detailOptions = normalizeDetailOptions({ const minimistOptions = { boolean: detailOptions - .filter( - option => !option.name.startsWith("no-") && option.type === "boolean" - ) + .filter(option => option.type === "boolean") .map(option => option.name), string: detailOptions - .filter( - option => !option.name.startsWith("no-") && option.type !== "boolean" - ) + .filter(option => option.type !== "boolean") .map(option => option.name), default: detailOptions .filter(option => option.default !== undefined) diff --git a/src/cli-util.js b/src/cli-util.js index 1ec627f42..66003f146 100644 --- a/src/cli-util.js +++ b/src/cli-util.js @@ -325,7 +325,7 @@ function formatFiles(argv) { } function createUsage() { - const options = constant.detailOptions.filter(option => !option.hidden); + const options = constant.detailOptions; const groupedOptions = options.reduce((current, option) => { const category = capitalize(option.category); @@ -344,24 +344,29 @@ function createUsage() { categoryOrder.splice(-1, 0, category); } - groupedOptions[category].sort((a, b) => { - const isNoA = a.name.startsWith("no-"); - const originalA = isNoA ? a.name.slice(3) : a.name; - const isNoB = b.name.startsWith("no-"); - const originalB = isNoB ? b.name.slice(3) : b.name; + for (let i = groupedOptions[category].length - 1; i >= 0; i--) { + const option = groupedOptions[category][i]; - return originalA === originalB - ? // put `no-option` after `option` - isNoA - isNoB - : // treat `no-option` as `option` - originalA.localeCompare(originalB); - }); + if (option.oppositeDescription) { + groupedOptions[category].splice( + i + 1, // put `no-option` after `option` + 0, + Object.assign({}, option, { + name: `no-${option.name}`, + type: "boolean", + hidden: false, + description: option.oppositeDescription + }) + ); + } + } }); usage += categoryOrder .map(category => { return `${category} options:\n\n${indent( groupedOptions[category] + .filter(option => !option.hidden) .map(option => createOptionUsage(option, 25)) .join("\n"), 2