UNPKG

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