prettier 4.0.2 → 4.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -1
  3. data/README.md +12 -1
  4. data/node_modules/prettier/LICENSE +227 -408
  5. data/node_modules/prettier/README.md +3 -3
  6. data/node_modules/prettier/bin/prettier.cjs +3 -2
  7. data/node_modules/prettier/doc.d.ts +10 -7
  8. data/node_modules/prettier/doc.js +17 -29
  9. data/node_modules/prettier/doc.mjs +12 -24
  10. data/node_modules/prettier/index.cjs +22 -29
  11. data/node_modules/prettier/index.d.ts +76 -68
  12. data/node_modules/prettier/index.mjs +16274 -13541
  13. data/node_modules/prettier/internal/cli.mjs +388 -79
  14. data/node_modules/prettier/package.json +7 -3
  15. data/node_modules/prettier/plugins/acorn.js +12 -12
  16. data/node_modules/prettier/plugins/acorn.mjs +12 -12
  17. data/node_modules/prettier/plugins/angular.js +1 -2
  18. data/node_modules/prettier/plugins/angular.mjs +1 -2
  19. data/node_modules/prettier/plugins/babel.js +11 -11
  20. data/node_modules/prettier/plugins/babel.mjs +11 -11
  21. data/node_modules/prettier/plugins/estree.d.ts +1 -0
  22. data/node_modules/prettier/plugins/estree.js +26 -26
  23. data/node_modules/prettier/plugins/estree.mjs +26 -26
  24. data/node_modules/prettier/plugins/flow.js +17 -17
  25. data/node_modules/prettier/plugins/flow.mjs +17 -17
  26. data/node_modules/prettier/plugins/glimmer.js +22 -22
  27. data/node_modules/prettier/plugins/glimmer.mjs +22 -22
  28. data/node_modules/prettier/plugins/graphql.js +9 -9
  29. data/node_modules/prettier/plugins/graphql.mjs +9 -9
  30. data/node_modules/prettier/plugins/html.js +17 -17
  31. data/node_modules/prettier/plugins/html.mjs +17 -17
  32. data/node_modules/prettier/plugins/markdown.js +46 -46
  33. data/node_modules/prettier/plugins/markdown.mjs +46 -46
  34. data/node_modules/prettier/plugins/meriyah.js +5 -5
  35. data/node_modules/prettier/plugins/meriyah.mjs +5 -5
  36. data/node_modules/prettier/plugins/postcss.js +28 -28
  37. data/node_modules/prettier/plugins/postcss.mjs +28 -28
  38. data/node_modules/prettier/plugins/typescript.js +20 -22
  39. data/node_modules/prettier/plugins/typescript.mjs +20 -22
  40. data/node_modules/prettier/plugins/yaml.js +38 -38
  41. data/node_modules/prettier/plugins/yaml.mjs +39 -39
  42. data/node_modules/prettier/standalone.d.ts +2 -2
  43. data/node_modules/prettier/standalone.js +31 -31
  44. data/node_modules/prettier/standalone.mjs +31 -31
  45. data/package.json +4 -4
  46. data/src/plugin.js +13 -5
  47. data/src/server.rb +8 -3
  48. metadata +2 -3
  49. data/node_modules/prettier/internal/internal.mjs +0 -6531
@@ -33,7 +33,7 @@ type ArrayElement<T> = T extends Array<infer E> ? E : never;
33
33
 
34
34
  // A union of the properties of the given object that are arrays.
35
35
  type ArrayProperties<T> = {
36
- [K in keyof T]: NonNullable<T[K]> extends any[] ? K : never;
36
+ [K in keyof T]: NonNullable<T[K]> extends readonly any[] ? K : never;
37
37
  }[keyof T];
38
38
 
39
39
  // A union of the properties of the given array T that can be used to index it.
@@ -50,8 +50,8 @@ type IndexValue<T, P> = T extends any[]
50
50
  ? T[P]
51
51
  : never
52
52
  : P extends keyof T
53
- ? T[P]
54
- : never;
53
+ ? T[P]
54
+ : never;
55
55
 
56
56
  // Determines if an object T is an array like string[] (in which case this
57
57
  // evaluates to false) or a tuple like [string] (in which case this evaluates to
@@ -60,8 +60,8 @@ type IndexValue<T, P> = T extends any[]
60
60
  type IsTuple<T> = T extends []
61
61
  ? true
62
62
  : T extends [infer First, ...infer Remain]
63
- ? IsTuple<Remain>
64
- : false;
63
+ ? IsTuple<Remain>
64
+ : false;
65
65
 
