Skip to content

Commit 5f5dc17

Browse files
authoredApr 21, 2024··
feat(core): add option to apply biome to generated files (#1321)
* feat: add `biome` option to types * feat: added `biome` to optional normalization process * feat: execute auto correct if `biome` option is present * feat: add `biome` into `cli` options * chore: update `biome` error message * docs: add `output.biome` option to guide
1 parent 913ac00 commit 5f5dc17

File tree

5 files changed

+31
-1
lines changed

5 files changed

+31
-1
lines changed
 

‎docs/src/pages/reference/configuration/output.md

+10
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,16 @@ Default Value: `false`.
389389

390390
Can be used to specify `tslint` ([TSLint is deprecated in favour of eslint + plugins](https://github.com/palantir/tslint#tslint)) as typescript linter instead of `eslint`. You need to have tslint in your dependencies.
391391

392+
### biome
393+
394+
Type: `Boolean`.
395+
396+
Default Value: `false`.
397+
398+
You can apply `lint` and `format` of [`biome`](https://biomejs.dev/) to the generated file. You need to have `@biomejs/biome` in your dependencies.
399+
400+
The automatically generated source code does not comply with some lint rules included in the default ruleset for `biome`, so please control them in the your `biome` configuration file.
401+
392402
### headers
393403

394404
Type: `Boolean`.

‎packages/core/src/types.ts

+3
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export type NormalizedOutputOptions = {
5151
clean: boolean | string[];
5252
prettier: boolean;
5353
tslint: boolean;
54+
biome: boolean;
5455
tsconfig?: Tsconfig;
5556
packageJson?: PackageJson;
5657
headers: boolean;
@@ -171,6 +172,7 @@ export type OutputOptions = {
171172
clean?: boolean | string[];
172173
prettier?: boolean;
173174
tslint?: boolean;
175+
biome?: boolean;
174176
tsconfig?: string | Tsconfig;
175177
packageJson?: string;
176178
headers?: boolean;
@@ -527,6 +529,7 @@ export interface GlobalOptions {
527529
clean?: boolean | string[];
528530
prettier?: boolean;
529531
tslint?: boolean;
532+
biome?: boolean;
530533
mock?: boolean | GlobalMockOptions;
531534
client?: OutputClient;
532535
mode?: OutputMode;

‎packages/orval/src/bin/orval.ts

+3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ cli
3838
.option('--clean [path]', 'Clean output directory')
3939
.option('--prettier [path]', 'Prettier generated files')
4040
.option('--tslint [path]', 'tslint generated files')
41+
.option('--biome [path]', 'biome generated files')
4142
.option('--tsconfig [path]', 'path to your tsconfig file')
4243
.action(async (paths, cmd) => {
4344
if (!cmd.config && isString(cmd.input) && isString(cmd.output)) {
@@ -48,6 +49,7 @@ cli
4849
clean: cmd.clean,
4950
prettier: cmd.prettier,
5051
tslint: cmd.tslint,
52+
biome: cmd.biome,
5153
mock: cmd.mock,
5254
client: cmd.client,
5355
mode: cmd.mode,
@@ -81,6 +83,7 @@ cli
8183
clean: cmd.clean,
8284
prettier: cmd.prettier,
8385
tslint: cmd.tslint,
86+
biome: cmd.biome,
8487
mock: cmd.mock,
8588
client: cmd.client,
8689
mode: cmd.mode,

‎packages/orval/src/utils/options.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export const normalizeOptions = async (
7878
workspace,
7979
);
8080

81-
const { clean, prettier, client, mode, tslint } = globalOptions;
81+
const { clean, prettier, client, mode, tslint, biome } = globalOptions;
8282

8383
const tsconfig = await loadTsconfig(
8484
outputOptions.tsconfig || globalOptions.tsconfig,
@@ -136,6 +136,7 @@ export const normalizeOptions = async (
136136
clean: outputOptions.clean ?? clean ?? false,
137137
prettier: outputOptions.prettier ?? prettier ?? false,
138138
tslint: outputOptions.tslint ?? tslint ?? false,
139+
biome: outputOptions.biome ?? biome ?? false,
139140
tsconfig,
140141
packageJson,
141142
headers: outputOptions.headers ?? false,

‎packages/orval/src/write-specs.ts

+13
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,19 @@ export const writeSpecs = async (
180180
}
181181
}
182182

183+
if (output.biome) {
184+
try {
185+
await execa('biome', ['check', '--apply', ...paths]);
186+
} catch (e: any) {
187+
const message =
188+
e.exitCode === 1
189+
? e.stdout + e.stderr
190+
: `⚠️ ${projectTitle ? `${projectTitle} - ` : ''}biome not found`;
191+
192+
log(chalk.yellow(message));
193+
}
194+
}
195+
183196
createSuccessMessage(projectTitle);
184197
};
185198

0 commit comments

Comments
 (0)
Please sign in to comment.