From e1fe51f4d96e7f25aac331ca398cf3f71eeeecb3 Mon Sep 17 00:00:00 2001 From: dafuga Date: Fri, 25 Aug 2023 23:22:13 -0700 Subject: [PATCH] style: linted --- src/codegen.ts | 13 +++++++++++-- src/codegen/helpers.ts | 21 ++++++++++----------- src/codegen/structs.ts | 3 +-- test/tests/codegen.ts | 2 +- test/tests/helpers/generic.ts | 7 +++---- 5 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/codegen.ts b/src/codegen.ts index 990b4f4..4ddd77c 100644 --- a/src/codegen.ts +++ b/src/codegen.ts @@ -19,8 +19,17 @@ export async function codegen(contractName, abi) { '@wharfkit/contract' ) - const allAntelopeImports = ['ABI', 'Action', 'Blob', 'Struct', 'Name', ...getCoreImports(abi)] - const antelopeImports = allAntelopeImports.filter((item, index) => allAntelopeImports.indexOf(item) === index) + const allAntelopeImports = [ + 'ABI', + 'Action', + 'Blob', + 'Struct', + 'Name', + ...getCoreImports(abi), + ] + const antelopeImports = allAntelopeImports.filter( + (item, index) => allAntelopeImports.indexOf(item) === index + ) antelopeImports.sort() diff --git a/src/codegen/helpers.ts b/src/codegen/helpers.ts index d078309..87a6e18 100644 --- a/src/codegen/helpers.ts +++ b/src/codegen/helpers.ts @@ -11,9 +11,8 @@ Object.keys(Antelope).map((key) => { } }) -export const ANTELOPE_CLASS_MAPPINGS - = { - block_timestamp_type: 'BlockTimestamp' +export const ANTELOPE_CLASS_MAPPINGS = { + block_timestamp_type: 'BlockTimestamp', } export function getCoreImports(abi: ABI.Def) { @@ -119,8 +118,12 @@ export function findCoreClass(type: string): string | undefined { const parsedType = parseType(type).split('_').join('') - return ANTELOPE_CLASSES.find((antelopeClass) => parsedType === antelopeClass.toLowerCase()) || - ANTELOPE_CLASSES.find((antelopeClass) => parsedType.replace(/[0-9]/g, '') === antelopeClass.toLowerCase()) + return ( + ANTELOPE_CLASSES.find((antelopeClass) => parsedType === antelopeClass.toLowerCase()) || + ANTELOPE_CLASSES.find( + (antelopeClass) => parsedType.replace(/[0-9]/g, '') === antelopeClass.toLowerCase() + ) + ) } export function findCoreType(type: string): string | undefined { @@ -184,11 +187,7 @@ function findVariantType( return abiVariant.types.join(' | ') } -export function findAbiType( - type: string, - abi: ABI.Def, - typeNamespace = '' -): string | undefined { +export function findAbiType(type: string, abi: ABI.Def, typeNamespace = ''): string | undefined { let typeString = type const aliasType = findAliasType(typeString, abi) @@ -217,7 +216,7 @@ export function findExternalType(type: string, abi: ABI.Def, typeNamespace?: str typeString = parseType(typeString) const relevantAbitype = findAbiType(typeString, abi, typeNamespace) - + if (relevantAbitype) { typeString = relevantAbitype } diff --git a/src/codegen/structs.ts b/src/codegen/structs.ts index 4583a9b..1697b1d 100644 --- a/src/codegen/structs.ts +++ b/src/codegen/structs.ts @@ -159,7 +159,6 @@ function orderStructs(structs) { const orderedStructs: StructData[] = [] for (const struct of structs) { - orderedStructs.push(...findDependencies(struct, structs)) orderedStructs.push(struct) } @@ -196,7 +195,7 @@ function findFieldStructType( namespace: string | null, abi: ABI.Def ): ts.Identifier | ts.StringLiteral { - let fieldTypeString = findFieldStructTypeString(typeString, namespace, abi) + const fieldTypeString = findFieldStructTypeString(typeString, namespace, abi) if (['string', 'boolean', 'number'].includes(fieldTypeString)) { return ts.factory.createStringLiteral(fieldTypeString) diff --git a/test/tests/codegen.ts b/test/tests/codegen.ts index e434031..bdf7c4e 100644 --- a/test/tests/codegen.ts +++ b/test/tests/codegen.ts @@ -5,9 +5,9 @@ import fs from 'fs' import {Contract} from 'src/contract' import Eosio from '$test/data/contracts/mock-eosio' +import EosioMsig from '$test/data/contracts/mock-eosio.msig' import EosioToken from '$test/data/contracts/mock-eosio.token' import RewardsGm from '$test/data/contracts/mock-rewards.gm' -import EosioMsig from '$test/data/contracts/mock-eosio.msig' import {generateCodegenContract, removeCodegenContracts} from '$test/utils/codegen' import {runGenericContractTests} from './helpers/generic' diff --git a/test/tests/helpers/generic.ts b/test/tests/helpers/generic.ts index 6435b5a..306ce10 100644 --- a/test/tests/helpers/generic.ts +++ b/test/tests/helpers/generic.ts @@ -20,8 +20,8 @@ export function getMockParams(contract: Contract): ActionDataType { actor: 'foo', permission: 'active', }, - } - } + } + } case 'eosio.token': { return { owner: 'foo', @@ -33,7 +33,7 @@ export function getMockParams(contract: Contract): ActionDataType { account: 'foo', weight: 1, } - } + } default: { throw new Error(`getMockParams not implemented for ${contract.account}`) } @@ -44,7 +44,6 @@ export function runGenericContractTests(contract: Contract) { // suite: tableNames // contains tables assert.isArray(contract.tableNames) - console.log({ name: String(contract.account), tables: contract.tableNames }) assert.isTrue(contract.tableNames.length > 0) // suite: table