prettier 4.0.1 → 4.0.3

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 +216 -326
  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 +12 -24
  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 +71 -61
  12. data/node_modules/prettier/index.mjs +16061 -13848
  13. data/node_modules/prettier/internal/cli.mjs +380 -70
  14. data/node_modules/prettier/internal/internal.mjs +195 -6014
  15. data/node_modules/prettier/package.json +7 -2
  16. data/node_modules/prettier/plugins/acorn.js +12 -12
  17. data/node_modules/prettier/plugins/acorn.mjs +12 -12
  18. data/node_modules/prettier/plugins/angular.js +2 -2
  19. data/node_modules/prettier/plugins/angular.mjs +2 -2
  20. data/node_modules/prettier/plugins/babel.js +11 -11
  21. data/node_modules/prettier/plugins/babel.mjs +11 -11
  22. data/node_modules/prettier/plugins/estree.d.ts +1 -0
  23. data/node_modules/prettier/plugins/estree.js +25 -25
  24. data/node_modules/prettier/plugins/estree.mjs +25 -25
  25. data/node_modules/prettier/plugins/flow.js +17 -17
  26. data/node_modules/prettier/plugins/flow.mjs +17 -17
  27. data/node_modules/prettier/plugins/glimmer.js +22 -22
  28. data/node_modules/prettier/plugins/glimmer.mjs +22 -22
  29. data/node_modules/prettier/plugins/graphql.js +9 -9
  30. data/node_modules/prettier/plugins/graphql.mjs +9 -9
  31. data/node_modules/prettier/plugins/html.js +17 -17
  32. data/node_modules/prettier/plugins/html.mjs +17 -17
  33. data/node_modules/prettier/plugins/markdown.js +46 -46
  34. data/node_modules/prettier/plugins/markdown.mjs +46 -46
  35. data/node_modules/prettier/plugins/meriyah.js +5 -5
  36. data/node_modules/prettier/plugins/meriyah.mjs +5 -5
  37. data/node_modules/prettier/plugins/postcss.js +28 -28
  38. data/node_modules/prettier/plugins/postcss.mjs +28 -28
  39. data/node_modules/prettier/plugins/typescript.js +20 -22
  40. data/node_modules/prettier/plugins/typescript.mjs +20 -22
  41. data/node_modules/prettier/plugins/yaml.js +38 -38
  42. data/node_modules/prettier/plugins/yaml.mjs +39 -39
  43. data/node_modules/prettier/standalone.d.ts +1 -1
  44. data/node_modules/prettier/standalone.js +29 -26
  45. data/node_modules/prettier/standalone.mjs +29 -26
  46. data/package.json +6 -5
  47. data/src/plugin.js +10 -5
  48. data/src/server.rb +8 -3
  49. metadata +2 -2
