Skip to content

Commit

Permalink
feat: use biome linter
Browse files Browse the repository at this point in the history
  • Loading branch information
RafaelGSS committed Dec 27, 2024
1 parent a46008f commit 7870e91
Show file tree
Hide file tree
Showing 41 changed files with 1,325 additions and 1,184 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,8 @@ jobs:
- name: Install dependencies
run: npm install

- name: Run linter
run: npm run lint

- name: Run tests
run: npm test
23 changes: 23 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"$schema": "https://biomejs.dev/schemas/1.8.3/schema.json",
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"style": {
"noParameterAssign": "off"
}
}
},
"formatter": {
"enabled": true
},
"files": {
"ignore": [
"examples/deleting-properties/node.js"
]
}
}
36 changes: 18 additions & 18 deletions examples/create-uint32array/node.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
const { Suite } = require('../../lib');
const { Suite } = require("../../lib");

const suite = new Suite();

suite
.add(`new Uint32Array(1024)`, function () {
return new Uint32Array(1024);
})
.add(`new Uint32Array(1024) with 10 repetitions`, {repeatSuite: 10}, function () {
return new Uint32Array(1024);
})
.add(`[Managed] new Uint32Array(1024)`, function (timer) {
const assert = require('node:assert');
.add("new Uint32Array(1024)", () => new Uint32Array(1024))
.add(
"new Uint32Array(1024) with 10 repetitions",
{ repeatSuite: 10 },
() => new Uint32Array(1024),
)
.add("[Managed] new Uint32Array(1024)", (timer) => {
const assert = require("node:assert");

let r;
let r;

timer.start();
for (let i = 0; i < timer.count; i++) {
r = new Uint32Array(1024);
}
timer.end(timer.count);
timer.start();
for (let i = 0; i < timer.count; i++) {
r = new Uint32Array(1024);
}
timer.end(timer.count);

assert.ok(r);
})
.run();
assert.ok(r);
})
.run();
121 changes: 70 additions & 51 deletions examples/crypto-verify/node.js
Original file line number Diff line number Diff line change
@@ -1,67 +1,86 @@
const crypto = require('node:crypto');
const { readFileSync } = require('fs');
const { Suite } = require('../../lib');
const crypto = require("node:crypto");
const { readFileSync } = require("node:fs");
const { Suite } = require("../../lib");

const rsaPrivateKey = readFileSync(`${__dirname}/private-key.pem`, 'utf-8');
const rsaPublicKey = readFileSync(`${__dirname}/public-key.pem`, 'utf-8');
const rsaPrivateKey = readFileSync(`${__dirname}/private-key.pem`, "utf-8");
const rsaPublicKey = readFileSync(`${__dirname}/public-key.pem`, "utf-8");

const thing = 'hello world';
const algorithm = 'RSA-SHA256';
const signature = crypto.createSign(algorithm).update(thing).sign(rsaPrivateKey, 'base64');
const thing = "hello world";
const algorithm = "RSA-SHA256";
const signature = crypto
.createSign(algorithm)
.update(thing)
.sign(rsaPrivateKey, "base64");

const suite = new Suite();

