Skip to content

Commit

Permalink
lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
xlc committed Jan 12, 2025
1 parent 95a5ba9 commit 91ea7b7
Show file tree
Hide file tree
Showing 138 changed files with 556 additions and 507 deletions.
36 changes: 32 additions & 4 deletions biome.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
"vcs": { "enabled": false, "clientKind": "git", "useIgnoreFile": false },
"vcs": { "enabled": true, "clientKind": "git", "useIgnoreFile": true },
"files": {
"ignoreUnknown": false,
"ignore": [
"*.json",
"*.txt",
"*.snap",
"*.wasm",
Expand All @@ -15,7 +16,8 @@
"**/executor/**",
"**/vendor/**",
"**/dist/**",
"**/node_modules/**"
"**/node_modules/**",
"packages/e2e/src/rpc-methods-test-scripts.js"
]
},
"formatter": {
Expand Down Expand Up @@ -53,7 +55,21 @@
"organizeImports": { "enabled": true },
"linter": {
"enabled": true,
"rules": { "recommended": true },
"rules": {
"recommended": true,
"suspicious": {
"noExplicitAny": "off",
"noAssignInExpressions": "off"
},
"style": {
"noUnusedTemplateLiteral": "off",
"noNonNullAssertion": "off",
"noParameterAssign": "off"
},
"complexity": {
"noForEach": "off"
}
},
"ignore": [
"**/.eslintrc.js",
"**/node_modules/",
Expand All @@ -80,5 +96,17 @@
"attributePosition": "auto",
"bracketSpacing": true
}
}
},
"overrides": [
{
"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
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
"packageManager": "[email protected]",
"private": true,
"type": "module",
"workspaces": ["packages/*", "executor"],
"workspaces": [
"packages/*",
"executor"
],
"scripts": {
"lint": "tsc --noEmit --project tsconfig.lint.json && biome check .",
"fix": "biome check --write .",
Expand All @@ -32,8 +35,7 @@
"node": ">=v20"
},
"lint-staged": {
"*.{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",
Expand Down
6 changes: 5 additions & 1 deletion packages/chopsticks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@
"@types/yargs": "^17.0.33",
"typescript": "^5.7.2"
},
"files": ["dist/esm/**", "dist/cjs/**", "chopsticks.cjs"],
"files": [
"dist/esm/**",
"dist/cjs/**",
"chopsticks.cjs"
],
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"exports": {
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
24 changes: 12 additions & 12 deletions packages/chopsticks/src/plugins/dry-run/dry-run-preimage.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { HexString } from '@polkadot/util/types'
import { blake2AsHex } from '@polkadot/util-crypto'
import { compactAddLength, hexToU8a } from '@polkadot/util'
import { blake2AsHex } from '@polkadot/util-crypto'
import type { HexString } from '@polkadot/util/types'

import { Block, newHeader, runTask, setStorage, taskHandler } from '@acala-network/chopsticks-core'
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 dryRunPreimage = async (argv: DryRunSchemaType) => {
const context = await setupContext(argv)

const extrinsic = argv['preimage']
const extrinsic = argv.preimage

const block = context.chain.head
const registry = await block.registry
Expand Down Expand Up @@ -103,17 +103,17 @@ export const dryRunPreimage = async (argv: DryRunSchemaType) => {

const filePath = await generateHtmlDiffPreviewFile(block, result.Call.storageDiff, hash)
console.log(`Generated preview ${filePath}`)
if (argv['open']) {
if (argv.open) {
openHtml(filePath)
}

// if dry-run preimage has extrinsic arguments then dry-run extrinsic
// this is useful to test something after preimage is applied
if (argv['extrinsic']) {
if (argv.extrinsic) {
await context.chain.newBlock()
const input = argv['address']
? { call: argv['extrinsic'] as HexString, address: argv['address'] }
: (argv['extrinsic'] 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)
if (outcome.isErr) {
throw new Error(outcome.asErr.toString())
Expand All @@ -124,10 +124,10 @@ export const dryRunPreimage = async (argv: DryRunSchemaType) => {
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)
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/chopsticks/src/plugins/dry-run/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { configSchema } from '../../schema/index.js'
import { z } from 'zod'
import { configSchema } from '../../schema/index.js'

export const dryRunSchema = z.object({
...configSchema.shape,
Expand All @@ -23,7 +23,7 @@ export const dryRunSchema = z.object({
description: 'Block hash to dry run',
})
.optional(),
['output-path']: z
'output-path': z
.string({
description: 'File path to print output',
})
Expand Down
4 changes: 2 additions & 2 deletions packages/chopsticks/src/plugins/dry-run/rpc.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { z } from 'zod'

import { Context, ResponseError } from '@acala-network/chopsticks-core'
import { type Context, ResponseError } from '@acala-network/chopsticks-core'
import { zHash, zHex } from '../../schema/index.js'
import { decodeStorageDiff } from '../../utils/decoder.js'
import { generateHtmlDiff } from '../../utils/generate-html-diff.js'
import { zHash, zHex } from '../../schema/index.js'

const zParaId = z.string().regex(/^\d+$/).transform(Number)

Expand Down
2 changes: 1 addition & 1 deletion packages/chopsticks/src/plugins/fetch-storage/cli.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from 'zod'
import _ from 'lodash'
import type { Argv } from 'yargs'
import { z } from 'zod'

import { configSchema, getYargsOptions } from '../../schema/index.js'
import { fetchStorages, logger } from '../../utils/fetch-storages.js'
Expand Down
10 changes: 5 additions & 5 deletions packages/chopsticks/src/plugins/follow-chain/cli.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Block, defaultLogger, runTask, taskHandler } from '@acala-network/chopsticks-core'
import { Header } from '@polkadot/types/interfaces'
import { HexString } from '@polkadot/util/types'
import { z } from 'zod'
import type { Header } from '@polkadot/types/interfaces'
import type { HexString } from '@polkadot/util/types'
import _ from 'lodash'
import type { Argv } from 'yargs'
import { z } from 'zod'

import { setupContext } from '../../context.js'
import { handler } from '../../rpc/index.js'
import { configSchema, getYargsOptions } from '../../schema/index.js'
import { createServer } from '../../server.js'
import { handler } from '../../rpc/index.js'
import { setupContext } from '../../context.js'

const logger = defaultLogger.child({ name: 'follow-chain' })

Expand Down
4 changes: 2 additions & 2 deletions packages/chopsticks/src/plugins/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Handlers, environment } from '@acala-network/chopsticks-core'
import { lstatSync, readFileSync, readdirSync } from 'node:fs'
import { type Handlers, environment } from '@acala-network/chopsticks-core'
import _ from 'lodash'
import type { Argv } from 'yargs'

import { defaultLogger } from '../logger.js'
import { resolve } from 'node:path'
import { defaultLogger } from '../logger.js'

const logger = defaultLogger.child({ name: 'plugin' })

Expand Down
Loading

0 comments on commit 91ea7b7

Please sign in to comment.