Skip to content

Commit 4ea3e18

Browse files
author
beita1
committed
feat: install eslint and eslint fix part 3
1 parent 2c8b9d9 commit 4ea3e18

File tree

11 files changed

+226
-173
lines changed

11 files changed

+226
-173
lines changed

.eslintrc.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"parser": "@typescript-eslint/parser",
3+
"parserOptions": {
4+
"project": "tsconfig.json"
5+
},
6+
"plugins": [
7+
"@typescript-eslint/eslint-plugin"
8+
],
9+
"extends": [
10+
"airbnb-base",
11+
"plugin:@typescript-eslint/recommended",
12+
"plugin:@typescript-eslint/eslint-recommended"
13+
],
14+
"root": true,
15+
"env": {
16+
"node": true,
17+
"commonjs": true
18+
},
19+
"rules": {
20+
"@typescript-eslint/interface-name-prefix": "off",
21+
"@typescript-eslint/explicit-function-return-type": "off",
22+
"@typescript-eslint/no-explicit-any": "off",
23+
"@typescript-eslint/explicit-module-boundary-types": "off",
24+
"@typescript-eslint/no-unused-vars": "off",
25+
"@typescript-eslint/ban-types": "off",
26+
"import/no-unresolved": "off",
27+
"import/extensions": "off",
28+
"no-underscore-dangle": "off",
29+
"indent": [
30+
"error",
31+
2
32+
],
33+
"max-len": 0
34+
}
35+
}

@types/index.d.ts

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Task from "../src/task";
1+
import Task from '../src/task';
22

