Skip to content

Commit

Permalink
Fix linter
Browse files Browse the repository at this point in the history
  • Loading branch information
apporc committed Nov 28, 2023
1 parent 0f5edb6 commit 5b06b6d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"commander": "^11.0.0",
"node-fetch": "^2.6.1",
"prettier": "^2.2.1",
"typescript": "^4.9.5"
"typescript": "^4.9.5",
"eslint": "^8.48.0"
},
"resolutions": {
"@wharfkit/antelope": "^1.0.0"
Expand Down
18 changes: 14 additions & 4 deletions src/commands/contract/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import * as eslint from 'eslint'
import * as fs from 'fs'
import * as prettier from 'prettier'
import * as ts from 'typescript'
import * as fs from 'fs'

import type {ABIDef} from '@wharfkit/antelope'
import {abiToBlob, ContractKit} from '@wharfkit/contract'

import {log, makeClient} from '../../utils'
import {generateContractClass} from './class'
import {generateImportStatement, getCoreImports} from './helpers'
import {generateActionNamesInterface, generateActionsNamespace} from './interfaces'
import {generateTableMap, generateTableTypesInterface} from './maps'
import {generateNamespace} from './namespace'
import {generateStructClasses} from './structs'
import {log, makeClient} from '../../utils'
import {generateActionsTypeAlias, generateRowType, generateTablesTypeAlias} from './types'

const printer = ts.createPrinter()
Expand Down Expand Up @@ -189,8 +190,9 @@ export async function generateContract(contractName, abi) {
}
}

function runPrettier(codeText: string) {
return prettier.format(codeText, {
async function runPrettier(codeText: string) {
// First prettier and then eslint fix, cause prettier result cann't pass eslint check
const prettiered = prettier.format(codeText, {
arrowParens: 'always',
bracketSpacing: false,
endOfLine: 'lf',
Expand All @@ -201,6 +203,14 @@ function runPrettier(codeText: string) {
trailingComma: 'es5',
parser: 'typescript',
})

const linter = new eslint.ESLint({useEslintrc: true, fix: true})
const results = await linter.lintText(prettiered)
if (results.length != 0) {
return results[0].output
} else {
return prettiered
}
}

function cleanupImports(imports: string[]) {
Expand Down
2 changes: 1 addition & 1 deletion test/data/contracts/mock-eosio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ import {
UInt32,
UInt64,
UInt8,
VarUInt,
Variant,
VarUInt,
} from '@wharfkit/antelope'
import type {ActionOptions, ContractArgs, PartialBy, Table} from '@wharfkit/contract'
import {Contract as BaseContract} from '@wharfkit/contract'
Expand Down

0 comments on commit 5b06b6d

Please sign in to comment.