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 newNode
500 * @returns anything if you want to replace the node with it
501 */
502 massageAstNode?: ((node: any, newNode: any, parent: any) => any) | undefined;
503 hasPrettierIgnore?: ((path: AstPath<T>) => boolean) | undefined;
504 canAttachComment?: ((node: T) => boolean) | undefined;
505 isBlockComment?: ((node: T) => boolean) | undefined;
506 willPrintOwnComments?: ((path: AstPath<T>) => boolean) | undefined;
507 printComment?:
508 | ((commentPath: AstPath<T>, options: ParserOptions<T>) => Doc)
509 | undefined;
510 /**
511 * By default, Prettier searches all object properties (except for a few predefined ones) of each node recursively.
512 * This function can be provided to override that behavior.
513 * @param node The node whose children should be returned.
514 * @param options Current options.
515 * @returns `[]` if the node has no children or `undefined` to fall back on the default behavior.
516 */
517 getCommentChildNodes?:
518 | ((node: T, options: ParserOptions<T>) => T[] | undefined)
519 | undefined;
520 handleComments?:
521 | {
522 ownLine?:
523 | ((
524 commentNode: any,
525 text: string,
526 options: ParserOptions<T>,
527 ast: T,
528 isLastComment: boolean,
529 ) => boolean)
530 | undefined;
531 endOfLine?:
532 | ((
533 commentNode: any,
534 text: string,
535 options: ParserOptions<T>,
536 ast: T,
537 isLastComment: boolean,
538 ) => boolean)
539 | undefined;
540 remaining?:
541 | ((
542 commentNode: any,
543 text: string,
544 options: ParserOptions<T>,
545 ast: T,
546 isLastComment: boolean,
547 ) => boolean)
548 | undefined;
549 }
550 | undefined;
551 getVisitorKeys?:
552 | ((node: T, nonTraversableKeys: Set<string>) => string[])
553 | undefined;
554}
555
556export interface CursorOptions extends Options {
557 /**
558 * Specify where the cursor is.
559 */
560 cursorOffset: number;
561}
562
563export interface CursorResult {
564 formatted: string;
565 cursorOffset: number;
566}
567
568/**
569 * `format` is used to format text using Prettier. [Options](https://prettier.io/docs/en/options.html) may be provided to override the defaults.
570 */
571export function format(source: string, options?: Options): Promise<string>;
572
573/**
574 * `check` checks to see if the file has been formatted with Prettier given those options and returns a `Boolean`.
575 * This is similar to the `--list-different` parameter in the CLI and is useful for running Prettier in CI scenarios.
576 */
577export function check(source: string, options?: Options): Promise<boolean>;
578
579/**
580 * `formatWithCursor` both formats the code, and translates a cursor position from unformatted code to formatted code.
581 * This is useful for editor integrations, to prevent the cursor from moving when code is formatted.
582 *
583 * The `cursorOffset` option should be provided, to specify where the cursor is.
584 */
585export function formatWithCursor(
586 source: string,
587 options: CursorOptions,
588): Promise<CursorResult>;
589
590export interface ResolveConfigOptions {
591 /**
592 * If set to `false`, all caching will be bypassed.
593 */
594 useCache?: boolean | undefined;
595 /**
596 * Pass directly the path of the config file if you don't wish to search for it.
597 */
598 config?: string | undefined;
599 /**
600 * If set to `true` and an `.editorconfig` file is in your project,
601 * Prettier will parse it and convert its properties to the corresponding prettier configuration.
602 * This configuration will be overridden by `.prettierrc`, etc. Currently,
603 * the following EditorConfig properties are supported:
604 * - indent_style
605 * - indent_size/tab_width
606 * - max_line_length
607 */
608 editorconfig?: boolean | undefined;
609}
610
611/**
612 * `resolveConfig` can be used to resolve configuration for a given source file,
613 * passing its path or url as the first argument. The config search will start at
614 * the file location and continue to search up the directory.
615 * (You can use `process.cwd()` to start searching from the current directory).
616 *
617 * A promise is returned which will resolve to:
618 *
619 * - An options object, providing a [config file](https://prettier.io/docs/en/configuration.html) was found.
620 * - `null`, if no file was found.
621 *
622 * The promise will be rejected if there was an error parsing the configuration file.
623 */
624export function resolveConfig(
625 fileUrlOrPath: string | URL,
626 options?: ResolveConfigOptions,
627): Promise<Options | null>;
628
629/**
630 * `resolveConfigFile` can be used to find the path of the Prettier configuration file,
631 * that will be used when resolving the config (i.e. when calling `resolveConfig`).
632 *
633 * A promise is returned which will resolve to:
634 *
635 * - The path of the configuration file.
636 * - `null`, if no file was found.
637 *
638 * The promise will be rejected if there was an error parsing the configuration file.
639 */
640export function resolveConfigFile(
641 fileUrlOrPath?: string | URL,
642): Promise<string | null>;
643
644/**
645 * As you repeatedly call `resolveConfig`, the file system structure will be cached for performance. This function will clear the cache.
646 * Generally this is only needed for editor integrations that know that the file system has changed since the last format took place.
647 */
648export function clearConfigCache(): Promise<void>;
649
650export interface SupportLanguage {
651 name: string;
652 since?: string | undefined;
653 parsers: BuiltInParserName[] | string[];
654 group?: string | undefined;
655 tmScope?: string | undefined;
656 aceMode?: string | undefined;
657 codemirrorMode?: string | undefined;
658 codemirrorMimeType?: string | undefined;
659 aliases?: string[] | undefined;
660 extensions?: string[] | undefined;
661 filenames?: string[] | undefined;
662 linguistLanguageId?: number | undefined;
663 vscodeLanguageIds?: string[] | undefined;
664 interpreters?: string[] | undefined;
665}
666
667export interface SupportOptionRange {
668 start: number;
669 end: number;
670 step: number;
671}
672
673export type SupportOptionType =
674 | "int"
675 | "string"
676 | "boolean"
677 | "choice"
678 | "path";
679
680export type CoreCategoryType =
681 | "Config"
682 | "Editor"
683 | "Format"
684 | "Other"
685 | "Output"
686 | "Global"
687 | "Special";
688
689export interface BaseSupportOption<Type extends SupportOptionType> {
690 readonly name?: string | undefined;
691 /**
692 * Usually you can use {@link CoreCategoryType}
693 */
694 category: string;
695 /**
696 * The type of the option.
697 *
698 * When passing a type other than the ones listed below, the option is
699 * treated as taking any string as argument, and `--option <${type}>` will
700 * be displayed in --help.
701 */
702 type: Type;
703 /**
704 * Indicate that the option is deprecated.
705 *
706 * Use a string to add an extra message to --help for the option,
707 * for example to suggest a replacement option.
708 */
709 deprecated?: true | string | undefined;
710 /**
711 * Description to be displayed in --help. If omitted, the option won't be
712 * shown at all in --help.
713 */
714 description?: string | undefined;
715}
716
717export interface IntSupportOption extends BaseSupportOption<"int"> {
718 default?: number | undefined;
719 array?: false | undefined;
720 range?: SupportOptionRange | undefined;
721}
722
723export interface IntArraySupportOption extends BaseSupportOption<"int"> {
724 default?: Array<{ value: number[] }> | undefined;
725 array: true;
726}
727
728export interface StringSupportOption extends BaseSupportOption<"string"> {
729 default?: string | undefined;
730 array?: false | undefined;
731}
732
733export interface StringArraySupportOption extends BaseSupportOption<"string"> {
734 default?: Array<{ value: string[] }> | undefined;
735 array: true;
736}
737
738export interface BooleanSupportOption extends BaseSupportOption<"boolean"> {
739 default?: boolean | undefined;
740 array?: false | undefined;
741 description: string;
742 oppositeDescription?: string | undefined;
743}
744
745export interface BooleanArraySupportOption
746 extends BaseSupportOption<"boolean"> {
747 default?: Array<{ value: boolean[] }> | undefined;
748 array: true;
749}
750
751export interface ChoiceSupportOption<Value = any>
752 extends BaseSupportOption<"choice"> {
753 default?: Value | Array<{ value: Value }> | undefined;
754 description: string;
755 choices: Array<{
756 since?: string | undefined;
757 value: Value;
758 description: string;
759 }>;
760}
761
762export interface PathSupportOption extends BaseSupportOption<"path"> {
763 default?: string | undefined;
764 array?: false | undefined;
765}
766
767export interface PathArraySupportOption extends BaseSupportOption<"path"> {
768 default?: Array<{ value: string[] }> | undefined;
769 array: true;
770}
771
772export type SupportOption =
773 | IntSupportOption
774 | IntArraySupportOption
775 | StringSupportOption
776 | StringArraySupportOption
777 | BooleanSupportOption
778 | BooleanArraySupportOption
779 | ChoiceSupportOption
780 | PathSupportOption
781 | PathArraySupportOption;
782
783export interface SupportOptions extends Record<string, SupportOption> {}
784
785export interface SupportInfo {
786 languages: SupportLanguage[];
787 options: SupportOption[];
788}
789
790export interface FileInfoOptions {
791 ignorePath?: string | URL | (string | URL)[] | undefined;
792 withNodeModules?: boolean | undefined;
793 plugins?: Array<string | Plugin> | undefined;
794 resolveConfig?: boolean | undefined;
795}
796
797export interface FileInfoResult {
798 ignored: boolean;
799 inferredParser: string | null;
800}
801
802export function getFileInfo(
803 file: string | URL,
804 options?: FileInfoOptions,
805): Promise<FileInfoResult>;
806
807export interface SupportInfoOptions {
808 plugins?: Array<string | Plugin> | undefined;
809 showDeprecated?: boolean | undefined;
810}
811
812/**
813 * Returns an object representing the parsers, languages and file types Prettier supports for the current version.
814 */
815export function getSupportInfo(
816 options?: SupportInfoOptions,
817): Promise<SupportInfo>;
818
819/**
820 * `version` field in `package.json`
821 */
822export const version: string;
823
824// https://github.com/prettier/prettier/blob/next/src/utils/public.js
825export namespace util {
826 interface SkipOptions {
827 backwards?: boolean | undefined;
828 }
829
830 type Quote = "'" | '"';
831
832 function getMaxContinuousCount(text: string, searchString: string): number;
833
834 function getStringWidth(text: string): number;
835
836 function getAlignmentSize(
837 text: string,
838 tabWidth: number,
839 startIndex?: number | undefined,
840 ): number;
841
842 function getIndentSize(value: string, tabWidth: number): number;
843
844 function skipNewline(
845 text: string,
846 startIndex: number | false,
847 options?: SkipOptions | undefined,
848 ): number | false;
849
850 function skipInlineComment(
851 text: string,
852 startIndex: number | false,
853 ): number | false;
854
855 function skipTrailingComment(
856 text: string,
857 startIndex: number | false,
858 ): number | false;
859
860 function skipTrailingComment(
861 text: string,
862 startIndex: number | false,
863 ): number | false;
864
865 function hasNewline(
866 text: string,
867 startIndex: number,
868 options?: SkipOptions | undefined,
869 ): boolean;
870
871 function hasNewlineInRange(
872 text: string,
873 startIndex: number,
874 endIndex: number,
875 ): boolean;
876
877 function hasSpaces(
878 text: string,
879 startIndex: number,
880 options?: SkipOptions | undefined,
881 ): boolean;
882
883 function getNextNonSpaceNonCommentCharacterIndex(
884 text: string,
885 startIndex: number,
886 ): number | false;
887
888 function getNextNonSpaceNonCommentCharacter(
889 text: string,
890 startIndex: number,
891 ): string;
892
893 function isNextLineEmpty(text: string, startIndex: number): boolean;
894
895 function isPreviousLineEmpty(text: string, startIndex: number): boolean;
896
897 function makeString(
898 rawText: string,
899 enclosingQuote: Quote,
900 unescapeUnnecessaryEscapes?: boolean | undefined,
901 ): string;
902
903 function skip(
904 characters: string | RegExp,
905 ): (
906 text: string,
907 startIndex: number | false,
908 options?: SkipOptions,
909 ) => number | false;
910
911 const skipWhitespace: (
912 text: string,
913 startIndex: number | false,
914 options?: SkipOptions,
915 ) => number | false;
916
917 const skipSpaces: (
918 text: string,
919 startIndex: number | false,
920 options?: SkipOptions,
921 ) => number | false;
922
923 const skipToLineEnd: (
924 text: string,
925 startIndex: number | false,
926 options?: SkipOptions,
927 ) => number | false;
928
929 const skipEverythingButNewLine: (
930 text: string,
931 startIndex: number | false,
932 options?: SkipOptions,
933 ) => number | false;
934
935 function addLeadingComment(node: any, comment: any): void;
936
937 function addDanglingComment(node: any, comment: any, marker: any): void;
938
939 function addTrailingComment(node: any, comment: any): void;
940}
941
\No newline at end of file