UNPKG

prettier-plugin-embed

Version:

A configurable Prettier plugin to format embedded languages in JS/TS files.

47 lines (46 loc) 2.57 kB
import type { TemplateLiteral } from "estree"; import type { AstPath, Doc, Options } from "prettier"; import type { printer } from "prettier/doc"; import type { OmitIndexSignature } from "type-fest"; import type { AutocompleteStringList, EmbeddedDefaultComment, EmbeddedDefaultTag, EmbeddedLanguage, PluginEmbedOptions, makeCommentsOptionName, makeIdentifiersOptionName, makeTagsOptionName } from "./embedded/index.js"; import type { PluginEmbedLanguageAgnosticOptions } from "./options.js"; export type InternalPrintFun = (selector?: string | number | (string | number)[] | AstPath<TemplateLiteral>) => Doc; export interface EmbedderPayload { commentOrTag: string; kind: "comment" | "tag"; embeddedOverrideOptions: EmbeddedOverride["options"] | undefined; } export type Embedder<T extends Options = Options> = (textToDoc: (text: string, options: T) => Promise<Doc>, print: InternalPrintFun, path: AstPath<TemplateLiteral>, options: T, embedderPayload: EmbedderPayload) => Promise<Doc>; type EmbeddedCommentsOrTags = AutocompleteStringList<EmbeddedDefaultComment | EmbeddedDefaultTag>; type EmbeddedComments = AutocompleteStringList<EmbeddedDefaultComment>; type EmbeddedTags = AutocompleteStringList<EmbeddedDefaultTag>; type EmbeddedOverrideOptions = Omit<Omit<OmitIndexSignature<Options>, keyof PluginEmbedOptions> & Omit<PluginEmbedOptions, keyof PluginEmbedLanguageAgnosticOptions | ReturnType<typeof makeIdentifiersOptionName<EmbeddedLanguage>> | ReturnType<typeof makeCommentsOptionName<EmbeddedLanguage>> | ReturnType<typeof makeTagsOptionName<EmbeddedLanguage>>>, keyof printer.Options | "endOfLine" | "parser" | "filepath" | "embeddedLanguageFormatting" | `__${string}`>; interface EmbeddedOverrideWithIdentifiers { /** * @deprecated Please use `comments` or `tags`. */ identifiers: EmbeddedCommentsOrTags; comments?: EmbeddedComments; tags?: EmbeddedTags; options: EmbeddedOverrideOptions; } interface EmbeddedOverrideWithComments { /** * @deprecated Please use `comments` or `tags`. */ identifiers?: EmbeddedCommentsOrTags; comments: EmbeddedComments; tags?: EmbeddedTags; options: EmbeddedOverrideOptions; } interface EmbeddedOverrideWithTags { /** * @deprecated Please use `comments` or `tags`. */ identifiers?: EmbeddedCommentsOrTags; comments?: EmbeddedComments; tags: EmbeddedTags; options: EmbeddedOverrideOptions; } export type EmbeddedOverride = EmbeddedOverrideWithComments | EmbeddedOverrideWithTags | EmbeddedOverrideWithIdentifiers; export {};