@@ -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.
@@ -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 {
@@ -575,11 +576,9 @@ export function check(source: string, options?: Options): Promise<boolean>;
575
576
  */
576
577
  export function formatWithCursor(
577
578
  source: string,
578
- options: CursorOptions
579
+ options: CursorOptions,
579
580
  ): Promise<CursorResult>;
580
581
 
581
- export function formatAST(ast: any, options?: Options): Promise<string>;
582
-
583
582
  export interface ResolveConfigOptions {
584
583
  /**
585
584
  * If set to `false`, all caching will be bypassed.
@@ -603,8 +602,8 @@ export interface ResolveConfigOptions {
603
602
 
604
603
  /**
605
604
  * `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.
605
+ * passing its path or url as the first argument. The config search will start at
606
+ * the file location and continue to search up the directory.
608
607
  * (You can use `process.cwd()` to start searching from the current directory).
609
608
  *
610
609
  * A promise is returned which will resolve to:
@@ -615,8 +614,8 @@ export interface ResolveConfigOptions {
615
614
  * The promise will be rejected if there was an error parsing the configuration file.
616
615
  */
617
616
  export function resolveConfig(
618
- filePath: string,
619
- options?: ResolveConfigOptions
617
+ fileUrlOrPath: string | URL,
618
+ options?: ResolveConfigOptions,
620
619
  ): Promise<Options | null>;
621
620
 
622
621
  /**
@@ -630,7 +629,9 @@ export function resolveConfig(
630
629
  *
631
630
  * The promise will be rejected if there was an error parsing the configuration file.
632
631
  */
633
- export function resolveConfigFile(filePath?: string): Promise<string | null>;
632
+ export function resolveConfigFile(
633
+ fileUrlOrPath?: string | URL,
634
+ ): Promise<string | null>;
634
635
 
635
636
  /**
636
637
  * As you repeatedly call `resolveConfig`, the file system structure will be cached for performance. This function will clear the cache.
@@ -779,7 +780,7 @@ export interface SupportInfo {
779
780
  }
780
781
 
781
782
  export interface FileInfoOptions {
782
- ignorePath?: string | string[] | undefined;
783
+ ignorePath?: string | URL | (string | URL)[] | undefined;
783
784
  withNodeModules?: boolean | undefined;
784
785
  plugins?: string[] | undefined;
785
786
  resolveConfig?: boolean | undefined;
@@ -791,8 +792,8 @@ export interface FileInfoResult {
791
792
  }
792
793
 
793
794
  export function getFileInfo(
794
- filePath: string,
795
- options?: FileInfoOptions
795
+ file: string | URL,
796
+ options?: FileInfoOptions,
796
797
  ): Promise<FileInfoResult>;
797
798
 
798
799
  /**
@@ -820,7 +821,7 @@ export namespace util {
820
821
  function getAlignmentSize(
821
822
  text: string,
822
823
  tabWidth: number,
823
- startIndex?: number | undefined
824
+ startIndex?: number | undefined,
824
825
  ): number;
825
826
 
826
827
  function getIndentSize(value: string, tabWidth: number): number;
@@ -828,83 +829,92 @@ export namespace util {
828
829
  function skipNewline(
829
830
  text: string,
830
831
  startIndex: number | false,
831
- options?: SkipOptions | undefined
832
+ options?: SkipOptions | undefined,
832
833
  ): number | false;
833
834
 
834
835
  function skipInlineComment(
835
836
  text: string,
836
- startIndex: number | false
837
+ startIndex: number | false,
837
838
  ): number | false;
838
839
 
839
840
  function skipTrailingComment(
840
841
  text: string,
841
- startIndex: number | false
842
+ startIndex: number | false,
842
843
  ): number | false;
843
844
 
844
845
  function skipTrailingComment(
845
846
  text: string,
846
- startIndex: number | false
847
+ startIndex: number | false,
847
848
  ): number | false;
848
849
 
849
850
  function hasNewline(
850
851
  text: string,
851
852
  startIndex: number,
852
- options?: SkipOptions | undefined
853
+ options?: SkipOptions | undefined,
853
854
  ): boolean;
854
855
 
855
856
  function hasNewlineInRange(
856
857
  text: string,
857
858
  startIndex: number,
858
- endIndex: number
859
+ endIndex: number,
859
860
  ): boolean;
860
861
 
861
862
  function hasSpaces(
862
863
  text: string,
863
864
  startIndex: number,
864
- options?: SkipOptions | undefined
865
+ options?: SkipOptions | undefined,
865
866
  ): boolean;
866
867
 
868
+ function getNextNonSpaceNonCommentCharacterIndex(
869
+ text: string,
870
+ startIndex: number,
871
+ ): number | false;
872
+
867
873
  function getNextNonSpaceNonCommentCharacter(
868
874
  text: string,
869
- startIndex: number
875
+ startIndex: number,
870
876
  ): string;
871
877
 
878
+ function isNextLineEmpty(text: string, startIndex: number): boolean;
879
+
880
+ function isPreviousLineEmpty(text: string, startIndex: number): boolean;
881
+
872
882
  function makeString(
873
883
  rawText: string,
874
884
  enclosingQuote: Quote,
875
- unescapeUnnecessaryEscapes?: boolean | undefined
885
+ unescapeUnnecessaryEscapes?: boolean | undefined,
876
886
  ): string;
877
887
 
878
888
  function skip(
879
- characters: string | RegExp
889
+ characters: string | RegExp,
880
890
  ): (
881
891
  text: string,
882
892
  startIndex: number | false,
883
- options?: SkipOptions
893
+ options?: SkipOptions,
884
894
  ) => number | false;
885
895
 
886
896
  const skipWhitespace: (
887
897
  text: string,
888
898
  startIndex: number | false,
889
- options?: SkipOptions
899
+ options?: SkipOptions,
890
900
  ) => number | false;
891
901
 
892
902
  const skipSpaces: (
893
903
  text: string,
894
904
  startIndex: number | false,
895
- options?: SkipOptions
905
+ options?: SkipOptions,
896
906
  ) => number | false;
897
907
 
898
908
  const skipToLineEnd: (
899
909
  text: string,
900
910
  startIndex: number | false,
901
- options?: SkipOptions
911
+ options?: SkipOptions,
902
912
  ) => number | false;
903
913
 
904
914
  const skipEverythingButNewLine: (
905
915
  text: string,
906
916
  startIndex: number | false,
907
- options?: SkipOptions
917
+ options?: SkipOptions,
908
918
  ) => number | false;
909
919
 
910
920
  function addLeadingComment(node: any, comment: any): void;