forked from OKEAMAH/prettier
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcore-options.evaluate.js
More file actions
218 lines (214 loc) · 7.1 KB
/
core-options.evaluate.js
File metadata and controls
218 lines (214 loc) · 7.1 KB
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
import { outdent } from "outdent";
import {
CATEGORY_CONFIG,
CATEGORY_EDITOR,
CATEGORY_GLOBAL,
CATEGORY_OTHER,
CATEGORY_SPECIAL,
} from "./option-categories.js";
/**
* @typedef {Object} OptionInfo
* @property {string} category
* @property {'int' | 'boolean' | 'choice' | 'path' | 'string' | 'flag'} type
* @property {boolean} [array] - indicate it's an array of the specified type
* @property {OptionValueInfo} [default]
* @property {OptionRangeInfo} [range] - for type int
* @property {string} description
* @property {string} [deprecated] - deprecated since version
* @property {OptionRedirectInfo | string} [redirect] - redirect deprecated option
* @property {(value: any) => boolean} [exception]
* @property {OptionChoiceInfo[]} [choices] - for type choice
* @property {string} [cliName]
* @property {string} [cliCategory]
* @property {string} [cliDescription]
*
* @typedef {number | boolean | string | []} OptionValue
* @typedef {OptionValue | [{ value: OptionValue }]} OptionValueInfo
*
* @typedef {Object} OptionRedirectInfo
* @property {string} option
* @property {OptionValue} value
*
* @typedef {Object} OptionRangeInfo
* @property {number} start - recommended range start
* @property {number} end - recommended range end
* @property {number} step - recommended range step
*
* @typedef {Object} OptionChoiceInfo
* @property {boolean | string} value - boolean for the option that is originally boolean type
* @property {string} description
* @property {string} [deprecated] - deprecated since version
* @property {OptionValueInfo} [redirect] - redirect deprecated value
*/
/** @type {{ [name: string]: OptionInfo }} */
const options = {
cursorOffset: {
category: CATEGORY_SPECIAL,
type: "int",
default: -1,
range: { start: -1, end: Number.POSITIVE_INFINITY, step: 1 },
description:
"Print (to stderr) where a cursor at the given position would move to after formatting.",
cliCategory: CATEGORY_EDITOR,
},
endOfLine: {
category: CATEGORY_GLOBAL,
type: "choice",
default: "lf",
description: "Which end of line characters to apply.",
choices: [
{
value: "lf",
description: String.raw`Line Feed only (\n), common on Linux and macOS as well as inside git repos`,
},
{
value: "crlf",
description: String.raw`Carriage Return + Line Feed characters (\r\n), common on Windows`,
},
{
value: "cr",
description: String.raw`Carriage Return character only (\r), used very rarely`,
},
{
value: "auto",
description: outdent`
Maintain existing
(mixed values within one file are normalised by looking at what's used after the first line)
`,
},
],
},
filepath: {
category: CATEGORY_SPECIAL,
type: "path",
description:
"Specify the input filepath. This will be used to do parser inference.",
cliName: "stdin-filepath",
cliCategory: CATEGORY_OTHER,
cliDescription: "Path to the file to pretend that stdin comes from.",
},
insertPragma: {
category: CATEGORY_SPECIAL,
type: "boolean",
default: false,
description: "Insert @format pragma into file's first docblock comment.",
cliCategory: CATEGORY_OTHER,
},
parser: {
category: CATEGORY_GLOBAL,
type: "choice",
default: undefined,
description: "Which parser to use.",
exception: (value) =>
typeof value === "string" || typeof value === "function",
choices: [
{ value: "flow", description: "Flow" },
{ value: "babel", description: "JavaScript" },
{ value: "babel-flow", description: "Flow" },
{ value: "babel-ts", description: "TypeScript" },
{ value: "typescript", description: "TypeScript" },
{ value: "acorn", description: "JavaScript" },
{ value: "espree", description: "JavaScript" },
{ value: "meriyah", description: "JavaScript" },
{ value: "css", description: "CSS" },
{ value: "less", description: "Less" },
{ value: "scss", description: "SCSS" },
{ value: "json", description: "JSON" },
{ value: "json5", description: "JSON5" },
{ value: "jsonc", description: "JSON with Comments" },
{ value: "json-stringify", description: "JSON.stringify" },
{ value: "graphql", description: "GraphQL" },
{ value: "markdown", description: "Markdown" },
{ value: "mdx", description: "MDX" },
{ value: "vue", description: "Vue" },
{ value: "yaml", description: "YAML" },
{ value: "glimmer", description: "Ember / Handlebars" },
{ value: "html", description: "HTML" },
{ value: "angular", description: "Angular" },
{ value: "lwc", description: "Lightning Web Components" },
],
},
plugins: {
type: "path",
array: true,
default: [{ value: [] }],
category: CATEGORY_GLOBAL,
description:
"Add a plugin. Multiple plugins can be passed as separate `--plugin`s.",
exception: (value) =>
typeof value === "string" || typeof value === "object",
cliName: "plugin",
cliCategory: CATEGORY_CONFIG,
},
printWidth: {
category: CATEGORY_GLOBAL,
type: "int",
default: 80,
description: "The line length where Prettier will try wrap.",
range: { start: 0, end: Number.POSITIVE_INFINITY, step: 1 },
},
rangeEnd: {
category: CATEGORY_SPECIAL,
type: "int",
default: Number.POSITIVE_INFINITY,
range: { start: 0, end: Number.POSITIVE_INFINITY, step: 1 },
description: outdent`
Format code ending at a given character offset (exclusive).
The range will extend forwards to the end of the selected statement.
`,
cliCategory: CATEGORY_EDITOR,
},
rangeStart: {
category: CATEGORY_SPECIAL,
type: "int",
default: 0,
range: { start: 0, end: Number.POSITIVE_INFINITY, step: 1 },
description: outdent`
Format code starting at a given character offset.
The range will extend backwards to the start of the first line containing the selected statement.
`,
cliCategory: CATEGORY_EDITOR,
},
requirePragma: {
category: CATEGORY_SPECIAL,
type: "boolean",
default: false,
description: outdent`
Require either '@prettier' or '@format' to be present in the file's first docblock comment
in order for it to be formatted.
`,
cliCategory: CATEGORY_OTHER,
},
tabWidth: {
type: "int",
category: CATEGORY_GLOBAL,
default: 2,
description: "Number of spaces per indentation level.",
range: { start: 0, end: Number.POSITIVE_INFINITY, step: 1 },
},
useTabs: {
category: CATEGORY_GLOBAL,
type: "boolean",
default: false,
description: "Indent with tabs instead of spaces.",
},
embeddedLanguageFormatting: {
category: CATEGORY_GLOBAL,
type: "choice",
default: "auto",
description:
"Control how Prettier formats quoted code embedded in the file.",
choices: [
{
value: "auto",
description:
"Format embedded code if Prettier can automatically identify it.",
},
{
value: "off",
description: "Never automatically format embedded code.",
},
],
},
};
export default options;