Skip to content

Commit 41cf263

Browse files
authored
Use BiomeJS for linting, formatting (openapi-ts#1626)
1 parent 1f9d08f commit 41cf263

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+733
-2504
lines changed

.eslintignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

.eslintrc.cjs

Lines changed: 0 additions & 68 deletions
This file was deleted.

.prettierignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

.prettierrc

Lines changed: 0 additions & 3 deletions
This file was deleted.

.vscode/extensions.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"recommendations": ["biomejs.biome"]
3+
}

.vscode/settings.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"[javascript]": {
3+
"editor.defaultFormatter": "biomejs.biome"
4+
},
5+
"[json]": {
6+
"editor.defaultFormatter": "biomejs.biome"
7+
},
8+
"[markdown]": {
9+
"editor.defaultFormatter": "esbenp.prettier-vscode"
10+
},
11+
"[typescript]": {
12+
"editor.defaultFormatter": "biomejs.biome"
13+
}
14+
}

biome.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"$schema": "https://biomejs.dev/schemas/1.7.0/schema.json",
3+
"organizeImports": {
4+
"enabled": false
5+
},
6+
"files": {
7+
"ignore": ["**/dist/**"]
8+
},
9+
"formatter": {
10+
"indentStyle": "space",
11+
"indentWidth": 2,
12+
"lineWidth": 120
13+
},
14+
"linter": {
15+
"enabled": true,
16+
"rules": {
17+
"recommended": true,
18+
"complexity": {
19+
"noExcessiveNestedTestSuites": "off",
20+
"useArrowFunction": "off"
21+
},
22+
"suspicious": {
23+
"noConsoleLog": "error",
24+
"noExplicitAny": "off"
25+
},
26+
"style": {
27+
"noUselessElse": "off",
28+
"useBlockStatements": "error"
29+
}
30+
}
31+
}
32+
}

