From dc0f919074ea2b290efde14048b96206e5bdf30b Mon Sep 17 00:00:00 2001 From: Kevin Brown Date: Mon, 10 Aug 2020 13:15:58 +1000 Subject: [PATCH] Bump prettier dependency, reformat code to match new default style. --- package-lock.json | 25 +++++++++++++-------- package.json | 4 ++-- src/accounts/utils.ts | 2 +- src/cli/lamington-build.ts | 2 +- src/cli/lamington-init.ts | 2 +- src/cli/lamington-start.ts | 2 +- src/cli/lamington-stop.ts | 2 +- src/cli/lamington-test.ts | 2 +- src/cli/utils.ts | 10 ++++----- src/contracts/contract.ts | 10 ++++----- src/contracts/typeGenerator.test.ts | 34 ++++++++++++++--------------- src/contracts/typeGenerator.ts | 7 +++--- src/contracts/utils.ts | 4 ++-- src/eosManager.ts | 4 ++-- src/utils.ts | 8 +++---- 15 files changed, 63 insertions(+), 55 deletions(-) diff --git a/package-lock.json b/package-lock.json index cb0d248..2225886 100644 --- a/package-lock.json +++ b/package-lock.json @@ -64,6 +64,7 @@ "version": "2.2.0", "resolved": "https://registry.npmjs.org/@types/chalk/-/chalk-2.2.0.tgz", "integrity": "sha512-1zzPV9FDe1I/WHhRkf9SNgqtRJWZqrBWgu7JGveuHmmyR9CnAPCie2N/x+iHrgnpYBIcCJWHBoMRv2TRWktsvw==", + "dev": true, "requires": { "chalk": "*" } @@ -136,9 +137,9 @@ "dev": true }, "@types/ncp": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/@types/ncp/-/ncp-2.0.3.tgz", - "integrity": "sha512-eZatZMWhPHUHY/1hUUqwGrWzBAE9deYR3L0QJMicpVkBUOrQslhWblw5Ye+rKuzvFG/UQ3jDolMcjhC2WKUQ5w==", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/@types/ncp/-/ncp-2.0.1.tgz", + "integrity": "sha512-TeiJ7uvv/92ugSqZ0v9l0eNXzutlki0aK+R1K5bfA5SYUil46ITlxLW4iNTCf55P4L5weCmaOdtxGeGWvudwPg==", "dev": true, "requires": { "@types/node": "*" @@ -1568,9 +1569,9 @@ "integrity": "sha1-uULm1L3mUwBe9rcTYd74cn0GReA=" }, "prettier": { - "version": "1.19.1", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.19.1.tgz", - "integrity": "sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==", + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.0.5.tgz", + "integrity": "sha512-7PtVymN48hGcO4fGjybyBSIWDsLU4H4XlvOHfq91pz9kkGlonzwTfYkaIEwiRg/dAJF9YlbsduBAgtYLi+8cFg==", "dev": true }, "progress": { @@ -1971,6 +1972,12 @@ "source-map": "^0.6.1", "uglify-js": "^3.1.4" } + }, + "typescript": { + "version": "3.7.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.7.5.tgz", + "integrity": "sha512-/P5lkRXkWHNAbcJIiHPfRoKqyd7bsyCma1hZNUGfn20qm64T6ZBlrzprymeu918H+mB/0rIg2gGK/BXkhhYgBw==", + "dev": true } } }, @@ -1987,9 +1994,9 @@ } }, "typescript": { - "version": "3.7.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.7.5.tgz", - "integrity": "sha512-/P5lkRXkWHNAbcJIiHPfRoKqyd7bsyCma1hZNUGfn20qm64T6ZBlrzprymeu918H+mB/0rIg2gGK/BXkhhYgBw==", + "version": "3.9.7", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.7.tgz", + "integrity": "sha512-BLbiRkiBzAwsjut4x/dsibSTB6yWpwT5qWmC2OfuCg3GgVQCSgMs4vEctYPhsaGtd0AeuuHMkjZ2h2WG8MSzRw==", "dev": true }, "uglify-js": { diff --git a/package.json b/package.json index 24937d1..9c51177 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "copy:configs": "cp -R ./src/eosio-config ./lib/eosio-config", "clean": "rm -rf ./lib", "docs": "typedoc --out api-docs ./src", - "format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"", + "format": "prettier --write \"src/**/*.ts\"", "lamington:init": "lamington init", "prepublishOnly": "npm test", "prepare": "npm run build", @@ -62,7 +62,7 @@ "auto-changelog": "1.16.2", "eosjs": "20.0.3", "eosjs-ecc": "4.0.7", - "prettier": "1.19.1", + "prettier": "2.0.5", "ts-node": "8.6.2", "typedoc": "0.16.10", "typescript": "3.9.7" diff --git a/src/accounts/utils.ts b/src/accounts/utils.ts index 3885bb1..dcc218d 100644 --- a/src/accounts/utils.ts +++ b/src/accounts/utils.ts @@ -28,7 +28,7 @@ export const accountNameFromPublicKey = (publicKey: string) => hashToEOSName(ecc export const hashToEOSName = (data: string) => `l${data .substring(0, 11) - .replace(digitPattern, match => digitMapping[match]) + .replace(digitPattern, (match) => digitMapping[match]) .toLowerCase()}`; export type EosioAction = { diff --git a/src/cli/lamington-build.ts b/src/cli/lamington-build.ts index de8315c..6ac8683 100644 --- a/src/cli/lamington-build.ts +++ b/src/cli/lamington-build.ts @@ -25,7 +25,7 @@ const run = async () => { } }; -run().catch(async error => { +run().catch(async (error) => { process.exitCode = 1; console.log(error); diff --git a/src/cli/lamington-init.ts b/src/cli/lamington-init.ts index 345a2f9..80ed6ae 100644 --- a/src/cli/lamington-init.ts +++ b/src/cli/lamington-init.ts @@ -26,7 +26,7 @@ const run = async () => { ); }; -run().catch(error => { +run().catch((error) => { process.exitCode = 1; console.log(error); }); diff --git a/src/cli/lamington-start.ts b/src/cli/lamington-start.ts index 516a8ef..f05e555 100644 --- a/src/cli/lamington-start.ts +++ b/src/cli/lamington-start.ts @@ -16,7 +16,7 @@ const run = async () => { await startEos(); }; -run().catch(error => { +run().catch((error) => { process.exitCode = 1; console.log(error); }); diff --git a/src/cli/lamington-stop.ts b/src/cli/lamington-stop.ts index 34305cf..a75ec95 100644 --- a/src/cli/lamington-stop.ts +++ b/src/cli/lamington-stop.ts @@ -17,7 +17,7 @@ const run = async () => { await stopContainer(); }; -run().catch(error => { +run().catch((error) => { process.exitCode = 1; console.log(error); }); diff --git a/src/cli/lamington-test.ts b/src/cli/lamington-test.ts index f25d29a..bf35ae0 100644 --- a/src/cli/lamington-test.ts +++ b/src/cli/lamington-test.ts @@ -37,7 +37,7 @@ const run = async () => { } }; -run().catch(async error => { +run().catch(async (error) => { process.exitCode = 1; console.log(error); diff --git a/src/cli/utils.ts b/src/cli/utils.ts index 773a689..aa48c36 100644 --- a/src/cli/utils.ts +++ b/src/cli/utils.ts @@ -298,7 +298,7 @@ export const runTests = async () => { // Run the tests. await new Promise((resolve, reject) => - mocha.run(failures => { + mocha.run((failures) => { if (failures) return reject(failures); return resolve(); }) @@ -350,7 +350,7 @@ export const buildAll = async (match?: string[]) => { }; const onlyMatches = (paths: string[], matches: string[] = []) => { - return paths.filter(filePath => { + return paths.filter((filePath) => { return matches.reduce((result, str) => { const pattern = new RegExp(str, 'gi'); return result || pattern.test(filePath); @@ -359,7 +359,7 @@ const onlyMatches = (paths: string[], matches: string[] = []) => { }; const includeMatches = (paths: string[]) => { - return paths.filter(filePath => { + return paths.filter((filePath) => { return ConfigManager.include.reduce((result, match) => { const pattern = new RegExp(match, 'gi'); return result || pattern.test(filePath); @@ -368,7 +368,7 @@ const includeMatches = (paths: string[]) => { }; const filterMatches = (paths: string[]) => { - return paths.filter(filePath => { + return paths.filter((filePath) => { return !ConfigManager.exclude.reduce((result, match) => { const pattern = new RegExp(match, 'gi'); return result || pattern.test(filePath); @@ -462,7 +462,7 @@ export const compileContract = async (contractPath: string) => { contractPath )}" "${outputPath}" "${basename}" ${buildFlags}` ) - .catch(err => { + .catch((err) => { spinner.fail('Failed to compile'); console.log(` --> ${err}`); throw err; diff --git a/src/contracts/contract.ts b/src/contracts/contract.ts index 332848f..1c91d6a 100644 --- a/src/contracts/contract.ts +++ b/src/contracts/contract.ts @@ -87,7 +87,7 @@ export class Contract implements EOSJSContract { this.types = types; // Set up all the actions as methods on the contract. for (const action of actions.values()) { - (this as any)[action.name] = function() { + (this as any)[action.name] = function () { const data: { [key: string]: any } = {}; // Copy the params across for the call. @@ -141,7 +141,7 @@ export class Contract implements EOSJSContract { } // And now the tables. for (const table of abi.tables) { - (this as any)[camelCase(table.name) + 'Table'] = function() { + (this as any)[camelCase(table.name) + 'Table'] = function () { return this.getTableRows(table.name, arguments[0]); }; } @@ -182,14 +182,14 @@ export class Contract implements EOSJSContract { // This mapping will always be limited to just the types we do special // things with in Lamington world, and will always match the generated // types for table rows. Other values will pass through untouched. - const tableAbi = this._abi.tables.find(tableAbi => tableAbi.name === table); + const tableAbi = this._abi.tables.find((tableAbi) => tableAbi.name === table); if (!tableAbi) throw new Error(`Could not find ABI for table ${table}`); const tableRowType = this.types.get(tableAbi.type); if (!tableRowType) throw new Error(`Could not find table row type for table ${table}`); // Bool is the only type we need to fiddle with at the moment, so only do this if // there's a field with a bool type in it. - const booleanFields = tableRowType.fields.filter(field => field.typeName === 'bool'); + const booleanFields = tableRowType.fields.filter((field) => field.typeName === 'bool'); if (booleanFields.length > 0) { // Map all `bool` fields from numbers to booleans @@ -208,7 +208,7 @@ export class Contract implements EOSJSContract { } } - const dateFields = tableRowType.fields.filter(field => field.typeName === 'time_point_sec'); + const dateFields = tableRowType.fields.filter((field) => field.typeName === 'time_point_sec'); if (dateFields.length > 0) { // Map all `time_point_sec` fields from numbers to Date diff --git a/src/contracts/typeGenerator.test.ts b/src/contracts/typeGenerator.test.ts index 5504440..e561f49 100644 --- a/src/contracts/typeGenerator.test.ts +++ b/src/contracts/typeGenerator.test.ts @@ -40,9 +40,9 @@ const stringNumberTypes = [ 'table_name', ]; -describe('type generator', function() { - context('map parameter types', function() { - it(`should map 'string' to 'string'`, function() { +describe('type generator', function () { + context('map parameter types', function () { + it(`should map 'string' to 'string'`, function () { assert.equal( mapParameterType({ eosType: 'string' }), 'string', @@ -50,13 +50,13 @@ describe('type generator', function() { ); }); - it(`should map 'bool' to 'boolean'`, function() { + it(`should map 'bool' to 'boolean'`, function () { assert.equal(mapParameterType({ eosType: 'bool' }), 'boolean'); }); - context('eos types', function() { - it(`should map name types to 'string|number'`, function() { - stringNumberTypes.map(eosType => + context('eos types', function () { + it(`should map name types to 'string|number'`, function () { + stringNumberTypes.map((eosType) => assert.equal( mapParameterType({ eosType }), 'string|number', @@ -65,7 +65,7 @@ describe('type generator', function() { ); }); - it(`should map 'checksum' to 'string'`, function() { + it(`should map 'checksum' to 'string'`, function () { assert.equal( mapParameterType({ eosType: 'checksum' }), 'string', @@ -74,9 +74,9 @@ describe('type generator', function() { }); }); - context('big numbers', function() { - numberTypes.forEach(eosType => { - it(`should map '${eosType}' to 'number'`, function() { + context('big numbers', function () { + numberTypes.forEach((eosType) => { + it(`should map '${eosType}' to 'number'`, function () { assert.equal( mapParameterType({ eosType }), 'number', @@ -86,12 +86,12 @@ describe('type generator', function() { }); }); - context('complex types', function() { - it(`should handle array types`, function() { + context('complex types', function () { + it(`should handle array types`, function () { assert.equal(mapParameterType({ eosType: 'bool[]' }), 'Array'); }); - it(`should handle custom types from the contract`, function() { + it(`should handle custom types from the contract`, function () { assert.equal( mapParameterType({ eosType: 'pair_uint8_string', @@ -102,7 +102,7 @@ describe('type generator', function() { ); }); - it(`should handle custom types in containers`, function() { + it(`should handle custom types in containers`, function () { assert.equal( mapParameterType({ eosType: 'pair_uint8_string[]', @@ -302,8 +302,8 @@ describe('type generator', function() { }); }); - context('type generation integration tests', function() { - before(async function() { + context('type generation integration tests', function () { + before(async function () { // This can take a long time. this.timeout(400000); diff --git a/src/contracts/typeGenerator.ts b/src/contracts/typeGenerator.ts index 6415de0..18eda79 100644 --- a/src/contracts/typeGenerator.ts +++ b/src/contracts/typeGenerator.ts @@ -111,8 +111,9 @@ export const generateTypesFromString = async ( // Generate tables const generatedTables = contractTables.map( (table: any) => - `${camelCase(table.name) + - 'Table'}(options?: GetTableRowsOptions): Promise>;` ); @@ -215,7 +216,7 @@ const saveInterface = async (contractIdentifier: string, interfaceContent: strin // Open a write stream to file const file = fs.createWriteStream(`${contractIdentifier}.ts`); - file.write(interfaceContent, error => { + file.write(interfaceContent, (error) => { if (error) { throw error; } diff --git a/src/contracts/utils.ts b/src/contracts/utils.ts index 1b3ecac..16ce712 100644 --- a/src/contracts/utils.ts +++ b/src/contracts/utils.ts @@ -7,7 +7,7 @@ export const pascalCase = (value: string) => { const snakePattern = /[_.]+./g; const upperFirst = value[0].toUpperCase() + value.slice(1); - return upperFirst.replace(snakePattern, match => match[match.length - 1].toUpperCase()); + return upperFirst.replace(snakePattern, (match) => match[match.length - 1].toUpperCase()); }; /** @@ -18,5 +18,5 @@ export const pascalCase = (value: string) => { */ export const camelCase = (value: string) => { const snakePattern = /[_.]+./g; - return value.replace(snakePattern, match => match[match.length - 1].toUpperCase()); + return value.replace(snakePattern, (match) => match[match.length - 1].toUpperCase()); }; diff --git a/src/eosManager.ts b/src/eosManager.ts index 2e0af3e..b39b873 100644 --- a/src/eosManager.ts +++ b/src/eosManager.ts @@ -126,11 +126,11 @@ export class EOSManager { return await eos .transact(transaction, flattenedOptions) - .then(value => { + .then((value) => { logOutput(chalk.green('Succeeded: ') + JSON.stringify(value, null, 4)); return value; }) - .catch(error => { + .catch((error) => { logOutput( chalk.red('Threw error: ') + error + diff --git a/src/utils.ts b/src/utils.ts index 39999c5..2a39310 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -33,7 +33,7 @@ export const untilBlocknumber = async (number: number) => { * @param delayInMs Process sleep duration */ export const sleep = async (delayInMs: number) => - new Promise(resolve => setTimeout(resolve, delayInMs)); + new Promise((resolve) => setTimeout(resolve, delayInMs)); /** * Pauses the current process for the 500ms EOS block time @@ -206,7 +206,7 @@ export const assertEOSErrorIncludesMessage = async ( const eosErrorName = errorName || 'eosio_assert_message_exception'; // Execute operation and handle exceptions if ( - !(await assertExpectedEOSError(operation, eosErrorName, error => { + !(await assertExpectedEOSError(operation, eosErrorName, (error) => { let errorMessage = error.json.error.details[0].message; if (!errorMessage) { @@ -256,7 +256,7 @@ export async function debugPromise( : debugPrefix + 'error - ' + successMessage + ': '; const promiseTimer = timer(); return promise - .then(value => { + .then((value) => { if (ConfigManager.debugLevelVerbose || ConfigManager.debugLevelMin) { console.log(chalk.green(successString) + chalk.blue(' (%s)'), promiseTimer.ms); } @@ -265,7 +265,7 @@ export async function debugPromise( } return value; }) - .catch(err => { + .catch((err) => { assert.fail(errorString + err); }); }