11// Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
22// SPDX-License-Identifier: BSD-3-Clause-Clear
33
4+ import { format , type FormatConfig } from "oxfmt"
45import path from "path"
5- import { format , type Options } from "prettier"
66import type { JSONOutput } from "typedoc"
77
88import type { FormattedType } from "@qualcomm-ui/typedoc-common"
99
10- import { isTypeOverride } from "../guards"
10+ import { formatObjectPropertyName , isTypeOverride } from "../guards"
1111
1212import { dedent } from "./dedent"
1313import type { KnownInterfaces , QuiDeclarationReflection } from "./types"
@@ -93,11 +93,11 @@ export function escape(src: string) {
9393
9494export const defaultPrintWidth = 30
9595
96- const prettierOpts : Options = {
96+ const formatConfig : FormatConfig = {
9797 bracketSpacing : false ,
98- endOfLine : "auto" ,
98+ endOfLine : "lf" ,
99+ insertFinalNewline : false ,
99100 jsxSingleQuote : true ,
100- parser : "typescript" ,
101101 printWidth : defaultPrintWidth ,
102102 semi : false ,
103103 singleQuote : true ,
@@ -118,14 +118,14 @@ export async function prettyType(type: string, printWidth: number) {
118118 try {
119119 // we need valid typescript for prettier to work.
120120 const dummyType = `type ___DUMMY = ${ type } `
121- const result = await format ( dummyType , {
122- ...prettierOpts ,
121+ const result = await format ( "file.tsx" , dummyType , {
122+ ...formatConfig ,
123123 printWidth,
124124 } )
125- const formatted = dedent ( result . replace ( "type ___DUMMY =" , " " ) . trim ( ) )
125+ const formatted = dedent ( result . code . replace ( "type ___DUMMY =" , " " ) . trim ( ) )
126126 prettierCache [ type ] = formatted
127127 return formatted
128- } catch ( e ) {
128+ } catch {
129129 return type
130130 }
131131}
@@ -135,7 +135,9 @@ export async function prettyImportStatement(str: string): Promise<string> {
135135 return prettierCache [ str ]
136136 }
137137 try {
138- prettierCache [ str ] = ( await format ( str , prettierOpts ) ) . trim ( )
138+ prettierCache [ str ] = (
139+ await format ( "file.tsx" , str , formatConfig )
140+ ) . code . trim ( )
139141 return prettierCache [ str ]
140142 } catch ( e ) {
141143 return str
@@ -211,9 +213,9 @@ export class TypeFormatter {
211213 } `
212214 }
213215 }
214- const name = `${ p . flags . isRest ? "..." : "" } ${
215- p . name . includes ( "-" ) ? `" ${ p . name } "` : p . name
216- } `
216+ const name = `${ p . flags . isRest ? "..." : "" } ${ formatObjectPropertyName (
217+ p . name ,
218+ ) } `
217219 return `${ name } ${ p . flags ?. isOptional ? "?" : "" } : ${ replaceType (
218220 p . type
219221 ? this . formatType ( p . type as JSONOutput . SomeType , opts )
@@ -360,7 +362,7 @@ export class TypeFormatter {
360362 if ( children && children . length > 0 ) {
361363 children . forEach ( ( child ) => {
362364 obj . push ( {
363- name : child . name . includes ( "-" ) ? `" ${ child . name } "` : child . name ,
365+ name : formatObjectPropertyName ( child . name ) ,
364366 optional : child . flags ?. isOptional ,
365367 type :
366368 // exported variable with methods
0 commit comments