Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): add option to apply biome to generated files #1321

Merged
merged 6 commits into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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