suite
.add(`crypto.createVerify('${algorithm}')`, function () {
var verifier = crypto.createVerify(algorithm);
verifier.update(thing);
verifier.verify(rsaPublicKey, signature, 'base64');
})
.add(`crypto.verify('${algorithm}')`, function () {
crypto.verify(algorithm, thing, rsaPublicKey, Buffer.from(signature, 'base64'));
})
.add(`[Managed] crypto.createVerify('RSA-SHA256')`, function (timer) {
const crypto = require('node:crypto');
const { readFileSync } =require('node:fs');
const assert = require('node:assert');
.add(`crypto.createVerify('${algorithm}')`, () => {
const verifier = crypto.createVerify(algorithm);
verifier.update(thing);
verifier.verify(rsaPublicKey, signature, "base64");
})
.add(`crypto.verify('${algorithm}')`, () => {
crypto.verify(
algorithm,
thing,
rsaPublicKey,
Buffer.from(signature, "base64"),
);
})
.add(`[Managed] crypto.createVerify('RSA-SHA256')`, (timer) => {
const crypto = require("node:crypto");
const { readFileSync } = require("node:fs");
const assert = require("node:assert");

const rsaPrivateKey = readFileSync(`${__dirname}/private-key.pem`, 'utf-8');
const rsaPublicKey = readFileSync(`${__dirname}/public-key.pem`, 'utf-8');
const rsaPrivateKey = readFileSync(`${__dirname}/private-key.pem`, "utf-8");
const rsaPublicKey = readFileSync(`${__dirname}/public-key.pem`, "utf-8");

const thing = 'hello world'
const signature = crypto.createSign('RSA-SHA256').update(thing).sign(rsaPrivateKey, 'base64')
const thing = "hello world";
const signature = crypto
.createSign("RSA-SHA256")
.update(thing)
.sign(rsaPrivateKey, "base64");

let verifier;
let verifier;

timer.start();
for (let i = 0; i < timer.count; i++) {
verifier = crypto.createVerify('RSA-SHA256')
verifier.update(thing)
verifier.verify(rsaPublicKey, signature, 'base64')
}
timer.end(timer.count);
timer.start();
for (let i = 0; i < timer.count; i++) {
verifier = crypto.createVerify("RSA-SHA256");
verifier.update(thing);
verifier.verify(rsaPublicKey, signature, "base64");
}
timer.end(timer.count);

assert.ok(verifier);
})
.add(`[Managed] crypto.verify('RSA-SHA256')`, function (timer) {
const crypto = require('node:crypto');
const { readFileSync } = require('node:fs');
const assert = require('node:assert');
assert.ok(verifier);
})
.add(`[Managed] crypto.verify('RSA-SHA256')`, (timer) => {
const crypto = require("node:crypto");
const { readFileSync } = require("node:fs");
const assert = require("node:assert");

const rsaPrivateKey = readFileSync(`${__dirname}/private-key.pem`, 'utf-8');
const rsaPublicKey = readFileSync(`${__dirname}/public-key.pem`, 'utf-8');
const rsaPrivateKey = readFileSync(`${__dirname}/private-key.pem`, "utf-8");
const rsaPublicKey = readFileSync(`${__dirname}/public-key.pem`, "utf-8");

const thing = 'hello world'
const signature = crypto.createSign('RSA-SHA256').update(thing).sign(rsaPrivateKey, 'base64')
const thing = "hello world";
const signature = crypto
.createSign("RSA-SHA256")
.update(thing)
.sign(rsaPrivateKey, "base64");

let r;
let r;

timer.start();
for (let i = 0; i < timer.count; i++) {
r = crypto.verify('RSA-SHA256', thing, rsaPublicKey, Buffer.from(signature, 'base64'));
}
timer.end(timer.count);
timer.start();
for (let i = 0; i < timer.count; i++) {
r = crypto.verify(
"RSA-SHA256",
thing,
rsaPublicKey,
Buffer.from(signature, "base64"),
);
}
timer.end(timer.count);

assert.ok(r);
})
.run();
assert.ok(r);
})
.run();
22 changes: 11 additions & 11 deletions examples/deleting-properties/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,52 +7,52 @@ NullObject.prototype = Object.create(null);
%NeverOptimizeFunction(NullObject);

