UNPKG

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