Skip to content

Commit

Permalink
chore: biome
Browse files Browse the repository at this point in the history
  • Loading branch information
hugomrdias committed May 8, 2024
1 parent 522ea80 commit 746f683
Show file tree
Hide file tree
Showing 82 changed files with 3,271 additions and 5,073 deletions.
48 changes: 48 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "js",
//https://containers.dev/templates or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/typescript-node",
// https://containers.dev/features
"features": {
"ghcr.io/devcontainers/features/github-cli:1": {
"installDirectlyFromGitHubRelease": true,
"version": "latest"
},
"ghcr.io/devcontainers/features/node:1": {
"nodeGypDependencies": true,
"version": "lts"
}
},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "pnpm install",

"customizations": {
"codespaces": {
"openFiles": ["readme.md"]
},
"vscode": {
"extensions": [
"biomejs.biome",
"github.vscode-pull-request-github",
"yoavbls.pretty-ts-errors"
],
"settings": {
"editor.defaultFormatter": "biomejs.biome",
"editor.codeActionsOnSave": {
"quickfix.biome": "explicit",
"source.organizeImports.biome": "explicit"
},
"editor.formatOnSave": true,
"javascript.format.enable": false,
"javascript.preferences.importModuleSpecifierEnding": "js",
"typescript.format.enable": false,
"typescript.preferences.importModuleSpecifierEnding": "auto",
"typescript.enablePromptUseWorkspaceTsdk": true
}
}
}
}
3 changes: 2 additions & 1 deletion .github/release-please-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"packages/iso-passkeys": {},
"packages/iso-web": {},
"packages/iso-kv": {},
"packages/iso-websocket": {}
"packages/iso-websocket": {},
"packages/iso-config": {}
}
}
3 changes: 2 additions & 1 deletion .github/release-please-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"packages/iso-signatures": "0.3.2",
"packages/iso-web": "1.0.5",
"packages/iso-kv": "3.0.2",
"packages/iso-websocket": "0.2.0"
"packages/iso-websocket": "0.2.0",
"packages/iso-config": "0.0.1"
}
3 changes: 2 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ jobs:
contains(fromJson(needs.release.outputs.paths_released), 'packages/iso-signatures') ||
contains(fromJson(needs.release.outputs.paths_released), 'packages/iso-web') ||
contains(fromJson(needs.release.outputs.paths_released), 'packages/iso-kv') ||
contains(fromJson(needs.release.outputs.paths_released), 'packages/iso-websocket')
contains(fromJson(needs.release.outputs.paths_released), 'packages/iso-websocket') ||
contains(fromJson(needs.release.outputs.paths_released), 'packages/iso-config')
runs-on: ubuntu-latest
permissions:
contents: read
Expand Down
3 changes: 1 addition & 2 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"recommendations": [
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"biomejs.biome",
"github.vscode-pull-request-github",
"yoavbls.pretty-ts-errors"
]
Expand Down
22 changes: 4 additions & 18 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,10 @@
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.defaultFormatter": "biomejs.biome",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit",
"source.organizeImports": "never"
"quickfix.biome": "explicit",
"source.organizeImports.biome": "explicit"
},
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact",
"html",
"nunjucks",
"json",
"jsonc",
"json5",
"markdown",
"yaml",
"github-actions-workflow"
],
"editor.formatOnSave": true,
"javascript.format.enable": false,
"javascript.preferences.importModuleSpecifierEnding": "js",
"typescript.format.enable": false,
Expand Down
3 changes: 3 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["iso-config/biome"]
}
30 changes: 9 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@
"name": "iso-repo",
"version": "0.0.0",
"private": true,
"workspaces": [
"packages/*"
],
"packageManager": "[email protected]",
"workspaces": ["packages/*"],
"packageManager": "[email protected]",
"engines": {
"node": ">=18"
"node": ">=20"
},
"scripts": {
"format": "prettier --write '**/*.{js,ts,yml,json}' --ignore-path .gitignore",
"format:check": "prettier --check '**/*.{js,ts,yml,json}' --ignore-path .gitignore",
"format": "biome check --apply --no-errors-on-unmatched --files-ignore-unknown=true .",
"clean": "rm -rf docs node_modules pnpm-lock.yaml packages/*/{pnpm-lock.yaml,coverage,.nyc_output,dist,node_modules,.next}",
"lint": "pnpm -r --if-present run lint",
"test": "pnpm -r --if-present run test",
Expand All @@ -22,28 +19,19 @@
},
"devDependencies": {
"depcheck": "^1.4.7",
"hd-scripts": "^9.1.0",
"iso-config": "workspace:^",
"lint-staged": "^15.2.2",
"prettier": "3.2.5",
"simple-git-hooks": "^2.11.0",
"typedoc": "^0.25.12",
"typedoc-plugin-missing-exports": "^2.2.0",
"typescript": "5.3.3"
"typescript": "5.4.5",
"@biomejs/biome": "1.7.3"
},
"simple-git-hooks": {
"pre-commit": "npx lint-staged"
},
"lint-staged": {
"*.{js,ts,yml,json}": "prettier --write",
"*": "eslint --fix"
},
"eslintConfig": {
"extends": [
"./node_modules/hd-scripts/eslint/index.js"
],
"ignorePatterns": [
"docs"
]
},
"prettier": "hd-scripts/prettier.config.js"
"*": "biome check --no-errors-on-unmatched --files-ignore-unknown=true"
}
}
3 changes: 3 additions & 0 deletions packages/iso-base/bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,15 @@ const buffers = {
const main = () =>
bench.run(async () => {
for (const [k, libs] of Object.entries(codecs)) {
// biome-ignore lint/suspicious/noConsoleLog: <explanation>
console.log(`==== ${k} ====`)
for (const [size, [samples, buf]] of Object.entries(buffers)) {
// encode
for (const [lib, fn] of Object.entries(libs.encode))
await bench.mark(`${k} (encode) ${size} ${lib}`, samples, () =>
fn(buf)
)
// biome-ignore lint/suspicious/noConsoleLog: <explanation>
console.log()

// decode
Expand All @@ -69,6 +71,7 @@ const main = () =>
await bench.mark(`${k} (decode) ${size} ${lib}`, samples, () =>
fn(str)
)
// biome-ignore lint/suspicious/noConsoleLog: <explanation>
console.log()
}
}
Expand Down
63 changes: 13 additions & 50 deletions packages/iso-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,39 +69,19 @@
},
"typesVersions": {
"*": {
"utils": [
"dist/src/utils"
],
"crypto": [
"dist/src/crypto"
],
"utf8": [
"dist/src/utf8"
],
"rfc4648": [
"dist/src/rfc4648"
],
"base-x": [
"dist/src/base-x"
],
"varint": [
"dist/src/varint"
],
"ec-compression": [
"dist/src/ec-compression"
],
"leb128": [
"dist/src/leb128"
]
"utils": ["dist/src/utils"],
"crypto": ["dist/src/crypto"],
"utf8": ["dist/src/utf8"],
"rfc4648": ["dist/src/rfc4648"],
"base-x": ["dist/src/base-x"],
"varint": ["dist/src/varint"],
"ec-compression": ["dist/src/ec-compression"],
"leb128": ["dist/src/leb128"]
}
},
"files": [
"src",
"dist/src/*.d.ts",
"dist/src/*.d.ts.map"
],
"files": ["src", "dist/src/*.d.ts", "dist/src/*.d.ts.map"],
"scripts": {
"lint": "tsc --build && eslint . && prettier --check '**/*.{js,ts,yml,json}' --ignore-path ../../.gitignore",
"lint": "tsc --build && biome check --no-errors-on-unmatched --files-ignore-unknown=true .",
"test": "tsc --build && pnpm run test:node && pnpm run test:browser",
"test:node": "mocha 'test/**/!(*.browser).test.js'",
"test:browser": "playwright-test 'test/**/!(*.node).test.js'"
Expand All @@ -119,30 +99,13 @@
"micro-bmark": "^0.3.1",
"mocha": "^10.3.0",
"playwright-test": "^14.1.1",
"typescript": "5.3.3"
"typescript": "5.4.5"
},
"publishConfig": {
"provenance": true
},
"eslintConfig": {
"extends": [
"../../node_modules/hd-scripts/eslint/index.js"
],
"env": {
"mocha": true
},
"ignorePatterns": [
"dist"
]
},
"depcheck": {
"specials": [
"bin"
],
"ignores": [
"@types/*",
"hd-scripts",
"assert"
]
"specials": ["bin"],
"ignores": ["@types/*", "assert"]
}
}
2 changes: 1 addition & 1 deletion packages/iso-base/src/base-x.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const bases = {
export function baseX(base) {
const alphabet = bases[base]
return {
encode(input, pad) {
encode(input, _pad) {
if (typeof input === 'string') {
input = utf8.decode(input)
}
Expand Down
3 changes: 1 addition & 2 deletions packages/iso-base/src/crypto-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export const webcrypto = globalThis.crypto
export function randomBytes(length = 32) {
if (globalThis.crypto) {
return globalThis.crypto.getRandomValues(new Uint8Array(length))
} else {
throw new Error("The environment doesn't have randomBytes function")
}
throw new Error("The environment doesn't have randomBytes function")
}
3 changes: 1 addition & 2 deletions packages/iso-base/src/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export const webcrypto = /** @type {Crypto} */ (crypto.webcrypto)
export function randomBytes(length = 32) {
if (crypto.webcrypto) {
return crypto.webcrypto.getRandomValues(new Uint8Array(length))
} else {
throw new Error("The environment doesn't have randomBytes function")
}
throw new Error("The environment doesn't have randomBytes function")
}
4 changes: 3 additions & 1 deletion packages/iso-base/src/ec-compression.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ const curveToPointLength = {
* @param {Curve} curve
*/
export function getConstantsForCurve(curve) {
let prime, b, pIdent
let prime
let b
let pIdent
const two = BigInt(2)

switch (curve) {
Expand Down
4 changes: 3 additions & 1 deletion packages/iso-base/src/rfc4648.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const decode = (string, alphabet, bitsPerChar) => {
// Read one character from the string:
const value = codes[string[i]]
if (value === undefined) {
throw new SyntaxError('Invalid character ' + string[i])
throw new SyntaxError(`Invalid character ${string[i]}`)
}

// Append the bits to the buffer:
Expand Down Expand Up @@ -133,6 +133,8 @@ const bases = {
* @param {((str: string) => string)} [normalize] - Normalize
* @returns {Codec} - Codec
*/

// biome-ignore lint/style/useDefaultParameterLast: <explanation>
export function rfc4648(base, padding = false, normalize) {
const [bits, alphabet] = bases[base]
return {
Expand Down
4 changes: 3 additions & 1 deletion packages/iso-base/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ export function concat(arrays, length) {
* @param {Uint8Array} bb
*/
export function equals(aa, bb) {
if (aa === bb) return true
if (aa === bb) {
return true
}
if (aa.byteLength !== bb.byteLength) {
return false
}
Expand Down
Loading

0 comments on commit 746f683

Please sign in to comment.