mirror of
https://github.com/oxc-project/oxc.git
synced 2026-09-14 19:36:11 +08:00
a26f856402
`ExternalFormatter` is merely a transport that calls the JS side via napi; it is not referred to as a formatter.
71 lines
3.5 KiB
TypeScript
71 lines
3.5 KiB
TypeScript
/* auto-generated by NAPI-RS */
|
|
/* eslint-disable */
|
|
export interface Comment {
|
|
type: 'Line' | 'Block'
|
|
value: string
|
|
start: number
|
|
end: number
|
|
}
|
|
|
|
export interface ErrorLabel {
|
|
message: string | null
|
|
start: number
|
|
end: number
|
|
}
|
|
|
|
export interface OxcError {
|
|
severity: Severity
|
|
message: string
|
|
labels: Array<ErrorLabel>
|
|
helpMessage: string | null
|
|
codeframe: string | null
|
|
}
|
|
|
|
export declare const enum Severity {
|
|
Error = 'Error',
|
|
Warning = 'Warning',
|
|
Advice = 'Advice'
|
|
}
|
|
/**
|
|
* NAPI based format API entry point.
|
|
*
|
|
* Since it internally uses `await prettier.format()` in JS side, `formatSync()` cannot be provided.
|
|
*
|
|
* # Panics
|
|
* Panics if the current working directory cannot be determined.
|
|
*/
|
|
export declare function format(filename: string, sourceText: string, options: any | undefined | null, formatFileCb: (options: Record<string, any>, code: string) => Promise<{ ok: true; code: string; } | { ok: false; error: string }>, formatEmbeddedCb: (options: Record<string, any>, code: string) => Promise<string | null>, formatEmbeddedDocCb: (options: Record<string, any>, code: string) => Promise<string | null>, sortTailwindClassesCb: (options: Record<string, any>, classes: string[]) => Promise<string[] | null>): Promise<FormatResult>
|
|
|
|
export interface FormatResult {
|
|
/** The formatted code. */
|
|
code: string
|
|
/** Parse and format errors. */
|
|
errors: Array<OxcError>
|
|
}
|
|
|
|
/**
|
|
* NAPI based `textToDoc` API entry point for `prettier-plugin-oxfmt`.
|
|
*
|
|
* This API is specialized for JS/TS snippets embedded in non-JS files.
|
|
* Unlike `format()`, it is called only for js-in-xxx `textToDoc()` flow.
|
|
*/
|
|
export declare function jsTextToDoc(sourceExt: string, sourceText: string, oxfmtPluginOptionsJson: string, parentContext: string, formatFileCb: (options: Record<string, any>, code: string) => Promise<{ ok: true; code: string; } | { ok: false; error: string }>, formatEmbeddedCb: (options: Record<string, any>, code: string) => Promise<string | null>, formatEmbeddedDocCb: (options: Record<string, any>, code: string) => Promise<string | null>, sortTailwindClassesCb: (options: Record<string, any>, classes: string[]) => Promise<string[] | null>): Promise<string | null>
|
|
|
|
/**
|
|
* NAPI based JS CLI entry point.
|
|
* For pure Rust CLI entry point, see `main.rs`.
|
|
*
|
|
* JS side passes in:
|
|
* 1. `args`: Command line arguments (process.argv.slice(2))
|
|
* 2. `load_js_config_cb`: Callback to load JS/TS config files
|
|
* 3. `init_external_services_cb`: Callback to initialize external services (JS worker pool)
|
|
* 4. `format_file_cb`: Callback to format files
|
|
* 5. `format_embedded_cb`: Callback to format embedded code in templates
|
|
* 6. `sort_tailwindcss_classes_cb`: Callback to sort Tailwind classes
|
|
*
|
|
* Returns a tuple of `[mode, exitCode]`:
|
|
* - `mode`: If main logic will run in JS side, use this to indicate which mode
|
|
* - `exitCode`: If main logic already ran in Rust side, return the exit code
|
|
*/
|
|
export declare function runCli(args: Array<string>, loadJsConfigCb: (path: string) => Promise<any>, initExternalServicesCb: (numThreads: number) => Promise<void>, formatFileCb: (options: Record<string, any>, code: string) => Promise<{ ok: true; code: string; } | { ok: false; error: string }>, formatEmbeddedCb: (options: Record<string, any>, code: string) => Promise<string | null>, formatEmbeddedDocCb: (options: Record<string, any>, code: string) => Promise<string | null>, sortTailwindcssClassesCb: (options: Record<string, any>, classes: string[]) => Promise<string[] | null>): Promise<[string, number | undefined | null]>
|