UNPKG

34.2 kBTypeScriptView Raw
1// Type definitions for prettier 2.6
2// Project: https://prettier.io
3// https://github.com/prettier/prettier
4// Definitions by: Ika <https://github.com/ikatyang>
5// Ifiok Jr. <https://github.com/ifiokjr>
6// Florian Imdahl <https://github.com/ffflorian>
7// Sosuke Suzuki <https://github.com/sosukesuzuki>
8// Christopher Quadflieg <https://github.com/Shinigami92>
9// Georgii Dolzhykov <https://github.com/thorn0>
10// JounQin <https://github.com/JounQin>
11// Chuah Chee Shian <https://github.com/shian15810>
12// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
13// Minimum TypeScript Version: 4.2
14
15// Adding export {} here to shut off automatic exporting from index.d.ts. There
16// are quite a few utility types here that don't need to be shipped with the
17// exported module.
18export {};
19
20// This utility is here to handle the case where you have an explicit union
21// between string literals and the generic string type. It would normally
22// resolve out to just the string type, but this generic LiteralUnion maintains
23// the intellisense of the original union.
24//
25// It comes from this issue: microsoft/TypeScript#29729:
26// https://github.com/microsoft/TypeScript/issues/29729#issuecomment-700527227
27export type LiteralUnion<T extends U, U = string> = T | (Pick<U, never> & { _?: never | undefined });
28
29export type AST = any;
30export type Doc = doc.builders.Doc;
31
32// The type of elements that make up the given array T.
33type ArrayElement<T> = T extends Array<infer E> ? E : never;
34
35// A union of the properties of the given object that are arrays.
36type ArrayProperties<T> = { [K in keyof T]: T[K] extends any[] ? K : never }[keyof T];
37
38// A union of the properties of the given array T that can be used to index it.
39// If the array is a tuple, then that's going to be the explicit indices of the
40// array, otherwise it's going to just be number.
41type IndexProperties<T extends { length: number }> = IsTuple<T> extends true
42 ? Exclude<Partial<T>['length'], T['length']>
43 : 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[] ? (P extends number ? T[P] : never) : P extends keyof T ? T[P] : never;
48
49// Determines if an object T is an array like string[] (in which case this
50// evaluates to false) or a tuple like [string] (in which case this evaluates to
51// true).
52// eslint-disable-next-line @typescript-eslint/no-unused-vars
53type IsTuple<T> = T extends [] ? true : T extends [infer First, ...infer Remain] ? IsTuple<Remain> : false;
54
55type CallProperties<T> = T extends any[] ? IndexProperties<T> : keyof T;
56type IterProperties<T> = T extends any[] ? IndexProperties<T> : ArrayProperties<T>;
57
58type CallCallback<T, U> = (path: AstPath<T>, index: number, value: any) => U;
59type EachCallback<T> = (path: AstPath<ArrayElement<T>>, index: number, value: any) => void;
60type MapCallback<T, U> = (path: AstPath<ArrayElement<T>>, index: number, value: any) => U;
61
62// https://github.com/prettier/prettier/blob/main/src/common/ast-path.js
63export class AstPath<T = any> {
64 constructor(value: T);
65 stack: T[];
66 callParent<U>(callback: (path: this) => U, count?: number): U;
67 getName(): PropertyKey | null;
68 getValue(): T;
69 getNode(count?: number): T | null;
70 getParentNode(count?: number): T | null;
71 match(...predicates: Array<(node: any, name: string | null, number: number | null) => boolean>): boolean;
72
73 // For each of the tree walk functions (call, each, and map) this provides 5
74 // strict type signatures, along with a fallback at the end if you end up
75 // calling more than 5 properties deep. This helps a lot with typing because
76 // for the majority of cases you're calling fewer than 5 properties, so the
77 // tree walk functions have a clearer understanding of what you're doing.
78 //
79 // Note that resolving these types is somewhat complicated, and it wasn't
80 // even supported until TypeScript 4.2 (before it would just say that the
81 // type instantiation was excessively deep and possibly infinite).
82
83 call<U>(callback: CallCallback<T, U>): U;
84 call<U, P1 extends CallProperties<T>>(callback: CallCallback<IndexValue<T, P1>, U>, prop1: P1): U;
85 call<U, P1 extends keyof T, P2 extends CallProperties<T[P1]>>(
86 callback: CallCallback<IndexValue<IndexValue<T, P1>, P2>, U>,
87 prop1: P1,
88 prop2: P2,
89 ): U;
90 call<U, P1 extends keyof T, P2 extends CallProperties<T[P1]>, P3 extends CallProperties<IndexValue<T[P1], P2>>>(
91 callback: CallCallback<IndexValue<IndexValue<IndexValue<T, P1>, P2>, P3>, U>,
92 prop1: P1,
93 prop2: P2,
94 prop3: P3,
95 ): U;
96 call<
97 U,
98 P1 extends keyof T,
99 P2 extends CallProperties<T[P1]>,
100 P3 extends CallProperties<IndexValue<T[P1], P2>>,
101 P4 extends CallProperties<IndexValue<IndexValue<T[P1], P2>, P3>>
102 >(
103 callback: CallCallback<IndexValue<IndexValue<IndexValue<IndexValue<T, P1>, P2>, P3>, P4>, U>,
104 prop1: P1,
105 prop2: P2,
106 prop3: P3,
107 prop4: P4,
108 ): U;
109 call<U, P extends PropertyKey>(
110 callback: CallCallback<any, U>,
111 prop1: P,
112 prop2: P,
113 prop3: P,
114 prop4: P,
115 ...props: P[]
116 ): U;
117
118 each(callback: EachCallback<T>): void;
119 each<P1 extends IterProperties<T>>(callback: EachCallback<IndexValue<T, P1>>, prop1: P1): void;
120 each<P1 extends keyof T, P2 extends IterProperties<T[P1]>>(
121 callback: EachCallback<IndexValue<IndexValue<T, P1>, P2>>,
122 prop1: P1,
123 prop2: P2,
124 ): void;
125 each<P1 extends keyof T, P2 extends IterProperties<T[P1]>, P3 extends IterProperties<IndexValue<T[P1], P2>>>(
126 callback: EachCallback<IndexValue<IndexValue<IndexValue<T, P1>, P2>, P3>>,
127 prop1: P1,
128 prop2: P2,
129 prop3: P3,
130 ): void;
131 each<
132 P1 extends keyof T,
133 P2 extends IterProperties<T[P1]>,
134 P3 extends IterProperties<IndexValue<T[P1], P2>>,
135 P4 extends IterProperties<IndexValue<IndexValue<T[P1], P2>, P3>>
136 >(
137 callback: EachCallback<IndexValue<IndexValue<IndexValue<IndexValue<T, P1>, P2>, P3>, P4>>,
138 prop1: P1,
139 prop2: P2,
140 prop3: P3,
141 prop4: P4,
142 ): void;
143 each(
144 callback: EachCallback<any[]>,
145 prop1: PropertyKey,
146 prop2: PropertyKey,
147 prop3: PropertyKey,
148 prop4: PropertyKey,
149 ...props: PropertyKey[]
150 ): void;
151
152 map<U>(callback: MapCallback<T, U>): U[];
153 map<U, P1 extends IterProperties<T>>(callback: MapCallback<IndexValue<T, P1>, U>, prop1: P1): U[];
154 map<U, P1 extends keyof T, P2 extends IterProperties<T[P1]>>(
155 callback: MapCallback<IndexValue<IndexValue<T, P1>, P2>, U>,
156 prop1: P1,
157 prop2: P2,
158 ): U[];
159 map<U, P1 extends keyof T, P2 extends IterProperties<T[P1]>, P3 extends IterProperties<IndexValue<T[P1], P2>>>(
160 callback: MapCallback<IndexValue<IndexValue<IndexValue<T, P1>, P2>, P3>, U>,
161 prop1: P1,
162 prop2: P2,
163 prop3: P3,
164 ): U[];
165 map<
166 U,
167 P1 extends keyof T,
168 P2 extends IterProperties<T[P1]>,
169 P3 extends IterProperties<IndexValue<T[P1], P2>>,
170 P4 extends IterProperties<IndexValue<IndexValue<T[P1], P2>, P3>>
171 >(
172 callback: MapCallback<IndexValue<IndexValue<IndexValue<IndexValue<T, P1>, P2>, P3>, P4>, U>,
173 prop1: P1,
174 prop2: P2,
175 prop3: P3,
176 prop4: P4,
177 ): U[];
178 map<U>(
179 callback: MapCallback<any[], U>,
180 prop1: PropertyKey,
181 prop2: PropertyKey,
182 prop3: PropertyKey,
183 prop4: PropertyKey,
184 ...props: PropertyKey[]
185 ): U[];
186}
187
188/** @deprecated `FastPath` was renamed to `AstPath` */
189export type FastPath<T = any> = AstPath<T>;
190
191export type BuiltInParser = (text: string, options?: any) => AST;
192export type BuiltInParserName =
193 | 'angular'
194 | 'babel-flow'
195 | 'babel-ts'
196 | 'babel'
197 | 'css'
198 | 'espree'
199 | 'flow'
200 | 'glimmer'
201 | 'graphql'
202 | 'html'
203 | 'json-stringify'
204 | 'json'
205 | 'json5'
206 | 'less'
207 | 'lwc'
208 | 'markdown'
209 | 'mdx'
210 | 'meriyah'
211 | 'scss'
212 | 'typescript'
213 | 'vue'
214 | 'yaml';
215export type BuiltInParsers = Record<BuiltInParserName, BuiltInParser>;
216
217export type CustomParser = (text: string, parsers: BuiltInParsers, options: Options) => AST;
218
219/**
220 * For use in `.prettierrc.js`, `.prettierrc.cjs`, `prettier.config.js` or `prettier.config.cjs`.
221 */
222export interface Config extends Options {
223 overrides?: Array<{
224 files: string | string[];
225 excludeFiles?: string | string[];
226 options?: Options;
227 }>;
228}
229
230export interface Options extends Partial<RequiredOptions> {}
231
232export interface RequiredOptions extends doc.printer.Options {
233 /**
234 * Print semicolons at the ends of statements.
235 * @default true
236 */
237 semi: boolean;
238 /**
239 * Use single quotes instead of double quotes.
240 * @default false
241 */
242 singleQuote: boolean;
243 /**
244 * Use single quotes in JSX.
245 * @default false
246 */
247 jsxSingleQuote: boolean;
248 /**
249 * Print trailing commas wherever possible.
250 * @default 'es5'
251 */
252 trailingComma: 'none' | 'es5' | 'all';
253 /**
254 * Print spaces between brackets in object literals.
255 * @default true
256 */
257 bracketSpacing: boolean;
258 /**
259 * Put the `>` of a multi-line HTML (HTML, JSX, Vue, Angular) element at the end of the last line instead of being
260 * alone on the next line (does not apply to self closing elements).
261 * @default false
262 */
263 bracketSameLine: boolean;
264 /**
265 * Put the `>` of a multi-line JSX element at the end of the last line instead of being alone on the next line.
266 * @default false
267 * @deprecated use bracketSameLine instead
268 */
269 jsxBracketSameLine: boolean;
270 /**
271 * Format only a segment of a file.
272 * @default 0
273 */
274 rangeStart: number;
275 /**
276 * Format only a segment of a file.
277 * @default Infinity
278 */
279 rangeEnd: number;
280 /**
281 * Specify which parser to use.
282 */
283 parser: LiteralUnion<BuiltInParserName> | CustomParser;
284 /**
285 * Specify the input filepath. This will be used to do parser inference.
286 */
287 filepath: string;
288 /**
289 * Prettier can restrict itself to only format files that contain a special comment, called a pragma, at the top of the file.
290 * This is very useful when gradually transitioning large, unformatted codebases to prettier.
291 * @default false
292 */
293 requirePragma: boolean;
294 /**
295 * Prettier can insert a special @format marker at the top of files specifying that
296 * the file has been formatted with prettier. This works well when used in tandem with
297 * the --require-pragma option. If there is already a docblock at the top of
298 * the file then this option will add a newline to it with the @format marker.
299 * @default false
300 */
301 insertPragma: boolean;
302 /**
303 * By default, Prettier will wrap markdown text as-is since some services use a linebreak-sensitive renderer.
304 * In some cases you may want to rely on editor/viewer soft wrapping instead, so this option allows you to opt out.
305 * @default 'preserve'
306 */
307 proseWrap: 'always' | 'never' | 'preserve';
308 /**
309 * Include parentheses around a sole arrow function parameter.
310 * @default 'always'
311 */
312 arrowParens: 'avoid' | 'always';
313 /**
314 * Provide ability to support new languages to prettier.
315 */
316 plugins: Array<string | Plugin>;
317 /**
318 * Specify plugin directory paths to search for plugins if not installed in the same `node_modules` where prettier is located.
319 */
320 pluginSearchDirs: string[] | false;
321 /**
322 * How to handle whitespaces in HTML.
323 * @default 'css'
324 */
325 htmlWhitespaceSensitivity: 'css' | 'strict' | 'ignore';
326 /**
327 * Which end of line characters to apply.
328 * @default 'lf'
329 */
330 endOfLine: 'auto' | 'lf' | 'crlf' | 'cr';
331 /**
332 * Change when properties in objects are quoted.
333 * @default 'as-needed'
334 */
335 quoteProps: 'as-needed' | 'consistent' | 'preserve';
336 /**
337 * Whether or not to indent the code inside <script> and <style> tags in Vue files.
338 * @default false
339 */
340 vueIndentScriptAndStyle: boolean;
341 /**
342 * Control whether Prettier formats quoted code embedded in the file.
343 * @default 'auto'
344 */
345 embeddedLanguageFormatting: 'auto' | 'off';
346 /**
347 * Enforce single attribute per line in HTML, Vue and JSX.
348 * @default false
349 */
350 singleAttributePerLine: boolean;
351}
352
353export interface ParserOptions<T = any> extends RequiredOptions {
354 locStart: (node: T) => number;
355 locEnd: (node: T) => number;
356 originalText: string;
357}
358
359export interface Plugin<T = any> {
360 languages?: SupportLanguage[] | undefined;
361 parsers?: { [parserName: string]: Parser<T> } | undefined;
362 printers?: { [astFormat: string]: Printer<T> } | undefined;
363 options?: SupportOptions | undefined;
364 defaultOptions?: Partial<RequiredOptions> | undefined;
365}
366
367export interface Parser<T = any> {
368 parse: (text: string, parsers: { [parserName: string]: Parser }, options: ParserOptions<T>) => T;
369 astFormat: string;
370 hasPragma?: ((text: string) => boolean) | undefined;
371 locStart: (node: T) => number;
372 locEnd: (node: T) => number;
373 preprocess?: ((text: string, options: ParserOptions<T>) => string) | undefined;
374}
375
376export interface Printer<T = any> {
377 print(path: AstPath<T>, options: ParserOptions<T>, print: (path: AstPath<T>) => Doc): Doc;
378 embed?:
379 | ((
380 path: AstPath<T>,
381 print: (path: AstPath<T>) => Doc,
382 textToDoc: (text: string, options: Options) => Doc,
383 options: ParserOptions<T>,
384 ) => Doc | null)
385 | undefined;
386 insertPragma?: ((text: string) => string) | undefined;
387 /**
388 * @returns `null` if you want to remove this node
389 * @returns `void` if you want to use modified newNode
390 * @returns anything if you want to replace the node with it
391 */
392 massageAstNode?: ((node: any, newNode: any, parent: any) => any) | undefined;
393 hasPrettierIgnore?: ((path: AstPath<T>) => boolean) | undefined;
394 canAttachComment?: ((node: T) => boolean) | undefined;
395 isBlockComment?: ((node: T) => boolean) | undefined;
396 willPrintOwnComments?: ((path: AstPath<T>) => boolean) | undefined;
397 printComment?: ((commentPath: AstPath<T>, options: ParserOptions<T>) => Doc) | undefined;
398 handleComments?:
399 | {
400 ownLine?:
401 | ((
402 commentNode: any,
403 text: string,
404 options: ParserOptions<T>,
405 ast: T,
406 isLastComment: boolean,
407 ) => boolean)
408 | undefined;
409 endOfLine?:
410 | ((
411 commentNode: any,
412 text: string,
413 options: ParserOptions<T>,
414 ast: T,
415 isLastComment: boolean,
416 ) => boolean)
417 | undefined;
418 remaining?:
419 | ((
420 commentNode: any,
421 text: string,
422 options: ParserOptions<T>,
423 ast: T,
424 isLastComment: boolean,
425 ) => boolean)
426 | undefined;
427 }
428 | undefined;
429}
430
431export interface CursorOptions extends Options {
432 /**
433 * Specify where the cursor is.
434 */
435 cursorOffset: number;
436 rangeStart?: never;
437 rangeEnd?: never;
438}
439
440export interface CursorResult {
441 formatted: string;
442 cursorOffset: number;
443}
444
445/**
446 * `format` is used to format text using Prettier. [Options](https://prettier.io/docs/en/options.html) may be provided to override the defaults.
447 */
448export function format(source: string, options?: Options): string;
449
450/**
451 * `check` checks to see if the file has been formatted with Prettier given those options and returns a `Boolean`.
452 * This is similar to the `--list-different` parameter in the CLI and is useful for running Prettier in CI scenarios.
453 */
454export function check(source: string, options?: Options): boolean;
455
456/**
457 * `formatWithCursor` both formats the code, and translates a cursor position from unformatted code to formatted code.
458 * This is useful for editor integrations, to prevent the cursor from moving when code is formatted.
459 *
460 * The `cursorOffset` option should be provided, to specify where the cursor is. This option cannot be used with `rangeStart` and `rangeEnd`.
461 */
462export function formatWithCursor(source: string, options: CursorOptions): CursorResult;
463
464export interface ResolveConfigOptions {
465 /**
466 * If set to `false`, all caching will be bypassed.
467 */
468 useCache?: boolean | undefined;
469 /**
470 * Pass directly the path of the config file if you don't wish to search for it.
471 */
472 config?: string | undefined;
473 /**
474 * If set to `true` and an `.editorconfig` file is in your project,
475 * Prettier will parse it and convert its properties to the corresponding prettier configuration.
476 * This configuration will be overridden by `.prettierrc`, etc. Currently,
477 * the following EditorConfig properties are supported:
478 * - indent_style
479 * - indent_size/tab_width
480 * - max_line_length
481 */
482 editorconfig?: boolean | undefined;
483}
484
485/**
486 * `resolveConfig` can be used to resolve configuration for a given source file,
487 * passing its path as the first argument. The config search will start at the
488 * file path and continue to search up the directory.
489 * (You can use `process.cwd()` to start searching from the current directory).
490 *
491 * A promise is returned which will resolve to:
492 *
493 * - An options object, providing a [config file](https://prettier.io/docs/en/configuration.html) was found.
494 * - `null`, if no file was found.
495 *
496 * The promise will be rejected if there was an error parsing the configuration file.
497 */
498export function resolveConfig(filePath: string, options?: ResolveConfigOptions): Promise<Options | null>;
499export namespace resolveConfig {
500 function sync(filePath: string, options?: ResolveConfigOptions): Options | null;
501}
502
503/**
504 * `resolveConfigFile` can be used to find the path of the Prettier configuration file,
505 * that will be used when resolving the config (i.e. when calling `resolveConfig`).
506 *
507 * A promise is returned which will resolve to:
508 *
509 * - The path of the configuration file.
510 * - `null`, if no file was found.
511 *
512 * The promise will be rejected if there was an error parsing the configuration file.
513 */
514export function resolveConfigFile(filePath?: string): Promise<string | null>;
515export namespace resolveConfigFile {
516 function sync(filePath?: string): string | null;
517}
518
519/**
520 * As you repeatedly call `resolveConfig`, the file system structure will be cached for performance. This function will clear the cache.
521 * Generally this is only needed for editor integrations that know that the file system has changed since the last format took place.
522 */
523export function clearConfigCache(): void;
524
525export interface SupportLanguage {
526 name: string;
527 since?: string | undefined;
528 parsers: BuiltInParserName[] | string[];
529 group?: string | undefined;
530 tmScope?: string | undefined;
531 aceMode?: string | undefined;
532 codemirrorMode?: string | undefined;
533 codemirrorMimeType?: string | undefined;
534 aliases?: string[] | undefined;
535 extensions?: string[] | undefined;
536 filenames?: string[] | undefined;
537 linguistLanguageId?: number | undefined;
538 vscodeLanguageIds?: string[] | undefined;
539}
540
541export interface SupportOptionRange {
542 start: number;
543 end: number;
544 step: number;
545}
546
547export type SupportOptionType = 'int' | 'boolean' | 'choice' | 'path';
548
549export type CoreCategoryType = 'Config' | 'Editor' | 'Format' | 'Other' | 'Output' | 'Global' | 'Special';
550
551export interface BaseSupportOption<Type extends SupportOptionType> {
552 readonly name?: string | undefined;
553 since: string;
554 /**
555 * Usually you can use {@link CoreCategoryType}
556 */
557 category: string;
558 /**
559 * The type of the option.
560 *
561 * When passing a type other than the ones listed below, the option is
562 * treated as taking any string as argument, and `--option <${type}>` will
563 * be displayed in --help.
564 */
565 type: Type;
566 /**
567 * Indicate that the option is deprecated.
568 *
569 * Use a string to add an extra message to --help for the option,
570 * for example to suggest a replacement option.
571 */
572 deprecated?: true | string | undefined;
573 /**
574 * Description to be displayed in --help. If omitted, the option won't be
575 * shown at all in --help.
576 */
577 description?: string | undefined;
578}
579
580export interface IntSupportOption extends BaseSupportOption<'int'> {
581 default?: number | undefined;
582 array?: false | undefined;
583 range?: SupportOptionRange | undefined;
584}
585
586export interface IntArraySupportOption extends BaseSupportOption<'int'> {
587 default?: Array<{ value: number[] }> | undefined;
588 array: true;
589}
590
591export interface BooleanSupportOption extends BaseSupportOption<'boolean'> {
592 default?: boolean | undefined;
593 array?: false | undefined;
594 description: string;
595 oppositeDescription?: string | undefined;
596}
597
598export interface BooleanArraySupportOption extends BaseSupportOption<'boolean'> {
599 default?: Array<{ value: boolean[] }> | undefined;
600 array: true;
601}
602
603export interface ChoiceSupportOption<Value = any> extends BaseSupportOption<'choice'> {
604 default?: Value | Array<{ since: string; value: Value }> | undefined;
605 description: string;
606 choices: Array<{
607 since?: string | undefined;
608 value: Value;
609 description: string;
610 }>;
611}
612
613export interface PathSupportOption extends BaseSupportOption<'path'> {
614 default?: string | undefined;
615 array?: false | undefined;
616}
617
618export interface PathArraySupportOption extends BaseSupportOption<'path'> {
619 default?: Array<{ value: string[] }> | undefined;
620 array: true;
621}
622
623export type SupportOption =
624 | IntSupportOption
625 | IntArraySupportOption
626 | BooleanSupportOption
627 | BooleanArraySupportOption
628 | ChoiceSupportOption
629 | PathSupportOption
630 | PathArraySupportOption;
631
632export interface SupportOptions extends Record<string, SupportOption> {}
633
634export interface SupportInfo {
635 languages: SupportLanguage[];
636 options: SupportOption[];
637}
638
639export interface FileInfoOptions {
640 ignorePath?: string | undefined;
641 withNodeModules?: boolean | undefined;
642 plugins?: string[] | undefined;
643 resolveConfig?: boolean | undefined;
644}
645
646export interface FileInfoResult {
647 ignored: boolean;
648 inferredParser: string | null;
649}
650
651export function getFileInfo(filePath: string, options?: FileInfoOptions): Promise<FileInfoResult>;
652
653export namespace getFileInfo {
654 function sync(filePath: string, options?: FileInfoOptions): FileInfoResult;
655}
656
657/**
658 * Returns an object representing the parsers, languages and file types Prettier supports for the current version.
659 */
660export function getSupportInfo(): SupportInfo;
661
662/**
663 * `version` field in `package.json`
664 */
665export const version: string;
666
667// https://github.com/prettier/prettier/blob/main/src/common/util-shared.js
668export namespace util {
669 interface SkipOptions {
670 backwards?: boolean | undefined;
671 }
672
673 type Quote = "'" | '"';
674
675 function addDanglingComment(node: any, comment: any, marker: any): void;
676 function addLeadingComment(node: any, comment: any): void;
677 function addTrailingComment(node: any, comment: any): void;
678 function getAlignmentSize(value: string, tabWidth: number, startIndex?: number): number;
679 function getIndentSize(value: string, tabWidth: number): number;
680 function getMaxContinuousCount(str: string, target: string): number;
681 function getNextNonSpaceNonCommentCharacterIndex<N>(
682 text: string,
683 node: N,
684 locEnd: (node: N) => number,
685 ): number | false;
686 function getStringWidth(text: string): number;
687 function hasNewline(text: string, index: number, opts?: SkipOptions): boolean;
688 function hasNewlineInRange(text: string, start: number, end: number): boolean;
689 function hasSpaces(text: string, index: number, opts?: SkipOptions): boolean;
690 function isNextLineEmpty<N>(text: string, node: N, locEnd: (node: N) => number): boolean;
691 function isNextLineEmptyAfterIndex(text: string, index: number): boolean;
692 function isPreviousLineEmpty<N>(text: string, node: N, locStart: (node: N) => number): boolean;
693 function makeString(rawContent: string, enclosingQuote: Quote, unescapeUnnecessaryEscapes?: boolean): string;
694 function skip(chars: string | RegExp): (text: string, index: number | false, opts?: SkipOptions) => number | false;
695 function skipEverythingButNewLine(text: string, index: number | false, opts?: SkipOptions): number | false;
696 function skipInlineComment(text: string, index: number | false): number | false;
697 function skipNewline(text: string, index: number | false, opts?: SkipOptions): number | false;
698 function skipSpaces(text: string, index: number | false, opts?: SkipOptions): number | false;
699 function skipToLineEnd(text: string, index: number | false, opts?: SkipOptions): number | false;
700 function skipTrailingComment(text: string, index: number | false): number | false;
701 function skipWhitespace(text: string, index: number | false, opts?: SkipOptions): number | false;
702}
703
704// https://github.com/prettier/prettier/blob/main/src/document/index.js
705export namespace doc {
706 namespace builders {
707 type DocCommand =
708 | Align
709 | BreakParent
710 | Concat
711 | Cursor
712 | Fill
713 | Group
714 | IfBreak
715 | Indent
716 | IndentIfBreak
717 | Label
718 | Line
719 | LineSuffix
720 | LineSuffixBoundary
721 | Trim;
722 type Doc = string | Doc[] | DocCommand;
723
724 interface Align {
725 type: 'align';
726 contents: Doc;
727 n: number | string | { type: 'root' };
728 }
729
730 interface BreakParent {
731 type: 'break-parent';
732 }
733
734 interface Concat {
735 type: 'concat';
736 parts: Doc[];
737 }
738
739 interface Cursor {
740 type: 'cursor';
741 placeholder: symbol;
742 }
743
744 interface Fill {
745 type: 'fill';
746 parts: Doc[];
747 }
748
749 interface Group {
750 type: 'group';
751 contents: Doc;
752 break: boolean;
753 expandedStates: Doc[];
754 }
755
756 interface HardlineWithoutBreakParent extends Line {
757 hard: true;
758 }
759
760 interface IfBreak {
761 type: 'if-break';
762 breakContents: Doc;
763 flatContents: Doc;
764 }
765
766 interface Indent {
767 type: 'indent';
768 contents: Doc;
769 }
770
771 interface IndentIfBreak {
772 type: 'indent-if-break';
773 }
774
775 interface Label {
776 type: 'label';
777 }
778
779 interface Line {
780 type: 'line';
781 soft?: boolean | undefined;
782 hard?: boolean | undefined;
783 literal?: boolean | undefined;
784 }
785
786 interface LineSuffix {
787 type: 'line-suffix';
788 contents: Doc;
789 }
790
791 interface LineSuffixBoundary {
792 type: 'line-suffix-boundary';
793 }
794
795 interface LiterallineWithoutBreakParent extends Line {
796 hard: true;
797 literal: true;
798 }
799
800 interface Softline extends Line {
801 soft: true;
802 }
803
804 interface Trim {
805 type: 'trim';
806 }
807
808 interface GroupOptions {
809 shouldBreak?: boolean | undefined;
810 id?: symbol | undefined;
811 }
812
813 function addAlignmentToDoc(doc: Doc, size: number, tabWidth: number): Doc;
814 /** @see [align](https://github.com/prettier/prettier/blob/main/commands.md#align) */
815 function align(widthOrString: Align['n'], doc: Doc): Align;
816 /** @see [breakParent](https://github.com/prettier/prettier/blob/main/commands.md#breakparent) */
817 const breakParent: BreakParent;
818 /**
819 * @see [concat](https://github.com/prettier/prettier/blob/main/commands.md#deprecated-concat)
820 * @deprecated use `Doc[]` instead
821 */
822 function concat(docs: Doc[]): Concat;
823 /** @see [conditionalGroup](https://github.com/prettier/prettier/blob/main/commands.md#conditionalgroup) */
824 function conditionalGroup(alternatives: Doc[], options?: GroupOptions): Group;
825 /** @see [dedent](https://github.com/prettier/prettier/blob/main/commands.md#dedent) */
826 function dedent(doc: Doc): Align;
827 /** @see [dedentToRoot](https://github.com/prettier/prettier/blob/main/commands.md#dedenttoroot) */
828 function dedentToRoot(doc: Doc): Align;
829 /** @see [fill](https://github.com/prettier/prettier/blob/main/commands.md#fill) */
830 function fill(docs: Doc[]): Fill;
831 /** @see [group](https://github.com/prettier/prettier/blob/main/commands.md#group) */
832 function group(doc: Doc, opts?: GroupOptions): Group;
833 /** @see [hardline](https://github.com/prettier/prettier/blob/main/commands.md#hardline) */
834 const hardline: Concat;
835 /** @see [hardlineWithoutBreakParent](https://github.com/prettier/prettier/blob/main/commands.md#hardlinewithoutbreakparent-and-literallinewithoutbreakparent) */
836 const hardlineWithoutBreakParent: HardlineWithoutBreakParent;
837 /** @see [ifBreak](https://github.com/prettier/prettier/blob/main/commands.md#ifbreak) */
838 function ifBreak(ifBreak: Doc, noBreak?: Doc, options?: { groupId?: symbol | undefined }): IfBreak;
839 /** @see [indent](https://github.com/prettier/prettier/blob/main/commands.md#indent) */
840 function indent(doc: Doc): Indent;
841 /** @see [indentIfBreak](https://github.com/prettier/prettier/blob/main/commands.md#indentifbreak) */
842 function indentIfBreak(doc: Doc, opts: { groupId: symbol; negate?: boolean | undefined }): IndentIfBreak;
843 /** @see [join](https://github.com/prettier/prettier/blob/main/commands.md#join) */
844 function join(sep: Doc, docs: Doc[]): Concat;
845 /** @see [label](https://github.com/prettier/prettier/blob/main/commands.md#label) */
846 function label(label: string, doc: Doc): Label;
847 /** @see [line](https://github.com/prettier/prettier/blob/main/commands.md#line) */
848 const line: Line;
849 /** @see [lineSuffix](https://github.com/prettier/prettier/blob/main/commands.md#linesuffix) */
850 function lineSuffix(suffix: Doc): LineSuffix;
851 /** @see [lineSuffixBoundary](https://github.com/prettier/prettier/blob/main/commands.md#linesuffixboundary) */
852 const lineSuffixBoundary: LineSuffixBoundary;
853 /** @see [literalline](https://github.com/prettier/prettier/blob/main/commands.md#literalline) */
854 const literalline: Concat;
855 /** @see [literallineWithoutBreakParent](https://github.com/prettier/prettier/blob/main/commands.md#hardlinewithoutbreakparent-and-literallinewithoutbreakparent) */
856 const literallineWithoutBreakParent: LiterallineWithoutBreakParent;
857 /** @see [markAsRoot](https://github.com/prettier/prettier/blob/main/commands.md#markasroot) */
858 function markAsRoot(doc: Doc): Align;
859 /** @see [softline](https://github.com/prettier/prettier/blob/main/commands.md#softline) */
860 const softline: Softline;
861 /** @see [trim](https://github.com/prettier/prettier/blob/main/commands.md#trim) */
862 const trim: Trim;
863 /** @see [cursor](https://github.com/prettier/prettier/blob/main/commands.md#cursor) */
864 const cursor: Cursor;
865 }
866 namespace debug {
867 function printDocToDebug(doc: Doc): string;
868 }
869 namespace printer {
870 function printDocToString(
871 doc: Doc,
872 options: Options,
873 ): {
874 formatted: string;
875 cursorNodeStart?: number | undefined;
876 cursorNodeText?: string | undefined;
877 };
878 interface Options {
879 /**
880 * Specify the line length that the printer will wrap on.
881 * @default 80
882 */
883 printWidth: number;
884 /**
885 * Specify the number of spaces per indentation-level.
886 * @default 2
887 */
888 tabWidth: number;
889 /**
890 * Indent lines with tabs instead of spaces
891 * @default false
892 */
893 useTabs: boolean;
894 parentParser?: string | undefined;
895 __embeddedInHtml?: boolean | undefined;
896 }
897 }
898 namespace utils {
899 function cleanDoc(doc: Doc): Doc;
900 function findInDoc<T = Doc>(doc: Doc, callback: (doc: Doc) => T, defaultValue: T): T;
901 function getDocParts(doc: Doc): Doc;
902 function isConcat(doc: Doc): boolean;
903 function isEmpty(doc: Doc): boolean;
904 function isLineNext(doc: Doc): boolean;
905 function mapDoc<T = Doc>(doc: Doc, callback: (doc: Doc) => T): T;
906 function normalizeDoc(doc: Doc): Doc;
907 function normalizeParts(parts: Doc[]): Doc[];
908 function propagateBreaks(doc: Doc): void;
909 function removeLines(doc: Doc): Doc;
910 function replaceNewlinesWithLiterallines(doc: Doc): Doc;
911 function stripTrailingHardline(doc: Doc): Doc;
912 function traverseDoc(
913 doc: Doc,
914 onEnter?: (doc: Doc) => void | boolean,
915 onExit?: (doc: Doc) => void,
916 shouldTraverseConditionalGroups?: boolean,
917 ): void;
918 function willBreak(doc: Doc): boolean;
919 }
920}
921
\No newline at end of file