Skip to content

chore: replace eslint and prettier with biomejs #32

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 10 commits into from
Apr 2, 2025
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
11 changes: 0 additions & 11 deletions .prettierrc.js

This file was deleted.

52 changes: 52 additions & 0 deletions biome.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
"vcs": {
"defaultBranch": "master"
},
"extends": [
"@chainsafe/biomejs-config",
"@chainsafe/biomejs-config/recommended",
"@chainsafe/biomejs-config/esm",
"@chainsafe/biomejs-config/erasable-syntax"
],
"files": {
"include": ["src/**/*.ts", "test/**/*.ts"]
},
"linter": {
"rules": {
"style": {
// We use `+` operator for string concatenation a lot
"useTemplate": "off",
// We use to export types and object without differentiating
"useExportType": "off",
// We use to import types and object without differentiating
"useImportType": "off"
}
}
},
"overrides": [
// TODO: Due to enum change disabling this for now
// Will bring it back as we update the base config
{
"include": ["*"],
"linter": {
"rules": {
"style": {
"useNamingConvention": "off"
}
}
}
},
{
"include": ["src/utils/gaContext.ts", "src/github/octokit.ts"],
"linter": {
"rules": {
"style": {
// This file using `snake_case` a lot due to Github Api
"useNamingConvention": "off"
}
}
}
}
]
}
77 changes: 0 additions & 77 deletions eslint.config.js

This file was deleted.