33
declare global {
44
/**
@@ -14,12 +14,12 @@ declare global {
1414
* the last error that was thrown while running the task
1515
*/
1616
error?: unknown;
17-
17+
1818
/**
1919
* The amount of time in milliseconds to run the benchmark task (cycle).
2020
*/
2121
totalTime: number;
22-
22+
2323
/**
2424
* the minimum value in the samples
2525
*/
@@ -28,159 +28,159 @@ declare global {
2828
* the maximum value in the samples
2929
*/
3030
max: number;
31-
31+
3232
/**
3333
* the number of operations per second
3434
*/
3535
hz: number;
36-
36+
3737
/**
3838
* how long each operation takes (ms)
3939
*/
4040
period: number;
41-
41+
4242
/**
4343
* task samples of each task iteration time (ms)
4444
*/
4545
samples: number[];
46-
46+
4747
/**
4848
* samples mean/average (estimate of the population mean)
4949
*/
5050
mean: number;
51-
51+
5252
/**
5353
* samples variance (estimate of the population variance)
5454
*/
5555
variance: number;
56-
56+
5757
/**
5858
* samples standard deviation (estimate of the population standard deviation)
5959
*/
6060
sd: number;
61-
61+
6262
/**
6363
* standard error of the mean (a.k.a. the standard deviation of the sampling distribution of the sample mean)
6464
*/
6565
sem: number;
66-
66+
6767
/**
6868
* degrees of freedom
6969
*/
7070
df: number;
71-
71+
7272
/**
7373
* critical value of the samples
7474
*/
7575
critical: number;
76-
76+
7777
/**
7878
* margin of error
7979
*/
8080
moe: number;
81-
81+
8282
/**
8383
* relative margin of error
8484
*/
8585
rme: number;
86-
86+
8787
/**
8888
* p75 percentile
8989
*/
9090
p75: number;
91-
91+
9292
/**
9393
* p99 percentile
9494
*/
9595
p99: number;
96-
96+
9797
/**
9898
* p995 percentile
9999
*/
100100
p995: number;
101-
101+
102102
/**
103103
* p999 percentile
104104
*/
105105
p999: number;
106106
};
107-
107+
108108
/**
109109
* Both the `Task` and `Bench` objects extend the `EventTarget` object,
110110
* so you can attach a listeners to different types of events
111111
* to each class instance using the universal `addEventListener` and
112112
* `removeEventListener`
113113
*/
114-
114+
115115
/**
116116
* Bench events
117117
*/
118118
export type IBenchEvents =
119-
| "abort" // when a signal aborts
120-
| "complete" // when running a benchmark finishes
121-
| "error" // when the benchmark task throws
122-
| "reset" // when the reset function gets called
123-
| "start" // when running the benchmarks gets started
124-
| "warmup" // when the benchmarks start getting warmed up (before start)
125-
| "cycle" // when running each benchmark task gets done (cycle)
126-
| "add" // when a Task gets added to the Bench
127-
| "remove"; // when a Task gets removed of the Bench
128-
119+
| 'abort' // when a signal aborts
120+
| 'complete' // when running a benchmark finishes
121+
| 'error' // when the benchmark task throws
122+
| 'reset' // when the reset function gets called
123+
| 'start' // when running the benchmarks gets started
124+
| 'warmup' // when the benchmarks start getting warmed up (before start)
125+
| 'cycle' // when running each benchmark task gets done (cycle)
126+
| 'add' // when a Task gets added to the Bench
127+
| 'remove'; // when a Task gets removed of the Bench
128+
129+
export type IHook = (task: Task, mode: 'warmup' | 'run') => void | Promise<void>;
130+
129131
/**
130132
* task events
131133
*/
132134
export type ITaskEvents =
133-
| "abort"
134-
| "complete"
135-
| "error"
136-
| "reset"
137-
| "start"
138-
| "warmup"
139-
| "cycle";
140-
135+
| 'abort'
136+
| 'complete'
137+
| 'error'
138+
| 'reset'
139+
| 'start'
140+
| 'warmup'
141+
| 'cycle';
142+
141143
export type IOptions = {
142144
/**
143145
* time needed for running a benchmark task (milliseconds) @default 500
144146
*/
145147
time?: number;
146-
148+
147149
/**
148150
* number of times that a task should run if even the time option is finished @default 10
149151
*/
150152
iterations?: number;
151-
153+
152154
/**
153155
* function to get the current timestamp in milliseconds
154156
*/
155157
now?: () => number;
156-
158+
157159
/**
158160
* An AbortSignal for aborting the benchmark
159161
*/
160162
signal?: AbortSignal;
161-
163+
162164
/**
163165
* warmup time (milliseconds) @default 100ms
164166
*/
165167
warmupTime?: number;
166-
168+
167169
/**
168170
* warmup iterations @default 5
169171
*/
170172
warmupIterations?: number;
171-
173+
172174
/**
173175
* setup function to run before each benchmark task (cycle)
174176
*/
175177
setup?: IHook;
176-
178+
177179
/**
178180
* teardown function to run after each benchmark task (cycle)
179181
*/
180182
teardown?: IHook;
181183
};
182-
183-
export type IHook = (task: Task, mode: "warmup" | "run") => void | Promise<void>;
184184

185185
export type IBenchEvent = Event & {
186186
task: Task | null;

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ completely based on the Web APIs with proper timing using `process.hrtime` or
1616
_In case you need more tiny libraries like tinypool or tinyspy, please consider submitting an [RFC](https://github.com/tinylibs/rfcs)_
1717

1818
## Requirements
19-
- node version >= v14
19+
- node version >= v16
2020

2121
## Installing
2222

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,14 @@
3636
"@size-limit/preset-small-lib": "^7.0.4",
3737
"@size-limit/time": "^7.0.4",
3838
"@types/node": "^18.7.13",
39+
"@typescript-eslint/eslint-plugin": "^5.35.1",
40+
"@typescript-eslint/parser": "^5.35.1",
3941
"bumpp": "^8.2.0",
42+
"changelogithub": "^0.12.4",
4043
"clean-publish": "^3.4.4",
44+
"eslint": "^8.22.0",
45+
"eslint-config-airbnb-base": "^15.0.0",
46+
"eslint-plugin-import": "^2.26.0",
4147
"happy-dom": "^2.25.1",
4248
"husky": "^7.0.4",
4349
"nano-staged": "^0.5.0",
@@ -47,8 +53,7 @@
4753
"tsup": "^5.11.7",
4854
"typescript": "^4.5.4",
4955
"vite": "^2.9.12",
50-
"vitest": "^0.14.2",
51-
"changelogithub": "^0.6.5"
56+
"vitest": "^0.14.2"
5257
},
5358
"keywords": [
5459
"spy",

src/bench.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { createBenchEvent } from "./event";
2-
import Task from "./task";
3-
import { now } from "./utils";
1+
import { createBenchEvent } from './event';
2+
import Task from './task';
3+
import { now } from './utils';
44

55
/**
66
* The Benchmark instance for keeping track of the benchmark tasks and controlling
@@ -20,8 +20,10 @@ export default class Bench extends EventTarget {
2020
iterations = 10;
2121

2222
now = now;
23-
setup: IHook = () => {};
24-
teardown: IHook = () => {};
23+
24+
setup: IHook;
25+
26+
teardown: IHook;
2527

2628
constructor(options: IOptions = {}) {
2729
super();
@@ -31,8 +33,10 @@ export default class Bench extends EventTarget {
3133
this.time = options.time ?? this.time;
3234
this.iterations = options.iterations ?? this.iterations;
3335
this.signal = options.signal;
34-
this.setup = options.setup ?? this.setup;
35-
this.teardown = options.teardown ?? this.teardown;
36+
// eslint-disable-next-line @typescript-eslint/no-empty-function
37+
this.setup = options.setup ?? (() => {});
38+
// eslint-disable-next-line @typescript-eslint/no-empty-function
39+
this.teardown = options.teardown ?? (() => {});
3640

3741
if (this.signal) {
3842
this.signal.addEventListener(

src/event.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import Task from "./task";
1+
import Task from './task';
22

3-
export function createBenchEvent(
3+
function createBenchEvent(
44
eventType: IBenchEvents,
5-
target: Task | null = null
5+
target: Task | null = null,
66
) {
77
const event = new Event(eventType);
88
Object.defineProperty(event, 'task', {
@@ -13,3 +13,8 @@ export function createBenchEvent(
1313
});
1414
return event;
1515
}
16+
17+
export default createBenchEvent;
18+
export {
19+
createBenchEvent,
20+
};

src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import Bench from "./bench";
2-
import Task from "./task";
1+
import Bench from './bench';
2+
import Task from './task';
33

4-
export { now } from "./utils";
4+
export { now } from './utils';
55

66
export { Bench, Task };
77
export default Bench;

0 commit comments

Comments
 (0)