Skip to content

Commit

Permalink
chore: biome lint
Browse files Browse the repository at this point in the history
  • Loading branch information
ModyQyW committed Sep 3, 2024
1 parent 18eec3c commit e3b9514
Show file tree
Hide file tree
Showing 34 changed files with 137 additions and 141 deletions.
2 changes: 1 addition & 1 deletion docs/.vitepress/theme/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import DefaultTheme from "vitepress/theme";
import type { Theme } from "vitepress";
import DefaultTheme from "vitepress/theme";
import "./custom.css";

const theme: Theme = {
Expand Down
13 changes: 6 additions & 7 deletions packages/core/src/adapters/download.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import statuses from "statuses";
import { settle } from "../core/settle";
import type { UnCancelTokenListener } from "../core/UnCancelToken";
import { UnCanceledError } from "../core/UnCanceledError";
import { settle } from "../core/settle";
import type { UnConfig, UnData, UnResponse } from "../types";
import { buildDownloadConfig } from "../utils";
import { UnCancelTokenListener } from "../core/UnCancelToken";
import type { UnData, UnConfig, UnResponse } from "../types";

export const downloadAdapter = <T = UnData, D = UnData>(
config: UnConfig<T, D>,
Expand Down Expand Up @@ -102,8 +102,8 @@ export const downloadAdapter = <T = UnData, D = UnData>(
if (!task) {
return;
}
// @ts-expect-error no types
reject(
// @ts-expect-error type not existed
!cancel || cancel.type
? new UnCanceledError(undefined, config, task)
: cancel,
Expand All @@ -113,9 +113,8 @@ export const downloadAdapter = <T = UnData, D = UnData>(
};

cancelToken?.subscribe(onCanceled);
// @ts-expect-error no types
signal?.aborted
? onCanceled()
: signal?.addEventListener("abort", onCanceled);
? onCanceled({})
: signal?.addEventListener?.("abort", onCanceled);
}
});
13 changes: 6 additions & 7 deletions packages/core/src/adapters/request.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import statuses from "statuses";
import { settle } from "../core/settle";
import type { UnCancelTokenListener } from "../core/UnCancelToken";
import { UnCanceledError } from "../core/UnCanceledError";
import { settle } from "../core/settle";
import type { UnConfig, UnData, UnResponse } from "../types";
import { buildRequestConfig } from "../utils";
import { UnCancelTokenListener } from "../core/UnCancelToken";
import type { UnData, UnConfig, UnResponse } from "../types";

export const requestAdapter = <T = UnData, D = UnData>(
config: UnConfig<T, D>,
Expand Down Expand Up @@ -95,8 +95,8 @@ export const requestAdapter = <T = UnData, D = UnData>(
if (!task) {
return;
}
// @ts-expect-error no types
reject(
// @ts-expect-error type not existed
!cancel || cancel.type
? new UnCanceledError(undefined, config, task)
: cancel,
Expand All @@ -106,9 +106,8 @@ export const requestAdapter = <T = UnData, D = UnData>(
};

cancelToken?.subscribe(onCanceled);
// @ts-expect-error no types
signal?.aborted
? onCanceled()
: signal?.addEventListener("abort", onCanceled);
? onCanceled({})
: signal?.addEventListener?.("abort", onCanceled);
}
});
13 changes: 6 additions & 7 deletions packages/core/src/adapters/upload.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import statuses from "statuses";
import { settle } from "../core/settle";
import type { UnCancelTokenListener } from "../core/UnCancelToken";
import { UnCanceledError } from "../core/UnCanceledError";
import { settle } from "../core/settle";
import type { UnConfig, UnData, UnResponse } from "../types";
import { buildUploadConfig } from "../utils";
import { UnCancelTokenListener } from "../core/UnCancelToken";
import type { UnData, UnConfig, UnResponse } from "../types";

export const uploadAdapter = <T = UnData, D = UnData>(config: UnConfig<T, D>) =>
new Promise<UnResponse<T, D>>((resolve, reject) => {
Expand Down Expand Up @@ -96,8 +96,8 @@ export const uploadAdapter = <T = UnData, D = UnData>(config: UnConfig<T, D>) =>
if (!task) {
return;
}
// @ts-expect-error no types
reject(
// @ts-expect-error type not existed
!cancel || cancel.type
? new UnCanceledError(undefined, config, task)
: cancel,
Expand All @@ -107,9 +107,8 @@ export const uploadAdapter = <T = UnData, D = UnData>(config: UnConfig<T, D>) =>
};

cancelToken?.subscribe(onCanceled);
// @ts-expect-error no types
signal?.aborted
? onCanceled()
: signal?.addEventListener("abort", onCanceled);
? onCanceled({})
: signal?.addEventListener?.("abort", onCanceled);
}
});
9 changes: 5 additions & 4 deletions packages/core/src/composables.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { noop, until } from "@vueuse/core";
import type { Ref, ShallowRef } from "vue-demi";
import { ref, shallowRef } from "vue-demi";
import { noop, until } from "@vueuse/core";
import type {
UnInstance,
UnResponse,
UnCancelTokenSource,
UnConfig,
UnData,
UnInstance,
UnResponse,
} from "./index";
import { un, UnError } from "./index";
import { UnError, un } from "./index";