14 changes: 5 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"build:esm": "tsc -p tsconfig.build.esm.json && echo '{\"type\": \"module\"}' > ./lib/esm/package.json",
"build:cjs": "tsc -p tsconfig.build.cjs.json && echo '{\"type\": \"commonjs\"}' > ./lib/cjs/package.json",
"test:unit": "vitest run test/unit/**/*.test.ts",
"lint": "eslint --color src/ test/",
"lint": "biome check",
"lint:fix": "biome check --write",
"prepublishOnly": "yarn build",
"benchmark": "node --loader ts-node/esm ./src/cli/cli.ts 'test/perf/**/@(!(errors)).test.ts'",
"writeDocs": "node --loader ts-node/esm scripts/writeOptionsMd.ts"
Expand All @@ -42,18 +43,13 @@
"@types/yargs": "^17.0.33",
"@types/debug": "^4.1.12",
"dotenv": "^10.0.0",
"eslint": "^9.15.0",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-typescript": "^3.6.3",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-prettier": "^5.2.1",
"prettier": "^3.4.0",
"rimraf": "^5.0.10",
"ts-node": "^10.9.2",
"typescript": "^5.8.2",
"typescript-eslint": "^8.16.0",
"vitest": "^3.0.6",
"vitest-in-process-pool": "^2.0.0"
"vitest-in-process-pool": "^2.0.0",
"@biomejs/biome": "^1.9.4",
"@chainsafe/biomejs-config": "^0.1.1"
},
"dependencies": {
"@actions/cache": "^4.0.0",
Expand Down
5 changes: 2 additions & 3 deletions src/benchmark/benchmarkFn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import fs from "node:fs";
import path from "node:path";
import {getCurrentSuite, setFn} from "@vitest/runner";
import {createChainable} from "@vitest/runner/utils";
import {store} from "./globalState.js";
import {BenchApi, BenchmarkOpts, BenchmarkRunOptsWithFn, PartialBy} from "../types.js";
import {runBenchFn} from "./runBenchmarkFn.js";
import {store} from "./globalState.js";
import {getBenchmarkOptionsWithDefaults} from "./options.js";
import {runBenchFn} from "./runBenchmarkFn.js";

export const bench: BenchApi = createBenchmarkFunction(function <T, T2>(
this: Record<"skip" | "only", boolean | undefined>,
Expand Down Expand Up @@ -64,7 +64,6 @@ export const bench: BenchApi = createBenchmarkFunction(function <T, T2>(
const cleanup = (): void => {
store.removeOptions(task);
// Clear up the assigned handler to clean the memory
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
setFn(task, null);
};
Expand Down
4 changes: 2 additions & 2 deletions src/benchmark/convergence/coefficientOfVariance.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Debug from "debug";
import {BenchmarkOpts, ConvergenceCheckFn} from "../../types.js";
import {
OutlierSensitivityEnum,
calcMean,
calcMedian,
calcVariance,
filterOutliers,
OutlierSensitivityEnum,
sortData,
} from "../../utils/math.js";

Expand All @@ -20,7 +20,7 @@ export function createCVConvergenceCriteria(
const minSamples = Math.max(5, minRuns);
const maxSamplesForCV = 1000;

return function canTerminate(runIdx: number, totalNs: bigint, runsNs: bigint[]): boolean {
return function canTerminate(runIdx: number, _totalNs: bigint, runsNs: bigint[]): boolean {
const currentMs = Date.now();
const elapsedMs = currentMs - startMs;
const timeSinceLastCheck = currentMs - lastConvergenceSample;
Expand Down
1 change: 0 additions & 1 deletion src/benchmark/convergence/linearAverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export function createLinearConvergenceCriteria(
let lastConvergenceSample = startMs;
const sampleEveryMs = 100;

// eslint-disable-next-line @typescript-eslint/no-unused-vars
return function canTerminate(runIdx: number, totalNs: bigint, _runNs: bigint[]): boolean {
const currentMs = Date.now();
const elapsedMs = currentMs - startMs;
Expand Down
8 changes: 5 additions & 3 deletions src/benchmark/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ function getRatioRow(result: BenchmarkResult, prevResult: BenchmarkResult | null

if (ratio > threshold) {
return `\u001b[91m${str}\u001b[0m`; // red
} else if (ratio < 1 / threshold) {
}

if (ratio < 1 / threshold) {
return `\u001b[92m${str}\u001b[0m`; // green
} else {
return str;
}

return str;
}

function prettyTime(nanoSec: number): [number, string] {
Expand Down
4 changes: 2 additions & 2 deletions src/benchmark/globalState.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Debug from "debug";
import type {Suite, SuiteCollector, Task} from "@vitest/runner";
import {BenchmarkResult, BenchmarkOpts, BenchmarkResults} from "../types.js";
import Debug from "debug";
import {BenchmarkOpts, BenchmarkResult, BenchmarkResults} from "../types.js";

const debug = Debug("@chainsafe/benchmark/state");

Expand Down
8 changes: 3 additions & 5 deletions src/benchmark/reporter.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {Task, Suite, File} from "@vitest/runner";
import {color, consoleLog, symbols} from "../utils/output.js";
import {store} from "./globalState.js";
import {File, Suite, Task} from "@vitest/runner";
import {Benchmark, BenchmarkOpts, BenchmarkResult} from "../types.js";
import {color, consoleLog, symbols} from "../utils/output.js";
import {formatResultRow} from "./format.js";
import {store} from "./globalState.js";
import {defaultBenchmarkOptions} from "./options.js";

export class BenchmarkReporter {
Expand Down Expand Up @@ -129,7 +129,6 @@ export class BenchmarkReporter {
}
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
onSuiteFinished(_suite: Suite): void {
--this.indents;

Expand All @@ -138,7 +137,6 @@ export class BenchmarkReporter {
}
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
onComplete(_files: File[]): void {
consoleLog();
this.indents += 2;
Expand Down
18 changes: 9 additions & 9 deletions src/benchmark/runBenchmarkFn.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Debug from "debug";
import {BenchmarkResult, BenchmarkOpts, Convergence, ConvergenceCheckFn, ConvergenceEnum} from "../types.js";
import {calcSum, filterOutliers, OutlierSensitivityEnum} from "../utils/math.js";
import {getBenchmarkOptionsWithDefaults} from "./options.js";
import {createLinearConvergenceCriteria} from "./convergence/linearAverage.js";
import {BenchmarkOpts, BenchmarkResult, Convergence, ConvergenceCheckFn, ConvergenceEnum} from "../types.js";
import {OutlierSensitivityEnum, calcSum, filterOutliers} from "../utils/math.js";
import {createCVConvergenceCriteria} from "./convergence/coefficientOfVariance.js";
import {createLinearConvergenceCriteria} from "./convergence/linearAverage.js";
import {getBenchmarkOptionsWithDefaults} from "./options.js";

const debug = Debug("@chainsafe/benchmark/run");

Expand Down Expand Up @@ -121,14 +121,14 @@ Consider adjusting 'maxWarmUpMs' or 'maxWarmUpRuns' options orextend 'maxMs'
if your function is very slow.
`.trim()
);
} else {
throw Error(
`
}

throw Error(
`
No run was completed before 'maxMs' ${maxMs}. Consider extending the 'maxMs' time if
either the before(), beforeEach() or fn() functions are too slow.
`.trim()
);
}
);
}

let averageNs!: number;
Expand Down
15 changes: 7 additions & 8 deletions src/benchmark/runner.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import path from "node:path";
import {
File,
startTests,
Suite,
Task,
VitestRunner,
VitestRunnerConfig,
VitestRunnerImportSource,
startTests,
} from "@vitest/runner";
import path from "node:path";
import Debug from "debug";
import {Benchmark, BenchmarkOpts, BenchmarkResults} from "../types.js";
import {BenchmarkReporter} from "./reporter.js";
import {store} from "./globalState.js";
import {BenchmarkReporter} from "./reporter.js";

const debug = Debug("@chainsafe/benchmark/runner");

Expand Down Expand Up @@ -63,8 +63,7 @@ export class BenchmarkRunner implements VitestRunner {
}
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
async onAfterRunTask(task: Task): Promise<void> {
async onAfterRunTask(_task: Task): Promise<void> {
// To help maintain consistent memory usage patterns
// we trigger garbage collection manually
if (this.triggerGC && global.gc) {
Expand Down Expand Up @@ -93,9 +92,9 @@ export class BenchmarkRunner implements VitestRunner {
debug("starting tests %O", files);
const res = await startTests(files, this);

const passed = res.filter((r) => r.result?.state == "pass");
const skipped = res.filter((r) => r.result?.state == "skip");
const failed = res.filter((r) => r.result?.state == "fail");
const passed = res.filter((r) => r.result?.state === "pass");
const skipped = res.filter((r) => r.result?.state === "skip");
const failed = res.filter((r) => r.result?.state === "fail");

debug("finished tests. passed: %i, skipped: %i, failed: %i", passed.length, skipped.length, failed.length);

Expand Down
Loading