Skip to content

Commit

Permalink
feat(core): add option to apply biome to generated files (#1321)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
soartec-lab authored Apr 21, 2024
1 parent 913ac00 commit 5f5dc17
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 1 deletion.
10 changes: 10 additions & 0 deletions docs/src/pages/reference/configuration/output.md
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,16 @@ Default Value: `false`.

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.

### biome

Type: `Boolean`.

Default Value: `false`.

You can apply `lint` and `format` of [`biome`](https://biomejs.dev/) to the generated file. You need to have `@biomejs/biome` in your dependencies.

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.

### headers

Type: `Boolean`.
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export type NormalizedOutputOptions = {
clean: boolean | string[];
prettier: boolean;
tslint: boolean;
biome: boolean;
tsconfig?: Tsconfig;
packageJson?: PackageJson;
headers: boolean;
Expand Down Expand Up @@ -171,6 +172,7 @@ export type OutputOptions = {
clean?: boolean | string[];
prettier?: boolean;
tslint?: boolean;
biome?: boolean;
tsconfig?: string | Tsconfig;
packageJson?: string;
headers?: boolean;
Expand Down Expand Up @@ -527,6 +529,7 @@ export interface GlobalOptions {
clean?: boolean | string[];
prettier?: boolean;
tslint?: boolean;
biome?: boolean;
mock?: boolean | GlobalMockOptions;
client?: OutputClient;
mode?: OutputMode;
Expand Down
3 changes: 3 additions & 0 deletions packages/orval/src/bin/orval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ cli
.option('--clean [path]', 'Clean output directory')
.option('--prettier [path]', 'Prettier generated files')
.option('--tslint [path]', 'tslint generated files')
.option('--biome [path]', 'biome generated files')
.option('--tsconfig [path]', 'path to your tsconfig file')
.action(async (paths, cmd) => {
if (!cmd.config && isString(cmd.input) && isString(cmd.output)) {
Expand All @@ -48,6 +49,7 @@ cli
clean: cmd.clean,
prettier: cmd.prettier,
tslint: cmd.tslint,
biome: cmd.biome,
mock: cmd.mock,
client: cmd.client,
mode: cmd.mode,
Expand Down Expand Up @@ -81,6 +83,7 @@ cli
clean: cmd.clean,
prettier: cmd.prettier,
tslint: cmd.tslint,
biome: cmd.biome,
mock: cmd.mock,
client: cmd.client,
mode: cmd.mode,
Expand Down
3 changes: 2 additions & 1 deletion packages/orval/src/utils/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const normalizeOptions = async (
workspace,
);

const { clean, prettier, client, mode, tslint } = globalOptions;
const { clean, prettier, client, mode, tslint, biome } = globalOptions;

const tsconfig = await loadTsconfig(
outputOptions.tsconfig || globalOptions.tsconfig,
Expand Down Expand Up @@ -136,6 +136,7 @@ export const normalizeOptions = async (
clean: outputOptions.clean ?? clean ?? false,
prettier: outputOptions.prettier ?? prettier ?? false,
tslint: outputOptions.tslint ?? tslint ?? false,
biome: outputOptions.biome ?? biome ?? false,
tsconfig,
packageJson,
headers: outputOptions.headers ?? false,
Expand Down
13 changes: 13 additions & 0 deletions packages/orval/src/write-specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,19 @@ export const writeSpecs = async (
}
}

if (output.biome) {
try {
await execa('biome', ['check', '--apply', ...paths]);
} catch (e: any) {
const message =
e.exitCode === 1
? e.stdout + e.stderr
: `⚠️ ${projectTitle ? `${projectTitle} - ` : ''}biome not found`;

log(chalk.yellow(message));
}
}

createSuccessMessage(projectTitle);
};

Expand Down

0 comments on commit 5f5dc17

Please sign in to comment.