From be22996fd371e4edd545718e429c59142eab22ce Mon Sep 17 00:00:00 2001 From: ikatyang Date: Thu, 7 Sep 2017 13:39:39 +0800 Subject: [PATCH] refactor: sort usages --- src/cli-constant.js | 40 ++++---------- .../__snapshots__/early-exit.js.snap | 53 ++++++++++--------- 2 files changed, 36 insertions(+), 57 deletions(-) diff --git a/src/cli-constant.js b/src/cli-constant.js index d7d8c713..b9c721e6 100644 --- a/src/cli-constant.js +++ b/src/cli-constant.js @@ -188,10 +188,12 @@ const options = { } }; -const optionArray = Object.keys(options).reduce( - (current, name) => current.concat(Object.assign({ name }, options[name])), - [] -); +const optionArray = Object.keys(options) + .sort() + .reduce( + (current, name) => current.concat(Object.assign({ name }, options[name])), + [] + ); const booleanOptionNames = optionArray .filter(option => option.isFormatOption && option.type === "boolean") @@ -241,33 +243,9 @@ Usage: prettier [opts] [filename ...] Available options: ${indent( - [ - "write", - "list-different", - "config", - "config-precedence", - "no-config", - "find-config-path", - "ignore-path", - "stdin", - "stdin-filepath", - "print-width", - "tab-width", - "use-tabs", - "no-semi", - "single-quote", - "no-bracket-spacing", - "jsx-bracket-same-line", - "trailing-comma", - "parser", - "cursor-offset", - "range-start", - "range-end", - "no-color", - "with-node-modules", - "version" - ] - .map(name => createOptionUsage(name, options[name])) + optionArray + .filter(option => !option.isHidden) + .map(option => createOptionUsage(option.name, option)) .join("\n"), 2 )} diff --git a/tests_integration/__tests__/__snapshots__/early-exit.js.snap b/tests_integration/__tests__/__snapshots__/early-exit.js.snap index 6a6c8777..4fa026e8 100644 --- a/tests_integration/__tests__/__snapshots__/early-exit.js.snap +++ b/tests_integration/__tests__/__snapshots__/early-exit.js.snap @@ -4,8 +4,6 @@ exports[`show usage with --help 1`] = ` "Usage: prettier [opts] [filename ...] Available options: - --write Edit the file in-place. (Beware!) - --list-different or -l Print filenames of files that are different from Prettier formatting. --config Path to a prettier configuration file (.prettierrc, package.json, prettier.config.js). --config-precedence Defines how config file should be evaluated in combination of CLI options @@ -14,37 +12,40 @@ Available options: prefer-file | default config => config file (if config file is found) or default config => CLI options (if no config file is found) Defaults to cli-override - --no-config Do not look for a configuration file. - --find-config-path - Finds and prints the path to a configuration file for a given input file. - --ignore-path Path to a file containing patterns that describe files to ignore. - Defaults to ./.prettierignore. - --stdin Read input from stdin. - --stdin-filepath Path to the file used to read from stdin. - --print-width Specify the length of line that the printer will wrap on. Defaults to 80. - --tab-width Specify the number of spaces per indentation-level. Defaults to 2. - --use-tabs Indent lines with tabs instead of spaces. - --no-semi Do not print semicolons, except at the beginning of lines which may need them. - --single-quote Use single quotes instead of double quotes. - --no-bracket-spacing Do not print spaces between brackets. - --jsx-bracket-same-line Put > on the last line instead of at a new line. - --trailing-comma - Print trailing commas wherever possible when multi-line. Defaults to none. - --parser - Specify which parse to use. Defaults to babylon. --cursor-offset Print (to stderr) where a cursor at the given position would move to after formatting. This option cannot be used with --range-start and --range-end - --range-start Format code starting at a given character offset. - The range will extend backwards to the start of the first line containing the selected statement. - This option cannot be used with --cursor-offset. - Defaults to 0. + --find-config-path + Finds and prints the path to a configuration file for a given input file. + --help or -h Show help + --ignore-path Path to a file containing patterns that describe files to ignore. + Defaults to ./.prettierignore. + --jsx-bracket-same-line Put > on the last line instead of at a new line. + --list-different or -l Print filenames of files that are different from Prettier formatting. + --no-bracket-spacing Do not print spaces between brackets. + --no-color Do not colorize error messages. + --no-config Do not look for a configuration file. + --no-semi Do not print semicolons, except at the beginning of lines which may need them. + --parser + Specify which parse to use. Defaults to babylon. + --print-width Specify the length of line that the printer will wrap on. Defaults to 80. --range-end Format code ending at a given character offset (exclusive). The range will extend forwards to the end of the selected statement. This option cannot be used with --cursor-offset. Defaults to Infinity. - --no-color Do not colorize error messages. - --with-node-modules Process files inside 'node_modules' directory. + --range-start Format code starting at a given character offset. + The range will extend backwards to the start of the first line containing the selected statement. + This option cannot be used with --cursor-offset. + Defaults to 0. + --single-quote Use single quotes instead of double quotes. + --stdin Read input from stdin. + --stdin-filepath Path to the file used to read from stdin. + --tab-width Specify the number of spaces per indentation-level. Defaults to 2. + --trailing-comma + Print trailing commas wherever possible when multi-line. Defaults to none. + --use-tabs Indent lines with tabs instead of spaces. --version or -v Print Prettier version. + --with-node-modules Process files inside 'node_modules' directory. + --write Edit the file in-place. (Beware!) "