MCPcopy Index your code
hub / github.com/babel/babel / formatCode

Function formatCode

scripts/utils/formatCode.ts:9–24  ·  view source on GitHub ↗
(
  code: string,
  filename: string
)

Source from the content-addressed store, hash-verified

7 * @returns {Promise<string>} - The formatted code.
8 */
9export default async function formatCode(
10 code: string,
11 filename: string
12): Promise<string> {
13 const prettierConfig = await prettier.resolveConfig(filename);
14 if (!prettierConfig) {
15 throw new Error(
16 `No Prettier configuration found for file: ${filename}. Please ensure a valid Prettier config exists.`
17 );
18 }
19 prettierConfig.filepath = filename;
20 // let prettier automatically determine the parser for non-ts files
21 prettierConfig.parser = filename.endsWith(".ts") ? "babel-ts" : undefined;
22
23 return prettier.format(code, prettierConfig);
24}

Callers 4

generateHelpersFunction · 0.85
applyBabelToSourceFunction · 0.85
generateStandaloneFunction · 0.85
buildBabelParserDtsFunction · 0.85

Calls 2

formatMethod · 0.80
endsWithMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…