Skip to content

Commit d057046

Browse files
committed
chore: lint
1 parent 00f1b70 commit d057046

File tree

10 files changed

+244
-206
lines changed

10 files changed

+244
-206
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ Remove all hook handlers.
203203
Registers a (sync) callback to be called before each hook is being called.
204204

205205
```js
206-
hookable.beforeEach((event) => { console.log(`${event.name} hook is being called with ${event.args}`)}`)
206+
hookable.beforeEach((event) => { console.log(`${event.name} hook is being called with ${event.args}`)})
207207
hookable.hook('test', () => { console.log('running test hook') })
208208

209209
// test hook is being called with []
@@ -216,7 +216,7 @@ await hookable.callHook('test')
216216
Registers a (sync) callback to be called after each hook is being called.
217217

218218
```js
219-
hookable.afterEach((event) => { console.log(`${event.name} hook called with ${event.args}`)}`)
219+
hookable.afterEach((event) => { console.log(`${event.name} hook called with ${event.args}`)})
220220
hookable.hook('test', () => { console.log('running test hook') })
221221

222222
// running test hook

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
},
3535
"devDependencies": {
3636
"@types/node": "^22.14.0",
37-
"@vitest/coverage-c8": "^0.33.0",
37+
"@vitest/coverage-v8": "3.1.1",
3838
"changelogen": "^0.6.1",
3939
"eslint": "^9.23.0",
4040
"eslint-config-unjs": "^0.4.2",
@@ -46,4 +46,4 @@
4646
"vitest": "^3.1.1"
4747
},
4848
"packageManager": "pnpm@10.7.1"
49-
}
49+
}

pnpm-lock.yaml

Lines changed: 203 additions & 171 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

