1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | export type AST = any;
|
11 | export type Doc = doc.builders.Doc;
|
12 |
|
13 |
|
14 | export interface FastPath<T = any> {
|
15 | stack: any[];
|
16 | getName(): null | PropertyKey;
|
17 | getValue(): T;
|
18 | getNode(count?: number): null | T;
|
19 | getParentNode(count?: number): null | T;
|
20 | call<U>(callback: (path: this) => U, ...names: PropertyKey[]): U;
|
21 | each(callback: (path: this) => void, ...names: PropertyKey[]): void;
|
22 | map<U>(callback: (path: this, index: number) => U, ...names: PropertyKey[]): U[];
|
23 | }
|
24 |
|
25 | export type BuiltInParser = (text: string, options?: any) => AST;
|
26 | export type BuiltInParserName =
|
27 | | 'babel'
|
28 | | 'babel-flow'
|
29 | | 'babel-ts'
|
30 | | 'flow'
|
31 | | 'typescript'
|
32 | | 'css'
|
33 | | 'less'
|
34 | | 'scss'
|
35 | | 'json'
|
36 | | 'json5'
|
37 | | 'json-stringify'
|
38 | | 'graphql'
|
39 | | 'markdown'
|
40 | | 'vue'
|
41 | | 'html'
|
42 | | 'angular'
|
43 | | 'mdx'
|
44 | | 'yaml'
|
45 | | 'lwc';
|
46 |
|
47 | export type CustomParser = (text: string, parsers: Record<BuiltInParserName, BuiltInParser>, options: Options) => AST;
|
48 |
|
49 | export interface Options extends Partial<RequiredOptions> {}
|
50 | export interface RequiredOptions extends doc.printer.Options {
|
51 | |
52 |
|
53 |
|
54 |
|
55 | semi: boolean;
|
56 | |
57 |
|
58 |
|
59 |
|
60 | singleQuote: boolean;
|
61 | |
62 |
|
63 |
|
64 |
|
65 | jsxSingleQuote: boolean;
|
66 | |
67 |
|
68 |
|
69 |
|
70 | trailingComma: 'none' | 'es5' | 'all';
|
71 | |
72 |
|
73 |
|
74 |
|
75 | bracketSpacing: boolean;
|
76 | |
77 |
|
78 |
|
79 |
|
80 | jsxBracketSameLine: boolean;
|
81 | |
82 |
|
83 |
|
84 |
|
85 | rangeStart: number;
|
86 | |
87 |
|
88 |
|
89 |
|
90 | rangeEnd: number;
|
91 | |
92 |
|
93 |
|
94 | parser: BuiltInParserName | CustomParser;
|
95 | |
96 |
|
97 |
|
98 | filepath: string;
|
99 | |
100 |
|
101 |
|
102 |
|
103 |
|
104 | requirePragma: boolean;
|
105 | |
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 | insertPragma: boolean;
|
113 | |
114 |
|
115 |
|
116 |
|
117 |
|
118 | proseWrap: 'always' | 'never' | 'preserve';
|
119 | |
120 |
|
121 |
|
122 |
|
123 | arrowParens: 'avoid' | 'always';
|
124 | |
125 |
|
126 |
|
127 | plugins: Array<string | Plugin>;
|
128 | |
129 |
|
130 |
|
131 |
|
132 | htmlWhitespaceSensitivity: 'css' | 'strict' | 'ignore';
|
133 | |
134 |
|
135 |
|
136 |
|
137 | endOfLine: 'auto' | 'lf' | 'crlf' | 'cr';
|
138 | |
139 |
|
140 |
|
141 |
|
142 | quoteProps: 'as-needed' | 'consistent' | 'preserve';
|
143 | |
144 |
|
145 |
|
146 |
|
147 | vueIndentScriptAndStyle: boolean;
|
148 | }
|
149 |
|
150 | export interface ParserOptions extends RequiredOptions {
|
151 | locStart: (node: any) => number;
|
152 | locEnd: (node: any) => number;
|
153 | originalText: string;
|
154 | }
|
155 |
|
156 | export interface Plugin {
|
157 | languages?: SupportLanguage[];
|
158 | parsers?: { [parserName: string]: Parser };
|
159 | printers?: { [astFormat: string]: Printer };
|
160 | options?: SupportOption[];
|
161 | defaultOptions?: Partial<RequiredOptions>;
|
162 | }
|
163 |
|
164 | export interface Parser {
|
165 | parse: (text: string, parsers: { [parserName: string]: Parser }, options: ParserOptions) => AST;
|
166 | astFormat: string;
|
167 | hasPragma?: (text: string) => boolean;
|
168 | locStart: (node: any) => number;
|
169 | locEnd: (node: any) => number;
|
170 | preprocess?: (text: string, options: ParserOptions) => string;
|
171 | }
|
172 |
|
173 | export interface Printer {
|
174 | print(path: FastPath, options: ParserOptions, print: (path: FastPath) => Doc): Doc;
|
175 | embed?: (
|
176 | path: FastPath,
|
177 | print: (path: FastPath) => Doc,
|
178 | textToDoc: (text: string, options: Options) => Doc,
|
179 | options: ParserOptions,
|
180 | ) => Doc | null;
|
181 | insertPragma?: (text: string) => string;
|
182 | |
183 |
|
184 |
|
185 |
|
186 |
|
187 | massageAstNode?: (node: any, newNode: any, parent: any) => any;
|
188 | hasPrettierIgnore?: (path: FastPath) => boolean;
|
189 | canAttachComment?: (node: any) => boolean;
|
190 | willPrintOwnComments?: (path: FastPath) => boolean;
|
191 | printComments?: (path: FastPath, print: (path: FastPath) => Doc, options: ParserOptions, needsSemi: boolean) => Doc;
|
192 | handleComments?: {
|
193 | ownLine?: (commentNode: any, text: string, options: ParserOptions, ast: any, isLastComment: boolean) => boolean;
|
194 | endOfLine?: (
|
195 | commentNode: any,
|
196 | text: string,
|
197 | options: ParserOptions,
|
198 | ast: any,
|
199 | isLastComment: boolean,
|
200 | ) => boolean;
|
201 | remaining?: (
|
202 | commentNode: any,
|
203 | text: string,
|
204 | options: ParserOptions,
|
205 | ast: any,
|
206 | isLastComment: boolean,
|
207 | ) => boolean;
|
208 | };
|
209 | }
|
210 |
|
211 | export interface CursorOptions extends Options {
|
212 | |
213 |
|
214 |
|
215 | cursorOffset: number;
|
216 | rangeStart?: never;
|
217 | rangeEnd?: never;
|
218 | }
|
219 |
|
220 | export interface CursorResult {
|
221 | formatted: string;
|
222 | cursorOffset: number;
|
223 | }
|
224 |
|
225 |
|
226 |
|
227 |
|
228 | export function format(source: string, options?: Options): string;
|
229 |
|
230 |
|
231 |
|
232 |
|
233 |
|
234 | export function check(source: string, options?: Options): boolean;
|
235 |
|
236 |
|
237 |
|
238 |
|
239 |
|
240 |
|
241 |
|
242 | export function formatWithCursor(source: string, options: CursorOptions): CursorResult;
|
243 |
|
244 | export interface ResolveConfigOptions {
|
245 | |
246 |
|
247 |
|
248 | useCache?: boolean;
|
249 | |
250 |
|
251 |
|
252 | config?: string;
|
253 | |
254 |
|
255 |
|
256 |
|
257 |
|
258 |
|
259 |
|
260 |
|
261 |
|
262 | editorconfig?: boolean;
|
263 | }
|
264 |
|
265 |
|
266 |
|
267 |
|
268 |
|
269 |
|
270 |
|
271 |
|
272 |
|
273 |
|
274 |
|
275 |
|
276 |
|
277 |
|
278 | export function resolveConfig(filePath: string, options?: ResolveConfigOptions): Promise<null | Options>;
|
279 | export namespace resolveConfig {
|
280 | function sync(filePath: string, options?: ResolveConfigOptions): null | Options;
|
281 | }
|
282 |
|
283 |
|
284 |
|
285 |
|
286 |
|
287 |
|
288 |
|
289 |
|
290 |
|
291 |
|
292 |
|
293 |
|
294 | export function resolveConfigFile(filePath?: string): Promise<null | string>;
|
295 | export namespace resolveConfigFile {
|
296 | function sync(filePath?: string): null | string;
|
297 | }
|
298 |
|
299 |
|
300 |
|
301 |
|
302 |
|
303 | export function clearConfigCache(): void;
|
304 |
|
305 | export interface SupportLanguage {
|
306 | name: string;
|
307 | since?: string;
|
308 | parsers: BuiltInParserName[] | string[];
|
309 | group?: string;
|
310 | tmScope?: string;
|
311 | aceMode?: string;
|
312 | codemirrorMode?: string;
|
313 | codemirrorMimeType?: string;
|
314 | aliases?: string[];
|
315 | extensions?: string[];
|
316 | filenames?: string[];
|
317 | linguistLanguageId?: number;
|
318 | vscodeLanguageIds?: string[];
|
319 | }
|
320 |
|
321 | export interface SupportOptionDefault {
|
322 | since: string;
|
323 | value: SupportOptionValue;
|
324 | }
|
325 |
|
326 | export interface SupportOption {
|
327 | since?: string;
|
328 | type: 'int' | 'boolean' | 'choice' | 'path';
|
329 | array?: boolean;
|
330 | deprecated?: string;
|
331 | redirect?: SupportOptionRedirect;
|
332 | description: string;
|
333 | oppositeDescription?: string;
|
334 | default: SupportOptionValue | SupportOptionDefault[];
|
335 | range?: SupportOptionRange;
|
336 | choices?: SupportOptionChoice[];
|
337 | category: string;
|
338 | }
|
339 |
|
340 | export interface SupportOptionRedirect {
|
341 | options: string;
|
342 | value: SupportOptionValue;
|
343 | }
|
344 |
|
345 | export interface SupportOptionRange {
|
346 | start: number;
|
347 | end: number;
|
348 | step: number;
|
349 | }
|
350 |
|
351 | export interface SupportOptionChoice {
|
352 | value: boolean | string;
|
353 | description?: string;
|
354 | since?: string;
|
355 | deprecated?: string;
|
356 | redirect?: SupportOptionValue;
|
357 | }
|
358 |
|
359 | export type SupportOptionValue = number | boolean | string;
|
360 |
|
361 | export interface SupportInfo {
|
362 | languages: SupportLanguage[];
|
363 | options: SupportOption[];
|
364 | }
|
365 |
|
366 | export interface FileInfoOptions {
|
367 | ignorePath?: string;
|
368 | withNodeModules?: boolean;
|
369 | plugins?: string[];
|
370 | resolveConfig?: boolean;
|
371 | }
|
372 |
|
373 | export interface FileInfoResult {
|
374 | ignored: boolean;
|
375 | inferredParser: string | null;
|
376 | }
|
377 |
|
378 | export function getFileInfo(filePath: string, options?: FileInfoOptions): Promise<FileInfoResult>;
|
379 |
|
380 | export namespace getFileInfo {
|
381 | function sync(filePath: string, options?: FileInfoOptions): FileInfoResult;
|
382 | }
|
383 |
|
384 |
|
385 |
|
386 |
|
387 | export function getSupportInfo(): SupportInfo;
|
388 |
|
389 |
|
390 |
|
391 |
|
392 | export const version: string;
|
393 |
|
394 |
|
395 | export namespace util {
|
396 | function isNextLineEmpty(text: string, node: any, locEnd: (node: any) => number): boolean;
|
397 | function isNextLineEmptyAfterIndex(text: string, index: number): boolean;
|
398 | function isPreviousLineEmpty(text: string, node: any, locStart: (node: any) => number): boolean;
|
399 | function getNextNonSpaceNonCommentCharacterIndex(text: string, node: any, options: ParserOptions): number;
|
400 | function makeString(rawContent: string, enclosingQuote: "'" | '"', unescapeUnnecessaryEscapes: boolean): string;
|
401 | function addLeadingComment(node: any, commentNode: any): void;
|
402 | function addDanglingComment(node: any, commentNode: any): void;
|
403 | function addTrailingComment(node: any, commentNode: any): void;
|
404 | }
|
405 |
|
406 |
|
407 | export namespace doc {
|
408 | namespace builders {
|
409 | type Doc =
|
410 | | string
|
411 | | Align
|
412 | | BreakParent
|
413 | | Concat
|
414 | | Fill
|
415 | | Group
|
416 | | IfBreak
|
417 | | Indent
|
418 | | Line
|
419 | | LineSuffix
|
420 | | LineSuffixBoundary;
|
421 |
|
422 | interface Align {
|
423 | type: 'align';
|
424 | contents: Doc;
|
425 | n: number | string | { type: 'root' };
|
426 | }
|
427 |
|
428 | interface BreakParent {
|
429 | type: 'break-parent';
|
430 | }
|
431 |
|
432 | interface Concat {
|
433 | type: 'concat';
|
434 | parts: Doc[];
|
435 | }
|
436 |
|
437 | interface Fill {
|
438 | type: 'fill';
|
439 | parts: Doc[];
|
440 | }
|
441 |
|
442 | interface Group {
|
443 | type: 'group';
|
444 | contents: Doc;
|
445 | break: boolean;
|
446 | expandedStates: Doc[];
|
447 | }
|
448 |
|
449 | interface IfBreak {
|
450 | type: 'if-break';
|
451 | breakContents: Doc;
|
452 | flatContents: Doc;
|
453 | }
|
454 |
|
455 | interface Indent {
|
456 | type: 'indent';
|
457 | contents: Doc;
|
458 | }
|
459 |
|
460 | interface Line {
|
461 | type: 'line';
|
462 | soft?: boolean;
|
463 | hard?: boolean;
|
464 | literal?: boolean;
|
465 | }
|
466 |
|
467 | interface LineSuffix {
|
468 | type: 'line-suffix';
|
469 | contents: Doc;
|
470 | }
|
471 |
|
472 | interface LineSuffixBoundary {
|
473 | type: 'line-suffix-boundary';
|
474 | }
|
475 |
|
476 | function addAlignmentToDoc(doc: Doc, size: number, tabWidth: number): Doc;
|
477 | function align(n: Align['n'], contents: Doc): Align;
|
478 | const breakParent: BreakParent;
|
479 | function concat(contents: Doc[]): Concat;
|
480 | function conditionalGroup(states: Doc[], opts?: { shouldBreak: boolean }): Group;
|
481 | function dedent(contents: Doc): Align;
|
482 | function dedentToRoot(contents: Doc): Align;
|
483 | function fill(parts: Doc[]): Fill;
|
484 | function group(contents: Doc, opts?: { shouldBreak: boolean }): Group;
|
485 | const hardline: Concat;
|
486 | function ifBreak(breakContents: Doc, flatContents: Doc): IfBreak;
|
487 | function indent(contents: Doc): Indent;
|
488 | function join(separator: Doc, parts: Doc[]): Concat;
|
489 | const line: Line;
|
490 | function lineSuffix(contents: Doc): LineSuffix;
|
491 | const lineSuffixBoundary: LineSuffixBoundary;
|
492 | const literalline: Concat;
|
493 | function markAsRoot(contents: Doc): Align;
|
494 | const softline: Line;
|
495 | }
|
496 | namespace debug {
|
497 | function printDocToDebug(doc: Doc): string;
|
498 | }
|
499 | namespace printer {
|
500 | function printDocToString(
|
501 | doc: Doc,
|
502 | options: Options,
|
503 | ): {
|
504 | formatted: string;
|
505 | cursorNodeStart?: number;
|
506 | cursorNodeText?: string;
|
507 | };
|
508 | interface Options {
|
509 | |
510 |
|
511 |
|
512 |
|
513 | printWidth: number;
|
514 | |
515 |
|
516 |
|
517 |
|
518 | tabWidth: number;
|
519 | |
520 |
|
521 |
|
522 |
|
523 | useTabs: boolean;
|
524 | }
|
525 | }
|
526 | namespace utils {
|
527 | function isEmpty(doc: Doc): boolean;
|
528 | function isLineNext(doc: Doc): boolean;
|
529 | function willBreak(doc: Doc): boolean;
|
530 | function traverseDoc(
|
531 | doc: Doc,
|
532 | onEnter?: (doc: Doc) => void | boolean,
|
533 | onExit?: (doc: Doc) => void,
|
534 | shouldTraverseConditionalGroups?: boolean,
|
535 | ): void;
|
536 | function mapDoc<T>(doc: Doc, callback: (doc: Doc) => T): T;
|
537 | function propagateBreaks(doc: Doc): void;
|
538 | function removeLines(doc: Doc): Doc;
|
539 | function stripTrailingHardline(doc: Doc): Doc;
|
540 | }
|
541 | }
|