UNPKG

26.3 kBTypeScriptView Raw
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.
9export {};
10
11import { builders, printer, utils } from "./doc.js";
12
13export 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
24export type LiteralUnion<T extends U, U = string> =
25 | T
26 | (Pick<U, never> & { _?: never | undefined });
27
28export type AST = any;
29export type Doc = doc.builders.Doc;
30
31// The type of elements that make up the given array T.
32type ArrayElement<T> = T extends Array<infer E> ? E : never;
33
34// A union of the properties of the given object that are arrays.
35type ArrayProperties<T> = {
36 [K in keyof T]: NonNullable<T[K]> extends readonly 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.
42type 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.
48type 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
60type IsTuple<T> = T extends []
61 ? true
62 : T extends [infer First, ...infer Remain]
63 ? IsTuple<Remain>
64 : false;
65
66type CallProperties<T> = T extends any[] ? IndexProperties<T> : keyof T;
67type IterProperties<T> = T extends any[]
68 ? IndexProperties<T>
69 : ArrayProperties<T>;
70
71type CallCallback<T, U> = (path: AstPath<T>, index: number, value: any) => U;
72type EachCallback<T> = (
73 path: AstPath<ArrayElement<T>>,
74 index: number,
75 value: any,
76) => void;
77type 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
84export 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` */
276export type FastPath<T = any> = AstPath<T>;
277
278export type BuiltInParser = (text: string, options?: any) => AST;
279export 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";
303export type BuiltInParsers = Record<BuiltInParserName, BuiltInParser>;
304
305/**
306 * For use in `.prettierrc.js`, `.prettierrc.cjs`, `prettierrc.mjs`, `prettier.config.js`, `prettier.config.cjs`, `prettier.config.mjs`
307 */
308export interface Config extends Options {
309 overrides?: Array<{
310 files: string | string[];
311 excludeFiles?: string | string[];
312 options?: Options;
313 }>;
314}
315
316export interface Options extends Partial<RequiredOptions> {}
317
318export interface RequiredOptions extends doc.printer.Options {
319 /**
320 * Print semicolons at the ends of statements.
321 * @default true
322 */
323 semi: boolean;
324 /**
325 * Use single quotes instead of double quotes.
326 * @default false
327 */
328 singleQuote: boolean;
329 /**
330 * Use single quotes in JSX.
331 * @default false
332 */
333 jsxSingleQuote: boolean;
334 /**
335 * Print trailing commas wherever possible.
336 * @default "all"
337 */
338 trailingComma: "none" | "es5" | "all";
339 /**
340 * Print spaces between brackets in object literals.
341 * @default true
342 */
343 bracketSpacing: boolean;
344 /**
345 * Put the `>` of a multi-line HTML (HTML, JSX, Vue, Angular) element at the end of the last line instead of being
346 * alone on the next line (does not apply to self closing elements).
347 * @default false
348 */
349 bracketSameLine: boolean;
350 /**
351 * Put the `>` of a multi-line JSX element at the end of the last line instead of being alone on the next line.
352 * @default false
353 * @deprecated use bracketSameLine instead
354 */
355 jsxBracketSameLine: boolean;
356 /**
357 * Format only a segment of a file.
358 * @default 0
359 */
360 rangeStart: number;
361 /**
362 * Format only a segment of a file.
363 * @default Number.POSITIVE_INFINITY
364 */
365 rangeEnd: number;
366 /**
367 * Specify which parser to use.
368 */
369 parser: LiteralUnion<BuiltInParserName>;
370 /**
371 * Specify the input filepath. This will be used to do parser inference.
372 */
373 filepath: string;
374 /**
375 * Prettier can restrict itself to only format files that contain a special comment, called a pragma, at the top of the file.
376 * This is very useful when gradually transitioning large, unformatted codebases to prettier.
377 * @default false
378 */
379 requirePragma: boolean;
380 /**
381 * Prettier can insert a special @format marker at the top of files specifying that
382 * the file has been formatted with prettier. This works well when used in tandem with
383 * the --require-pragma option. If there is already a docblock at the top of
384 * the file then this option will add a newline to it with the @format marker.
385 * @default false
386 */
387 insertPragma: boolean;
388 /**
389 * By default, Prettier will wrap markdown text as-is since some services use a linebreak-sensitive renderer.
390 * In some cases you may want to rely on editor/viewer soft wrapping instead, so this option allows you to opt out.
391 * @default "preserve"
392 */
393 proseWrap: "always" | "never" | "preserve";
394 /**
395 * Include parentheses around a sole arrow function parameter.
396 * @default "always"
397 */
398 arrowParens: "avoid" | "always";
399 /**
400 * Provide ability to support new languages to prettier.
401 */
402 plugins: Array<string | Plugin>;
403 /**
404 * How to handle whitespaces in HTML.
405 * @default "css"
406 */
407 htmlWhitespaceSensitivity: "css" | "strict" | "ignore";
408 /**
409 * Which end of line characters to apply.
410 * @default "lf"
411 */
412 endOfLine: "auto" | "lf" | "crlf" | "cr";
413 /**
414 * Change when properties in objects are quoted.
415 * @default "as-needed"
416 */
417 quoteProps: "as-needed" | "consistent" | "preserve";
418 /**
419 * Whether or not to indent the code inside <script> and <style> tags in Vue files.
420 * @default false
421 */
422 vueIndentScriptAndStyle: boolean;
423 /**
424 * Control whether Prettier formats quoted code embedded in the file.
425 * @default "auto"
426 */
427 embeddedLanguageFormatting: "auto" | "off";
428 /**
429 * Enforce single attribute per line in HTML, Vue and JSX.
430 * @default false
431 */
432 singleAttributePerLine: boolean;
433}
434
435export interface ParserOptions<T = any> extends RequiredOptions {
436 locStart: (node: T) => number;
437 locEnd: (node: T) => number;
438 originalText: string;
439}
440
441export interface Plugin<T = any> {
442 languages?: SupportLanguage[] | undefined;
443 parsers?: { [parserName: string]: Parser<T> } | undefined;
444 printers?: { [astFormat: string]: Printer<T> } | undefined;
445 options?: SupportOptions | undefined;
446 defaultOptions?: Partial<RequiredOptions> | undefined;
447}
448
449export interface Parser<T = any> {
450 parse: (text: string, options: ParserOptions<T>) => T | Promise<T>;
451 astFormat: string;
452 hasPragma?: ((text: string) => boolean) | undefined;
453 locStart: (node: T) => number;
454 locEnd: (node: T) => number;
455 preprocess?:
456 | ((text: string, options: ParserOptions<T>) => string)
457 | undefined;
458}
459
460export interface Printer<T = any> {
461 print(
462 path: AstPath<T>,
463 options: ParserOptions<T>,
464 print: (path: AstPath<T>) => Doc,
465 args?: unknown,
466 ): Doc;
467 embed?:
468 | ((
469 path: AstPath,
470 options: Options,
471 ) =>
472 | ((
473 textToDoc: (text: string, options: Options) => Promise<Doc>,
474 print: (
475 selector?: string | number | Array<string | number> | AstPath,
476 ) => Doc,
477 path: AstPath,
478 options: Options,
479 ) => Promise<Doc | undefined> | Doc | undefined)
480 | Doc
481 | null)
482 | undefined;
483 preprocess?:
484 | ((ast: T, options: ParserOptions<T>) => T | Promise<T>)
485 | undefined;
486 insertPragma?: (text: string) => string;
487 /**
488 * @returns `null` if you want to remove this node
489 * @returns `void` if you want to use modified newNode
490 * @returns anything if you want to replace the node with it
491 */
492 massageAstNode?: ((node: any, newNode: any, parent: any) => any) | undefined;
493 hasPrettierIgnore?: ((path: AstPath<T>) => boolean) | undefined;
494 canAttachComment?: ((node: T) => boolean) | undefined;
495 isBlockComment?: ((node: T) => boolean) | undefined;
496 willPrintOwnComments?: ((path: AstPath<T>) => boolean) | undefined;
497 printComment?:
498 | ((commentPath: AstPath<T>, options: ParserOptions<T>) => Doc)
499 | undefined;
500 /**
501 * By default, Prettier searches all object properties (except for a few predefined ones) of each node recursively.
502 * This function can be provided to override that behavior.
503 * @param node The node whose children should be returned.
504 * @param options Current options.
505 * @returns `[]` if the node has no children or `undefined` to fall back on the default behavior.
506 */
507 getCommentChildNodes?:
508 | ((node: T, options: ParserOptions<T>) => T[] | undefined)
509 | undefined;
510 handleComments?:
511 | {
512 ownLine?:
513 | ((
514 commentNode: any,
515 text: string,
516 options: ParserOptions<T>,
517 ast: T,
518 isLastComment: boolean,
519 ) => boolean)
520 | undefined;
521 endOfLine?:
522 | ((
523 commentNode: any,
524 text: string,
525 options: ParserOptions<T>,
526 ast: T,
527 isLastComment: boolean,
528 ) => boolean)
529 | undefined;
530 remaining?:
531 | ((
532 commentNode: any,
533 text: string,
534 options: ParserOptions<T>,
535 ast: T,
536 isLastComment: boolean,
537 ) => boolean)
538 | undefined;
539 }
540 | undefined;
541 getVisitorKeys?:
542 | ((node: T, nonTraversableKeys: Set<string>) => string[])
543 | undefined;
544}
545
546export interface CursorOptions extends Options {
547 /**
548 * Specify where the cursor is.
549 */
550 cursorOffset: number;
551 rangeStart?: never;
552 rangeEnd?: never;
553}
554
555export interface CursorResult {
556 formatted: string;
557 cursorOffset: number;
558}
559
560/**
561 * `format` is used to format text using Prettier. [Options](https://prettier.io/docs/en/options.html) may be provided to override the defaults.
562 */
563export function format(source: string, options?: Options): Promise<string>;
564
565/**
566 * `check` checks to see if the file has been formatted with Prettier given those options and returns a `Boolean`.
567 * This is similar to the `--list-different` parameter in the CLI and is useful for running Prettier in CI scenarios.
568 */
569export function check(source: string, options?: Options): Promise<boolean>;
570
571/**
572 * `formatWithCursor` both formats the code, and translates a cursor position from unformatted code to formatted code.
573 * This is useful for editor integrations, to prevent the cursor from moving when code is formatted.
574 *
575 * The `cursorOffset` option should be provided, to specify where the cursor is. This option cannot be used with `rangeStart` and `rangeEnd`.
576 */
577export function formatWithCursor(
578 source: string,
579 options: CursorOptions,
580): Promise<CursorResult>;
581
582export interface ResolveConfigOptions {
583 /**
584 * If set to `false`, all caching will be bypassed.
585 */
586 useCache?: boolean | undefined;
587 /**
588 * Pass directly the path of the config file if you don't wish to search for it.
589 */
590 config?: string | undefined;
591 /**
592 * If set to `true` and an `.editorconfig` file is in your project,
593 * Prettier will parse it and convert its properties to the corresponding prettier configuration.
594 * This configuration will be overridden by `.prettierrc`, etc. Currently,
595 * the following EditorConfig properties are supported:
596 * - indent_style
597 * - indent_size/tab_width
598 * - max_line_length
599 */
600 editorconfig?: boolean | undefined;
601}
602
603/**
604 * `resolveConfig` can be used to resolve configuration for a given source file,
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.
607 * (You can use `process.cwd()` to start searching from the current directory).
608 *
609 * A promise is returned which will resolve to:
610 *
611 * - An options object, providing a [config file](https://prettier.io/docs/en/configuration.html) was found.
612 * - `null`, if no file was found.
613 *
614 * The promise will be rejected if there was an error parsing the configuration file.
615 */
616export function resolveConfig(
617 fileUrlOrPath: string | URL,
618 options?: ResolveConfigOptions,
619): Promise<Options | null>;
620
621/**
622 * `resolveConfigFile` can be used to find the path of the Prettier configuration file,
623 * that will be used when resolving the config (i.e. when calling `resolveConfig`).
624 *
625 * A promise is returned which will resolve to:
626 *
627 * - The path of the configuration file.
628 * - `null`, if no file was found.
629 *
630 * The promise will be rejected if there was an error parsing the configuration file.
631 */
632export function resolveConfigFile(
633 fileUrlOrPath?: string | URL,
634): Promise<string | null>;
635
636/**
637 * As you repeatedly call `resolveConfig`, the file system structure will be cached for performance. This function will clear the cache.
638 * Generally this is only needed for editor integrations that know that the file system has changed since the last format took place.
639 */
640export function clearConfigCache(): Promise<void>;
641
642export interface SupportLanguage {
643 name: string;
644 since?: string | undefined;
645 parsers: BuiltInParserName[] | string[];
646 group?: string | undefined;
647 tmScope?: string | undefined;
648 aceMode?: string | undefined;
649 codemirrorMode?: string | undefined;
650 codemirrorMimeType?: string | undefined;
651 aliases?: string[] | undefined;
652 extensions?: string[] | undefined;
653 filenames?: string[] | undefined;
654 linguistLanguageId?: number | undefined;
655 vscodeLanguageIds?: string[] | undefined;
656 interpreters?: string[] | undefined;
657}
658
659export interface SupportOptionRange {
660 start: number;
661 end: number;
662 step: number;
663}
664
665export type SupportOptionType =
666 | "int"
667 | "string"
668 | "boolean"
669 | "choice"
670 | "path";
671
672export type CoreCategoryType =
673 | "Config"
674 | "Editor"
675 | "Format"
676 | "Other"
677 | "Output"
678 | "Global"
679 | "Special";
680
681export interface BaseSupportOption<Type extends SupportOptionType> {
682 readonly name?: string | undefined;
683 /**
684 * Usually you can use {@link CoreCategoryType}
685 */
686 category: string;
687 /**
688 * The type of the option.
689 *
690 * When passing a type other than the ones listed below, the option is
691 * treated as taking any string as argument, and `--option <${type}>` will
692 * be displayed in --help.
693 */
694 type: Type;
695 /**
696 * Indicate that the option is deprecated.
697 *
698 * Use a string to add an extra message to --help for the option,
699 * for example to suggest a replacement option.
700 */
701 deprecated?: true | string | undefined;
702 /**
703 * Description to be displayed in --help. If omitted, the option won't be
704 * shown at all in --help.
705 */
706 description?: string | undefined;
707}
708
709export interface IntSupportOption extends BaseSupportOption<"int"> {
710 default?: number | undefined;
711 array?: false | undefined;
712 range?: SupportOptionRange | undefined;
713}
714
715export interface IntArraySupportOption extends BaseSupportOption<"int"> {
716 default?: Array<{ value: number[] }> | undefined;
717 array: true;
718}
719
720export interface StringSupportOption extends BaseSupportOption<"string"> {
721 default?: string | undefined;
722 array?: false | undefined;
723}
724
725export interface StringArraySupportOption extends BaseSupportOption<"string"> {
726 default?: Array<{ value: string[] }> | undefined;
727 array: true;
728}
729
730export interface BooleanSupportOption extends BaseSupportOption<"boolean"> {
731 default?: boolean | undefined;
732 array?: false | undefined;
733 description: string;
734 oppositeDescription?: string | undefined;
735}
736
737export interface BooleanArraySupportOption
738 extends BaseSupportOption<"boolean"> {
739 default?: Array<{ value: boolean[] }> | undefined;
740 array: true;
741}
742
743export interface ChoiceSupportOption<Value = any>
744 extends BaseSupportOption<"choice"> {
745 default?: Value | Array<{ value: Value }> | undefined;
746 description: string;
747 choices: Array<{
748 since?: string | undefined;
749 value: Value;
750 description: string;
751 }>;
752}
753
754export interface PathSupportOption extends BaseSupportOption<"path"> {
755 default?: string | undefined;
756 array?: false | undefined;
757}
758
759export interface PathArraySupportOption extends BaseSupportOption<"path"> {
760 default?: Array<{ value: string[] }> | undefined;
761 array: true;
762}
763
764export type SupportOption =
765 | IntSupportOption
766 | IntArraySupportOption
767 | StringSupportOption
768 | StringArraySupportOption
769 | BooleanSupportOption
770 | BooleanArraySupportOption
771 | ChoiceSupportOption
772 | PathSupportOption
773 | PathArraySupportOption;
774
775export interface SupportOptions extends Record<string, SupportOption> {}
776
777export interface SupportInfo {
778 languages: SupportLanguage[];
779 options: SupportOption[];
780}
781
782export interface FileInfoOptions {
783 ignorePath?: string | URL | (string | URL)[] | undefined;
784 withNodeModules?: boolean | undefined;
785 plugins?: string[] | undefined;
786 resolveConfig?: boolean | undefined;
787}
788
789export interface FileInfoResult {
790 ignored: boolean;
791 inferredParser: string | null;
792}
793
794export function getFileInfo(
795 file: string | URL,
796 options?: FileInfoOptions,
797): Promise<FileInfoResult>;
798
799/**
800 * Returns an object representing the parsers, languages and file types Prettier supports for the current version.
801 */
802export function getSupportInfo(): Promise<SupportInfo>;
803
804/**
805 * `version` field in `package.json`
806 */
807export const version: string;
808
809// https://github.com/prettier/prettier/blob/next/src/utils/public.js
810export namespace util {
811 interface SkipOptions {
812 backwards?: boolean | undefined;
813 }
814
815 type Quote = "'" | '"';
816
817 function getMaxContinuousCount(text: string, searchString: string): number;
818
819 function getStringWidth(text: string): number;
820
821 function getAlignmentSize(
822 text: string,
823 tabWidth: number,
824 startIndex?: number | undefined,
825 ): number;
826
827 function getIndentSize(value: string, tabWidth: number): number;
828
829 function skipNewline(
830 text: string,
831 startIndex: number | false,
832 options?: SkipOptions | undefined,
833 ): number | false;
834
835 function skipInlineComment(
836 text: string,
837 startIndex: number | false,
838 ): number | false;
839
840 function skipTrailingComment(
841 text: string,
842 startIndex: number | false,
843 ): number | false;
844
845 function skipTrailingComment(
846 text: string,
847 startIndex: number | false,
848 ): number | false;
849
850 function hasNewline(
851 text: string,
852 startIndex: number,
853 options?: SkipOptions | undefined,
854 ): boolean;
855
856 function hasNewlineInRange(
857 text: string,
858 startIndex: number,
859 endIndex: number,
860 ): boolean;
861
862 function hasSpaces(
863 text: string,
864 startIndex: number,
865 options?: SkipOptions | undefined,
866 ): boolean;
867
868 function getNextNonSpaceNonCommentCharacterIndex(
869 text: string,
870 startIndex: number,
871 ): number | false;
872
873 function getNextNonSpaceNonCommentCharacter(
874 text: string,
875 startIndex: number,
876 ): string;
877
878 function isNextLineEmpty(text: string, startIndex: number): boolean;
879
880 function isPreviousLineEmpty(text: string, startIndex: number): boolean;
881
882 function makeString(
883 rawText: string,
884 enclosingQuote: Quote,
885 unescapeUnnecessaryEscapes?: boolean | undefined,
886 ): string;
887
888 function skip(
889 characters: string | RegExp,
890 ): (
891 text: string,
892 startIndex: number | false,
893 options?: SkipOptions,
894 ) => number | false;
895
896 const skipWhitespace: (
897 text: string,
898 startIndex: number | false,
899 options?: SkipOptions,
900 ) => number | false;
901
902 const skipSpaces: (
903 text: string,
904 startIndex: number | false,
905 options?: SkipOptions,
906 ) => number | false;
907
908 const skipToLineEnd: (
909 text: string,
910 startIndex: number | false,
911 options?: SkipOptions,
912 ) => number | false;
913
914 const skipEverythingButNewLine: (
915 text: string,
916 startIndex: number | false,
917 options?: SkipOptions,
918 ) => number | false;
919
920 function addLeadingComment(node: any, comment: any): void;
921
922 function addDanglingComment(node: any, comment: any, marker: any): void;
923
924 function addTrailingComment(node: any, comment: any): void;
925}
926
\No newline at end of file