Skip to content
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

biomejs install #875

Merged
merged 6 commits into from
Jan 12, 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
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
root = true
[*]
indent_style=tab
indent_size=tab
indent_size=2
tab_width=4
end_of_line=lf
charset=utf-8
Expand Down
11 changes: 0 additions & 11 deletions .eslintignore

This file was deleted.

33 changes: 0 additions & 33 deletions .eslintrc

This file was deleted.

112 changes: 112 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
"vcs": { "enabled": true, "clientKind": "git", "useIgnoreFile": true },
"files": {
"ignoreUnknown": false,
"ignore": [
"*.json",
"*.txt",
"*.snap",
"*.wasm",
"*.html",
"*.md",
"*.gitignore",
"*.yml",
"*.tsbuildinfo",
"**/executor/**",
"**/vendor/**",
"**/dist/**",
"**/node_modules/**",
"packages/e2e/src/rpc-methods-test-scripts.js"
]
},
"formatter": {
"enabled": true,
"useEditorconfig": true,
"formatWithErrors": false,
"indentStyle": "tab",
"indentWidth": 2,
"lineEnding": "lf",
"lineWidth": 120,
"attributePosition": "auto",
"bracketSpacing": true,
"ignore": [
"**/tsconfig.tsbuildinfo",
"**/.gitignore",
"**/.yarn",
"**/*.yml",
"**/*.md",
"**/executor/**",
"**/vendor/**",
"**/.pnp.cjs",
"**/.pnp.loader.mjs",
"**/lib/**",
"**/dist/**",
"**/node_modules/**",
"**/preview/",
"**/packages/core/scripts/",
"packages/core/src/wasm-executor/browser-wasm-executor.js",
"packages/core/src/wasm-executor/node-wasm-executor.js",
"packages/e2e/src/rpc-methods-test-scripts.js",
"packages/e2e/blobs/**",
"packages/web-test/playwright-report/**"
]
},
"organizeImports": { "enabled": true },
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"suspicious": {
"noExplicitAny": "off",
"noAssignInExpressions": "off"
},
"style": {
"noUnusedTemplateLiteral": "off",
"noNonNullAssertion": "off",
"noParameterAssign": "off"
},
"complexity": {
"noForEach": "off",
"useLiteralKeys": "off"
}
},
"ignore": [
"**/node_modules/",
"**/executor/",
"**/vendor/",
"**/lib/",
"**/dist/",
"packages/core/scripts/",
"**/chopsticks.js",
"packages/core/src/wasm-executor/browser-wasm-executor.js",
"packages/core/src/wasm-executor/node-wasm-executor.js",
"packages/web-test/playwright-report"
]
},
"javascript": {
"formatter": {
"jsxQuoteStyle": "double",
"quoteProperties": "asNeeded",
"trailingCommas": "all",
"semicolons": "asNeeded",
"arrowParentheses": "always",
"bracketSameLine": false,
"quoteStyle": "single",
"attributePosition": "auto",
"bracketSpacing": true
}
},
"overrides": [
gluneau marked this conversation as resolved.
Show resolved Hide resolved
{
"include": ["**/*.test.ts", "packages/web-test"],
"linter": {
"rules": {
"style": {
"noNonNullAssertion": "off"
}
}
}
}
]
}
4 changes: 2 additions & 2 deletions loader.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as tsConfigPaths from 'tsconfig-paths'
import { pathToFileURL } from 'url'
import { pathToFileURL } from 'node:url'
import { resolve as resolveTs } from 'ts-node/esm'
import * as tsConfigPaths from 'tsconfig-paths'

