prettier 3.2.1 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +22 -2
  3. data/README.md +23 -59
  4. data/lib/prettier.rb +7 -5
  5. data/node_modules/prettier/LICENSE +5205 -0
  6. data/node_modules/prettier/README.md +109 -0
  7. data/node_modules/prettier/{bin-prettier.js → bin/prettier.cjs} +10 -5
  8. data/node_modules/prettier/doc.d.ts +240 -0
  9. data/node_modules/prettier/doc.js +1257 -1309
  10. data/node_modules/prettier/doc.mjs +1312 -0
  11. data/node_modules/prettier/index.cjs +655 -0
  12. data/node_modules/prettier/index.d.ts +915 -0
  13. data/node_modules/prettier/index.mjs +21845 -0
  14. data/node_modules/prettier/internal/cli.mjs +6978 -0
  15. data/node_modules/prettier/internal/internal.mjs +6531 -0
  16. data/node_modules/prettier/package.json +179 -6
  17. data/node_modules/prettier/plugins/acorn.d.ts +6 -0
  18. data/node_modules/prettier/plugins/acorn.js +13 -0
  19. data/node_modules/prettier/plugins/acorn.mjs +13 -0
  20. data/node_modules/prettier/plugins/angular.d.ts +8 -0
  21. data/node_modules/prettier/plugins/angular.js +2 -0
  22. data/node_modules/prettier/plugins/angular.mjs +2 -0
  23. data/node_modules/prettier/plugins/babel.d.ts +17 -0
  24. data/node_modules/prettier/plugins/babel.js +16 -0
  25. data/node_modules/prettier/plugins/babel.mjs +16 -0
  26. data/node_modules/prettier/plugins/estree.d.ts +0 -0
  27. data/node_modules/prettier/plugins/estree.js +35 -0
  28. data/node_modules/prettier/plugins/estree.mjs +35 -0
  29. data/node_modules/prettier/plugins/flow.d.ts +5 -0
  30. data/node_modules/prettier/plugins/flow.js +21 -0
  31. data/node_modules/prettier/plugins/flow.mjs +21 -0
  32. data/node_modules/prettier/plugins/glimmer.d.ts +5 -0
  33. data/node_modules/prettier/plugins/glimmer.js +30 -0
  34. data/node_modules/prettier/plugins/glimmer.mjs +30 -0
  35. data/node_modules/prettier/plugins/graphql.d.ts +5 -0
  36. data/node_modules/prettier/plugins/graphql.js +29 -0
  37. data/node_modules/prettier/plugins/graphql.mjs +29 -0
  38. data/node_modules/prettier/plugins/html.d.ts +8 -0
  39. data/node_modules/prettier/plugins/html.js +19 -0
  40. data/node_modules/prettier/plugins/html.mjs +19 -0
  41. data/node_modules/prettier/plugins/markdown.d.ts +7 -0
  42. data/node_modules/prettier/plugins/markdown.js +59 -0
  43. data/node_modules/prettier/plugins/markdown.mjs +59 -0
  44. data/node_modules/prettier/plugins/meriyah.d.ts +5 -0
  45. data/node_modules/prettier/plugins/meriyah.js +5 -0
  46. data/node_modules/prettier/plugins/meriyah.mjs +5 -0
  47. data/node_modules/prettier/plugins/postcss.d.ts +7 -0
  48. data/node_modules/prettier/plugins/postcss.js +52 -0
  49. data/node_modules/prettier/plugins/postcss.mjs +52 -0
  50. data/node_modules/prettier/plugins/typescript.d.ts +5 -0
  51. data/node_modules/prettier/plugins/typescript.js +27 -0
  52. data/node_modules/prettier/plugins/typescript.mjs +27 -0
  53. data/node_modules/prettier/plugins/yaml.d.ts +5 -0
  54. data/node_modules/prettier/plugins/yaml.js +161 -0
  55. data/node_modules/prettier/plugins/yaml.mjs +161 -0
  56. data/node_modules/prettier/standalone.d.ts +33 -0
  57. data/node_modules/prettier/standalone.js +34 -0
  58. data/node_modules/prettier/standalone.mjs +34 -0
  59. data/package.json +15 -10
  60. data/src/plugin.js +210 -14
  61. data/src/server.rb +50 -85
  62. metadata +60 -28
  63. data/CONTRIBUTING.md +0 -185
  64. data/node_modules/prettier/cli.js +0 -15085
  65. data/node_modules/prettier/index.js +0 -37282
  66. data/node_modules/prettier/parser-angular.js +0 -2
  67. data/node_modules/prettier/parser-babel.js +0 -27
  68. data/node_modules/prettier/parser-espree.js +0 -26
  69. data/node_modules/prettier/parser-flow.js +0 -35
  70. data/node_modules/prettier/parser-glimmer.js +0 -27
  71. data/node_modules/prettier/parser-graphql.js +0 -15
  72. data/node_modules/prettier/parser-html.js +0 -36
  73. data/node_modules/prettier/parser-markdown.js +0 -76
  74. data/node_modules/prettier/parser-meriyah.js +0 -19
  75. data/node_modules/prettier/parser-postcss.js +0 -76
  76. data/node_modules/prettier/parser-typescript.js +0 -280
  77. data/node_modules/prettier/parser-yaml.js +0 -150
  78. data/node_modules/prettier/third-party.js +0 -8978
  79. data/src/getInfo.js +0 -23
  80. data/src/netcat.js +0 -13
  81. data/src/parseSync.js +0 -227
