Skip to content

Commit 7a4843d

Browse files
committed
Prettier -> Biome
Signed-off-by: Sora Morimoto <[email protected]>
1 parent 821bfad commit 7a4843d

File tree

6 files changed

+39
-169
lines changed

6 files changed

+39
-169
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@
4343
"test": "vitest run"
4444
},
4545
"dependencies": {
46+
"@biomejs/js-api": "^0.7.1",
47+
"@biomejs/wasm-nodejs": "^1.9.4",
4648
"@types/swagger-schema-official": "^2.0.25",
4749
"citty": "^0.1.6",
4850
"consola": "^3.4.2",
49-
"cosmiconfig": "^9.0.0",
5051
"eta": "^2.2.0",
5152
"js-yaml": "^4.1.0",
5253
"lodash": "^4.17.21",
5354
"nanoid": "^5.1.5",
54-
"prettier": "~3.5.3",
5555
"swagger-schema-official": "2.0.0-bab6bed",
5656
"swagger2openapi": "^7.0.8",
5757
"typescript": "~5.8.2"

src/code-formatter.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Biome, Distribution } from "@biomejs/js-api";
12
import * as prettier from "prettier";
23
import * as typescript from "typescript";
34
import type { CodeGenConfig } from "./configuration.js";
@@ -34,23 +35,21 @@ export class CodeFormatter {
3435
return content;
3536
};
3637

37-
prettierFormat = async (content: string) => {
38-
const formatted = await prettier.format(
39-
content,
40-
this.config.prettierOptions,
41-
);
42-
return formatted;
38+
format = async (content: string) => {
39+
const biome = await Biome.create({ distribution: Distribution.NODE });
40+
const formatted = biome.formatContent(content, { filePath: "sta.ts" });
41+
return formatted.content;
4342
};
4443

4544
formatCode = async (
4645
code: string,
47-
{ removeUnusedImports = true, prettierFormat = true } = {},
46+
{ removeUnusedImports = true, format = true } = {},
4847
) => {
4948
if (removeUnusedImports) {
5049
code = this.removeUnusedImports(code);
5150
}
52-
if (prettierFormat) {
53-
code = await this.prettierFormat(code);
51+
if (format) {
52+
code = await this.format(code);
5453
}
5554
return code;
5655
};

src/configuration.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as cosmiconfig from "cosmiconfig";
21
import lodash from "lodash";
32
import type { OpenAPI } from "openapi-types";
43
import * as typescript from "typescript";
@@ -87,7 +86,6 @@ export class CodeGenConfig {
8786
outOfModuleApi: "Common",
8887
};
8988
routeNameDuplicatesMap = new Map();
90-
prettierOptions = { ...CONSTANTS.PRETTIER_OPTIONS };
9189
hooks: Hooks = {
9290
onPreBuildRoutePath: (_routePath: unknown) => void 0,
9391
onBuildRoutePath: (_routeData: unknown) => void 0,
@@ -390,7 +388,6 @@ export class CodeGenConfig {
390388
templateExtensions = [".eta", ".ejs"];
391389

392390
constructor({
393-
prettierOptions = getDefaultPrettierOptions(),
394391
codeGenConstructs,
395392
primitiveTypeConstructs,
396393
constants,
@@ -405,10 +402,6 @@ export class CodeGenConfig {
405402

406403
this.update({
407404
...otherConfig,
408-
prettierOptions:
409-
prettierOptions === undefined
410-
? getDefaultPrettierOptions()
411-
: prettierOptions,
412405
hooks: lodash.merge(this.hooks, hooks || {}),
413406
constants: {
414407
...CONSTANTS,
@@ -430,20 +423,3 @@ export class CodeGenConfig {
430423
objectAssign(this, update);
431424
};
432425
}
433-
434-
const getDefaultPrettierOptions = () => {
435-
const prettier = cosmiconfig
436-
.cosmiconfigSync("prettier", {
437-
searchStrategy: "global",
438-
})
439-
.search();
440-
441-
if (prettier) {
442-
return {
443-
...prettier.config,
444-
parser: "typescript",
445-
};
446-
}
447-
448-
return { ...CONSTANTS.PRETTIER_OPTIONS };
449-
};

src/constants.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,6 @@ export const HTTP_CLIENT = {
2121
AXIOS: "axios",
2222
} as const;
2323

24-
export const PRETTIER_OPTIONS = {
25-
printWidth: 120,
26-
tabWidth: 2,
27-
trailingComma: "all",
28-
parser: "typescript",
29-
} as const;
30-
3124
export const PROJECT_VERSION = packageJson.version;
3225

3326
export const RESERVED_BODY_ARG_NAMES = ["data", "body", "reqBody"];

types/index.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,6 @@ interface GenerateApiParamsBase {
107107
* extract response error type to data contract
108108
*/
109109
extractResponseError?: boolean;
110-
/**
111-
* prettier configuration
112-
*/
113-
prettier?: object;
114110
/**
115111
* Output only errors to console (default: false)
116112
*/

0 commit comments

Comments
 (0)