Skip to content

Commit 97cd586

Browse files
committed
refactor(type-formatter): replace prettier with oxfmt
Signed-off-by: Ryan Bower <rbower@qti.qualcomm.com>
1 parent f535c90 commit 97cd586

4 files changed

Lines changed: 34 additions & 32 deletions

File tree

packages/common/typedoc/build.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,20 @@ async function main(argv: string[]) {
66
const IS_WATCH = hasArg(argv, "--watch")
77
const BUILD_MODE = getArg(argv, "--mode") || "production"
88

9+
const external: string[] = [
10+
"@commander-js/extra-typings",
11+
"cosmiconfig",
12+
"oxfmt",
13+
"typedoc",
14+
"typescript",
15+
]
16+
917
const buildOpts: BuildOptions = {
1018
bundle: true,
1119
define: {
1220
"process.env.BUILD_MODE": JSON.stringify(BUILD_MODE),
1321
},
14-
external: [
15-
"typescript",
16-
"prettier",
17-
"typedoc",
18-
"@commander-js/extra-typings",
19-
"cosmiconfig",
20-
],
22+
external,
2123
loader: {
2224
".node": "copy",
2325
},
@@ -34,13 +36,7 @@ async function main(argv: string[]) {
3436
...buildOpts,
3537
banner: {js: "#!/usr/bin/env node"},
3638
entryPoints: ["./src/cli.ts"],
37-
external: [
38-
"typescript",
39-
"prettier",
40-
"typedoc",
41-
"@commander-js/extra-typings",
42-
"cosmiconfig",
43-
],
39+
external,
4440
format: "esm",
4541
logLevel: IS_WATCH ? "error" : "warning",
4642
metafile: true,

packages/common/typedoc/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"inquirer": "^12.1.0",
5757
"lodash-es": "catalog:",
5858
"npm-run-all2": "catalog:",
59+
"oxfmt": "^0.48.0",
5960
"shx": "catalog:",
6061
"terminate": "^2.6.1",
6162
"tsx": "catalog:",
@@ -66,7 +67,7 @@
6667
"peerDependencies": {
6768
"@commander-js/extra-typings": ">=13.1.0",
6869
"@qualcomm-ui/typedoc-common": "workspace:^1.0.6",
69-
"prettier": ">=3 <4",
70+
"oxfmt": ">=0.48.0",
7071
"typedoc": ">=0.28.4",
7172
"typescript": ">=5.3.3",
7273
"cosmiconfig": ">=9.0.0"

packages/common/typedoc/src/internal/type-formatter.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
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"
45
import path from "path"
5-
import {format, type Options} from "prettier"
66
import type {JSONOutput} from "typedoc"
77

88
import type {FormattedType} from "@qualcomm-ui/typedoc-common"
99

10-
import {isTypeOverride} from "../guards"
10+
import {formatObjectPropertyName, isTypeOverride} from "../guards"
1111

1212
import {dedent} from "./dedent"
1313
import type {KnownInterfaces, QuiDeclarationReflection} from "./types"
@@ -93,11 +93,11 @@ export function escape(src: string) {
9393

9494
export 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

pnpm-lock.yaml

Lines changed: 6 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)