/** Align with v10.8.0 */

Expand Down Expand Up @@ -187,6 +187,7 @@ export function useUn<T = any, R = UnResponse<T>, D = any>(
.then(() => (error.value ? reject(error.value) : resolve(result)));
});
const promise = {
// biome-ignore lint/suspicious/noThenProperty: <explanation>
then: (...args) => waitUntilFinished().then(...args),
catch: (...args) => waitUntilFinished().catch(...args),
} as Promise<OverallUseUnReturn<T, R, D>>;
Expand Down
15 changes: 9 additions & 6 deletions packages/core/src/core/Un.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { buildFullPath, buildUrl, mergeConfig } from "../utils";
import type { UnConfig, UnData, UnResponse } from "../types";
import { buildFullPath, buildUrl, mergeConfig } from "../utils";
import {
UnInterceptorManager,
UnInterceptorManagerHandlerFulfilled,
UnInterceptorManagerHandlerRejected,
type UnInterceptorManagerHandlerFulfilled,
type UnInterceptorManagerHandlerRejected,
} from "./UnInterceptorManager";
import { dispatchRequest } from "./dispatchRequest";

Expand Down Expand Up @@ -141,10 +141,13 @@ export class Un<T = UnData, D = UnData> {
return await this._request(configOrUrl, config);
} catch (error) {
if (error instanceof Error) {
// biome-ignore lint/suspicious/noImplicitAnyLet: <explanation>
let dummy;
Error.captureStackTrace
? Error.captureStackTrace((dummy = {}))
: (dummy = new Error());
? // biome-ignore lint/suspicious/noAssignInExpressions: <explanation>
Error.captureStackTrace((dummy = {}))
: // biome-ignore lint/suspicious/noAssignInExpressions: <explanation>
(dummy = new Error());
// slice off the Error: ... line
const stack = dummy.stack ? dummy.stack.replace(/^.+\n/, "") : "";
if (!error.stack) {
Expand All @@ -154,7 +157,7 @@ export class Un<T = UnData, D = UnData> {
stack &&
!String(error.stack).endsWith(stack.replace(/^.+\n.+\n/, ""))
) {
error.stack += "\n" + stack;
error.stack += `\n${stack}`;
}
}
throw error;
Expand Down
7 changes: 4 additions & 3 deletions packages/core/src/core/UnCancelToken.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { describe, it, expect } from "vitest";
import { noop } from "@modyqyw/utils";
import { UnCancelToken, UnCanceler } from "./UnCancelToken";
import { describe, expect, it } from "vitest";
import { UnCancelToken, type UnCanceler } from "./UnCancelToken";
import { UnCanceledError } from "./UnCanceledError";

function noop() {}

describe("core:UnCancelToken", () => {
describe("constructor", () => {
it("throws when executor is not specified", () => {
Expand Down
15 changes: 9 additions & 6 deletions packages/core/src/core/UnCancelToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ export interface UnCancelStatic {
new (message?: string): UnCancel;
}

export interface UnCanceler<T = UnData, D = UnData> {
(message?: string, config?: UnConfig<T, D>, task?: UnTask): void;
}
export type UnCanceler<T = UnData, D = UnData> = (
message?: string,
config?: UnConfig<T, D>,
task?: UnTask,
) => void;

export interface UnCancelTokenListener {
(reason: UnCancel | PromiseLike<UnCancel>): void;
}
export type UnCancelTokenListener = (
reason: UnCancel | PromiseLike<UnCancel>,
) => void;

export interface UnCancelTokenSource<T = UnData, D = UnData> {
token: UnCancelToken;
Expand Down Expand Up @@ -51,6 +53,7 @@ export class UnCancelToken<T = UnData, D = UnData> {
this.listeners = [];
});

// biome-ignore lint/suspicious/noThenProperty: <explanation>
this.promise.then = (onfulfilled) => {
let _resolve: UnCancelTokenListener;
const promise = new Promise<UnCancel>((resolve) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/core/UnCanceledError.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, expect } from "vitest";
import { describe, expect, it } from "vitest";
import { UnCanceledError } from "./UnCanceledError";

describe("core:UnCanceledError", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/core/UnError.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, expect } from "vitest";
import { describe, expect, it } from "vitest";
import { UnError } from "./UnError";

describe("core::UnError", () => {
Expand Down
10 changes: 4 additions & 6 deletions packages/core/src/core/UnInterceptorManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ export interface UnInterceptorOptions<T = UnData, D = UnData> {
runWhen?: (config: UnConfig<T, D>) => boolean;
}

export interface UnInterceptorManagerHandlerFulfilled<V> {
(value: V): V | Promise<V>;
}
export type UnInterceptorManagerHandlerFulfilled<V> = (
value: V,
) => V | Promise<V>;

export interface UnInterceptorManagerHandlerRejected {
(error: any): any;
}
export type UnInterceptorManagerHandlerRejected = (error: any) => any;

export interface UnInterceptorManagerHandler<V, T = V, D = UnData>
extends UnInterceptorOptions<T, D> {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/core/dispatchRequest.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { adapters, requestAdapter } from "../adapters";
import type { UnConfig, UnData } from "../types";
import { isUnCancel } from "./isUnCancel";
import { UnCanceledError } from "./UnCanceledError";
import { isUnCancel } from "./isUnCancel";

const throwIfCancellationRequested = <T = UnData, D = UnData>(
config: UnConfig<T, D>,
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/core/isUnCancel.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, it, expect } from "vitest";
import { isUnCancel } from "./isUnCancel";
import { describe, expect, it } from "vitest";
import { UnCanceledError } from "./UnCanceledError";
import { isUnCancel } from "./isUnCancel";

describe("core:isCancel", () => {
it("returns true if value is a CanceledError", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/core/isUnCancel.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { UnCancel } from "./UnCancelToken";
import type { UnCancel } from "./UnCancelToken";

export const isUnCancel = (value: any): value is UnCancel =>
value?.isUnCanceledError === true;
2 changes: 1 addition & 1 deletion packages/core/src/core/isUnError.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, expect } from "vitest";
import { describe, expect, it } from "vitest";
import { UnError } from "./UnError";
import { isUnError } from "./isUnError";

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/core/isUnError.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { UnData } from "../types";
import { UnError } from "./UnError";
import type { UnError } from "./UnError";

export const isUnError = <T = UnData, D = UnData>(
value: any,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/core/settle.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, expect, vi, beforeEach, type Mock } from "vitest";
import { type Mock, beforeEach, describe, expect, it, vi } from "vitest";
import type { UnResponse } from "../types";
import { settle } from "./settle";

Expand Down
16 changes: 8 additions & 8 deletions packages/core/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { expect, it, describe } from "vitest";
import { defaults } from "./defaults";
import { describe, expect, it } from "vitest";
import { un } from ".";
import { version } from "../package.json";
import {
HttpStatusCode,
Un,
UnInterceptorManager,
UnCanceledError,
UnCancelToken,
isUnCancel,
UnCanceledError,
UnError,
UnInterceptorManager,
isUnCancel,
isUnError,
HttpStatusCode,
} from "./core";
import { defaults } from "./defaults";
import { mergeConfig } from "./utils";
import { un } from ".";
import { version } from "../package.json";

describe("index", () => {
it("un should be defined", () => {
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { version } from "../package.json";
import {
HttpStatusCode,
isUnError,
Un,
UnCancel,
UnCanceledError,
type UnCancel,
UnCancelToken,
UnCancelTokenStatic,
type UnCancelTokenStatic,
UnCanceledError,
UnError,
isUnCancel,
isUnError,
} from "./core";
import { defaults } from "./defaults";
import type { UnConfig, UnData, UnResponse } from "./types";
import { extend, mergeConfig } from "./utils";
import { UnConfig, UnData, UnResponse } from "./types";

export interface UnInstance<T = UnData, D = UnData> extends Un<T, D> {
<TT = T, DD = D, R = UnResponse<TT, DD>>(
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/types/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import type { UnData } from "./common";
import type { UnConfig } from "./config";
import type { UnPromise } from "./promise";

export interface UnAdapter<T = UnData, D = UnData> {
(config: UnConfig<T, D>): UnPromise<T, D>;
}
export type UnAdapter<T = UnData, D = UnData> = (
config: UnConfig<T, D>,
) => UnPromise<T, D>;
Loading

0 comments on commit e3b9514

Please sign in to comment.