Skip to content

Commit

Permalink
style: linted
Browse files Browse the repository at this point in the history
  • Loading branch information
dafuga committed Aug 26, 2023
1 parent 97675bc commit e1fe51f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 20 deletions.
13 changes: 11 additions & 2 deletions src/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
21 changes: 10 additions & 11 deletions src/codegen/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions src/codegen/structs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ function orderStructs(structs) {
const orderedStructs: StructData[] = []

for (const struct of structs) {

orderedStructs.push(...findDependencies(struct, structs))
orderedStructs.push(struct)
}
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion test/tests/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
7 changes: 3 additions & 4 deletions test/tests/helpers/generic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export function getMockParams(contract: Contract): ActionDataType {
actor: 'foo',
permission: 'active',
},
}
}
}
}
case 'eosio.token': {
return {
owner: 'foo',
Expand All @@ -33,7 +33,7 @@ export function getMockParams(contract: Contract): ActionDataType {
account: 'foo',
weight: 1,
}
}
}
default: {
throw new Error(`getMockParams not implemented for ${contract.account}`)
}
Expand All @@ -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
Expand Down

0 comments on commit e1fe51f

Please sign in to comment.