docs/scripts/update-contributors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ async function main() {
206206
lastFetch: new Date().getTime(),
207207
};
208208
upsert(contributors[repo], userData);
209-
console.log(`Updated old contributor data for ${username}`); // eslint-disable-line no-console
209+
console.log(`Updated old contributor data for ${username}`); // biome-disable-line no-console
210210
fs.writeFileSync(
211211
new URL("../data/contributors.json", import.meta.url),
212212
JSON.stringify(contributors),

package.json

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,15 @@
1010
"scripts": {
1111
"build": "pnpm run -r --parallel --filter \"!*docs\" build",
1212
"lint": "pnpm run -r --parallel lint",
13+
"format": "pnpm run -r --parallel format",
1314
"test": "pnpm run -r --parallel test",
1415
"version": "pnpm run build && changeset version && pnpm i"
1516
},
1617
"devDependencies": {
18+
"@biomejs/biome": "^1.7.1",
1719
"@changesets/changelog-github": "^0.5.0",
1820
"@changesets/cli": "^2.27.1",
19-
"@typescript-eslint/eslint-plugin": "^7.7.1",
20-
"@typescript-eslint/parser": "^7.7.1",
2121
"del-cli": "^5.1.0",
22-
"eslint": "^8.57.0",
23-
"eslint-config-prettier": "^9.1.0",
24-
"eslint-plugin-import": "^2.29.1",
25-
"eslint-plugin-no-only-tests": "^3.1.0",
26-
"eslint-plugin-prettier": "^5.1.3",
27-
"eslint-plugin-vitest": "^0.2.8",
2822
"prettier": "^3.2.5",
2923
"typescript": "^5.4.5"
3024
}

packages/openapi-fetch/.eslintignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/openapi-fetch/.npmignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
.eslintignore
2-
.prettierignore
31
examples
42
test
53
vitest.config.ts

packages/openapi-fetch/.prettierignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

packages/openapi-fetch/CONTRIBUTING.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ npx vitest
5454

5555
As this is just a minimal fetch wrapper meant to provide deep type inference for API schemas, **testing TS types** is arguably more important than testing the runtime. So please make liberal use of `// @ts-expect-error`, and as a general rule of thumb, write more **unwanted** output tests than _wanted_ output tests.
5656

57+
### Running linting
58+
59+
Linting is handled via [Biome](https://biomejs.dev), a faster ESLint replacement. It was installed with `pnpm i` and can be run with:
60+
61+
```bash
62+
pnpm run lint
63+
```
64+
5765
### Changelogs
5866

5967
The changelog is generated via [changesets](https://github.com/changesets/changesets), and is separate from Git commit messages and pull request titles. To write a human-readable changelog for your changes, run:

packages/openapi-fetch/biome.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"$schema": "https://biomejs.dev/schemas/1.7.0/schema.json",
3+
"extends": ["../../biome.json"],
4+
"files": {
5+
"include": ["./src/", "./test/"],
6+
"ignore": ["**/fixtures/**/*"]
7+
}
8+
}

packages/openapi-fetch/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@
5252
"build:js": "mkdir -p dist && cp src/* dist",
5353
"build:js-min": "esbuild --bundle src/index.js --format=esm --minify --outfile=dist/index.min.js && cp dist/index.d.ts dist/index.min.d.ts",
5454
"build:cjs": "esbuild --bundle src/index.js --format=cjs --outfile=dist/cjs/index.cjs && cp dist/index.d.ts dist/cjs/index.d.cts",
55-
"lint": "pnpm run \"/^lint:/\"",
56-
"lint:js": "eslint \"{src,test}/**/*.{js,ts}\"",
57-
"lint:prettier": "prettier --check \"{src,test}/**/*\"",
55+
"format": "biome format . --write",
56+
"lint": "biome check .",
5857
"generate-types": "cd ../openapi-typescript && pnpm run build && cd ../openapi-fetch && ../openapi-typescript/bin/cli.js ./test/fixtures/api.yaml -o ./test/fixtures/v7-beta.d.ts && npx openapi-typescript ./test/fixtures/api.yaml -o ./test/fixtures/api.d.ts",
5958
"pretest": "pnpm run generate-types",
6059
"test": "pnpm run \"/^test:/\"",

packages/openapi-fetch/src/index.d.ts

Lines changed: 22 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ import type {
1111
SuccessResponse,
1212
} from "openapi-typescript-helpers";
1313

14-
// Note: though "any" is considered bad practice in general, this library relies
15-
// on "any" for type inference only it can give. Same goes for the "{}" type.
16-
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types */
17-
1814
/** Options for each client instance */
1915
export interface ClientOptions extends Omit<RequestInit, "headers"> {
2016
/** set the common root URL for all API requests */
@@ -30,20 +26,10 @@ export interface ClientOptions extends Omit<RequestInit, "headers"> {
3026

3127
export type HeadersOptions =
3228
| HeadersInit
33-
| Record<
34-
string,
35-
| string
36-
| number
37-
| boolean
38-
| (string | number | boolean)[]
39-
| null
40-
| undefined
41-
>;
29+
| Record<string, string | number | boolean | (string | number | boolean)[] | null | undefined>;
4230

4331
export type QuerySerializer<T> = (
44-
query: T extends { parameters: any }
45-
? NonNullable<T["parameters"]["query"]>
46-
: Record<string, unknown>,
32+
query: T extends { parameters: any } ? NonNullable<T["parameters"]["query"]> : Record<string, unknown>,
4733
) => string;
4834

4935
/** @see https://swagger.io/docs/specification/serialization/#query */
@@ -102,36 +88,26 @@ export type ParamsOption<T> = T extends {
10288
: { params: T["parameters"] }
10389
: DefaultParamsOption;
10490

105-
export type RequestBodyOption<T> =
106-
OperationRequestBodyContent<T> extends never
107-
? { body?: never }
108-
: undefined extends OperationRequestBodyContent<T>
109-
? { body?: OperationRequestBodyContent<T> }
110-
: { body: OperationRequestBodyContent<T> };
91+
export type RequestBodyOption<T> = OperationRequestBodyContent<T> extends never
92+
? { body?: never }
93+
: undefined extends OperationRequestBodyContent<T>
94+
? { body?: OperationRequestBodyContent<T> }
95+
: { body: OperationRequestBodyContent<T> };
11196

112-
export type FetchOptions<T> = RequestOptions<T> &
113-
Omit<RequestInit, "body" | "headers">;
97+
export type FetchOptions<T> = RequestOptions<T> & Omit<RequestInit, "body" | "headers">;
11498

11599
export type FetchResponse<T, O, Media extends MediaType> =
116100
| {
117101
data: ParseAsResponse<
118-
GetValueWithDefault<
119-
SuccessResponse<ResponseObjectMap<T>>,
120-
Media,
121-
Record<string, never>
122-
>,
102+
GetValueWithDefault<SuccessResponse<ResponseObjectMap<T>>, Media, Record<string, never>>,
123103
O
124104
>;
125105
error?: never;
126106
response: Response;
127107
}
128108
| {
129109
data?: never;
130-
error: GetValueWithDefault<
131-
ErrorResponse<ResponseObjectMap<T>>,
132-
Media,
133-
Record<string, never>
134-
>;
110+
error: GetValueWithDefault<ErrorResponse<ResponseObjectMap<T>>, Media, Record<string, never>>;
135111
response: Response;
136112
};
137113

@@ -168,40 +144,32 @@ export function onRequest(
168144
req: MiddlewareRequest,
169145
options: MergedOptions,
170146
): Request | undefined | Promise<Request | undefined>;
171-
export function onResponse(
172-
res: Response,
173-
options: MergedOptions,
174-
): Response | undefined | Promise<Response | undefined>;
147+
export function onResponse(res: Response, options: MergedOptions): Response | undefined | Promise<Response | undefined>;
175148

176149
export interface Middleware {
177150
onRequest?: typeof onRequest;
178151
onResponse?: typeof onResponse;
179152
}
180153

154+
// biome-ignore lint/complexity/noBannedTypes: though extending "{}" is a bad practice in general, this library relies on complex layers of inference, and extending off generic objects is necessary
181155
type PathMethods = Partial<Record<HttpMethod, {}>>;
182156

183157
/** This type helper makes the 2nd function param required if params/requestBody are required; otherwise, optional */
184-
export type MaybeOptionalInit<P extends PathMethods, M extends keyof P> =
185-
HasRequiredKeys<FetchOptions<FilterKeys<P, M>>> extends never
186-
? [(FetchOptions<FilterKeys<P, M>> | undefined)?]
187-
: [FetchOptions<FilterKeys<P, M>>];
158+
export type MaybeOptionalInit<P extends PathMethods, M extends keyof P> = HasRequiredKeys<
159+
FetchOptions<FilterKeys<P, M>>
160+
> extends never
161+
? [(FetchOptions<FilterKeys<P, M>> | undefined)?]
162+
: [FetchOptions<FilterKeys<P, M>>];
188163

189-
export type ClientMethod<
190-
Paths extends Record<string, PathMethods>,
191-
M extends HttpMethod,
192-
Media extends MediaType,
193-
> = <
164+
export type ClientMethod<Paths extends Record<string, PathMethods>, M extends HttpMethod, Media extends MediaType> = <
194165
P extends PathsWithMethod<Paths, M>,
195166
I extends MaybeOptionalInit<Paths[P], M>,
196167
>(
197168
url: P,
198169
...init: I
199170
) => Promise<FetchResponse<Paths[P][M], I[0], Media>>;
200171

201-
export default function createClient<
202-
Paths extends {},
203-
Media extends MediaType = MediaType,
204-
>(
172+
export default function createClient<Paths extends {}, Media extends MediaType = MediaType>(
205173
clientOptions?: ClientOptions,
206174
): {
207175
/** Call a GET endpoint */
@@ -249,13 +217,7 @@ export declare function serializeArrayParam(
249217
name: string,
250218
value: unknown[],
251219
options: {
252-
style:
253-
| "simple"
254-
| "label"
255-
| "matrix"
256-
| "form"
257-
| "spaceDelimited"
258-
| "pipeDelimited";
220+
style: "simple" | "label" | "matrix" | "form" | "spaceDelimited" | "pipeDelimited";
259221
explode: boolean;
260222
allowReserved?: boolean;
261223
},
@@ -271,10 +233,7 @@ export declare function createQuerySerializer<T = unknown>(
271233
* @type {import("./index.js").defaultPathSerializer}
272234
* @see https://swagger.io/docs/specification/serialization/#path
273235
*/
274-
export declare function defaultPathSerializer(
275-
pathname: string,
276-
pathParams: Record<string, unknown>,
277-
): string;
236+
export declare function defaultPathSerializer(pathname: string, pathParams: Record<string, unknown>): string;
278237

279238
/** Serialize body object to string */
280239
export declare function defaultBodySerializer<T>(body: T): string;
@@ -293,8 +252,4 @@ export declare function createFinalURL<O>(
293252
): string;
294253

295254
/** Merge headers a and b, with b taking priority */
296-
export declare function mergeHeaders(
297-
...allHeaders: (HeadersOptions | undefined)[]
298-
): Headers;
299-
300-
export {};
255+
export declare function mergeHeaders(...allHeaders: (HeadersOptions | undefined)[]): Headers;

0 commit comments

Comments
 (0)