const { absoluteBaseUrl, paths } = tsConfigPaths.loadConfig()
const matchPath = tsConfigPaths.createMatchPath(absoluteBaseUrl, paths)
Expand Down
22 changes: 4 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"executor"
],
"scripts": {
"lint": "tsc --noEmit --project tsconfig.lint.json && eslint . --ext .js,.ts && prettier --check .",
"fix": "eslint . --ext .js,.ts --fix && prettier -w .",
"lint": "tsc --noEmit --project tsconfig.lint.json && biome check .",
"fix": "biome check --write .",
"prepare": "husky install",
"clean": "yarn workspaces foreach --all -pvit run clean",
"build": "yarn workspaces foreach --all -pvit --include '@acala-network/*' run build",
Expand All @@ -34,30 +34,16 @@
"engines": {
"node": ">=v20"
},
"prettier": {
"tabWidth": 2,
"semi": false,
"singleQuote": true
},
"lint-staged": {
gluneau marked this conversation as resolved.
Show resolved Hide resolved
"*.{js,ts}": "eslint --cache --fix",
"*.{js,ts,css,md}": "prettier --write"
"*.{js,ts}": "biome check --write --no-errors-on-unmatched"
},
"devDependencies": {
"@biomejs/biome": "1.9.4",
"@swc/core": "^1.10.1",
"@types/node": "^22.10.2",
"@types/prettier": "^3.0.0",
"@typescript-eslint/eslint-plugin": "^8.18.1",
"@typescript-eslint/parser": "^8.18.1",
"@vitest/coverage-v8": "^2.1.8",
"@vitest/ui": "^2.1.8",
"eslint": "^8.57.1",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-typescript": "^3.7.0",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-sort-imports-es6-autofix": "^0.6.0",
"husky": "^9.1.7",
"prettier": "^3.4.2",
"ts-node": "^10.9.2",
"typedoc": "^0.27.5",
"typedoc-plugin-markdown": "^4.3.3",
Expand Down
13 changes: 6 additions & 7 deletions packages/chopsticks/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { config as dotenvConfig } from 'dotenv'
import { hideBin } from 'yargs/helpers'
import { z } from 'zod'
import _ from 'lodash'
import yargs from 'yargs'
import type { MiddlewareFunction } from 'yargs'
import { hideBin } from 'yargs/helpers'
import { z } from 'zod'

import { Blockchain, connectParachains, connectVertical, environment } from '@acala-network/chopsticks-core'
import { configSchema, fetchConfig, getYargsOptions } from './schema/index.js'
import { loadRpcMethodsByScripts, pluginExtendCli } from './plugins/index.js'
import { type Blockchain, connectParachains, connectVertical, environment } from '@acala-network/chopsticks-core'
import { setupWithServer } from './index.js'
import { loadRpcMethodsByScripts, pluginExtendCli } from './plugins/index.js'
import { configSchema, fetchConfig, getYargsOptions } from './schema/index.js'

dotenvConfig()

Expand All @@ -26,9 +26,8 @@ const processArgv: MiddlewareFunction<{ config?: string; port?: number; unsafeRp
} catch (error) {
if (error instanceof z.ZodError) {
throw new Error('Bad argv', { cause: error.flatten().fieldErrors })
} else {
throw error
}
throw error
}
}

Expand Down
20 changes: 14 additions & 6 deletions packages/chopsticks/src/context.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
import './utils/tunnel.js'
import { BlockEntry, GenesisProvider, defaultLogger, isUrl, setup, timeTravel } from '@acala-network/chopsticks-core'
import { Config } from './schema/index.js'
import { HexString } from '@polkadot/util/types'
import {
type BlockEntry,
GenesisProvider,
defaultLogger,
isUrl,
setup,
timeTravel,
} from '@acala-network/chopsticks-core'
import { SqliteDatabase } from '@acala-network/chopsticks-db'
import type { HexString } from '@polkadot/util/types'
import axios from 'axios'
import { apiFetching } from './logger.js'
import { overrideStorage, overrideWasm } from './utils/override.js'
import type { Config } from './schema/index.js'
import { startFetchStorageWorker } from './utils/fetch-storages.js'
import axios from 'axios'
import { overrideStorage, overrideWasm } from './utils/override.js'

const logger = defaultLogger.child({ name: 'setup-context' })

export const genesisFromUrl = async (url: string) => {
const getFile = async (url: string) => {
if (isUrl(url)) {
return axios.get(url).then((x) => x.data)
} else if (typeof process === 'object') {
}
if (typeof process === 'object') {
const { lstatSync, readFileSync } = await import('node:fs')
if (lstatSync(url).isFile()) {
return JSON.parse(String(readFileSync(url)))
Expand Down
2 changes: 1 addition & 1 deletion packages/chopsticks/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import _ from 'lodash'

export { defaultLogger, truncate } from '@acala-network/chopsticks-core'

const showProgress = process.stdout.isTTY && !process.env['CI'] && !process.env['TEST']
const showProgress = process.stdout.isTTY && !process.env.CI && !process.env.TEST

export const spinnerFrames =
process.platform === 'win32' ? ['-', '\\', '|', '/'] : ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']
Expand Down
6 changes: 3 additions & 3 deletions packages/chopsticks/src/plugins/decode-key/cli.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { HexString } from '@polkadot/util/types'
import { configSchema, getYargsOptions } from '../../schema/index.js'
import { decodeKey } from '@acala-network/chopsticks-core'
import { setupContext } from '../../context.js'
import type { HexString } from '@polkadot/util/types'
import type { Argv } from 'yargs'
import { setupContext } from '../../context.js'
import { configSchema, getYargsOptions } from '../../schema/index.js'

export const cli = (y: Argv) => {
y.command(
Expand Down
6 changes: 3 additions & 3 deletions packages/chopsticks/src/plugins/dry-run/cli.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Argv } from 'yargs'
import { z } from 'zod'
import { configSchema, getYargsOptions } from '../../schema/index.js'
import { dryRunExtrinsic } from './dry-run-extrinsic.js'
import { dryRunPreimage } from './dry-run-preimage.js'
import { z } from 'zod'
import type { Argv } from 'yargs'

const schema = z.object({
...configSchema.shape,
Expand All @@ -26,7 +26,7 @@ const schema = z.object({
description: 'Block hash to dry run',
})
.optional(),
['output-path']: z
'output-path': z
.string({
description: 'File path to print output',
})
Expand Down
22 changes: 11 additions & 11 deletions packages/chopsticks/src/plugins/dry-run/dry-run-extrinsic.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { HexString } from '@polkadot/util/types'
import { blake2AsHex } from '@polkadot/util-crypto'
import { writeFileSync } from 'node:fs'
import { blake2AsHex } from '@polkadot/util-crypto'
import type { HexString } from '@polkadot/util/types'

import { DryRunSchemaType } from './index.js'
import { setupContext } from '../../context.js'
import { defaultLogger } from '../../logger.js'
import { generateHtmlDiffPreviewFile } from '../../utils/generate-html-diff.js'
import { openHtml } from '../../utils/open-html.js'
import { setupContext } from '../../context.js'
import type { DryRunSchemaType } from './index.js'

export const dryRunExtrinsic = async (argv: DryRunSchemaType) => {
const context = await setupContext(argv)
Expand All @@ -15,25 +15,25 @@ export const dryRunExtrinsic = async (argv: DryRunSchemaType) => {
throw new Error('Extrinsic is required')
}

const input = argv['address']
? { call: argv['extrinsic'] as HexString, address: argv['address'] }
: (argv['extrinsic'] as HexString)
const { outcome, storageDiff } = await context.chain.dryRunExtrinsic(input, argv['at'] as HexString)
const input = argv.address
? { call: argv.extrinsic as HexString, address: argv.address }
: (argv.extrinsic as HexString)
const { outcome, storageDiff } = await context.chain.dryRunExtrinsic(input, argv.at as HexString)

if (outcome.isErr) {
throw new Error(outcome.asErr.toString())
}

defaultLogger.info(outcome.toHuman(), 'dry_run_outcome')

if (argv['html']) {
if (argv.html) {
const filePath = await generateHtmlDiffPreviewFile(
context.chain.head,
storageDiff,
blake2AsHex(argv['extrinsic'], 256),
blake2AsHex(argv.extrinsic, 256),
)
console.log(`Generated preview ${filePath}`)
if (argv['open']) {
if (argv.open) {
openHtml(filePath)
}
} else if (argv['output-path']) {
Expand Down
Loading
Loading