/
githubmirror
/
babel
Обзор
Документация
Войти
/
githubmirror
/
babel
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
scripts/utils/formatCode.ts
24 строки
820 B
liuxingbaoyu
chore: Migrate scripts to `.ts` (#17767)
13 фев 2026, 17:26
Не верифицирован
13 фев 2026, 17:26
931ddd6
Код
Авторство
О чём код?
import * as prettier from "prettier"; /** * Formats the given code using Prettier. * @param {string} code - The code to format. * @param {string} filename - The name of the file being formatted. * @returns {Promise<string>} - The formatted code. */ export default async function formatCode( code: string, filename: string ): Promise<string> { const prettierConfig = await prettier.resolveConfig(filename); if (!prettierConfig) { throw new Error( `No Prettier configuration found for file: ${filename}. Please ensure a valid Prettier config exists.` ); } prettierConfig.filepath = filename; // let prettier automatically determine the parser for non-ts files prettierConfig.parser = filename.endsWith(".ts") ? "babel-ts" : undefined; return prettier.format(code, prettierConfig); }