Skip to content

Commit

Permalink
feat: install eslint and eslint fix part 3
Browse files Browse the repository at this point in the history
  • Loading branch information
beita1 committed Aug 26, 2022
1 parent 2c8b9d9 commit 4ea3e18
Show file tree
Hide file tree
Showing 11 changed files with 226 additions and 173 deletions.
35 changes: 35 additions & 0 deletions .eslintrc.json
@@ -0,0 +1,35 @@
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "tsconfig.json"
},
"plugins": [
"@typescript-eslint/eslint-plugin"
],
"extends": [
"airbnb-base",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/eslint-recommended"
],
"root": true,
"env": {
"node": true,
"commonjs": true
},
"rules": {
"@typescript-eslint/interface-name-prefix": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/ban-types": "off",
"import/no-unresolved": "off",
"import/extensions": "off",
"no-underscore-dangle": "off",
"indent": [
"error",
2
],
"max-len": 0
}
}
94 changes: 47 additions & 47 deletions @types/index.d.ts
@@ -1,4 +1,4 @@
import Task from "../src/task";
import Task from '../src/task';

declare global {
/**
Expand All @@ -14,12 +14,12 @@ declare global {
* the last error that was thrown while running the task
*/
error?: unknown;

/**
* The amount of time in milliseconds to run the benchmark task (cycle).
*/
totalTime: number;

/**
* the minimum value in the samples
*/
Expand All @@ -28,159 +28,159 @@ declare global {
* the maximum value in the samples
*/
max: number;

/**
* the number of operations per second
*/
hz: number;

/**
* how long each operation takes (ms)
*/
period: number;

/**
* task samples of each task iteration time (ms)
*/
samples: number[];

/**
* samples mean/average (estimate of the population mean)
*/
mean: number;

/**
* samples variance (estimate of the population variance)
*/
variance: number;

/**
* samples standard deviation (estimate of the population standard deviation)
*/
sd: number;

/**
* standard error of the mean (a.k.a. the standard deviation of the sampling distribution of the sample mean)
*/
sem: number;

/**
* degrees of freedom
*/
df: number;

/**
* critical value of the samples
*/
critical: number;

/**
* margin of error
*/
moe: number;

/**
* relative margin of error
*/
rme: number;

/**
* p75 percentile
*/
p75: number;

/**
* p99 percentile
*/
p99: number;

/**
* p995 percentile
*/
p995: number;

/**
* p999 percentile
*/
p999: number;
};

/**
* Both the `Task` and `Bench` objects extend the `EventTarget` object,
* so you can attach a listeners to different types of events
* to each class instance using the universal `addEventListener` and
* `removeEventListener`
*/

/**
* Bench events
*/
export type IBenchEvents =
| "abort" // when a signal aborts
| "complete" // when running a benchmark finishes
| "error" // when the benchmark task throws
| "reset" // when the reset function gets called
| "start" // when running the benchmarks gets started
| "warmup" // when the benchmarks start getting warmed up (before start)
| "cycle" // when running each benchmark task gets done (cycle)
| "add" // when a Task gets added to the Bench
| "remove"; // when a Task gets removed of the Bench

| 'abort' // when a signal aborts
| 'complete' // when running a benchmark finishes
| 'error' // when the benchmark task throws
| 'reset' // when the reset function gets called
| 'start' // when running the benchmarks gets started
| 'warmup' // when the benchmarks start getting warmed up (before start)
| 'cycle' // when running each benchmark task gets done (cycle)
| 'add' // when a Task gets added to the Bench
| 'remove'; // when a Task gets removed of the Bench

export type IHook = (task: Task, mode: 'warmup' | 'run') => void | Promise<void>;

/**
* task events
*/
export type ITaskEvents =
| "abort"
| "complete"
| "error"
| "reset"
| "start"
| "warmup"
| "cycle";
| 'abort'
| 'complete'
| 'error'
| 'reset'
| 'start'
| 'warmup'
| 'cycle';

export type IOptions = {
/**
* time needed for running a benchmark task (milliseconds) @default 500
*/
time?: number;

/**
* number of times that a task should run if even the time option is finished @default 10
*/
iterations?: number;

/**
* function to get the current timestamp in milliseconds
*/
now?: () => number;

/**
* An AbortSignal for aborting the benchmark
*/
signal?: AbortSignal;

/**
* warmup time (milliseconds) @default 100ms
*/
warmupTime?: number;

/**
* warmup iterations @default 5
*/
warmupIterations?: number;

/**
* setup function to run before each benchmark task (cycle)
*/
setup?: IHook;

/**
* teardown function to run after each benchmark task (cycle)
*/
teardown?: IHook;
};

export type IHook = (task: Task, mode: "warmup" | "run") => void | Promise<void>;

export type IBenchEvent = Event & {
task: Task | null;
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -16,7 +16,7 @@ completely based on the Web APIs with proper timing using `process.hrtime` or
_In case you need more tiny libraries like tinypool or tinyspy, please consider submitting an [RFC](https://github.com/tinylibs/rfcs)_

## Requirements
- node version >= v14
- node version >= v16

## Installing

Expand Down
9 changes: 7 additions & 2 deletions package.json
Expand Up @@ -36,8 +36,14 @@
"@size-limit/preset-small-lib": "^7.0.4",
"@size-limit/time": "^7.0.4",
"@types/node": "^18.7.13",
"@typescript-eslint/eslint-plugin": "^5.35.1",
"@typescript-eslint/parser": "^5.35.1",
"bumpp": "^8.2.0",
"changelogithub": "^0.12.4",
"clean-publish": "^3.4.4",
"eslint": "^8.22.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.26.0",
"happy-dom": "^2.25.1",
"husky": "^7.0.4",
"nano-staged": "^0.5.0",
Expand All @@ -47,8 +53,7 @@
"tsup": "^5.11.7",
"typescript": "^4.5.4",
"vite": "^2.9.12",
"vitest": "^0.14.2",
"changelogithub": "^0.6.5"
"vitest": "^0.14.2"
},
"keywords": [
"spy",
Expand Down
18 changes: 11 additions & 7 deletions src/bench.ts
@@ -1,6 +1,6 @@
import { createBenchEvent } from "./event";
import Task from "./task";
import { now } from "./utils";
import { createBenchEvent } from './event';
import Task from './task';
import { now } from './utils';

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

now = now;
setup: IHook = () => {};
teardown: IHook = () => {};

setup: IHook;

teardown: IHook;

constructor(options: IOptions = {}) {
super();
Expand All @@ -31,8 +33,10 @@ export default class Bench extends EventTarget {
this.time = options.time ?? this.time;
this.iterations = options.iterations ?? this.iterations;
this.signal = options.signal;
this.setup = options.setup ?? this.setup;
this.teardown = options.teardown ?? this.teardown;
// eslint-disable-next-line @typescript-eslint/no-empty-function
this.setup = options.setup ?? (() => {});
// eslint-disable-next-line @typescript-eslint/no-empty-function
this.teardown = options.teardown ?? (() => {});

if (this.signal) {
this.signal.addEventListener(
Expand Down
11 changes: 8 additions & 3 deletions src/event.ts
@@ -1,8 +1,8 @@
import Task from "./task";
import Task from './task';

export function createBenchEvent(
function createBenchEvent(
eventType: IBenchEvents,
target: Task | null = null
target: Task | null = null,
) {
const event = new Event(eventType);
Object.defineProperty(event, 'task', {
Expand All @@ -13,3 +13,8 @@ export function createBenchEvent(
});
return event;
}

export default createBenchEvent;
export {
createBenchEvent,
};
6 changes: 3 additions & 3 deletions src/index.ts
@@ -1,7 +1,7 @@
import Bench from "./bench";
import Task from "./task";
import Bench from './bench';
import Task from './task';

export { now } from "./utils";
export { now } from './utils';

export { Bench, Task };
export default Bench;

0 comments on commit 4ea3e18

Please sign in to comment.