// Copied from `@types/prettier` // https://github.com/DefinitelyTyped/DefinitelyTyped/blob/5bb07fc4b087cb7ee91084afa6fe750551a7bbb1/types/prettier/index.d.ts // Minimum TypeScript Version: 4.2 // Add `export {}` here to shut off automatic exporting from index.d.ts. There // are quite a few utility types here that don't need to be shipped with the // exported module. export {}; import { builders, printer, utils } from "./doc.js"; export namespace doc { export { builders, printer, utils }; } // This utility is here to handle the case where you have an explicit union // between string literals and the generic string type. It would normally // resolve out to just the string type, but this generic LiteralUnion maintains // the intellisense of the original union. // // It comes from this issue: microsoft/TypeScript#29729: // https://github.com/microsoft/TypeScript/issues/29729#issuecomment-700527227 export type LiteralUnion = | T | (Pick & { _?: never | undefined }); export type AST = any; export type Doc = doc.builders.Doc; // The type of elements that make up the given array T. type ArrayElement = T extends Array ? E : never; // A union of the properties of the given object that are arrays. type ArrayProperties = { [K in keyof T]: NonNullable extends readonly any[] ? K : never; }[keyof T]; // A union of the properties of the given array T that can be used to index it. // If the array is a tuple, then that's going to be the explicit indices of the // array, otherwise it's going to just be number. type IndexProperties = IsTuple extends true ? Exclude["length"], T["length"]> : number; // Effectively performing T[P], except that it's telling TypeScript that it's // safe to do this for tuples, arrays, or objects. type IndexValue = T extends any[] ? P extends number ? T[P] : never : P extends keyof T ? T[P] : never; // Determines if an object T is an array like string[] (in which case this // evaluates to false) or a tuple like [string] (in which case this evaluates to // true). // eslint-disable-next-line @typescript-eslint/no-unused-vars type IsTuple = T extends [] ? true : T extends [infer First, ...infer Remain] ? IsTuple : false; type CallProperties = T extends any[] ? IndexProperties : keyof T; type IterProperties = T extends any[] ? IndexProperties : ArrayProperties; type CallCallback = (path: AstPath, index: number, value: any) => U; type EachCallback = ( path: AstPath>, index: number, value: any, ) => void; type MapCallback = ( path: AstPath>, index: number, value: any, ) => U; // https://github.com/prettier/prettier/blob/next/src/common/ast-path.js export class AstPath { constructor(value: T); get key(): string | null; get index(): number | null; get node(): T; get parent(): T | null; get grandparent(): T | null; get isInArray(): boolean; get siblings(): T[] | null; get next(): T | null; get previous(): T | null; get isFirst(): boolean; get isLast(): boolean; get isRoot(): boolean; get root(): T; get ancestors(): T[]; stack: T[]; callParent(callback: (path: this) => U, count?: number): U; /** * @deprecated Please use `AstPath#key` or `AstPath#index` */ getName(): PropertyKey | null; /** * @deprecated Please use `AstPath#node` or `AstPath#siblings` */ getValue(): T; getNode(count?: number): T | null; getParentNode(count?: number): T | null; match( ...predicates: Array< (node: any, name: string | null, number: number | null) => boolean > ): boolean; // For each of the tree walk functions (call, each, and map) this provides 5 // strict type signatures, along with a fallback at the end if you end up // calling more than 5 properties deep. This helps a lot with typing because // for the majority of cases you're calling fewer than 5 properties, so the // tree walk functions have a clearer understanding of what you're doing. // // Note that resolving these types is somewhat complicated, and it wasn't // even supported until TypeScript 4.2 (before it would just say that the // type instantiation was excessively deep and possibly infinite). call(callback: CallCallback): U; call>( callback: CallCallback, U>, prop1: P1, ): U; call>( callback: CallCallback, P2>, U>, prop1: P1, prop2: P2, ): U; call< U, P1 extends keyof T, P2 extends CallProperties, P3 extends CallProperties>, >( callback: CallCallback< IndexValue, P2>, P3>, U >, prop1: P1, prop2: P2, prop3: P3, ): U; call< U, P1 extends keyof T, P2 extends CallProperties, P3 extends CallProperties>, P4 extends CallProperties, P3>>, >( callback: CallCallback< IndexValue, P2>, P3>, P4>, U >, prop1: P1, prop2: P2, prop3: P3, prop4: P4, ): U; call( callback: CallCallback, prop1: P, prop2: P, prop3: P, prop4: P, ...props: P[] ): U; each(callback: EachCallback): void; each>( callback: EachCallback>, prop1: P1, ): void; each>( callback: EachCallback, P2>>, prop1: P1, prop2: P2, ): void; each< P1 extends keyof T, P2 extends IterProperties, P3 extends IterProperties>, >( callback: EachCallback, P2>, P3>>, prop1: P1, prop2: P2, prop3: P3, ): void; each< P1 extends keyof T, P2 extends IterProperties, P3 extends IterProperties>, P4 extends IterProperties, P3>>, >( callback: EachCallback< IndexValue, P2>, P3>, P4> >, prop1: P1, prop2: P2, prop3: P3, prop4: P4, ): void; each( callback: EachCallback, prop1: PropertyKey, prop2: PropertyKey, prop3: PropertyKey, prop4: PropertyKey, ...props: PropertyKey[] ): void; map(callback: MapCallback): U[]; map>( callback: MapCallback, U>, prop1: P1, ): U[]; map>( callback: MapCallback, P2>, U>, prop1: P1, prop2: P2, ): U[]; map< U, P1 extends keyof T, P2 extends IterProperties, P3 extends IterProperties>, >( callback: MapCallback, P2>, P3>, U>, prop1: P1, prop2: P2, prop3: P3, ): U[]; map< U, P1 extends keyof T, P2 extends IterProperties, P3 extends IterProperties>, P4 extends IterProperties, P3>>, >( callback: MapCallback< IndexValue, P2>, P3>, P4>, U >, prop1: P1, prop2: P2, prop3: P3, prop4: P4, ): U[]; map( callback: MapCallback, prop1: PropertyKey, prop2: PropertyKey, prop3: PropertyKey, prop4: PropertyKey, ...props: PropertyKey[] ): U[]; } /** @deprecated `FastPath` was renamed to `AstPath` */ export type FastPath = AstPath; export type BuiltInParser = (text: string, options?: any) => AST; export type BuiltInParserName = | "acorn" | "angular" | "babel-flow" | "babel-ts" | "babel" | "css" | "espree" | "flow" | "glimmer" | "graphql" | "html" | "json-stringify" | "json" | "json5" | "jsonc" | "less" | "lwc" | "markdown" | "mdx" | "meriyah" | "scss" | "typescript" | "vue" | "yaml"; export type BuiltInParsers = Record; /** * For use in `.prettierrc.js`, `.prettierrc.cjs`, `prettierrc.mjs`, `prettier.config.js`, `prettier.config.cjs`, `prettier.config.mjs` */ export interface Config extends Options { overrides?: Array<{ files: string | string[]; excludeFiles?: string | string[]; options?: Options; }>; } export interface Options extends Partial {} export interface RequiredOptions extends doc.printer.Options { /** * Print semicolons at the ends of statements. * @default true */ semi: boolean; /** * Use single quotes instead of double quotes. * @default false */ singleQuote: boolean; /** * Use single quotes in JSX. * @default false */ jsxSingleQuote: boolean; /** * Print trailing commas wherever possible. * @default "all" */ trailingComma: "none" | "es5" | "all"; /** * Print spaces between brackets in object literals. * @default true */ bracketSpacing: boolean; /** * Put the `>` of a multi-line HTML (HTML, JSX, Vue, Angular) element at the end of the last line instead of being * alone on the next line (does not apply to self closing elements). * @default false */ bracketSameLine: boolean; /** * Format only a segment of a file. * @default 0 */ rangeStart: number; /** * Format only a segment of a file. * @default Number.POSITIVE_INFINITY */ rangeEnd: number; /** * Specify which parser to use. */ parser: LiteralUnion; /** * Specify the input filepath. This will be used to do parser inference. */ filepath: string; /** * Prettier can restrict itself to only format files that contain a special comment, called a pragma, at the top of the file. * This is very useful when gradually transitioning large, unformatted codebases to prettier. * @default false */ requirePragma: boolean; /** * Prettier can insert a special @format marker at the top of files specifying that * the file has been formatted with prettier. This works well when used in tandem with * the --require-pragma option. If there is already a docblock at the top of * the file then this option will add a newline to it with the @format marker. * @default false */ insertPragma: boolean; /** * By default, Prettier will wrap markdown text as-is since some services use a linebreak-sensitive renderer. * In some cases you may want to rely on editor/viewer soft wrapping instead, so this option allows you to opt out. * @default "preserve" */ proseWrap: "always" | "never" | "preserve"; /** * Include parentheses around a sole arrow function parameter. * @default "always" */ arrowParens: "avoid" | "always"; /** * Provide ability to support new languages to prettier. */ plugins: Array; /** * How to handle whitespaces in HTML. * @default "css" */ htmlWhitespaceSensitivity: "css" | "strict" | "ignore"; /** * Which end of line characters to apply. * @default "lf" */ endOfLine: "auto" | "lf" | "crlf" | "cr"; /** * Change when properties in objects are quoted. * @default "as-needed" */ quoteProps: "as-needed" | "consistent" | "preserve"; /** * Whether or not to indent the code inside