suite
.add('Using delete property', function () {
.add('Using delete property', () => {
const data = { x: 1, y: 2, z: 3 }
delete data.y
data.y = undefined

data.x
data.y
data.z
})
.add('Using delete property (proto: null)', function () {
.add('Using delete property (proto: null)', () => {
const data = { __proto__: null, x: 1, y: 2, z: 3 }
delete data.y
data.y = undefined

data.x
data.y
data.z
})
.add('Using delete property (cached proto: null)', function () {
.add('Using delete property (cached proto: null)', () => {
const data = new NullObject()

data.x = 1
data.y = 2
data.z = 3

delete data.y
data.y = undefined

data.x
data.y
data.z
})
.add('Using undefined assignment', function () {
.add('Using undefined assignment', () => {
const data = { x: 1, y: 2, z: 3 }
data.y = undefined

data.x
data.y
data.z
})
.add('Using undefined assignment (proto: null)', function () {
.add('Using undefined assignment (proto: null)', () => {
const data = { __proto__: null, x: 1, y: 2, z: 3 }
data.y = undefined

data.x
data.y
data.z
})
.add('Using undefined property (cached proto: null)', function () {
.add('Using undefined property (cached proto: null)', () => {
const data = new NullObject()

data.x = 1
Expand All @@ -65,8 +65,8 @@ suite
data.y
data.z
})
.add('[Managed] Using undefined property (cached proto: null)', function (t) {
const NullObject = function () { }
.add('[Managed] Using undefined property (cached proto: null)', (t) => {
const NullObject = () => { }
NullObject.prototype = Object.create(null)

t.start();
Expand Down
8 changes: 4 additions & 4 deletions examples/empty/node.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const { Suite } = require('../../lib');
const { Suite } = require("../../lib");

const suite = new Suite();

suite
.add(`empty`, function () {})
.add(`empty async`, async function () {})
.run();
.add("empty", () => {})
.add("empty async", async () => {})
.run();
86 changes: 43 additions & 43 deletions examples/fs-read-async/node.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
const { Suite } = require('../../lib');
const { readFile } = require('node:fs/promises');
const { resolve } = require('node:path');
const { Suite } = require("../../lib");
const { readFile } = require("node:fs/promises");
const { resolve } = require("node:path");

const suite = new Suite();

const sampleFile = resolve(__dirname, 'sample-file.txt');
const sampleFile = resolve(__dirname, "sample-file.txt");

suite
.add('readFile', async function () {
const r = await readFile(sampleFile);
})
.add('readFile utf-8', async function () {
const r = await readFile(sampleFile, 'utf-8');
})
.add('[managed] readFile', async function (timer) {
const { readFile } = require('node:fs/promises');
const { resolve } = require('node:path');
const assert = require('node:assert');

const sampleFile = resolve(__dirname, 'sample-file.txt');
let r;

timer.start();
for (let i = 0; i < timer.count; i++) {
r = await readFile(sampleFile);
}
timer.end(timer.count);

assert.ok(r);
})
.add('[managed] readFile utf-8', async function (timer) {
const { readFile } = require('node:fs/promises');
const { resolve } = require('node:path');
const assert = require('node:assert');

const sampleFile = resolve(__dirname, 'sample-file.txt');
let r;

timer.start();
for (let i = 0; i < timer.count; i++) {
r = await readFile(sampleFile, 'utf-8');
}
timer.end(timer.count);

assert.ok(r);
})
.run();
.add("readFile", async () => {
const r = await readFile(sampleFile);
})
.add("readFile utf-8", async () => {
const r = await readFile(sampleFile, "utf-8");
})
.add("[managed] readFile", async (timer) => {
const { readFile } = require("node:fs/promises");
const { resolve } = require("node:path");
const assert = require("node:assert");

const sampleFile = resolve(__dirname, "sample-file.txt");
let r;

timer.start();
for (let i = 0; i < timer.count; i++) {
r = await readFile(sampleFile);
}
timer.end(timer.count);

assert.ok(r);
})
.add("[managed] readFile utf-8", async (timer) => {
const { readFile } = require("node:fs/promises");
const { resolve } = require("node:path");
const assert = require("node:assert");

const sampleFile = resolve(__dirname, "sample-file.txt");
let r;

timer.start();
for (let i = 0; i < timer.count; i++) {
r = await readFile(sampleFile, "utf-8");
}
timer.end(timer.count);

assert.ok(r);
})
.run();
Loading

0 comments on commit 7870e91

Please sign in to comment.