shims.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
declare global {
2-
// eslint-disable-next-line no-unused-vars
32
interface Console {
43
// https://developer.chrome.com/blog/devtools-modern-web-debugging/#linked-stack-traces
54
createTask(name: string): { run: <T extends () => any>(function_: T) => ReturnType<T> }

src/debugger.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ export interface CreateDebuggerOptions {
2222
filter?: string | ((event: string) => boolean);
2323
}
2424

25+
// eslint-disable-next-line unicorn/prefer-global-this
2526
const isBrowser = typeof window !== "undefined";
2627

2728
/** Start debugging hook names and timing in console */
2829
export function createDebugger(
2930
hooks: Hookable<any>,
30-
_options: CreateDebuggerOptions = {}
31+
_options: CreateDebuggerOptions = {},
3132
) {
3233
const options = <CreateDebuggerOptions>{
3334
inspect: isBrowser,

src/hookable.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type InferSpyEvent<HT extends Record<string, any>> = {
2424

2525
export class Hookable<
2626
HooksT extends Record<string, any> = Record<string, HookCallback>,
27-
HookNameT extends HookKeys<HooksT> = HookKeys<HooksT>
27+
HookNameT extends HookKeys<HooksT> = HookKeys<HooksT>,
2828
> {
2929
private _hooks: { [key: string]: HookCallback[] };
3030
private _before?: HookCallback[];
@@ -48,7 +48,7 @@ export class Hookable<
4848
hook<NameT extends HookNameT>(
4949
name: NameT,
5050
function_: InferCallback<HooksT, NameT>,
51-
options: { allowDeprecated?: boolean } = {}
51+
options: { allowDeprecated?: boolean } = {},
5252
) {
5353
if (!name || typeof function_ !== "function") {
5454
return () => {};
@@ -83,7 +83,9 @@ export class Hookable<
8383
get: () => "_" + name.replace(/\W+/g, "_") + "_hook_cb",
8484
configurable: true,
8585
});
86-
} catch {}
86+
} catch {
87+
// ignore
88+
}
8789
}
8890

8991
this._hooks[name] = this._hooks[name] || [];
@@ -100,7 +102,7 @@ export class Hookable<
100102

101103
hookOnce<NameT extends HookNameT>(
102104
name: NameT,
103-
function_: InferCallback<HooksT, NameT>
105+
function_: InferCallback<HooksT, NameT>,
104106
) {
105107
let _unreg: (() => void) | undefined;
106108
let _function: ((...arguments_: any) => any) | undefined = (
@@ -119,7 +121,7 @@ export class Hookable<
119121

120122
removeHook<NameT extends HookNameT>(
121123
name: NameT,
122-
function_: InferCallback<HooksT, NameT>
124+
function_: InferCallback<HooksT, NameT>,
123125
) {
124126
if (this._hooks[name]) {
125127
const index = this._hooks[name].indexOf(function_);
@@ -136,7 +138,7 @@ export class Hookable<
136138

137139
deprecateHook<NameT extends HookNameT>(
138140
name: NameT,
139-
deprecated: HookKeys<HooksT> | DeprecatedHook<HooksT>
141+
deprecated: HookKeys<HooksT> | DeprecatedHook<HooksT>,
140142
) {
141143
this._deprecatedHooks[name] =
142144
typeof deprecated === "string" ? { to: deprecated } : deprecated;
@@ -148,7 +150,7 @@ export class Hookable<
148150
}
149151

150152
deprecateHooks(
151-
deprecatedHooks: Partial<Record<HookNameT, DeprecatedHook<HooksT>>>
153+
deprecatedHooks: Partial<Record<HookNameT, DeprecatedHook<HooksT>>>,
152154
) {
153155
Object.assign(this._deprecatedHooks, deprecatedHooks);
154156
for (const name in deprecatedHooks) {
@@ -160,7 +162,7 @@ export class Hookable<
160162
const hooks = flatHooks<HooksT>(configHooks);
161163
// @ts-ignore
162164
const removeFns = Object.keys(hooks).map((key) =>
163-
this.hook(key as HookNameT, hooks[key])
165+
this.hook(key as HookNameT, hooks[key]),
164166
);
165167

166168
return () => {
@@ -206,8 +208,8 @@ export class Hookable<
206208
NameT extends HookNameT,
207209
CallFunction extends (
208210
hooks: HookCallback[],
209-
arguments_: Parameters<InferCallback<HooksT, NameT>>
210-
) => any
211+
arguments_: Parameters<InferCallback<HooksT, NameT>>,
212+
) => any,
211213
>(
212214
caller: CallFunction,
213215
name: NameT,
@@ -222,7 +224,7 @@ export class Hookable<
222224
}
223225
const result = caller(
224226
name in this._hooks ? [...this._hooks[name]] : [],
225-
arguments_
227+
arguments_,
226228
);
227229
if ((result as any) instanceof Promise) {
228230
return result.finally(() => {

src/types.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ export interface Hooks {
44
}
55
export type HookKeys<T> = keyof T & string;
66
export type DeprecatedHook<T> = { message?: string; to: HookKeys<T> };
7-
// eslint-disable-next-line no-unused-vars
87
export type DeprecatedHooks<T> = { [name in HookKeys<T>]: DeprecatedHook<T> };
98

109
// Utilities
@@ -14,8 +13,8 @@ type KnownKeys<T> = keyof {
1413
[K in keyof T as string extends K
1514
? never
1615
: number extends K
17-
? never
18-
: K]: never;
16+
? never
17+
: K]: never;
1918
};
2019
type StripGeneric<T> = Pick<
2120
T,

src/utils.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { NestedHooks, HookCallback } from "./types";
33
export function flatHooks<T>(
44
configHooks: NestedHooks<T>,
55
hooks: T = {} as T,
6-
parentName?: string
6+
parentName?: string,
77
): T {
88
for (const key in configHooks) {
99
// @ts-ignore
@@ -48,12 +48,12 @@ export function mergeHooks<T>(...hooks: NestedHooks<T>[]): T {
4848

4949
export function serial<T>(
5050
tasks: T[],
51-
function_: (task: T) => Promise<any> | any
51+
function_: (task: T) => Promise<any> | any,
5252
) {
5353
// eslint-disable-next-line unicorn/no-array-reduce
5454
return tasks.reduce(
5555
(promise, task) => promise.then(() => function_(task)),
56-
Promise.resolve()
56+
Promise.resolve(),
5757
);
5858
}
5959

@@ -62,7 +62,7 @@ type CreateTask = typeof console.createTask;
6262
const defaultTask: ReturnType<CreateTask> = { run: (function_) => function_() };
6363
const _createTask: CreateTask = () => defaultTask;
6464
const createTask =
65-
typeof console.createTask !== "undefined" ? console.createTask : _createTask;
65+
console.createTask === undefined ? _createTask : console.createTask;
6666

6767
export function serialTaskCaller(hooks: HookCallback[], args: any[]) {
6868
const name = args.shift();
@@ -71,7 +71,7 @@ export function serialTaskCaller(hooks: HookCallback[], args: any[]) {
7171
return hooks.reduce(
7272
(promise, hookFunction) =>
7373
promise.then(() => task.run(() => hookFunction(...args))),
74-
Promise.resolve()
74+
Promise.resolve(),
7575
);
7676
}
7777

@@ -87,7 +87,7 @@ export function serialCaller(hooks: HookCallback[], arguments_?: any[]) {
8787
return hooks.reduce(
8888
(promise, hookFunction) =>
8989
promise.then(() => hookFunction(...(arguments_ || []))),
90-
Promise.resolve()
90+
Promise.resolve(),
9191
);
9292
}
9393

test/debuger.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ describe("debugger", () => {
3838
await hooks.callHook("hook");
3939
expect(console.time).toBeCalledWith(expect.stringContaining("[tag] hook"));
4040
expect(console.timeEnd).toBeCalledWith(
41-
expect.stringContaining("[tag] hook")
41+
expect.stringContaining("[tag] hook"),
4242
);
4343
});
4444
it("should respect `inspect` option", async () => {

test/hookable.test.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable unicorn/consistent-function-scoping */
21
// @ts-nocheck
32
import { describe, test, beforeEach, expect, vi } from "vitest";
43
import { createHooks, flatHooks, mergeHooks } from "../src/index";
@@ -64,10 +63,10 @@ describe("core: hookable", () => {
6463
hook.hook("x", () => {});
6564

6665
expect(console.warn).toBeCalledWith(
67-
"a hook has been deprecated, please use c"
66+
"a hook has been deprecated, please use c",
6867
);
6968
expect(console.warn).toBeCalledWith(
70-
"b hook has been deprecated, please use c"
69+
"b hook has been deprecated, please use c",
7170
);
7271
expect(console.warn).toBeCalledWith("Custom");
7372
expect(console.warn).toBeCalledTimes(3);
@@ -94,7 +93,7 @@ describe("core: hookable", () => {
9493
hook.hook("b", () => {});
9594
hook.deprecateHook("a", "b");
9695
expect(console.warn).toBeCalledWith(
97-
"a hook has been deprecated, please use b"
96+
"a hook has been deprecated, please use b",
9897
);
9998
expect(hook._hooks.a).toBeUndefined();
10099
expect(hook._hooks.b).toEqual([expect.any(Function), expect.any(Function)]);
@@ -109,7 +108,7 @@ describe("core: hookable", () => {
109108
hook.hook("test:hook", () => {});
110109

111110
expect(console.warn).toBeCalledWith(
112-
"test:hook hook has been deprecated, please use test:before"
111+
"test:hook hook has been deprecated, please use test:before",
113112
);
114113
expect(hook._hooks["test:hook"]).toBeUndefined();
115114
expect(hook._hooks["test:before"]).toEqual([expect.any(Function)]);
@@ -349,16 +348,22 @@ describe("core: hookable", () => {
349348
const unreg = hook.beforeEach((event) => {
350349
unreg();
351350
expect(event.context.count).toBeUndefined();
352-
event.name === "test" && x++;
351+
if (event.name === "test") {
352+
x++;
353+
}
353354
event.context.count = x;
354355
});
355356
hook.beforeEach((event) => {
356-
event.name === "test" && x++;
357+
if (event.name === "test") {
358+
x++;
359+
}
357360
event.context.count = x;
358361
});
359362
hook.afterEach((event) => {
360363
expect(event.context.count).toEqual(x);
361-
event.name === "test" && x++;
364+
if (event.name === "test") {
365+
x++;
366+
}
362367
});
363368

364369
await hook.callHook("test");

0 commit comments

Comments
 (0)