@@ -0,0 +1,915 @@
1
+ // Copied from `@types/prettier`
2
+ // https://github.com/DefinitelyTyped/DefinitelyTyped/blob/5bb07fc4b087cb7ee91084afa6fe750551a7bbb1/types/prettier/index.d.ts
3
+
4
+ // Minimum TypeScript Version: 4.2
5
+
6
+ // Add `export {}` here to shut off automatic exporting from index.d.ts. There
7
+ // are quite a few utility types here that don't need to be shipped with the
8
+ // exported module.
9
+ export {};
10
+
11
+ import { builders, printer, utils } from "./doc.js";
12
+
13
+ export namespace doc {
14
+ export { builders, printer, utils };
15
+ }
16
+
17
+ // This utility is here to handle the case where you have an explicit union
18
+ // between string literals and the generic string type. It would normally
19
+ // resolve out to just the string type, but this generic LiteralUnion maintains
20
+ // the intellisense of the original union.
21
+ //
22
+ // It comes from this issue: microsoft/TypeScript#29729:
23
+ // https://github.com/microsoft/TypeScript/issues/29729#issuecomment-700527227
24
+ export type LiteralUnion<T extends U, U = string> =
25
+ | T
26
+ | (Pick<U, never> & { _?: never | undefined });
27
+
28
+ export type AST = any;
29
+ export type Doc = doc.builders.Doc;
30
+
31
+ // The type of elements that make up the given array T.
32
+ type ArrayElement<T> = T extends Array<infer E> ? E : never;
33
+
34
+ // A union of the properties of the given object that are arrays.
35
+ type ArrayProperties<T> = {
36
+ [K in keyof T]: NonNullable<T[K]> extends any[] ? K : never;
37
+ }[keyof T];
38
+
39
+ // A union of the properties of the given array T that can be used to index it.
40
+ // If the array is a tuple, then that's going to be the explicit indices of the
41
+ // array, otherwise it's going to just be number.
42
+ type IndexProperties<T extends { length: number }> = IsTuple<T> extends true
43
+ ? Exclude<Partial<T>["length"], T["length"]>
44
+ : number;
45
+
46
+ // Effectively performing T[P], except that it's telling TypeScript that it's
47
+ // safe to do this for tuples, arrays, or objects.
48
+ type IndexValue<T, P> = T extends any[]
49
+ ? P extends number
50
+ ? T[P]
51
+ : never
52
+ : P extends keyof T
53
+ ? T[P]
54
+ : never;
55
+
56
+ // Determines if an object T is an array like string[] (in which case this
57
+ // evaluates to false) or a tuple like [string] (in which case this evaluates to
58
+ // true).
59
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
60
+ type IsTuple<T> = T extends []
61
+ ? true
62
+ : T extends [infer First, ...infer Remain]
63
+ ? IsTuple<Remain>
64
+ : false;
65
+
66
+ type CallProperties<T> = T extends any[] ? IndexProperties<T> : keyof T;
67
+ type IterProperties<T> = T extends any[]
68
+ ? IndexProperties<T>
69
+ : ArrayProperties<T>;
70
+
71
+ type CallCallback<T, U> = (path: AstPath<T>, index: number, value: any) => U;
72
+ type EachCallback<T> = (
73
+ path: AstPath<ArrayElement<T>>,
74
+ index: number,
75
+ value: any
76
+ ) => void;
77
+ type MapCallback<T, U> = (
78
+ path: AstPath<ArrayElement<T>>,
79
+ index: number,
80
+ value: any
81
+ ) => U;
82
+
83
+ // https://github.com/prettier/prettier/blob/next/src/common/ast-path.js
84
+ export class AstPath<T = any> {
85
+ constructor(value: T);
86
+
87
+ get key(): string | null;
88
+ get index(): number | null;
89
+ get node(): T;
90
+ get parent(): T | null;
91
+ get grandparent(): T | null;
92
+ get isInArray(): boolean;
93
+ get siblings(): T[] | null;
94
+ get next(): T | null;
95
+ get previous(): T | null;
96
+ get isFirst(): boolean;
97
+ get isLast(): boolean;
98
+ get isRoot(): boolean;
99
+ get root(): T;
100
+ get ancestors(): T[];
101
+
102
+ stack: T[];
103
+
104
+ callParent<U>(callback: (path: this) => U, count?: number): U;
105
+
106
+ /**
107
+ * @deprecated Please use `AstPath#key` or `AstPath#index`
108
+ */
109
+ getName(): PropertyKey | null;
110
+
111
+ /**
112
+ * @deprecated Please use `AstPath#node` or `AstPath#siblings`
113
+ */
114
+ getValue(): T;
115
+
116
+ getNode(count?: number): T | null;
117
+
118
+ getParentNode(count?: number): T | null;
119
+
120
+ match(
121
+ ...predicates: Array<
122
+ (node: any, name: string | null, number: number | null) => boolean
123
+ >
124
+ ): boolean;
125
+
126
+ // For each of the tree walk functions (call, each, and map) this provides 5
127
+ // strict type signatures, along with a fallback at the end if you end up
128
+ // calling more than 5 properties deep. This helps a lot with typing because
129
+ // for the majority of cases you're calling fewer than 5 properties, so the
130
+ // tree walk functions have a clearer understanding of what you're doing.
131
+ //
132
+ // Note that resolving these types is somewhat complicated, and it wasn't
133
+ // even supported until TypeScript 4.2 (before it would just say that the
134
+ // type instantiation was excessively deep and possibly infinite).
135
+
136
+ call<U>(callback: CallCallback<T, U>): U;
137
+ call<U, P1 extends CallProperties<T>>(
138
+ callback: CallCallback<IndexValue<T, P1>, U>,
139
+ prop1: P1
140
+ ): U;
141
+ call<U, P1 extends keyof T, P2 extends CallProperties<T[P1]>>(
142
+ callback: CallCallback<IndexValue<IndexValue<T, P1>, P2>, U>,
143
+ prop1: P1,
144
+ prop2: P2
145
+ ): U;
146
+ call<
147
+ U,
148
+ P1 extends keyof T,
149
+ P2 extends CallProperties<T[P1]>,
150
+ P3 extends CallProperties<IndexValue<T[P1], P2>>
151
+ >(
152
+ callback: CallCallback<
153
+ IndexValue<IndexValue<IndexValue<T, P1>, P2>, P3>,
154
+ U
155
+ >,
156
+ prop1: P1,
157
+ prop2: P2,
158
+ prop3: P3
159
+ ): U;
160
+ call<
161
+ U,
162
+ P1 extends keyof T,
163
+ P2 extends CallProperties<T[P1]>,
164
+ P3 extends CallProperties<IndexValue<T[P1], P2>>,
165
+ P4 extends CallProperties<IndexValue<IndexValue<T[P1], P2>, P3>>
166
+ >(
167
+ callback: CallCallback<
168
+ IndexValue<IndexValue<IndexValue<IndexValue<T, P1>, P2>, P3>, P4>,
169
+ U
170
+ >,
171
+ prop1: P1,
172
+ prop2: P2,
173
+ prop3: P3,
174
+ prop4: P4
175
+ ): U;
176
+ call<U, P extends PropertyKey>(
177
+ callback: CallCallback<any, U>,
178
+ prop1: P,
179
+ prop2: P,
180
+ prop3: P,
181
+ prop4: P,
182
+ ...props: P[]
183
+ ): U;
184
+
185
+ each(callback: EachCallback<T>): void;
186
+ each<P1 extends IterProperties<T>>(
187
+ callback: EachCallback<IndexValue<T, P1>>,
188
+ prop1: P1
189
+ ): void;
190
+ each<P1 extends keyof T, P2 extends IterProperties<T[P1]>>(
191
+ callback: EachCallback<IndexValue<IndexValue<T, P1>, P2>>,
192
+ prop1: P1,
193
+ prop2: P2
194
+ ): void;
195
+ each<
196
+ P1 extends keyof T,
197
+ P2 extends IterProperties<T[P1]>,
198
+ P3 extends IterProperties<IndexValue<T[P1], P2>>
199
+ >(
200
+ callback: EachCallback<IndexValue<IndexValue<IndexValue<T, P1>, P2>, P3>>,
201
+ prop1: P1,
202
+ prop2: P2,
203
+ prop3: P3
204
+ ): void;
205
+ each<
206
+ P1 extends keyof T,
207
+ P2 extends IterProperties<T[P1]>,
208
+ P3 extends IterProperties<IndexValue<T[P1], P2>>,
209
+ P4 extends IterProperties<IndexValue<IndexValue<T[P1], P2>, P3>>
210
+ >(
211
+ callback: EachCallback<
212
+ IndexValue<IndexValue<IndexValue<IndexValue<T, P1>, P2>, P3>, P4>
213
+ >,
214
+ prop1: P1,
215
+ prop2: P2,
216
+ prop3: P3,
217
+ prop4: P4
218
+ ): void;
219
+ each(
220
+ callback: EachCallback<any[]>,
221
+ prop1: PropertyKey,
222
+ prop2: PropertyKey,
223
+ prop3: PropertyKey,
224
+ prop4: PropertyKey,
225
+ ...props: PropertyKey[]
226
+ ): void;
227
+
228
+ map<U>(callback: MapCallback<T, U>): U[];
229
+ map<U, P1 extends IterProperties<T>>(
230
+ callback: MapCallback<IndexValue<T, P1>, U>,
231
+ prop1: P1
232
+ ): U[];
233
+ map<U, P1 extends keyof T, P2 extends IterProperties<T[P1]>>(
234
+ callback: MapCallback<IndexValue<IndexValue<T, P1>, P2>, U>,
235
+ prop1: P1,
236
+ prop2: P2
237
+ ): U[];
238
+ map<
239
+ U,
240
+ P1 extends keyof T,
241
+ P2 extends IterProperties<T[P1]>,
242
+ P3 extends IterProperties<IndexValue<T[P1], P2>>
243
+ >(
244
+ callback: MapCallback<IndexValue<IndexValue<IndexValue<T, P1>, P2>, P3>, U>,
245
+ prop1: P1,
246
+ prop2: P2,
247
+ prop3: P3
248
+ ): U[];
249
+ map<
250
+ U,
251
+ P1 extends keyof T,
252
+ P2 extends IterProperties<T[P1]>,
253
+ P3 extends IterProperties<IndexValue<T[P1], P2>>,
254
+ P4 extends IterProperties<IndexValue<IndexValue<T[P1], P2>, P3>>
255
+ >(
256
+ callback: MapCallback<
257
+ IndexValue<IndexValue<IndexValue<IndexValue<T, P1>, P2>, P3>, P4>,
258
+ U
259
+ >,
260
+ prop1: P1,
261
+ prop2: P2,
262
+ prop3: P3,
263
+ prop4: P4
264
+ ): U[];
265
+ map<U>(
266
+ callback: MapCallback<any[], U>,
267
+ prop1: PropertyKey,
268
+ prop2: PropertyKey,
269
+ prop3: PropertyKey,
270
+ prop4: PropertyKey,
271
+ ...props: PropertyKey[]
272
+ ): U[];
273
+ }
274
+
275
+ /** @deprecated `FastPath` was renamed to `AstPath` */
276
+ export type FastPath<T = any> = AstPath<T>;
277
+
278
+ export type BuiltInParser = (text: string, options?: any) => AST;
279
+ export type BuiltInParserName =
280
+ | "acorn"
281
+ | "angular"
282
+ | "babel-flow"
283
+ | "babel-ts"
284
+ | "babel"
285
+ | "css"
286
+ | "espree"
287
+ | "flow"
288
+ | "glimmer"
289
+ | "graphql"
290
+ | "html"
291
+ | "json-stringify"
292
+ | "json"
293
+ | "json5"
294
+ | "less"
295
+ | "lwc"
296
+ | "markdown"
297
+ | "mdx"
298
+ | "meriyah"
299
+ | "scss"
300
+ | "typescript"
301
+ | "vue"
302
+ | "yaml";
303
+ export type BuiltInParsers = Record<BuiltInParserName, BuiltInParser>;
304
+
305
+ export type CustomParser = (
306
+ text: string,
307
+ options: Options
308
+ ) => AST | Promise<AST>;
309
+
310
+ /**
311
+ * For use in `.prettierrc.js`, `.prettierrc.cjs`, `prettierrc.mjs`, `prettier.config.js`, `prettier.config.cjs`, `prettier.config.mjs`
312
+ */
313
+ export interface Config extends Options {
314
+ overrides?: Array<{
315
+ files: string | string[];
316
+ excludeFiles?: string | string[];
317
+ options?: Options;
318
+ }>;
319
+ }
320
+
321
+ export interface Options extends Partial<RequiredOptions> {}
322
+
323
+ export interface RequiredOptions extends doc.printer.Options {
324
+ /**
325
+ * Print semicolons at the ends of statements.
326
+ * @default true
327
+ */
328
+ semi: boolean;
329
+ /**
330
+ * Use single quotes instead of double quotes.
331
+ * @default false
332
+ */
333
+ singleQuote: boolean;
334
+ /**
335
+ * Use single quotes in JSX.
336
+ * @default false
337
+ */
338
+ jsxSingleQuote: boolean;
339
+ /**
340
+ * Print trailing commas wherever possible.
341
+ * @default "all"
342
+ */
343
+ trailingComma: "none" | "es5" | "all";
344
+ /**
345
+ * Print spaces between brackets in object literals.
346
+ * @default true
347
+ */
348
+ bracketSpacing: boolean;
349
+ /**
350
+ * Put the `>` of a multi-line HTML (HTML, JSX, Vue, Angular) element at the end of the last line instead of being
351
+ * alone on the next line (does not apply to self closing elements).
352
+ * @default false
353
+ */
354
+ bracketSameLine: boolean;
355
+ /**
356
+ * Put the `>` of a multi-line JSX element at the end of the last line instead of being alone on the next line.
357
+ * @default false
358
+ * @deprecated use bracketSameLine instead
359
+ */
360
+ jsxBracketSameLine: boolean;
361
+ /**
362
+ * Format only a segment of a file.
363
+ * @default 0
364
+ */
365
+ rangeStart: number;
366
+ /**
367
+ * Format only a segment of a file.
368
+ * @default Number.POSITIVE_INFINITY
369
+ */
370
+ rangeEnd: number;
371
+ /**
372
+ * Specify which parser to use.
373
+ */
374
+ parser: LiteralUnion<BuiltInParserName> | CustomParser;
375
+ /**
376
+ * Specify the input filepath. This will be used to do parser inference.
377
+ */
378
+ filepath: string;
379
+ /**
380
+ * Prettier can restrict itself to only format files that contain a special comment, called a pragma, at the top of the file.
381
+ * This is very useful when gradually transitioning large, unformatted codebases to prettier.
382
+ * @default false
383
+ */
384
+ requirePragma: boolean;
385
+ /**
386
+ * Prettier can insert a special @format marker at the top of files specifying that
387
+ * the file has been formatted with prettier. This works well when used in tandem with
388
+ * the --require-pragma option. If there is already a docblock at the top of
389
+ * the file then this option will add a newline to it with the @format marker.
390
+ * @default false
391
+ */
392
+ insertPragma: boolean;
393
+ /**
394
+ * By default, Prettier will wrap markdown text as-is since some services use a linebreak-sensitive renderer.
395
+ * In some cases you may want to rely on editor/viewer soft wrapping instead, so this option allows you to opt out.
396
+ * @default "preserve"
397
+ */
398
+ proseWrap: "always" | "never" | "preserve";
399
+ /**
400
+ * Include parentheses around a sole arrow function parameter.
401
+ * @default "always"
402
+ */
403
+ arrowParens: "avoid" | "always";
404
+ /**
405
+ * Provide ability to support new languages to prettier.
406
+ */
407
+ plugins: Array<string | Plugin>;
408
+ /**
409
+ * How to handle whitespaces in HTML.
410
+ * @default "css"
411
+ */
412
+ htmlWhitespaceSensitivity: "css" | "strict" | "ignore";
413
+ /**
414
+ * Which end of line characters to apply.
415
+ * @default "lf"
416
+ */
417
+ endOfLine: "auto" | "lf" | "crlf" | "cr";
418
+ /**
419
+ * Change when properties in objects are quoted.
420
+ * @default "as-needed"
421
+ */
422
+ quoteProps: "as-needed" | "consistent" | "preserve";
423
+ /**
424
+ * Whether or not to indent the code inside <script> and <style> tags in Vue files.
425
+ * @default false
426
+ */
427
+ vueIndentScriptAndStyle: boolean;
428
+ /**
429
+ * Control whether Prettier formats quoted code embedded in the file.
430
+ * @default "auto"
431
+ */
432
+ embeddedLanguageFormatting: "auto" | "off";
433
+ /**
434
+ * Enforce single attribute per line in HTML, Vue and JSX.
435
+ * @default false
436
+ */
437
+ singleAttributePerLine: boolean;
438
+ }
439
+
440
+ export interface ParserOptions<T = any> extends RequiredOptions {
441
+ locStart: (node: T) => number;
442
+ locEnd: (node: T) => number;
443
+ originalText: string;
444
+ }
445
+
446
+ export interface Plugin<T = any> {
447
+ languages?: SupportLanguage[] | undefined;
448
+ parsers?: { [parserName: string]: Parser<T> } | undefined;
449
+ printers?: { [astFormat: string]: Printer<T> } | undefined;
450
+ options?: SupportOptions | undefined;
451
+ defaultOptions?: Partial<RequiredOptions> | undefined;
452
+ }
453
+
454
+ export interface Parser<T = any> {
455
+ parse: (text: string, options: ParserOptions<T>) => T | Promise<T>;
456
+ astFormat: string;
457
+ hasPragma?: ((text: string) => boolean) | undefined;
458
+ locStart: (node: T) => number;
459
+ locEnd: (node: T) => number;
460
+ preprocess?:
461
+ | ((text: string, options: ParserOptions<T>) => string)
462
+ | undefined;
463
+ }
464
+
465
+ export interface Printer<T = any> {
466
+ print(
467
+ path: AstPath<T>,
468
+ options: ParserOptions<T>,
469
+ print: (path: AstPath<T>) => Doc,
470
+ args?: unknown
471
+ ): Doc;
472
+ embed?:
473
+ | ((
474
+ path: AstPath,
475
+ options: Options
476
+ ) =>
477
+ | ((
478
+ textToDoc: (text: string, options: Options) => Promise<Doc>,
479
+ print: (
480
+ selector?: string | number | Array<string | number> | AstPath
481
+ ) => Doc,
482
+ path: AstPath,
483
+ options: Options
484
+ ) => Promise<Doc | undefined> | Doc | undefined)
485
+ | Doc
486
+ | null)
487
+ | undefined;
488
+ insertPragma?: (text: string) => string;
489
+ /**
490
+ * @returns `null` if you want to remove this node
491
+ * @returns `void` if you want to use modified newNode
492
+ * @returns anything if you want to replace the node with it
493
+ */
494
+ massageAstNode?: ((node: any, newNode: any, parent: any) => any) | undefined;
495
+ hasPrettierIgnore?: ((path: AstPath<T>) => boolean) | undefined;
496
+ canAttachComment?: ((node: T) => boolean) | undefined;
497
+ isBlockComment?: ((node: T) => boolean) | undefined;
498
+ willPrintOwnComments?: ((path: AstPath<T>) => boolean) | undefined;
499
+ printComment?:
500
+ | ((commentPath: AstPath<T>, options: ParserOptions<T>) => Doc)
501
+ | undefined;
502
+ /**
503
+ * By default, Prettier searches all object properties (except for a few predefined ones) of each node recursively.
504
+ * This function can be provided to override that behavior.
505
+ * @param node The node whose children should be returned.
506
+ * @param options Current options.
507
+ * @returns `[]` if the node has no children or `undefined` to fall back on the default behavior.
508
+ */
509
+ getCommentChildNodes?:
510
+ | ((node: T, options: ParserOptions<T>) => T[] | undefined)
511
+ | undefined;
512
+ handleComments?:
513
+ | {
514
+ ownLine?:
515
+ | ((
516
+ commentNode: any,
517
+ text: string,
518
+ options: ParserOptions<T>,
519
+ ast: T,
520
+ isLastComment: boolean
521
+ ) => boolean)
522
+ | undefined;
523
+ endOfLine?:
524
+ | ((
525
+ commentNode: any,
526
+ text: string,
527
+ options: ParserOptions<T>,
528
+ ast: T,
529
+ isLastComment: boolean
530
+ ) => boolean)
531
+ | undefined;
532
+ remaining?:
533
+ | ((
534
+ commentNode: any,
535
+ text: string,
536
+ options: ParserOptions<T>,
537
+ ast: T,
538
+ isLastComment: boolean
539
+ ) => boolean)
540
+ | undefined;
541
+ }
542
+ | undefined;
543
+ }
544
+
545
+ export interface CursorOptions extends Options {
546
+ /**
547
+ * Specify where the cursor is.
548
+ */
549
+ cursorOffset: number;
550
+ rangeStart?: never;
551
+ rangeEnd?: never;
552
+ }
553
+
554
+ export interface CursorResult {
555
+ formatted: string;
556
+ cursorOffset: number;
557
+ }
558
+
559
+ /**
560
+ * `format` is used to format text using Prettier. [Options](https://prettier.io/docs/en/options.html) may be provided to override the defaults.
561
+ */
562
+ export function format(source: string, options?: Options): Promise<string>;
563
+
564
+ /**
565
+ * `check` checks to see if the file has been formatted with Prettier given those options and returns a `Boolean`.
566
+ * This is similar to the `--list-different` parameter in the CLI and is useful for running Prettier in CI scenarios.
567
+ */
568
+ export function check(source: string, options?: Options): Promise<boolean>;
569
+
570
+ /**
571
+ * `formatWithCursor` both formats the code, and translates a cursor position from unformatted code to formatted code.
572
+ * This is useful for editor integrations, to prevent the cursor from moving when code is formatted.
573
+ *
574
+ * The `cursorOffset` option should be provided, to specify where the cursor is. This option cannot be used with `rangeStart` and `rangeEnd`.
575
+ */
576
+ export function formatWithCursor(
577
+ source: string,
578
+ options: CursorOptions
579
+ ): Promise<CursorResult>;
580
+
581
+ export function formatAST(ast: any, options?: Options): Promise<string>;
582
+
583
+ export interface ResolveConfigOptions {
584
+ /**
585
+ * If set to `false`, all caching will be bypassed.
586
+ */
587
+ useCache?: boolean | undefined;
588
+ /**
589
+ * Pass directly the path of the config file if you don't wish to search for it.
590
+ */
591
+ config?: string | undefined;
592
+ /**
593
+ * If set to `true` and an `.editorconfig` file is in your project,
594
+ * Prettier will parse it and convert its properties to the corresponding prettier configuration.
595
+ * This configuration will be overridden by `.prettierrc`, etc. Currently,
596
+ * the following EditorConfig properties are supported:
597
+ * - indent_style
598
+ * - indent_size/tab_width
599
+ * - max_line_length
600
+ */
601
+ editorconfig?: boolean | undefined;
602
+ }
603
+
604
+ /**
605
+ * `resolveConfig` can be used to resolve configuration for a given source file,
606
+ * passing its path as the first argument. The config search will start at the
607
+ * file path and continue to search up the directory.
608
+ * (You can use `process.cwd()` to start searching from the current directory).
609
+ *
610
+ * A promise is returned which will resolve to:
611
+ *
612
+ * - An options object, providing a [config file](https://prettier.io/docs/en/configuration.html) was found.
613
+ * - `null`, if no file was found.
614
+ *
615
+ * The promise will be rejected if there was an error parsing the configuration file.
616
+ */
617
+ export function resolveConfig(
618
+ filePath: string,
619
+ options?: ResolveConfigOptions
620
+ ): Promise<Options | null>;
621
+
622
+ /**
623
+ * `resolveConfigFile` can be used to find the path of the Prettier configuration file,
624
+ * that will be used when resolving the config (i.e. when calling `resolveConfig`).
625
+ *
626
+ * A promise is returned which will resolve to:
627
+ *
628
+ * - The path of the configuration file.
629
+ * - `null`, if no file was found.
630
+ *
631
+ * The promise will be rejected if there was an error parsing the configuration file.
632
+ */
633
+ export function resolveConfigFile(filePath?: string): Promise<string | null>;
634
+
635
+ /**
636
+ * As you repeatedly call `resolveConfig`, the file system structure will be cached for performance. This function will clear the cache.
637
+ * Generally this is only needed for editor integrations that know that the file system has changed since the last format took place.
638
+ */
639
+ export function clearConfigCache(): Promise<void>;
640
+
641
+ export interface SupportLanguage {
642
+ name: string;
643
+ since?: string | undefined;
644
+ parsers: BuiltInParserName[] | string[];
645
+ group?: string | undefined;
646
+ tmScope?: string | undefined;
647
+ aceMode?: string | undefined;
648
+ codemirrorMode?: string | undefined;
649
+ codemirrorMimeType?: string | undefined;
650
+ aliases?: string[] | undefined;
651
+ extensions?: string[] | undefined;
652
+ filenames?: string[] | undefined;
653
+ linguistLanguageId?: number | undefined;
654
+ vscodeLanguageIds?: string[] | undefined;
655
+ interpreters?: string[] | undefined;
656
+ }
657
+
658
+ export interface SupportOptionRange {
659
+ start: number;
660
+ end: number;
661
+ step: number;
662
+ }
663
+
664
+ export type SupportOptionType =
665
+ | "int"
666
+ | "string"
667
+ | "boolean"
668
+ | "choice"
669
+ | "path";
670
+
671
+ export type CoreCategoryType =
672
+ | "Config"
673
+ | "Editor"
674
+ | "Format"
675
+ | "Other"
676
+ | "Output"
677
+ | "Global"
678
+ | "Special";
679
+
680
+ export interface BaseSupportOption<Type extends SupportOptionType> {
681
+ readonly name?: string | undefined;
682
+ /**
683
+ * Usually you can use {@link CoreCategoryType}
684
+ */
685
+ category: string;
686
+ /**
687
+ * The type of the option.
688
+ *
689
+ * When passing a type other than the ones listed below, the option is
690
+ * treated as taking any string as argument, and `--option <${type}>` will
691
+ * be displayed in --help.
692
+ */
693
+ type: Type;
694
+ /**
695
+ * Indicate that the option is deprecated.
696
+ *
697
+ * Use a string to add an extra message to --help for the option,
698
+ * for example to suggest a replacement option.
699
+ */
700
+ deprecated?: true | string | undefined;
701
+ /**
702
+ * Description to be displayed in --help. If omitted, the option won't be
703
+ * shown at all in --help.
704
+ */
705
+ description?: string | undefined;
706
+ }
707
+
708
+ export interface IntSupportOption extends BaseSupportOption<"int"> {
709
+ default?: number | undefined;
710
+ array?: false | undefined;
711
+ range?: SupportOptionRange | undefined;
712
+ }
713
+
714
+ export interface IntArraySupportOption extends BaseSupportOption<"int"> {
715
+ default?: Array<{ value: number[] }> | undefined;
716
+ array: true;
717
+ }
718
+
719
+ export interface StringSupportOption extends BaseSupportOption<"string"> {
720
+ default?: string | undefined;
721
+ array?: false | undefined;
722
+ }
723
+
724
+ export interface StringArraySupportOption extends BaseSupportOption<"string"> {
725
+ default?: Array<{ value: string[] }> | undefined;
726
+ array: true;
727
+ }
728
+
729
+ export interface BooleanSupportOption extends BaseSupportOption<"boolean"> {
730
+ default?: boolean | undefined;
731
+ array?: false | undefined;
732
+ description: string;
733
+ oppositeDescription?: string | undefined;
734
+ }
735
+
736
+ export interface BooleanArraySupportOption
737
+ extends BaseSupportOption<"boolean"> {
738
+ default?: Array<{ value: boolean[] }> | undefined;
739
+ array: true;
740
+ }
741
+
742
+ export interface ChoiceSupportOption<Value = any>
743
+ extends BaseSupportOption<"choice"> {
744
+ default?: Value | Array<{ value: Value }> | undefined;
745
+ description: string;
746
+ choices: Array<{
747
+ since?: string | undefined;
748
+ value: Value;
749
+ description: string;
750
+ }>;
751
+ }
752
+
753
+ export interface PathSupportOption extends BaseSupportOption<"path"> {
754
+ default?: string | undefined;
755
+ array?: false | undefined;
756
+ }
757
+
758
+ export interface PathArraySupportOption extends BaseSupportOption<"path"> {
759
+ default?: Array<{ value: string[] }> | undefined;
760
+ array: true;
761
+ }
762
+
763
+ export type SupportOption =
764
+ | IntSupportOption
765
+ | IntArraySupportOption
766
+ | StringSupportOption
767
+ | StringArraySupportOption
768
+ | BooleanSupportOption
769
+ | BooleanArraySupportOption
770
+ | ChoiceSupportOption
771
+ | PathSupportOption
772
+ | PathArraySupportOption;
773
+
774
+ export interface SupportOptions extends Record<string, SupportOption> {}
775
+
776
+ export interface SupportInfo {
777
+ languages: SupportLanguage[];
778
+ options: SupportOption[];
779
+ }
780
+
781
+ export interface FileInfoOptions {
782
+ ignorePath?: string | string[] | undefined;
783
+ withNodeModules?: boolean | undefined;
784
+ plugins?: string[] | undefined;
785
+ resolveConfig?: boolean | undefined;
786
+ }
787
+
788
+ export interface FileInfoResult {
789
+ ignored: boolean;
790
+ inferredParser: string | null;
791
+ }
792
+
793
+ export function getFileInfo(
794
+ filePath: string,
795
+ options?: FileInfoOptions
796
+ ): Promise<FileInfoResult>;
797
+
798
+ /**
799
+ * Returns an object representing the parsers, languages and file types Prettier supports for the current version.
800
+ */
801
+ export function getSupportInfo(): Promise<SupportInfo>;
802
+
803
+ /**
804
+ * `version` field in `package.json`
805
+ */
806
+ export const version: string;
807
+
808
+ // https://github.com/prettier/prettier/blob/next/src/utils/public.js
809
+ export namespace util {
810
+ interface SkipOptions {
811
+ backwards?: boolean | undefined;
812
+ }
813
+
814
+ type Quote = "'" | '"';
815
+
816
+ function getMaxContinuousCount(text: string, searchString: string): number;
817
+
818
+ function getStringWidth(text: string): number;
819
+
820
+ function getAlignmentSize(
821
+ text: string,
822
+ tabWidth: number,
823
+ startIndex?: number | undefined
824
+ ): number;
825
+
826
+ function getIndentSize(value: string, tabWidth: number): number;
827
+
828
+ function skipNewline(
829
+ text: string,
830
+ startIndex: number | false,
831
+ options?: SkipOptions | undefined
832
+ ): number | false;
833
+
834
+ function skipInlineComment(
835
+ text: string,
836
+ startIndex: number | false
837
+ ): number | false;
838
+
839
+ function skipTrailingComment(
840
+ text: string,
841
+ startIndex: number | false
842
+ ): number | false;
843
+
844
+ function skipTrailingComment(
845
+ text: string,
846
+ startIndex: number | false
847
+ ): number | false;
848
+
849
+ function hasNewline(
850
+ text: string,
851
+ startIndex: number,
852
+ options?: SkipOptions | undefined
853
+ ): boolean;
854
+
855
+ function hasNewlineInRange(
856
+ text: string,
857
+ startIndex: number,
858
+ endIndex: number
859
+ ): boolean;
860
+
861
+ function hasSpaces(
862
+ text: string,
863
+ startIndex: number,
864
+ options?: SkipOptions | undefined
865
+ ): boolean;
866
+
867
+ function getNextNonSpaceNonCommentCharacter(
868
+ text: string,
869
+ startIndex: number
870
+ ): string;
871
+
872
+ function makeString(
873
+ rawText: string,
874
+ enclosingQuote: Quote,
875
+ unescapeUnnecessaryEscapes?: boolean | undefined
876
+ ): string;
877
+
878
+ function skip(
879
+ characters: string | RegExp
880
+ ): (
881
+ text: string,
882
+ startIndex: number | false,
883
+ options?: SkipOptions
884
+ ) => number | false;
885
+
886
+ const skipWhitespace: (
887
+ text: string,
888
+ startIndex: number | false,
889
+ options?: SkipOptions
890
+ ) => number | false;
891
+
892
+ const skipSpaces: (
893
+ text: string,
894
+ startIndex: number | false,
895
+ options?: SkipOptions
896
+ ) => number | false;
897
+
898
+ const skipToLineEnd: (
899
+ text: string,
900
+ startIndex: number | false,
901
+ options?: SkipOptions
902
+ ) => number | false;
903
+
904
+ const skipEverythingButNewLine: (
905
+ text: string,
906
+ startIndex: number | false,
907
+ options?: SkipOptions
908
+ ) => number | false;
909
+
910
+ function addLeadingComment(node: any, comment: any): void;
911
+
912
+ function addDanglingComment(node: any, comment: any, marker: any): void;
913
+
914
+ function addTrailingComment(node: any, comment: any): void;
915
+ }