forked from prettier/prettier
/
constant.js
262 lines (256 loc) · 7.93 KB
/
constant.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
"use strict";
const { outdent } = require("outdent");
const { coreOptions } = require("./prettier-internal.js");
const categoryOrder = [
coreOptions.CATEGORY_OUTPUT,
coreOptions.CATEGORY_FORMAT,
coreOptions.CATEGORY_CONFIG,
coreOptions.CATEGORY_EDITOR,
coreOptions.CATEGORY_OTHER,
];
/**
* {
* [optionName]: {
* // The type of the option. For 'choice', see also `choices` below.
* // When passing a type other than the ones listed below, the option is
* // treated as taking any string as argument, and `--option <${type}>` will
* // be displayed in --help.
* type: "boolean" | "choice" | "int" | string;
*
* // Default value to be passed to the minimist option `default`.
* default?: any;
*
* // Alias name to be passed to the minimist option `alias`.
* alias?: string;
*
* // For grouping options by category in --help.
* category?: string;
*
* // Description to be displayed in --help. If omitted, the option won't be
* // shown at all in --help (but see also `oppositeDescription` below).
* description?: string;
*
* // Description for `--no-${name}` to be displayed in --help. If omitted,
* // `--no-${name}` won't be shown.
* oppositeDescription?: string;
*
* // Indicate if this option is simply passed to the API.
* // true: use camelified name as the API option name.
* // string: use this value as the API option name.
* forwardToApi?: boolean | string;
*
* // Indicate that a CLI flag should be an array when forwarded to the API.
* array?: boolean;
*
* // Specify available choices for validation. They will also be displayed
* // in --help as <a|b|c>.
* // Use an object instead of a string if a choice is deprecated and should
* // be treated as `redirect` instead, or if you'd like to add description for
* // the choice.
* choices?: Array<
* | string
* | { value: string, description?: string, deprecated?: boolean, redirect?: string }
* >;
*
* // If the option has a value that is an exception to the regular value
* // constraints, indicate that value here (or use a function for more
* // flexibility).
* exception?: ((value: any) => boolean);
*
* // Indicate that the option is deprecated. Use a string to add an extra
* // message to --help for the option, for example to suggest a replacement
* // option.
* deprecated?: true | string;
* }
* }
*
* Note: The options below are sorted alphabetically.
*/
const options = {
cache: {
default: false,
description: "Only format changed files. Cannot use with --stdin-filepath.",
type: "boolean",
},
"cache-strategy": {
choices: [
{
description: "Use the file metadata such as timestamps as cache keys",
value: "metadata",
},
{
description: "Use the file content as cache keys",
value: "content",
},
],
default: "metadata",
description: "Strategy for the cache to use for detecting changed files.",
type: "choice",
},
check: {
type: "boolean",
category: coreOptions.CATEGORY_OUTPUT,
alias: "c",
description: outdent`
Check if the given files are formatted, print a human-friendly summary
message and paths to unformatted files (see also --list-different).
`,
},
color: {
// The supports-color package (a sub sub dependency) looks directly at
// `process.argv` for `--no-color` and such-like options. The reason it is
// listed here is to avoid "Ignored unknown option: --no-color" warnings.
// See https://github.com/chalk/supports-color/#info for more information.
type: "boolean",
default: true,
description: "Colorize error messages.",
oppositeDescription: "Do not colorize error messages.",
},
config: {
type: "path",
category: coreOptions.CATEGORY_CONFIG,
description:
"Path to a Prettier configuration file (.prettierrc, package.json, prettier.config.js).",
oppositeDescription: "Do not look for a configuration file.",
exception: (value) => value === false,
},
"config-precedence": {
type: "choice",
category: coreOptions.CATEGORY_CONFIG,
default: "cli-override",
choices: [
{
value: "cli-override",
description: "CLI options take precedence over config file",
},
{
value: "file-override",
description: "Config file take precedence over CLI options",
},
{
value: "prefer-file",
description: outdent`
If a config file is found will evaluate it and ignore other CLI options.
If no config file is found CLI options will evaluate as normal.
`,
},
],
description:
"Define in which order config files and CLI options should be evaluated.",
},
"debug-benchmark": {
// Run the formatting benchmarks. Requires 'benchmark' module to be installed.
type: "boolean",
},
"debug-check": {
// Run the formatting once again on the formatted output, throw if different.
type: "boolean",
},
"debug-print-doc": {
type: "boolean",
},
"debug-print-comments": {
type: "boolean",
},
"debug-print-ast": {
type: "boolean",
},
"debug-repeat": {
// Repeat the formatting a few times and measure the average duration.
type: "int",
default: 0,
},
editorconfig: {
type: "boolean",
category: coreOptions.CATEGORY_CONFIG,
description: "Take .editorconfig into account when parsing configuration.",
oppositeDescription:
"Don't take .editorconfig into account when parsing configuration.",
default: true,
},
"error-on-unmatched-pattern": {
type: "boolean",
oppositeDescription: "Prevent errors when pattern is unmatched.",
},
"find-config-path": {
type: "path",
category: coreOptions.CATEGORY_CONFIG,
description:
"Find and print the path to a configuration file for the given input file.",
},
"file-info": {
type: "path",
description: outdent`
Extract the following info (as JSON) for a given file path. Reported fields:
* ignored (boolean) - true if file path is filtered by --ignore-path
* inferredParser (string | null) - name of parser inferred from file path
`,
},
help: {
type: "flag",
alias: "h",
description: outdent`
Show CLI usage, or details about the given flag.
Example: --help write
`,
exception: (value) => value === "",
},
"ignore-path": {
type: "path",
category: coreOptions.CATEGORY_CONFIG,
default: ".prettierignore",
description: "Path to a file with patterns describing files to ignore.",
},
"ignore-unknown": {
type: "boolean",
alias: "u",
description: "Ignore unknown files.",
},
"list-different": {
type: "boolean",
category: coreOptions.CATEGORY_OUTPUT,
alias: "l",
description:
"Print the names of files that are different from Prettier's formatting (see also --check).",
},
loglevel: {
type: "choice",
description: "What level of logs to report.",
default: "log",
choices: ["silent", "error", "warn", "log", "debug"],
},
"plugin-search": {
type: "boolean",
oppositeDescription: "Disable plugin autoloading.",
},
"support-info": {
type: "boolean",
description: "Print support information as JSON.",
},
version: {
type: "boolean",
alias: "v",
description: "Print Prettier version.",
},
"with-node-modules": {
type: "boolean",
category: coreOptions.CATEGORY_CONFIG,
description: "Process files inside 'node_modules' directory.",
},
write: {
type: "boolean",
alias: "w",
category: coreOptions.CATEGORY_OUTPUT,
description: "Edit files in-place. (Beware!)",
},
};
const usageSummary = outdent`
Usage: prettier [options] [file/dir/glob ...]
By default, output is written to stdout.
Stdin is read if it is piped to Prettier and no files are given.
`;
module.exports = {
categoryOrder,
options,
usageSummary,
};