Skip to content

Use BiomeJS for linting, formatting #1626

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

Merged
merged 1 commit into from
Apr 23, 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
3 changes: 0 additions & 3 deletions .eslintignore

This file was deleted.

68 changes: 0 additions & 68 deletions .eslintrc.cjs

This file was deleted.

3 changes: 0 additions & 3 deletions .prettierignore

This file was deleted.

3 changes: 0 additions & 3 deletions .prettierrc

This file was deleted.

3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["biomejs.biome"]
}
14 changes: 14 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"[javascript]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[json]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[markdown]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "biomejs.biome"
}
}
32 changes: 32 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"$schema": "https://biomejs.dev/schemas/1.7.0/schema.json",
"organizeImports": {
"enabled": false
},
"files": {
"ignore": ["**/dist/**"]
},
"formatter": {
"indentStyle": "space",
"indentWidth": 2,
"lineWidth": 120
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"complexity": {
"noExcessiveNestedTestSuites": "off",
"useArrowFunction": "off"
},
"suspicious": {
"noConsoleLog": "error",
"noExplicitAny": "off"
},
"style": {
"noUselessElse": "off",
"useBlockStatements": "error"
}
}
}
}
2 changes: 1 addition & 1 deletion docs/scripts/update-contributors.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ async function main() {
lastFetch: new Date().getTime(),
};
upsert(contributors[repo], userData);
console.log(`Updated old contributor data for ${username}`); // eslint-disable-line no-console
console.log(`Updated old contributor data for ${username}`); // biome-disable-line no-console
fs.writeFileSync(
new URL("../data/contributors.json", import.meta.url),
JSON.stringify(contributors),
Expand Down
10 changes: 2 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,15 @@
"scripts": {
"build": "pnpm run -r --parallel --filter \"!*docs\" build",
"lint": "pnpm run -r --parallel lint",
"format": "pnpm run -r --parallel format",
"test": "pnpm run -r --parallel test",
"version": "pnpm run build && changeset version && pnpm i"
},
"devDependencies": {
"@biomejs/biome": "^1.7.1",
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.1",
"@typescript-eslint/eslint-plugin": "^7.7.1",
"@typescript-eslint/parser": "^7.7.1",
"del-cli": "^5.1.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-no-only-tests": "^3.1.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-vitest": "^0.2.8",
"prettier": "^3.2.5",
"typescript": "^5.4.5"
}
Expand Down
1 change: 0 additions & 1 deletion packages/openapi-fetch/.eslintignore

This file was deleted.

2 changes: 0 additions & 2 deletions packages/openapi-fetch/.npmignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
.eslintignore
.prettierignore
examples
test
vitest.config.ts
3 changes: 0 additions & 3 deletions packages/openapi-fetch/.prettierignore

This file was deleted.

8 changes: 8 additions & 0 deletions packages/openapi-fetch/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ npx vitest

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.

### Running linting

Linting is handled via [Biome](https://biomejs.dev), a faster ESLint replacement. It was installed with `pnpm i` and can be run with:

```bash
pnpm run lint
```

### Changelogs

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:
Expand Down
8 changes: 8 additions & 0 deletions packages/openapi-fetch/biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "https://biomejs.dev/schemas/1.7.0/schema.json",
"extends": ["../../biome.json"],
"files": {
"include": ["./src/", "./test/"],
"ignore": ["**/fixtures/**/*"]
}
}
5 changes: 2 additions & 3 deletions packages/openapi-fetch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@
"build:js": "mkdir -p dist && cp src/* dist",
"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",
"build:cjs": "esbuild --bundle src/index.js --format=cjs --outfile=dist/cjs/index.cjs && cp dist/index.d.ts dist/cjs/index.d.cts",
"lint": "pnpm run \"/^lint:/\"",
"lint:js": "eslint \"{src,test}/**/*.{js,ts}\"",
"lint:prettier": "prettier --check \"{src,test}/**/*\"",
"format": "biome format . --write",
"lint": "biome check .",
"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",
"pretest": "pnpm run generate-types",
"test": "pnpm run \"/^test:/\"",
Expand Down
89 changes: 22 additions & 67 deletions packages/openapi-fetch/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ import type {
SuccessResponse,
} from "openapi-typescript-helpers";

// Note: though "any" is considered bad practice in general, this library relies
// on "any" for type inference only it can give. Same goes for the "{}" type.
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types */

/** Options for each client instance */
export interface ClientOptions extends Omit<RequestInit, "headers"> {
/** set the common root URL for all API requests */
Expand All @@ -30,20 +26,10 @@ export interface ClientOptions extends Omit<RequestInit, "headers"> {

export type HeadersOptions =
| HeadersInit
| Record<
string,
| string
| number
| boolean
| (string | number | boolean)[]
| null
| undefined
>;
| Record<string, string | number | boolean | (string | number | boolean)[] | null | undefined>;

export type QuerySerializer<T> = (
query: T extends { parameters: any }
? NonNullable<T["parameters"]["query"]>
: Record<string, unknown>,
query: T extends { parameters: any } ? NonNullable<T["parameters"]["query"]> : Record<string, unknown>,
) => string;

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

export type RequestBodyOption<T> =
OperationRequestBodyContent<T> extends never
? { body?: never }
: undefined extends OperationRequestBodyContent<T>
? { body?: OperationRequestBodyContent<T> }
: { body: OperationRequestBodyContent<T> };
export type RequestBodyOption<T> = OperationRequestBodyContent<T> extends never
? { body?: never }
: undefined extends OperationRequestBodyContent<T>
? { body?: OperationRequestBodyContent<T> }
: { body: OperationRequestBodyContent<T> };

export type FetchOptions<T> = RequestOptions<T> &
Omit<RequestInit, "body" | "headers">;
export type FetchOptions<T> = RequestOptions<T> & Omit<RequestInit, "body" | "headers">;

export type FetchResponse<T, O, Media extends MediaType> =
| {
data: ParseAsResponse<
GetValueWithDefault<
SuccessResponse<ResponseObjectMap<T>>,
Media,
Record<string, never>
>,
GetValueWithDefault<SuccessResponse<ResponseObjectMap<T>>, Media, Record<string, never>>,
O
>;
error?: never;
response: Response;
}
| {
data?: never;
error: GetValueWithDefault<
ErrorResponse<ResponseObjectMap<T>>,
Media,
Record<string, never>
>;
error: GetValueWithDefault<ErrorResponse<ResponseObjectMap<T>>, Media, Record<string, never>>;
response: Response;
};

Expand Down Expand Up @@ -168,40 +144,32 @@ export function onRequest(
req: MiddlewareRequest,
options: MergedOptions,
): Request | undefined | Promise<Request | undefined>;
export function onResponse(
res: Response,
options: MergedOptions,
): Response | undefined | Promise<Response | undefined>;
export function onResponse(res: Response, options: MergedOptions): Response | undefined | Promise<Response | undefined>;

export interface Middleware {
onRequest?: typeof onRequest;
onResponse?: typeof onResponse;
}

// 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
type PathMethods = Partial<Record<HttpMethod, {}>>;

/** This type helper makes the 2nd function param required if params/requestBody are required; otherwise, optional */
export type MaybeOptionalInit<P extends PathMethods, M extends keyof P> =
HasRequiredKeys<FetchOptions<FilterKeys<P, M>>> extends never
? [(FetchOptions<FilterKeys<P, M>> | undefined)?]
: [FetchOptions<FilterKeys<P, M>>];
export type MaybeOptionalInit<P extends PathMethods, M extends keyof P> = HasRequiredKeys<
FetchOptions<FilterKeys<P, M>>
> extends never
? [(FetchOptions<FilterKeys<P, M>> | undefined)?]
: [FetchOptions<FilterKeys<P, M>>];

export type ClientMethod<
Paths extends Record<string, PathMethods>,
M extends HttpMethod,
Media extends MediaType,
> = <
export type ClientMethod<Paths extends Record<string, PathMethods>, M extends HttpMethod, Media extends MediaType> = <
P extends PathsWithMethod<Paths, M>,
I extends MaybeOptionalInit<Paths[P], M>,
>(
url: P,
...init: I
) => Promise<FetchResponse<Paths[P][M], I[0], Media>>;

export default function createClient<
Paths extends {},
Media extends MediaType = MediaType,
>(
export default function createClient<Paths extends {}, Media extends MediaType = MediaType>(
clientOptions?: ClientOptions,
): {
/** Call a GET endpoint */
Expand Down Expand Up @@ -249,13 +217,7 @@ export declare function serializeArrayParam(
name: string,
value: unknown[],
options: {
style:
| "simple"
| "label"
| "matrix"
| "form"
| "spaceDelimited"
| "pipeDelimited";
style: "simple" | "label" | "matrix" | "form" | "spaceDelimited" | "pipeDelimited";
explode: boolean;
allowReserved?: boolean;
},
Expand All @@ -271,10 +233,7 @@ export declare function createQuerySerializer<T = unknown>(
* @type {import("./index.js").defaultPathSerializer}
* @see https://swagger.io/docs/specification/serialization/#path
*/
export declare function defaultPathSerializer(
pathname: string,
pathParams: Record<string, unknown>,
): string;
export declare function defaultPathSerializer(pathname: string, pathParams: Record<string, unknown>): string;

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

/** Merge headers a and b, with b taking priority */
export declare function mergeHeaders(
...allHeaders: (HeadersOptions | undefined)[]
): Headers;

export {};
export declare function mergeHeaders(...allHeaders: (HeadersOptions | undefined)[]): Headers;
Loading