66
66
  type CallProperties<T> = T extends any[] ? IndexProperties<T> : keyof T;
67
67
  type IterProperties<T> = T extends any[]
@@ -72,12 +72,12 @@ type CallCallback<T, U> = (path: AstPath<T>, index: number, value: any) => U;
72
72
  type EachCallback<T> = (
73
73
  path: AstPath<ArrayElement<T>>,
74
74
  index: number,
75
- value: any
75
+ value: any,
76
76
  ) => void;
77
77
  type MapCallback<T, U> = (
78
78
  path: AstPath<ArrayElement<T>>,
79
79
  index: number,
80
- value: any
80
+ value: any,
81
81
  ) => U;
82
82
 
83
83
  // https://github.com/prettier/prettier/blob/next/src/common/ast-path.js
@@ -136,18 +136,18 @@ export class AstPath<T = any> {
136
136
  call<U>(callback: CallCallback<T, U>): U;
137
137
  call<U, P1 extends CallProperties<T>>(
138
138
  callback: CallCallback<IndexValue<T, P1>, U>,
139
- prop1: P1
139
+ prop1: P1,
140
140
  ): U;
141
141
  call<U, P1 extends keyof T, P2 extends CallProperties<T[P1]>>(
142
142
  callback: CallCallback<IndexValue<IndexValue<T, P1>, P2>, U>,
143
143
  prop1: P1,
144
- prop2: P2
144
+ prop2: P2,
145
145
  ): U;
146
146
  call<
147
147
  U,
148
148
  P1 extends keyof T,
149
149
  P2 extends CallProperties<T[P1]>,
150
- P3 extends CallProperties<IndexValue<T[P1], P2>>
150
+ P3 extends CallProperties<IndexValue<T[P1], P2>>,
151
151
  >(
152
152
  callback: CallCallback<
153
153
  IndexValue<IndexValue<IndexValue<T, P1>, P2>, P3>,
@@ -155,14 +155,14 @@ export class AstPath<T = any> {
155
155
  >,
156
156
  prop1: P1,
157
157
  prop2: P2,
158
- prop3: P3
158
+ prop3: P3,
159
159
  ): U;
160
160
  call<
161
161
  U,
162
162
  P1 extends keyof T,
163
163
  P2 extends CallProperties<T[P1]>,
164
164
  P3 extends CallProperties<IndexValue<T[P1], P2>>,
165
- P4 extends CallProperties<IndexValue<IndexValue<T[P1], P2>, P3>>
165
+ P4 extends CallProperties<IndexValue<IndexValue<T[P1], P2>, P3>>,
166
166
  >(
167
167
  callback: CallCallback<
168
168
  IndexValue<IndexValue<IndexValue<IndexValue<T, P1>, P2>, P3>, P4>,
@@ -171,7 +171,7 @@ export class AstPath<T = any> {
171
171
  prop1: P1,
172
172
  prop2: P2,
173
173
  prop3: P3,
174
- prop4: P4
174
+ prop4: P4,
175
175
  ): U;
176
176
  call<U, P extends PropertyKey>(
177
177
  callback: CallCallback<any, U>,
@@ -185,28 +185,28 @@ export class AstPath<T = any> {
185
185
  each(callback: EachCallback<T>): void;
186
186
  each<P1 extends IterProperties<T>>(
187
187
  callback: EachCallback<IndexValue<T, P1>>,
188
- prop1: P1
188
+ prop1: P1,
189
189
  ): void;
190
190
  each<P1 extends keyof T, P2 extends IterProperties<T[P1]>>(
191
191
  callback: EachCallback<IndexValue<IndexValue<T, P1>, P2>>,
192
192
  prop1: P1,
193
- prop2: P2
193
+ prop2: P2,
194
194
  ): void;
195
195
  each<
196
196
  P1 extends keyof T,
197
197
  P2 extends IterProperties<T[P1]>,
198
- P3 extends IterProperties<IndexValue<T[P1], P2>>
198
+ P3 extends IterProperties<IndexValue<T[P1], P2>>,
199
199
  >(
200
200
  callback: EachCallback<IndexValue<IndexValue<IndexValue<T, P1>, P2>, P3>>,
201
201
  prop1: P1,
202
202
  prop2: P2,
203
- prop3: P3
203
+ prop3: P3,
204
204
  ): void;
205
205
  each<
206
206
  P1 extends keyof T,
207
207
  P2 extends IterProperties<T[P1]>,
208
208
  P3 extends IterProperties<IndexValue<T[P1], P2>>,
209
- P4 extends IterProperties<IndexValue<IndexValue<T[P1], P2>, P3>>
209
+ P4 extends IterProperties<IndexValue<IndexValue<T[P1], P2>, P3>>,
210
210
  >(
211
211
  callback: EachCallback<
212
212
  IndexValue<IndexValue<IndexValue<IndexValue<T, P1>, P2>, P3>, P4>
@@ -214,7 +214,7 @@ export class AstPath<T = any> {
214
214
  prop1: P1,
215
215
  prop2: P2,
216
216
  prop3: P3,
217
- prop4: P4
217
+ prop4: P4,
218
218
  ): void;
219
219
  each(
220
220
  callback: EachCallback<any[]>,
@@ -228,30 +228,30 @@ export class AstPath<T = any> {
228
228
  map<U>(callback: MapCallback<T, U>): U[];
229
229
  map<U, P1 extends IterProperties<T>>(
230
230
  callback: MapCallback<IndexValue<T, P1>, U>,
231
- prop1: P1
231
+ prop1: P1,
232
232
  ): U[];
233
233
  map<U, P1 extends keyof T, P2 extends IterProperties<T[P1]>>(
234
234
  callback: MapCallback<IndexValue<IndexValue<T, P1>, P2>, U>,
235
235
  prop1: P1,
236
- prop2: P2
236
+ prop2: P2,
237
237
  ): U[];
238
238
  map<
239
239
  U,
240
240
  P1 extends keyof T,
241
241
  P2 extends IterProperties<T[P1]>,
242
- P3 extends IterProperties<IndexValue<T[P1], P2>>
242
+ P3 extends IterProperties<IndexValue<T[P1], P2>>,
243
243
  >(
244
244
  callback: MapCallback<IndexValue<IndexValue<IndexValue<T, P1>, P2>, P3>, U>,
245
245
  prop1: P1,
246
246
  prop2: P2,
247
- prop3: P3
247
+ prop3: P3,
248
248
  ): U[];
249
249
  map<
250
250
  U,
251
251
  P1 extends keyof T,
252
252
  P2 extends IterProperties<T[P1]>,
253
253
  P3 extends IterProperties<IndexValue<T[P1], P2>>,
254
- P4 extends IterProperties<IndexValue<IndexValue<T[P1], P2>, P3>>
254
+ P4 extends IterProperties<IndexValue<IndexValue<T[P1], P2>, P3>>,
255
255
  >(
256
256
  callback: MapCallback<
257
257
  IndexValue<IndexValue<IndexValue<IndexValue<T, P1>, P2>, P3>, P4>,
@@ -260,7 +260,7 @@ export class AstPath<T = any> {
260
260
  prop1: P1,
261
261
  prop2: P2,
262
262
  prop3: P3,
263
- prop4: P4
263
+ prop4: P4,
264
264
  ): U[];
265
265
  map<U>(
266
266
  callback: MapCallback<any[], U>,
@@ -302,11 +302,6 @@ export type BuiltInParserName =
302
302
  | "yaml";
303
303
  export type BuiltInParsers = Record<BuiltInParserName, BuiltInParser>;
304
304
 
305
- export type CustomParser = (
306
- text: string,
307
- options: Options
308
- ) => AST | Promise<AST>;
309
-
310
305
  /**
311
306
  * For use in `.prettierrc.js`, `.prettierrc.cjs`, `prettierrc.mjs`, `prettier.config.js`, `prettier.config.cjs`, `prettier.config.mjs`
312
307
  */
@@ -371,7 +366,7 @@ export interface RequiredOptions extends doc.printer.Options {
371
366
  /**
372
367
  * Specify which parser to use.
373
368
  */
374
- parser: LiteralUnion<BuiltInParserName> | CustomParser;
369
+ parser: LiteralUnion<BuiltInParserName>;
375
370
  /**
376
371
  * Specify the input filepath. This will be used to do parser inference.
377
372
  */
@@ -467,24 +462,27 @@ export interface Printer<T = any> {
467
462
  path: AstPath<T>,
468
463
  options: ParserOptions<T>,
469
464
  print: (path: AstPath<T>) => Doc,
470
- args?: unknown
465
+ args?: unknown,
471
466
  ): Doc;
472
467
  embed?:
473
468
  | ((
474
469
  path: AstPath,
475
- options: Options
470
+ options: Options,
476
471
  ) =>
477
472
  | ((
478
473
  textToDoc: (text: string, options: Options) => Promise<Doc>,
479
474
  print: (
480
- selector?: string | number | Array<string | number> | AstPath
475
+ selector?: string | number | Array<string | number> | AstPath,
481
476
  ) => Doc,
482
477
  path: AstPath,
483
- options: Options
478
+ options: Options,
484
479
  ) => Promise<Doc | undefined> | Doc | undefined)
485
480
  | Doc
486
481
  | null)
487
482
  | undefined;
483
+ preprocess?:
484
+ | ((ast: T, options: ParserOptions<T>) => T | Promise<T>)
485
+ | undefined;
488
486
  insertPragma?: (text: string) => string;
489
487
  /**
490
488
  * @returns `null` if you want to remove this node
@@ -517,7 +515,7 @@ export interface Printer<T = any> {
517
515
  text: string,
518
516
  options: ParserOptions<T>,
519
517
  ast: T,
520
- isLastComment: boolean
518
+ isLastComment: boolean,
521
519
  ) => boolean)
522
520
  | undefined;
523
521
  endOfLine?:
@@ -526,7 +524,7 @@ export interface Printer<T = any> {
526
524
  text: string,
527
525
  options: ParserOptions<T>,
528
526
  ast: T,
529
- isLastComment: boolean
527
+ isLastComment: boolean,
530
528
  ) => boolean)
531
529
  | undefined;
532
530
  remaining?:
@@ -535,11 +533,14 @@ export interface Printer<T = any> {
535
533
  text: string,
536
534
  options: ParserOptions<T>,
537
535
  ast: T,
538
- isLastComment: boolean
536
+ isLastComment: boolean,
539
537
  ) => boolean)
540
538
  | undefined;
541
539
  }
542
540
  | undefined;
541
+ getVisitorKeys?:
542
+ | ((node: T, nonTraversableKeys: Set<string>) => string[])
543
+ | undefined;
543
544
  }
544
545
 
545
546
  export interface CursorOptions extends Options {
@@ -547,8 +548,6 @@ export interface CursorOptions extends Options {
547
548
  * Specify where the cursor is.
548
549
  */
549
550
  cursorOffset: number;
550
- rangeStart?: never;
551
- rangeEnd?: never;
552
551
  }
553
552
 
554
553
  export interface CursorResult {
@@ -571,15 +570,13 @@ export function check(source: string, options?: Options): Promise<boolean>;
571
570
  * `formatWithCursor` both formats the code, and translates a cursor position from unformatted code to formatted code.
572
571
  * This is useful for editor integrations, to prevent the cursor from moving when code is formatted.
573
572
  *
574
- * The `cursorOffset` option should be provided, to specify where the cursor is. This option cannot be used with `rangeStart` and `rangeEnd`.
573
+ * The `cursorOffset` option should be provided, to specify where the cursor is.
575
574
  */
576
575
  export function formatWithCursor(
577
576
  source: string,
578
- options: CursorOptions
577
+ options: CursorOptions,
579
578
  ): Promise<CursorResult>;
580
579
 
581
- export function formatAST(ast: any, options?: Options): Promise<string>;
582
-
583
580
  export interface ResolveConfigOptions {
584
581
  /**
585
582
  * If set to `false`, all caching will be bypassed.
@@ -603,8 +600,8 @@ export interface ResolveConfigOptions {
603
600
 
604
601
  /**
605
602
  * `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.
603
+ * passing its path or url as the first argument. The config search will start at
604
+ * the file location and continue to search up the directory.
608
605
  * (You can use `process.cwd()` to start searching from the current directory).
609
606
  *
610
607
  * A promise is returned which will resolve to:
@@ -615,8 +612,8 @@ export interface ResolveConfigOptions {
615
612
  * The promise will be rejected if there was an error parsing the configuration file.
616
613
  */
617
614
  export function resolveConfig(
618
- filePath: string,
619
- options?: ResolveConfigOptions
615
+ fileUrlOrPath: string | URL,
616
+ options?: ResolveConfigOptions,
620
617
  ): Promise<Options | null>;
621
618
 
622
619
  /**
@@ -630,7 +627,9 @@ export function resolveConfig(
630
627
  *
631
628
  * The promise will be rejected if there was an error parsing the configuration file.
632
629
  */
633
- export function resolveConfigFile(filePath?: string): Promise<string | null>;
630
+ export function resolveConfigFile(
631
+ fileUrlOrPath?: string | URL,
632
+ ): Promise<string | null>;
634
633
 
635
634
  /**
636
635
  * As you repeatedly call `resolveConfig`, the file system structure will be cached for performance. This function will clear the cache.
@@ -779,7 +778,7 @@ export interface SupportInfo {
779
778
  }
780
779
 
781
780
  export interface FileInfoOptions {
782
- ignorePath?: string | string[] | undefined;
781
+ ignorePath?: string | URL | (string | URL)[] | undefined;
783
782
  withNodeModules?: boolean | undefined;
784
783
  plugins?: string[] | undefined;
785
784
  resolveConfig?: boolean | undefined;
@@ -791,8 +790,8 @@ export interface FileInfoResult {
791
790
  }
792
791
 
793
792
  export function getFileInfo(
794
- filePath: string,
795
- options?: FileInfoOptions
793
+ file: string | URL,
794
+ options?: FileInfoOptions,
796
795
  ): Promise<FileInfoResult>;
797
796
 
798
797
  /**
@@ -820,7 +819,7 @@ export namespace util {
820
819
  function getAlignmentSize(
821
820
  text: string,
822
821
  tabWidth: number,
823
- startIndex?: number | undefined
822
+ startIndex?: number | undefined,
824
823
  ): number;
825
824
 
826
825
  function getIndentSize(value: string, tabWidth: number): number;
@@ -828,83 +827,92 @@ export namespace util {
828
827
  function skipNewline(
829
828
  text: string,
830
829
  startIndex: number | false,
831
- options?: SkipOptions | undefined
830
+ options?: SkipOptions | undefined,
832
831
  ): number | false;
833
832
 
834
833
  function skipInlineComment(
835
834
  text: string,
836
- startIndex: number | false
835
+ startIndex: number | false,
837
836
  ): number | false;
838
837
 
839
838
  function skipTrailingComment(
840
839
  text: string,
841
- startIndex: number | false
840
+ startIndex: number | false,
842
841
  ): number | false;
843
842
 
844
843
  function skipTrailingComment(
845
844
  text: string,
846
- startIndex: number | false
845
+ startIndex: number | false,
847
846
  ): number | false;
848
847
 
849
848
  function hasNewline(
850
849
  text: string,
851
850
  startIndex: number,
852
- options?: SkipOptions | undefined
851
+ options?: SkipOptions | undefined,
853
852
  ): boolean;
854
853
 
855
854
  function hasNewlineInRange(
856
855
  text: string,
857
856
  startIndex: number,
858
- endIndex: number
857
+ endIndex: number,
859
858
  ): boolean;
860
859
 
861
860
  function hasSpaces(
862
861
  text: string,
863
862
  startIndex: number,
864
- options?: SkipOptions | undefined
863
+ options?: SkipOptions | undefined,
865
864
  ): boolean;
866
865
 
866
+ function getNextNonSpaceNonCommentCharacterIndex(
867
+ text: string,
868
+ startIndex: number,
869
+ ): number | false;
870
+
867
871
  function getNextNonSpaceNonCommentCharacter(
868
872
  text: string,
869
- startIndex: number
873
+ startIndex: number,
870
874
  ): string;
871
875
 
876
+ function isNextLineEmpty(text: string, startIndex: number): boolean;
877
+
878
+ function isPreviousLineEmpty(text: string, startIndex: number): boolean;
879
+
872
880
  function makeString(
873
881
  rawText: string,
874
882
  enclosingQuote: Quote,
875
- unescapeUnnecessaryEscapes?: boolean | undefined
883
+ unescapeUnnecessaryEscapes?: boolean | undefined,
876
884
  ): string;
877
885
 
878
886
  function skip(
879
- characters: string | RegExp
887
+ characters: string | RegExp,
880
888
  ): (
881
889
  text: string,
882
890
  startIndex: number | false,
883
- options?: SkipOptions
891
+ options?: SkipOptions,
884
892
  ) => number | false;
885
893
 
886
894
  const skipWhitespace: (
887
895
  text: string,
888
896
  startIndex: number | false,
889
- options?: SkipOptions
897
+ options?: SkipOptions,
890
898
  ) => number | false;
891
899
 
892
900
  const skipSpaces: (
893
901
  text: string,
894
902
  startIndex: number | false,
895
- options?: SkipOptions
903
+ options?: SkipOptions,
896
904
  ) => number | false;
897
905
 
898
906
  const skipToLineEnd: (
899
907
  text: string,
900
908
  startIndex: number | false,
901
- options?: SkipOptions
909
+ options?: SkipOptions,
902
910
  ) => number | false;
903
911
 
904
912
  const skipEverythingButNewLine: (
905
913
  text: string,
906
914
  startIndex: number | false,
907
- options?: SkipOptions
915
+ options?: SkipOptions,
908
916
  ) => number | false;
909
917
 
910
918
  function addLeadingComment(node: any, comment: any): void;