import { JS } from '../tree'; import { J } from '../../java'; import { Cursor, Tree } from '../../tree'; import { PrettierStyle } from '../style'; import { NamedStyles } from '../../style'; /** * Options for Prettier formatting. */ export interface PrettierFormatOptions { /** * Tab width for indentation. Defaults to 2. */ tabWidth?: number; /** * Use tabs instead of spaces. Defaults to false. */ useTabs?: boolean; /** * Print semicolons at the ends of statements. Defaults to true. */ semi?: boolean; /** * Use single quotes instead of double quotes. Defaults to false. */ singleQuote?: boolean; /** * Print trailing commas wherever possible. Defaults to 'all'. */ trailingComma?: 'all' | 'es5' | 'none'; /** * Print width for line wrapping. Defaults to 80. */ printWidth?: number; /** * Change when properties in objects are quoted. * - "as-needed" - Only add quotes around object properties where required. * - "consistent" - If at least one property in an object requires quotes, quote all properties. * - "preserve" - Respect the input use of quotes in object properties. * Defaults to "as-needed". */ quoteProps?: 'as-needed' | 'consistent' | 'preserve'; /** * The Prettier version to use (e.g., "3.4.2"). * If specified, loads that version from cache or installs it. * If not specified, uses the bundled Prettier. */ prettierVersion?: string; } /** * Formats a JavaScript/TypeScript AST using Prettier. * * This function: * 1. Prints the AST to a string * 2. Formats the string using Prettier * 3. Parses the formatted string back to an AST (without type attribution for performance) * 4. Reconciles the whitespace from the formatted AST back into the original AST * * The result preserves the original AST's structure, types, and markers while * applying Prettier's formatting rules for whitespace. * * @param sourceFile The source file to format * @param options Prettier formatting options * @param stopAfter Optional node to stop formatting after. Once this node is exited, * no more whitespace changes are applied to subsequent nodes. * @returns The formatted source file with reconciled whitespace */ export declare function prettierFormat(sourceFile: JS.CompilationUnit, options?: PrettierFormatOptions, stopAfter?: J): Promise; /** * Formats a subtree of a JavaScript/TypeScript AST using Prettier. * * This function is optimized for formatting a small part of a larger tree: * 1. Extracts the path from compilation unit to target * 2. Prunes the tree (replaces siblings with placeholders) * 3. Formats the pruned tree with Prettier * 4. Finds the target in the formatted tree * 5. Reconciles only the target subtree's whitespace * * @param target The subtree to format * @param cursor The cursor pointing to or near the target * @param options Prettier formatting options * @param stopAfter Optional node to stop formatting after * @returns The formatted subtree, or undefined if formatting failed */ export declare function prettierFormatSubtree(target: T, cursor: Cursor, options?: PrettierFormatOptions, stopAfter?: J): Promise; /** * Gets the PrettierStyle from the styles array or source file markers. * * @param tree The tree being formatted * @param cursor Optional cursor for walking up to find source file * @param styles Optional styles array to check first * @returns PrettierStyle if found, undefined otherwise */ export declare function getPrettierStyle(tree: Tree, cursor?: Cursor, styles?: NamedStyles[]): PrettierStyle | undefined; /** * Applies Prettier formatting to a tree. * * Configuration is resolved from the PrettierStyle marker on the source file. * * For compilation units, formats and reconciles the entire tree. * For subtrees, uses prettierFormatSubtree which prunes the tree for efficiency, * formats the pruned tree, and reconciles only the target subtree. * * @param tree The tree to format * @param prettierStyle The PrettierStyle containing config * @param p The visitor parameter * @param cursor Optional cursor for subtree formatting * @param stopAfter Optional tree to stop after * @returns The formatted tree */ export declare function applyPrettierFormatting(tree: R, prettierStyle: PrettierStyle, p: P, cursor?: Cursor, stopAfter?: Tree): Promise; //# sourceMappingURL=prettier-format.d.ts.map